diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index 6823e1f7..00000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,21 +0,0 @@ ---- -engines: - duplication: - enabled: true - config: - languages: - - ruby - fixme: - enabled: true - rubocop: - enabled: true - bundler-audit: - enabled: true -ratings: - paths: - - "**.rb" -exclude_paths: -- examples/ -- gemfiles/ -- spec/ -- test/ diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml new file mode 100644 index 00000000..500e990b --- /dev/null +++ b/.github/workflows/test-and-deploy.yml @@ -0,0 +1,115 @@ +name: Test and Deploy +on: + push: + branches: [ '*' ] + tags: [ '*' ] + pull_request: + branches: [ main ] + schedule: + # Run automatically at 8AM PST Monday-Friday + - cron: '0 15 * * 1-5' + workflow_dispatch: + +jobs: + test: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 20 + strategy: + matrix: + ruby: [ '2.4', '2.5', '2.6', '2.7', '3.0', '3.1', 'jruby-9.2' ] + env: + version: ${{ format('ruby:{0}', matrix.ruby) }} + DOCKER_LOGIN: ${{ secrets.DOCKER_USERNAME && secrets.DOCKER_AUTH_TOKEN }} + steps: + - name: Revise env version if necessary + run: echo "version=jruby:9.2" >> $GITHUB_ENV + if: ${{ matrix.ruby == 'jruby-9.2' }} + + - name: Checkout sendgrid-ruby + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Login to Docker Hub + if: env.DOCKER_LOGIN + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_AUTH_TOKEN }} + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + + - run: make install + + - name: Set up linter + run: bundle add rubocop --version "~> 1.24.1" --group "development" --skip-install + if: ${{ matrix.ruby != '2.4' }} + + - run: bundle install --with development + + - name: Run linter + run: bundle exec rubocop + if: ${{ matrix.ruby != '2.4' }} + + - name: Run tests + run: make test-docker + + deploy: + name: Deploy + if: success() && github.ref_type == 'tag' + needs: [ test ] + runs-on: ubuntu-latest + steps: + - name: Checkout sendgrid-ruby + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1 + bundler-cache: true + + - run: make install + + - name: Create GitHub Release + uses: sendgrid/dx-automator/actions/release@main + with: + footer: '**[RubyGems](https://rubygems.org/gems/sendgrid-ruby/versions/${version})**' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Publish to Rubygems + env: + GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_AUTH_TOKEN }} + run: | + mkdir -p $HOME/.gem + touch $HOME/.gem/credentials + chmod 0600 $HOME/.gem/credentials + printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + gem build *.gemspec + gem push *.gem + + notify-on-failure: + name: Slack notify on failure + if: failure() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref_type == 'tag') + needs: [ test, deploy ] + runs-on: ubuntu-latest + steps: + - uses: rtCamp/action-slack-notify@v2 + env: + SLACK_COLOR: failure + SLACK_ICON_EMOJI: ':github:' + SLACK_MESSAGE: ${{ format('Test *{0}*, Deploy *{1}*, {2}/{3}/actions/runs/{4}', needs.test.result, needs.deploy.result, github.server_url, github.repository, github.run_id) }} + SLACK_TITLE: Action Failure - ${{ github.repository }} + SLACK_USERNAME: GitHub Actions + SLACK_MSG_AUTHOR: twilio-dx + SLACK_FOOTER: Posted automatically using GitHub Actions + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + MSG_MINIMAL: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c7914181..813e62f4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,19 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-09-18 20:20:54 UTC using RuboCop version 0.91.0. +# on 2022-01-25 23:45:43 UTC using RuboCop version 1.22.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemfile, **/Gemfile, **/gems.rb +Bundler/OrderedGems: + Exclude: + - 'Gemfile' + # Offense count: 1 # Configuration parameters: Include. # Include: **/*.gemspec @@ -13,37 +21,37 @@ Gemspec/RequiredRubyVersion: Exclude: - 'sendgrid-ruby.gemspec' -# Offense count: 22 +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. +# SupportedStyles: final_newline, final_blank_line +Layout/TrailingEmptyLines: + Exclude: + - 'Gemfile' + +# Offense count: 24 Lint/UselessAssignment: Exclude: - 'examples/scopes/scopes.rb' - 'spec/rack/sendgrid_webhook_verification_spec.rb' -# Offense count: 8 -# Configuration parameters: IgnoredMethods. +# Offense count: 10 +# Configuration parameters: IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: - Max: 144 - -# Offense count: 9 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods. -# ExcludedMethods: refine -Metrics/BlockLength: - Max: 96 + Max: 134 # Offense count: 3 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 2006 - Exclude: - - 'test/sendgrid/test_sendgrid-ruby.rb' + Max: 2018 -# Offense count: 41 -# Configuration parameters: CountComments, CountAsOne, ExcludedMethods. +# Offense count: 45 +# Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. Metrics/MethodLength: Max: 141 -# Offense count: 2 -# Configuration parameters: CountKeywordArgs. +# Offense count: 4 +# Configuration parameters: CountKeywordArgs, MaxOptionalParameters. Metrics/ParameterLists: Max: 7 @@ -76,15 +84,15 @@ Naming/PredicateName: - 'examples/helpers/eventwebhook/example.rb' # Offense count: 35 +# Configuration parameters: AllowedConstants. Style/Documentation: Enabled: false -# Offense count: 4 -# Configuration parameters: EnforcedStyle. +# Offense count: 3 +# Configuration parameters: MaxUnannotatedPlaceholdersAllowed, IgnoredMethods. # SupportedStyles: annotated, template, unannotated Style/FormatStringToken: - Exclude: - - 'examples/emailactivity/emailactivity.rb' + EnforcedStyle: unannotated # Offense count: 97 # Cop supports --auto-correct. @@ -93,6 +101,14 @@ Style/FormatStringToken: Style/FrozenStringLiteralComment: Enabled: false +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +Style/HashSyntax: + Exclude: + - 'Gemfile' + # Offense count: 6 Style/MixinUsage: Exclude: @@ -103,9 +119,9 @@ Style/MixinUsage: - 'test/sendgrid/helpers/mail/test_attachment.rb' - 'test/sendgrid/helpers/mail/test_mail.rb' -# Offense count: 55 +# Offense count: 54 # Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Layout/LineLength: - Max: 3211 + Max: 381 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ebb65bb1..00000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -language: ruby -env: -- version=ruby:3.0 -- version=ruby:2.7 -- version=ruby:2.6 -- version=ruby:2.5 -- version=ruby:2.4 -- version=jruby:9.2 -gemfile: -- gemfiles/Sinatra_1.gemfile -- gemfiles/Sinatra_2.gemfile -script: -- if [[ "$TRAVIS_BRANCH" == "main" || "$TRAVIS_BRANCH" == "travis" ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then - echo "${DOCKER_PASSWORD}" | docker login -u "${DOCKER_USERNAME}" --password-stdin; - fi -- make test-docker -deploy: - provider: rubygems - api_key: "$RUBYGEMS_API_KEY" - gem: sendgrid-ruby - on: - tags: true - condition: $version = ruby:2.4 && $BUNDLE_GEMFILE = *"gemfiles/Sinatra_1.gemfile" -notifications: - slack: - if: branch = main - on_pull_requests: false - on_success: never - on_failure: change - rooms: - secure: oSeohwM+ernyiRYSRLpNlICk0wgj0lku3y5LuouJLRHs45tCAzLZLbgxsor18wCSJkmhfn2vg4Rn969VnskFuj70OhJSLBKL4UXBnR1Ji0ClpfJlGojcbY/5Z8N/eGDrvf5ofA0Jc+L/ut+oSCMXnstEGbx4wBpPTajHuRtvb34= diff --git a/CHANGELOG.md b/CHANGELOG.md index 9998c995..e1aaa23f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,17 @@ # Change Log All notable changes to this project will be documented in this file. +[2022-02-09] Version 6.6.1 +-------------------------- +**Library - Chore** +- [PR #482](https://github.com/sendgrid/sendgrid-ruby/pull/482): upgrade supported language versions. Thanks to [@childish-sambino](https://github.com/childish-sambino)! +- [PR #480](https://github.com/sendgrid/sendgrid-ruby/pull/480): add gh release to workflow. Thanks to [@shwetha-manvinkurke](https://github.com/shwetha-manvinkurke)! +- [PR #478](https://github.com/sendgrid/sendgrid-ruby/pull/478): migrate to gh actions. Thanks to [@beebzz](https://github.com/beebzz)! + +**Library - Fix** +- [PR #479](https://github.com/sendgrid/sendgrid-ruby/pull/479): set version env var for tests. Thanks to [@beebzz](https://github.com/beebzz)! + + [2021-11-03] Version 6.6.0 -------------------------- **Library - Feature** diff --git a/LICENSE b/LICENSE index e5439a92..5db04ff6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (C) 2021, Twilio SendGrid, Inc. +Copyright (C) 2022, Twilio SendGrid, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/Makefile b/Makefile index faee8997..c35f356a 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,6 @@ install: test: bundle exec rake - rubocop test-integ: test diff --git a/README.md b/README.md index bcc45efc..5de9faa2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![Twilio SendGrid Logo](twilio_sendgrid_logo.png) -[![Travis Badge](https://travis-ci.com/sendgrid/sendgrid-ruby.svg?branch=main)](https://travis-ci.com/sendgrid/sendgrid-ruby) +[![Travis Badge](https://github.com/sendgrid/sendgrid-ruby/actions/workflows/test-and-deploy.yml/badge.svg)](https://github.com/sendgrid/sendgrid-ruby/actions/workflows/test-and-deploy.yml) [![Gem Version](https://badge.fury.io/rb/sendgrid-ruby.svg)](https://badge.fury.io/rb/sendgrid-ruby) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) [![Twitter Follow](https://img.shields.io/twitter/follow/sendgrid.svg?style=social&label=Follow)](https://twitter.com/sendgrid) diff --git a/examples/new_marketing_campaigns/contacts.rb b/examples/new_marketing_campaigns/contacts.rb new file mode 100644 index 00000000..b41b4bb0 --- /dev/null +++ b/examples/new_marketing_campaigns/contacts.rb @@ -0,0 +1,29 @@ +require 'sendgrid-ruby' + +sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) + +################################################## +# Add or Update a Contact # +# POST /marketing/contacts # + +data = JSON.parse('{ + "list_ids": [ + "ca7a3796-e8a8-4029-9ccb-df8937940562" + ], + "contacts": [ + { + "address_line_1": "123 Elm St.", + "address_line_2": "Apt. 456", + "city": "Denver", + "country": "United States", + "email": "example@example.com", + "first_name": "User", + "last_name": "Example" + } + ] +}') + +response = sg.client.marketing.contacts.put(request_body: data) +puts response.status_code +puts response.body +puts response.headers diff --git a/examples/new_marketing_campaigns/customfields.rb b/examples/new_marketing_campaigns/customfields.rb new file mode 100644 index 00000000..de1a35fb --- /dev/null +++ b/examples/new_marketing_campaigns/customfields.rb @@ -0,0 +1,49 @@ +require 'sendgrid-ruby' + +sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) + +################################################## +# Create Custom Field Definition # +# POST /marketing/field_definitions # + +data = JSON.parse('{ + "name": "pet", + "field_type": "Text" +}') + +response = sg.client.marketing.field_definitions.post(request_body: data) +puts response.status_code +puts response.body +puts response.headers + +################################################## +# Get All Field Definitions # +# GET /marketing/field_definitions # + +response = sg.client.marketing.field_definitions.get +puts response.status_code +puts response.body +puts response.headers + +################################################## +# Update Custom Field Definition # +# PATCH /marketing/field_definitions/{custom_field_id} # + +data = JSON.parse('{ + "name": "new_custom_field_name" +}') +custom_field_id = 'e1_T' +response = sg.client.marketing.field_definitions._(custom_field_id).patch(request_body: data) +puts response.status_code +puts response.body +puts response.headers + +################################################## +# Delete Custom Field Definition # +# DELETE /marketing/field_definitions/{custom_field_id} # + +custom_field_id = 'e1_T' +response = sg.client.marketing.field_definitions._(custom_field_id).delete +puts response.status_code +puts response.body +puts response.headers diff --git a/examples/new_marketing_campaigns/lists.rb b/examples/new_marketing_campaigns/lists.rb new file mode 100644 index 00000000..ec50c06e --- /dev/null +++ b/examples/new_marketing_campaigns/lists.rb @@ -0,0 +1,35 @@ +require 'sendgrid-ruby' + +sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) + +################################################## +# Create List # +# GET /marketing/lists # + +data = JSON.parse('{ + "name": "list-name" +}') + +response = sg.client.marketing.lists.post(request_body: data) +puts response.status_code +puts response.body +puts response.headers + +################################################## +# Get All Lists # +# GET /marketing/lists # + +response = sg.client.marketing.lists.get +puts response.status_code +puts response.body +puts response.headers + +################################################## +# Get a List by ID # +# GET /marketing/lists/{id} # + +list_id = 'ca7a3796-e8a8-4029-9ccb-df8937940562' +response = sg.client.marketing.lists._(list_id).get +puts response.status_code +puts response.body +puts response.headers diff --git a/examples/new_marketing_campaigns/singlesends.rb b/examples/new_marketing_campaigns/singlesends.rb new file mode 100644 index 00000000..796e5233 --- /dev/null +++ b/examples/new_marketing_campaigns/singlesends.rb @@ -0,0 +1,28 @@ +require 'sendgrid-ruby' + +sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) + +################################################## +# Create Single Send # +# POST /marketing/singlesends # + +data = JSON.parse('{ + "name": "Example API Created Single Send", + "categories": [ + "unique opens" + ], + "send_to": { + "all": true + }, + "email_config": { + "design_id": "", + "editor": "design", + "suppression_group_id": 12, + "sender_id": 10 + } +}') + +response = sg.client.marketing.singlesends.post(request_body: data) +puts response.status_code +puts response.body +puts response.headers diff --git a/lib/sendgrid/version.rb b/lib/sendgrid/version.rb index 7947e20a..ab225ad9 100644 --- a/lib/sendgrid/version.rb +++ b/lib/sendgrid/version.rb @@ -1,3 +1,3 @@ module SendGrid - VERSION = '6.6.0'.freeze + VERSION = '6.6.1'.freeze end diff --git a/sendgrid-ruby.gemspec b/sendgrid-ruby.gemspec index 279d0c39..3856eb3b 100644 --- a/sendgrid-ruby.gemspec +++ b/sendgrid-ruby.gemspec @@ -25,7 +25,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rack' spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rspec' - spec.add_development_dependency 'rubocop' spec.add_development_dependency 'simplecov', '~> 0.18.5' spec.add_development_dependency 'sinatra', '>= 1.4.7', '< 3' end diff --git a/test/sendgrid/test_sendgrid-ruby.rb b/test/sendgrid/test_sendgrid-ruby.rb index 2a1c7451..0435c680 100644 --- a/test/sendgrid/test_sendgrid-ruby.rb +++ b/test/sendgrid/test_sendgrid-ruby.rb @@ -33,7 +33,7 @@ def test_init assert_equal(test_headers, sg.request_headers) assert_equal('v3', sg.version) assert_equal(subuser, sg.impersonate_subuser) - assert_equal('6.6.0', SendGrid::VERSION) + assert_equal('6.6.1', SendGrid::VERSION) assert_instance_of(SendGrid::Client, sg.client) assert_equal({}, sg.http_options) end @@ -2683,12 +2683,8 @@ def test_gitignore_exists assert(File.file?('./.gitignore')) end - def test_travis_exists - assert(File.file?('./.travis.yml')) - end - - def test_codeclimate_exists - assert(File.file?('./.codeclimate.yml')) + def test_gh_actions_exists + assert(File.file?('./.github/workflows/test-and-deploy.yml')) end def test_changelog_exists