diff --git a/.rubocop.yml b/.rubocop.yml index 8074b24a..a5b51f7b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,4 @@ inherit_from: .rubocop_todo.yml -Metrics/LineLength: - Max: 120 - Style/StringLiterals: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d150c54d..ce6105cc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,132 +1,25 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-09-09 23:09:21 UTC using RuboCop version 0.90.0. +# on 2020-09-18 20:20:54 UTC using RuboCop version 0.91.0. # 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. -Layout/BlockEndNewline: - Exclude: - - 'spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/ClosingParenthesisIndentation: - Exclude: - - 'examples/helpers/eventwebhook/example.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLineAfterGuardClause: - Exclude: - - 'lib/rack/sendgrid_webhook_verification.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/EmptyLineAfterMagicComment: - Exclude: - - 'test/sendgrid/helpers/mail/test_attachment.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only -Layout/EmptyLinesAroundClassBody: - Exclude: - - 'test/sendgrid/permissions/test_scopes.rb' - -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses -Layout/FirstArgumentIndentation: - Exclude: - - 'examples/helpers/eventwebhook/example.rb' - - 'spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: special_inside_parentheses, consistent, align_braces -Layout/FirstHashElementIndentation: - Exclude: - - 'spec/fixtures/event_webhook.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'spec/fixtures/event_webhook.rb' - -# Offense count: 27 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Layout/LineLength: - Max: 381 - -# Offense count: 1 -# Cop supports --auto-correct. -Layout/MultilineBlockLayout: - Exclude: - - 'spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb' - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. -# SupportedStylesForExponentOperator: space, no_space -Layout/SpaceAroundOperators: - Exclude: - - 'spec/fixtures/event_webhook.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForEmptyBraces. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceBeforeBlockBraces: - EnforcedStyle: space - -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -# SupportedStyles: space, no_space -# SupportedStylesForEmptyBraces: space, no_space -Layout/SpaceInsideBlockBraces: +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: Exclude: - - 'examples/ips/ips.rb' - - 'lib/sendgrid/helpers/ip_management/ip_management.rb' + - 'sendgrid-ruby.gemspec' -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: AllowInHeredoc. -Layout/TrailingWhitespace: - Exclude: - - 'examples/helpers/mail/example.rb' - - 'examples/mail/mail.rb' - - 'lib/sendgrid/helpers/permissions/scope.rb' - - 'spec/fixtures/event_webhook.rb' - - 'spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb' - - 'test/sendgrid/helpers/mail/test_attachment.rb' - -# Offense count: 2 -Lint/ImplicitStringConcatenation: - Exclude: - - 'test/sendgrid/helpers/mail/test_attachment.rb' - -# Offense count: 16 +# Offense count: 22 Lint/UselessAssignment: Exclude: + - 'examples/scopes/scopes.rb' - 'spec/rack/sendgrid_webhook_verification_spec.rb' -# Offense count: 4 +# Offense count: 8 # Configuration parameters: IgnoredMethods. Metrics/AbcSize: Max: 144 @@ -137,22 +30,22 @@ Metrics/AbcSize: Metrics/BlockLength: Max: 96 -# Offense count: 1 +# Offense count: 3 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 123 + Max: 2006 -# Offense count: 14 +# Offense count: 41 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods. Metrics/MethodLength: - Max: 83 + Max: 141 -# Offense count: 1 +# Offense count: 2 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: - Max: 6 + Max: 7 -# Offense count: 3 +# Offense count: 4 # Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, Regex, IgnoreExecutableScripts, AllowedAcronyms. # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS Naming/FileName: @@ -160,6 +53,14 @@ Naming/FileName: - 'gemfiles/Sinatra_1.gemfile' - 'gemfiles/Sinatra_2.gemfile' - 'lib/sendgrid-ruby.rb' + - 'test/sendgrid/test_sendgrid-ruby.rb' + +# Offense count: 1 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'lib/sendgrid/helpers/mail/personalization.rb' # Offense count: 1 # Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros. @@ -172,50 +73,9 @@ Naming/PredicateName: - 'spec/**/*' - 'examples/helpers/eventwebhook/example.rb' -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb' - -# Offense count: 14 +# Offense count: 35 Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'lib/sendgrid/helpers/inbound/app.rb' - - 'lib/sendgrid/helpers/ip_management/ip_management.rb' - - 'lib/sendgrid/helpers/mail/category.rb' - - 'lib/sendgrid/helpers/permissions/scope.rb' - - 'lib/sendgrid/helpers/settings/mail_settings_dto.rb' - - 'lib/sendgrid/helpers/settings/partner_settings_dto.rb' - - 'lib/sendgrid/helpers/settings/settings.rb' - - 'lib/sendgrid/helpers/settings/tracking_settings_dto.rb' - - 'lib/sendgrid/helpers/settings/user_settings_dto.rb' - - 'lib/sendgrid/helpers/stats/email_stats.rb' - - 'lib/sendgrid/helpers/stats/metrics.rb' - - 'lib/sendgrid/helpers/stats/stats_response.rb' - - 'lib/sendgrid/sendgrid.rb' - - 'lib/sendgrid/twilio_email.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: compact, expanded -Style/EmptyMethod: - Exclude: - - 'test/sendgrid/helpers/mail/test_attachment.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/Encoding: - Exclude: - - 'test/sendgrid/helpers/mail/test_attachment.rb' + Enabled: false # Offense count: 4 # Configuration parameters: EnforcedStyle. @@ -224,34 +84,14 @@ Style/FormatStringToken: Exclude: - 'examples/emailactivity/emailactivity.rb' -# Offense count: 72 +# Offense count: 97 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never Style/FrozenStringLiteralComment: Enabled: false -# Offense count: 2 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Exclude: - - 'lib/rack/sendgrid_webhook_verification.rb' - - 'lib/sendgrid/helpers/eventwebhook/eventwebhook.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/IfUnlessModifier: - Exclude: - - 'lib/sendgrid/helpers/eventwebhook/eventwebhook.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: IgnoredMethods. -Style/MethodCallWithoutArgsParentheses: - Exclude: - - 'examples/emailactivity/emailactivity.rb' - -# Offense count: 5 +# Offense count: 6 Style/MixinUsage: Exclude: - 'examples/helpers/eventwebhook/example.rb' @@ -259,63 +99,11 @@ Style/MixinUsage: - 'examples/helpers/settings/example.rb' - 'examples/helpers/stats/example.rb' - 'test/sendgrid/helpers/mail/test_attachment.rb' + - 'test/sendgrid/helpers/mail/test_mail.rb' -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: literals, strict -Style/MutableConstant: - Exclude: - - 'lib/sendgrid/helpers/eventwebhook/eventwebhook.rb' - - 'spec/fixtures/event_webhook.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/OrAssignment: - Exclude: - - 'lib/sendgrid/sendgrid.rb' - - 'lib/sendgrid/twilio_email.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -Style/RedundantCondition: - Exclude: - - 'lib/sendgrid/base_interface.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Exclude: - - 'lib/rack/sendgrid_webhook_verification.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Exclude: - - 'spec/rack/sendgrid_webhook_verification_spec.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, explicit -Style/RescueStandardError: - Exclude: - - 'lib/sendgrid/helpers/eventwebhook/eventwebhook.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Exclude: - - 'spec/fixtures/event_webhook.rb' - -# Offense count: 27 +# Offense count: 55 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Layout/LineLength: - Max: 381 + Max: 3211 diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ff18474..100569cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -171,7 +171,7 @@ All notable changes to this project will be documented in this file. ## [5.2.0] - 2017-10-30 ## ### Added -- PR #234: Helpers for email statistics - global, category, subuser +- PR #234: Helpers for email statistics - global, category, subuser - Thanks to [Awin Abi](https://github.com/awinabi) for the pull request! ## [5.1.0] - 2017-9-1 ## diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f54e47e8..10508b2d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -149,10 +149,10 @@ Please run your code through: ```bash # Clone your fork of the repo into the current directory git clone https://github.com/sendgrid/sendgrid-ruby - + # Navigate to the newly cloned directory cd sendgrid-ruby - + # Assign the original repo to a remote called "upstream" git remote add upstream https://github.com/sendgrid/sendgrid-ruby ``` diff --git a/Makefile b/Makefile index c35f356a..faee8997 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ install: test: bundle exec rake + rubocop test-integ: test diff --git a/README.md b/README.md index de51c4ab..32bb603f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![Twilio SendGrid Logo](twilio_sendgrid_logo.png) -[![Travis Badge](https://travis-ci.org/sendgrid/sendgrid-ruby.svg?branch=main)](https://travis-ci.org/sendgrid/sendgrid-ruby) +[![Travis Badge](https://travis-ci.org/sendgrid/sendgrid-ruby.svg?branch=main)](https://travis-ci.org/sendgrid/sendgrid-ruby) [![Gem Version](https://badge.fury.io/rb/sendgrid-ruby.svg)](https://badge.fury.io/rb/sendgrid-ruby) [![Email Notifications Badge](https://dx.sendgrid.com/badge/ruby)](https://dx.sendgrid.com/newsletter/ruby) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.md) diff --git a/Rakefile b/Rakefile index ad77bbfa..f94bea21 100644 --- a/Rakefile +++ b/Rakefile @@ -10,5 +10,5 @@ end RSpec::Core::RakeTask.new(:spec) -desc "Run tests" +desc 'Run tests' task default: %i[spec test] diff --git a/examples/accesssettings/accesssettings.rb b/examples/accesssettings/accesssettings.rb index caab8a17..90796bd6 100644 --- a/examples/accesssettings/accesssettings.rb +++ b/examples/accesssettings/accesssettings.rb @@ -63,7 +63,7 @@ # Retrieve a specific whitelisted IP # # GET /access_settings/whitelist/{rule_id} # -rule_id = "test_url_param" +rule_id = 'test_url_param' response = sg.client.access_settings.whitelist._(rule_id).get puts response.status_code puts response.body @@ -73,7 +73,7 @@ # Remove a specific IP from the whitelist # # DELETE /access_settings/whitelist/{rule_id} # -rule_id = "test_url_param" +rule_id = 'test_url_param' response = sg.client.access_settings.whitelist._(rule_id).delete puts response.status_code puts response.body diff --git a/examples/alerts/alerts.rb b/examples/alerts/alerts.rb index 81128508..365b4873 100644 --- a/examples/alerts/alerts.rb +++ b/examples/alerts/alerts.rb @@ -32,7 +32,7 @@ data = JSON.parse('{ "email_to": "example@example.com" }') -alert_id = "test_url_param" +alert_id = 'test_url_param' response = sg.client.alerts._(alert_id).patch(request_body: data) puts response.status_code puts response.body @@ -42,7 +42,7 @@ # Retrieve a specific alert # # GET /alerts/{alert_id} # -alert_id = "test_url_param" +alert_id = 'test_url_param' response = sg.client.alerts._(alert_id).get puts response.status_code puts response.body @@ -52,7 +52,7 @@ # Delete an alert # # DELETE /alerts/{alert_id} # -alert_id = "test_url_param" +alert_id = 'test_url_param' response = sg.client.alerts._(alert_id).delete puts response.status_code puts response.body diff --git a/examples/apikeys/apikeys.rb b/examples/apikeys/apikeys.rb index 575207c5..a709ec97 100644 --- a/examples/apikeys/apikeys.rb +++ b/examples/apikeys/apikeys.rb @@ -41,7 +41,7 @@ "user.profile.update" ] }') -api_key_id = "test_url_param" +api_key_id = 'test_url_param' response = sg.client.api_keys._(api_key_id).put(request_body: data) puts response.status_code puts response.body @@ -54,7 +54,7 @@ data = JSON.parse('{ "name": "A New Hope" }') -api_key_id = "test_url_param" +api_key_id = 'test_url_param' response = sg.client.api_keys._(api_key_id).patch(request_body: data) puts response.status_code puts response.body @@ -64,7 +64,7 @@ # Retrieve an existing API Key # # GET /api_keys/{api_key_id} # -api_key_id = "test_url_param" +api_key_id = 'test_url_param' response = sg.client.api_keys._(api_key_id).get puts response.status_code puts response.body @@ -74,7 +74,7 @@ # Delete API keys # # DELETE /api_keys/{api_key_id} # -api_key_id = "test_url_param" +api_key_id = 'test_url_param' response = sg.client.api_keys._(api_key_id).delete puts response.status_code puts response.body diff --git a/examples/asm/asm.rb b/examples/asm/asm.rb index 42023f99..dc4a5be1 100644 --- a/examples/asm/asm.rb +++ b/examples/asm/asm.rb @@ -35,7 +35,7 @@ "id": 103, "name": "Item Suggestions" }') -group_id = "test_url_param" +group_id = 'test_url_param' response = sg.client.asm.groups._(group_id).patch(request_body: data) puts response.status_code puts response.body @@ -45,7 +45,7 @@ # Get information on a single suppression group. # # GET /asm/groups/{group_id} # -group_id = "test_url_param" +group_id = 'test_url_param' response = sg.client.asm.groups._(group_id).get puts response.status_code puts response.body @@ -55,7 +55,7 @@ # Delete a suppression group. # # DELETE /asm/groups/{group_id} # -group_id = "test_url_param" +group_id = 'test_url_param' response = sg.client.asm.groups._(group_id).delete puts response.status_code puts response.body @@ -71,7 +71,7 @@ "test2@example.com" ] }') -group_id = "test_url_param" +group_id = 'test_url_param' response = sg.client.asm.groups._(group_id).suppressions.post(request_body: data) puts response.status_code puts response.body @@ -81,7 +81,7 @@ # Retrieve all suppressions for a suppression group # # GET /asm/groups/{group_id}/suppressions # -group_id = "test_url_param" +group_id = 'test_url_param' response = sg.client.asm.groups._(group_id).suppressions.get puts response.status_code puts response.body @@ -98,7 +98,7 @@ "doesnotexists@example.com" ] }') -group_id = "test_url_param" +group_id = 'test_url_param' response = sg.client.asm.groups._(group_id).suppressions.search.post(request_body: data) puts response.status_code puts response.body @@ -108,8 +108,8 @@ # Delete a suppression from a suppression group # # DELETE /asm/groups/{group_id}/suppressions/{email} # -group_id = "test_url_param" -email = "test_url_param" +group_id = 'test_url_param' +email = 'test_url_param' response = sg.client.asm.groups._(group_id).suppressions._(email).delete puts response.status_code puts response.body @@ -143,7 +143,7 @@ # Retrieve a Global Suppression # # GET /asm/suppressions/global/{email} # -email = "test_url_param" +email = 'test_url_param' response = sg.client.asm.suppressions.global._(email).get puts response.status_code puts response.body @@ -153,7 +153,7 @@ # Delete a Global Suppression # # DELETE /asm/suppressions/global/{email} # -email = "test_url_param" +email = 'test_url_param' response = sg.client.asm.suppressions.global._(email).delete puts response.status_code puts response.body @@ -163,7 +163,7 @@ # Retrieve all suppression groups for an email address # # GET /asm/suppressions/{email} # -email = "test_url_param" +email = 'test_url_param' response = sg.client.asm.suppressions._(email).get puts response.status_code puts response.body diff --git a/examples/campaigns/campaigns.rb b/examples/campaigns/campaigns.rb index a4c532fd..c0cba430 100644 --- a/examples/campaigns/campaigns.rb +++ b/examples/campaigns/campaigns.rb @@ -54,7 +54,7 @@ "subject": "New Products for Summer!", "title": "May Newsletter" }') -campaign_id = "test_url_param" +campaign_id = 'test_url_param' response = sg.client.campaigns._(campaign_id).patch(request_body: data) puts response.status_code puts response.body @@ -64,7 +64,7 @@ # Retrieve a single campaign # # GET /campaigns/{campaign_id} # -campaign_id = "test_url_param" +campaign_id = 'test_url_param' response = sg.client.campaigns._(campaign_id).get puts response.status_code puts response.body @@ -74,7 +74,7 @@ # Delete a Campaign # # DELETE /campaigns/{campaign_id} # -campaign_id = "test_url_param" +campaign_id = 'test_url_param' response = sg.client.campaigns._(campaign_id).delete puts response.status_code puts response.body @@ -87,7 +87,7 @@ data = JSON.parse('{ "send_at": 1489451436 }') -campaign_id = "test_url_param" +campaign_id = 'test_url_param' response = sg.client.campaigns._(campaign_id).schedules.patch(request_body: data) puts response.status_code puts response.body @@ -100,7 +100,7 @@ data = JSON.parse('{ "send_at": 1489771528 }') -campaign_id = "test_url_param" +campaign_id = 'test_url_param' response = sg.client.campaigns._(campaign_id).schedules.post(request_body: data) puts response.status_code puts response.body @@ -110,7 +110,7 @@ # View Scheduled Time of a Campaign # # GET /campaigns/{campaign_id}/schedules # -campaign_id = "test_url_param" +campaign_id = 'test_url_param' response = sg.client.campaigns._(campaign_id).schedules.get puts response.status_code puts response.body @@ -120,7 +120,7 @@ # Unschedule a Scheduled Campaign # # DELETE /campaigns/{campaign_id}/schedules # -campaign_id = "test_url_param" +campaign_id = 'test_url_param' response = sg.client.campaigns._(campaign_id).schedules.delete puts response.status_code puts response.body @@ -130,7 +130,7 @@ # Send a Campaign # # POST /campaigns/{campaign_id}/schedules/now # -campaign_id = "test_url_param" +campaign_id = 'test_url_param' response = sg.client.campaigns._(campaign_id).schedules.now.post puts response.status_code puts response.body @@ -143,7 +143,7 @@ data = JSON.parse('{ "to": "your.email@example.com" }') -campaign_id = "test_url_param" +campaign_id = 'test_url_param' response = sg.client.campaigns._(campaign_id).schedules.test.post(request_body: data) puts response.status_code puts response.body diff --git a/examples/clients/clients.rb b/examples/clients/clients.rb index 62990f20..23f261a1 100644 --- a/examples/clients/clients.rb +++ b/examples/clients/clients.rb @@ -17,7 +17,7 @@ # GET /clients/{client_type}/stats # params = JSON.parse('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}') -client_type = "test_url_param" +client_type = 'test_url_param' response = sg.client.clients._(client_type).stats.get(query_params: params) puts response.status_code puts response.body diff --git a/examples/contactdb/contactdb.rb b/examples/contactdb/contactdb.rb index 0fdc69a2..04ce3e53 100644 --- a/examples/contactdb/contactdb.rb +++ b/examples/contactdb/contactdb.rb @@ -28,7 +28,7 @@ # Retrieve a Custom Field # # GET /contactdb/custom_fields/{custom_field_id} # -custom_field_id = "test_url_param" +custom_field_id = 'test_url_param' response = sg.client.contactdb.custom_fields._(custom_field_id).get puts response.status_code puts response.body @@ -38,7 +38,7 @@ # Delete a Custom Field # # DELETE /contactdb/custom_fields/{custom_field_id} # -custom_field_id = "test_url_param" +custom_field_id = 'test_url_param' response = sg.client.contactdb.custom_fields._(custom_field_id).delete puts response.status_code puts response.body @@ -88,7 +88,7 @@ "name": "newlistname" }') params = JSON.parse('{"list_id": 1}') -list_id = "test_url_param" +list_id = 'test_url_param' response = sg.client.contactdb.lists._(list_id).patch(request_body: data, query_params: params) puts response.status_code puts response.body @@ -99,7 +99,7 @@ # GET /contactdb/lists/{list_id} # params = JSON.parse('{"list_id": 1}') -list_id = "test_url_param" +list_id = 'test_url_param' response = sg.client.contactdb.lists._(list_id).get(query_params: params) puts response.status_code puts response.body @@ -110,7 +110,7 @@ # DELETE /contactdb/lists/{list_id} # params = JSON.parse('{"delete_contacts": "true"}') -list_id = "test_url_param" +list_id = 'test_url_param' response = sg.client.contactdb.lists._(list_id).delete(query_params: params) puts response.status_code puts response.body @@ -124,7 +124,7 @@ "recipient_id1", "recipient_id2" ]') -list_id = "test_url_param" +list_id = 'test_url_param' response = sg.client.contactdb.lists._(list_id).recipients.post(request_body: data) puts response.status_code puts response.body @@ -135,7 +135,7 @@ # GET /contactdb/lists/{list_id}/recipients # params = JSON.parse('{"page": 1, "page_size": 1, "list_id": 1}') -list_id = "test_url_param" +list_id = 'test_url_param' response = sg.client.contactdb.lists._(list_id).recipients.get(query_params: params) puts response.status_code puts response.body @@ -145,8 +145,8 @@ # Add a Single Recipient to a List # # POST /contactdb/lists/{list_id}/recipients/{recipient_id} # -list_id = "test_url_param" -recipient_id = "test_url_param" +list_id = 'test_url_param' +recipient_id = 'test_url_param' response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).post puts response.status_code puts response.body @@ -157,8 +157,8 @@ # DELETE /contactdb/lists/{list_id}/recipients/{recipient_id} # params = JSON.parse('{"recipient_id": 1, "list_id": 1}') -list_id = "test_url_param" -recipient_id = "test_url_param" +list_id = 'test_url_param' +recipient_id = 'test_url_param' response = sg.client.contactdb.lists._(list_id).recipients._(recipient_id).delete(query_params: params) puts response.status_code puts response.body @@ -258,7 +258,7 @@ # Retrieve a single recipient # # GET /contactdb/recipients/{recipient_id} # -recipient_id = "test_url_param" +recipient_id = 'test_url_param' response = sg.client.contactdb.recipients._(recipient_id).get puts response.status_code puts response.body @@ -268,7 +268,7 @@ # Delete a Recipient # # DELETE /contactdb/recipients/{recipient_id} # -recipient_id = "test_url_param" +recipient_id = 'test_url_param' response = sg.client.contactdb.recipients._(recipient_id).delete puts response.status_code puts response.body @@ -278,7 +278,7 @@ # Retrieve the lists that a recipient is on # # GET /contactdb/recipients/{recipient_id}/lists # -recipient_id = "test_url_param" +recipient_id = 'test_url_param' response = sg.client.contactdb.recipients._(recipient_id).lists.get puts response.status_code puts response.body @@ -352,7 +352,7 @@ "name": "The Millers" }') params = JSON.parse('{"segment_id": "test_string"}') -segment_id = "test_url_param" +segment_id = 'test_url_param' response = sg.client.contactdb.segments._(segment_id).patch(request_body: data, query_params: params) puts response.status_code puts response.body @@ -363,7 +363,7 @@ # GET /contactdb/segments/{segment_id} # params = JSON.parse('{"segment_id": 1}') -segment_id = "test_url_param" +segment_id = 'test_url_param' response = sg.client.contactdb.segments._(segment_id).get(query_params: params) puts response.status_code puts response.body @@ -374,7 +374,7 @@ # DELETE /contactdb/segments/{segment_id} # params = JSON.parse('{"delete_contacts": "true"}') -segment_id = "test_url_param" +segment_id = 'test_url_param' response = sg.client.contactdb.segments._(segment_id).delete(query_params: params) puts response.status_code puts response.body @@ -385,7 +385,7 @@ # GET /contactdb/segments/{segment_id}/recipients # params = JSON.parse('{"page": 1, "page_size": 1}') -segment_id = "test_url_param" +segment_id = 'test_url_param' response = sg.client.contactdb.segments._(segment_id).recipients.get(query_params: params) puts response.status_code puts response.body diff --git a/examples/emailactivity/emailactivity.rb b/examples/emailactivity/emailactivity.rb index 6634eb36..5485f6cf 100644 --- a/examples/emailactivity/emailactivity.rb +++ b/examples/emailactivity/emailactivity.rb @@ -27,7 +27,7 @@ # GET /messages/{msg_id} # msg_id = "test_url_param" -response = sg.client.messages._(msg_id).get() +response = sg.client.messages._(msg_id).get puts response.status_code puts response.body puts response.headers @@ -36,7 +36,7 @@ # Request a CSV # # POST /messages/download # -response = sg.client.messages.download.post() +response = sg.client.messages.download.post puts response.status_code puts response.body puts response.headers diff --git a/examples/helpers/eventwebhook/example.rb b/examples/helpers/eventwebhook/example.rb index b99c7161..92ad81c1 100644 --- a/examples/helpers/eventwebhook/example.rb +++ b/examples/helpers/eventwebhook/example.rb @@ -8,9 +8,9 @@ def is_valid_signature(request) ec_public_key = event_webhook.convert_public_key_to_ecdsa(public_key) event_webhook.verify_signature( - ec_public_key, - request.body.read, - request.env[SendGrid::EventWebhookHeader::SIGNATURE], - request.env[SendGrid::EventWebhookHeader::TIMESTAMP] + ec_public_key, + request.body.read, + request.env[SendGrid::EventWebhookHeader::SIGNATURE], + request.env[SendGrid::EventWebhookHeader::TIMESTAMP] ) end diff --git a/examples/helpers/mail/example.rb b/examples/helpers/mail/example.rb index 41cf546e..b248a588 100644 --- a/examples/helpers/mail/example.rb +++ b/examples/helpers/mail/example.rb @@ -36,7 +36,7 @@ def kitchen_sink personalization.add_substitution(Substitution.new(key: '%city%', value: 'Denver')) personalization.add_custom_arg(CustomArg.new(key: 'user_id', value: '343')) personalization.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing')) - personalization.send_at = 1443636843 + personalization.send_at = 1_443_636_843 mail.add_personalization(personalization) personalization2 = Personalization.new @@ -53,7 +53,7 @@ def kitchen_sink personalization2.add_substitution(Substitution.new(key: '%city%', value: 'Denver')) personalization2.add_custom_arg(CustomArg.new(key: 'user_id', value: '343')) personalization2.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing')) - personalization2.send_at = 1443636843 + personalization2.send_at = 1_443_636_843 mail.add_personalization(personalization2) mail.add_content(Content.new(type: 'text/plain', value: 'some text here')) @@ -89,7 +89,7 @@ def kitchen_sink mail.add_custom_arg(CustomArg.new(key: 'campaign', value: 'welcome')) mail.add_custom_arg(CustomArg.new(key: 'weekday', value: 'morning')) - mail.send_at = 1443636842 + mail.send_at = 1_443_636_842 # This must be a valid [batch ID](https://sendgrid.com/docs/API_Reference/SMTP_API/scheduling_parameters.html) to work # mail.batch_id = 'sendgrid_batch_id' @@ -132,8 +132,8 @@ def dynamic_template_data_hello_world personalization = Personalization.new personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User')) personalization.add_dynamic_template_data( - "variable" => [ - { "foo" => "bar" }, { "foo" => "baz" } + 'variable' => [ + { 'foo' => 'bar' }, { 'foo' => 'baz' } ] ) mail.add_personalization(personalization) diff --git a/examples/helpers/settings/example.rb b/examples/helpers/settings/example.rb index 3cdb8494..0c2455e0 100644 --- a/examples/helpers/settings/example.rb +++ b/examples/helpers/settings/example.rb @@ -11,7 +11,7 @@ puts response.headers # Turn on bcc settings -response = settings.update_bcc(enabled: true, email: "email@example.com") +response = settings.update_bcc(enabled: true, email: 'email@example.com') puts response.status_code puts response.body puts response.headers diff --git a/examples/helpers/stats/example.rb b/examples/helpers/stats/example.rb index d50acdbf..109a0349 100644 --- a/examples/helpers/stats/example.rb +++ b/examples/helpers/stats/example.rb @@ -7,7 +7,7 @@ stats = SendGrid::EmailStats.new(sendgrid_client: sg_client) # Fetch stats by day, between 2 dates -from = Date.new(2017, 10, 01) +from = Date.new(2017, 10, 1) to = Date.new(2017, 10, 12) email_stats = stats.by_day(from, to) @@ -25,7 +25,7 @@ end # Fetch stats by week, between 2 dates for a category -from = Date.new(2017, 10, 01) +from = Date.new(2017, 10, 1) to = Date.new(2017, 10, 12) category = 'abcd' diff --git a/examples/ips/ips.rb b/examples/ips/ips.rb index eb341877..fc625cee 100644 --- a/examples/ips/ips.rb +++ b/examples/ips/ips.rb @@ -28,7 +28,7 @@ params = {} response = sg.client.ips.get(query_params: params) all_ips = JSON.parse(response.body) -unassigned_ips = all_ips.select {|ip| ip.subusers.empty?} +unassigned_ips = all_ips.select { |ip| ip.subusers.empty? } puts response.status_code puts response.body puts unassigned_ips @@ -62,7 +62,7 @@ data = JSON.parse('{ "name": "new_pool_name" }') -pool_name = "test_url_param" +pool_name = 'test_url_param' response = sg.client.ips.pools._(pool_name).put(request_body: data) puts response.status_code puts response.body @@ -72,7 +72,7 @@ # Retrieve all IPs in a specified pool. # # GET /ips/pools/{pool_name} # -pool_name = "test_url_param" +pool_name = 'test_url_param' response = sg.client.ips.pools._(pool_name).get puts response.status_code puts response.body @@ -82,7 +82,7 @@ # Delete an IP pool. # # DELETE /ips/pools/{pool_name} # -pool_name = "test_url_param" +pool_name = 'test_url_param' response = sg.client.ips.pools._(pool_name).delete puts response.status_code puts response.body @@ -95,7 +95,7 @@ data = JSON.parse('{ "ip": "0.0.0.0" }') -pool_name = "test_url_param" +pool_name = 'test_url_param' response = sg.client.ips.pools._(pool_name).ips.post(request_body: data) puts response.status_code puts response.body @@ -105,8 +105,8 @@ # Remove an IP address from a pool. # # DELETE /ips/pools/{pool_name}/ips/{ip} # -pool_name = "test_url_param" -ip = "test_url_param" +pool_name = 'test_url_param' +ip = 'test_url_param' response = sg.client.ips.pools._(pool_name).ips._(ip).delete puts response.status_code puts response.body @@ -137,7 +137,7 @@ # Retrieve warmup status for a specific IP address # # GET /ips/warmup/{ip_address} # -ip_address = "test_url_param" +ip_address = 'test_url_param' response = sg.client.ips.warmup._(ip_address).get puts response.status_code puts response.body @@ -147,7 +147,7 @@ # Remove an IP from warmup # # DELETE /ips/warmup/{ip_address} # -ip_address = "test_url_param" +ip_address = 'test_url_param' response = sg.client.ips.warmup._(ip_address).delete puts response.status_code puts response.body @@ -157,7 +157,7 @@ # Retrieve all IP pools an IP address belongs to # # GET /ips/{ip_address} # -ip_address = "test_url_param" +ip_address = 'test_url_param' response = sg.client.ips._(ip_address).get puts response.status_code puts response.body diff --git a/examples/mail/mail.rb b/examples/mail/mail.rb index fe8b8767..ad419c22 100644 --- a/examples/mail/mail.rb +++ b/examples/mail/mail.rb @@ -1,9 +1,7 @@ require 'sendgrid-ruby' - sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) - ################################################## # Create a batch ID # # POST /mail/batch # @@ -17,7 +15,7 @@ # Validate batch ID # # GET /mail/batch/{batch_id} # -batch_id = "test_url_param" +batch_id = 'test_url_param' response = sg.client.mail.batch._(batch_id).get puts response.status_code puts response.body @@ -166,8 +164,7 @@ } } }') -response = sg.client.mail._("send").post(request_body: data) +response = sg.client.mail._('send').post(request_body: data) puts response.status_code puts response.body puts response.headers - diff --git a/examples/scopes/scopes.rb b/examples/scopes/scopes.rb index 75447698..adec506b 100644 --- a/examples/scopes/scopes.rb +++ b/examples/scopes/scopes.rb @@ -1,8 +1,6 @@ require_relative '../../lib/sendgrid-ruby.rb' - sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) - ################################################## # Retrieve a list of scopes for which this user has access. # # GET /scopes # @@ -16,7 +14,6 @@ # Update the name & scopes of an API Key # # PUT /api_keys/{api_key_id} # - scopes = [ "user.profile.read", "user.profile.update" diff --git a/examples/senderauthentication/senderauthentication.rb b/examples/senderauthentication/senderauthentication.rb index 17d72431..5a9b2ab6 100644 --- a/examples/senderauthentication/senderauthentication.rb +++ b/examples/senderauthentication/senderauthentication.rb @@ -68,7 +68,7 @@ "custom_spf": true, "default": false }') -domain_id = "test_url_param" +domain_id = 'test_url_param' response = sg.client.whitelabel.domains._(domain_id).patch(request_body: data) puts response.status_code puts response.body @@ -78,7 +78,7 @@ # Retrieve a domain authentication. # # GET /whitelabel/domains/{domain_id} # -domain_id = "test_url_param" +domain_id = 'test_url_param' response = sg.client.whitelabel.domains._(domain_id).get puts response.status_code puts response.body @@ -88,7 +88,7 @@ # Delete a domain authentication. # # DELETE /whitelabel/domains/{domain_id} # -domain_id = "test_url_param" +domain_id = 'test_url_param' response = sg.client.whitelabel.domains._(domain_id).delete puts response.status_code puts response.body @@ -101,7 +101,7 @@ data = JSON.parse('{ "username": "jane@example.com" }') -domain_id = "test_url_param" +domain_id = 'test_url_param' response = sg.client.whitelabel.domains._(domain_id).subuser.post(request_body: data) puts response.status_code puts response.body @@ -114,7 +114,7 @@ data = JSON.parse('{ "ip": "192.168.0.1" }') -id = "test_url_param" +id = 'test_url_param' response = sg.client.whitelabel.domains._(id).ips.post(request_body: data) puts response.status_code puts response.body @@ -124,8 +124,8 @@ # Remove an IP from a domain authentication. # # DELETE /whitelabel/domains/{id}/ips/{ip} # -id = "test_url_param" -ip = "test_url_param" +id = 'test_url_param' +ip = 'test_url_param' response = sg.client.whitelabel.domains._(id).ips._(ip).delete puts response.status_code puts response.body @@ -135,7 +135,7 @@ # Validate a domain authentication. # # POST /whitelabel/domains/{id}/validate # -id = "test_url_param" +id = 'test_url_param' response = sg.client.whitelabel.domains._(id).validate.post puts response.status_code puts response.body @@ -169,7 +169,7 @@ # Retrieve a reverse DNS record # # GET /whitelabel/ips/{id} # -id = "test_url_param" +id = 'test_url_param' response = sg.client.whitelabel.ips._(id).get puts response.status_code puts response.body @@ -179,7 +179,7 @@ # Delete a reverse DNS record # # DELETE /whitelabel/ips/{id} # -id = "test_url_param" +id = 'test_url_param' response = sg.client.whitelabel.ips._(id).delete puts response.status_code puts response.body @@ -189,7 +189,7 @@ # Validate a reverse DNS record # # POST /whitelabel/ips/{id}/validate # -id = "test_url_param" +id = 'test_url_param' response = sg.client.whitelabel.ips._(id).validate.post puts response.status_code puts response.body @@ -257,7 +257,7 @@ data = JSON.parse('{ "default": true }') -id = "test_url_param" +id = 'test_url_param' response = sg.client.whitelabel.links._(id).patch(request_body: data) puts response.status_code puts response.body @@ -267,7 +267,7 @@ # Retrieve a Link Branding # # GET /whitelabel/links/{id} # -id = "test_url_param" +id = 'test_url_param' response = sg.client.whitelabel.links._(id).get puts response.status_code puts response.body @@ -277,7 +277,7 @@ # Delete a Link Branding # # DELETE /whitelabel/links/{id} # -id = "test_url_param" +id = 'test_url_param' response = sg.client.whitelabel.links._(id).delete puts response.status_code puts response.body @@ -287,7 +287,7 @@ # Validate a Link Branding # # POST /whitelabel/links/{id}/validate # -id = "test_url_param" +id = 'test_url_param' response = sg.client.whitelabel.links._(id).validate.post puts response.status_code puts response.body @@ -300,7 +300,7 @@ data = JSON.parse('{ "username": "jane@example.com" }') -link_id = "test_url_param" +link_id = 'test_url_param' response = sg.client.whitelabel.links._(link_id).subuser.post(request_body: data) puts response.status_code puts response.body diff --git a/examples/senders/senders.rb b/examples/senders/senders.rb index 8928243b..e9b2239f 100644 --- a/examples/senders/senders.rb +++ b/examples/senders/senders.rb @@ -58,7 +58,7 @@ "state": "Colorado", "zip": "80202" }') -sender_id = "test_url_param" +sender_id = 'test_url_param' response = sg.client.senders._(sender_id).patch(request_body: data) puts response.status_code puts response.body @@ -68,7 +68,7 @@ # View a Sender Identity # # GET /senders/{sender_id} # -sender_id = "test_url_param" +sender_id = 'test_url_param' response = sg.client.senders._(sender_id).get puts response.status_code puts response.body @@ -78,7 +78,7 @@ # Delete a Sender Identity # # DELETE /senders/{sender_id} # -sender_id = "test_url_param" +sender_id = 'test_url_param' response = sg.client.senders._(sender_id).delete puts response.status_code puts response.body @@ -88,7 +88,7 @@ # Resend Sender Identity Verification # # POST /senders/{sender_id}/resend_verification # -sender_id = "test_url_param" +sender_id = 'test_url_param' response = sg.client.senders._(sender_id).resend_verification.post puts response.status_code puts response.body diff --git a/examples/subusers/subusers.rb b/examples/subusers/subusers.rb index e56c2abe..0df9d31f 100644 --- a/examples/subusers/subusers.rb +++ b/examples/subusers/subusers.rb @@ -77,7 +77,7 @@ data = JSON.parse('{ "disabled": false }') -subuser_name = "test_url_param" +subuser_name = 'test_url_param' response = sg.client.subusers._(subuser_name).patch(request_body: data) puts response.status_code puts response.body @@ -87,7 +87,7 @@ # Delete a subuser # # DELETE /subusers/{subuser_name} # -subuser_name = "test_url_param" +subuser_name = 'test_url_param' response = sg.client.subusers._(subuser_name).delete puts response.status_code puts response.body @@ -100,7 +100,7 @@ data = JSON.parse('[ "127.0.0.1" ]') -subuser_name = "test_url_param" +subuser_name = 'test_url_param' response = sg.client.subusers._(subuser_name).ips.put(request_body: data) puts response.status_code puts response.body @@ -114,7 +114,7 @@ "email": "example@example.com", "frequency": 500 }') -subuser_name = "test_url_param" +subuser_name = 'test_url_param' response = sg.client.subusers._(subuser_name).monitor.put(request_body: data) puts response.status_code puts response.body @@ -128,7 +128,7 @@ "email": "example@example.com", "frequency": 50000 }') -subuser_name = "test_url_param" +subuser_name = 'test_url_param' response = sg.client.subusers._(subuser_name).monitor.post(request_body: data) puts response.status_code puts response.body @@ -138,7 +138,7 @@ # Retrieve monitor settings for a subuser # # GET /subusers/{subuser_name}/monitor # -subuser_name = "test_url_param" +subuser_name = 'test_url_param' response = sg.client.subusers._(subuser_name).monitor.get puts response.status_code puts response.body @@ -148,7 +148,7 @@ # Delete monitor settings # # DELETE /subusers/{subuser_name}/monitor # -subuser_name = "test_url_param" +subuser_name = 'test_url_param' response = sg.client.subusers._(subuser_name).monitor.delete puts response.status_code puts response.body @@ -159,7 +159,7 @@ # GET /subusers/{subuser_name}/stats/monthly # params = JSON.parse('{"date": "test_string", "sort_by_direction": "asc", "limit": 1, "sort_by_metric": "test_string", "offset": 1}') -subuser_name = "test_url_param" +subuser_name = 'test_url_param' response = sg.client.subusers._(subuser_name).stats.monthly.get(query_params: params) puts response.status_code puts response.body diff --git a/examples/suppression/suppression.rb b/examples/suppression/suppression.rb index 27b04ff6..4bb07591 100644 --- a/examples/suppression/suppression.rb +++ b/examples/suppression/suppression.rb @@ -1,9 +1,7 @@ require 'sendgrid-ruby' - sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']) - ################################################## # Retrieve all blocks # # GET /suppression/blocks # @@ -34,7 +32,7 @@ # Retrieve a specific block # # GET /suppression/blocks/{email} # -email = "test_url_param" +email = 'test_url_param' response = sg.client.suppression.blocks._(email).get puts response.status_code puts response.body @@ -44,7 +42,7 @@ # Delete a specific block # # DELETE /suppression/blocks/{email} # -email = "test_url_param" +email = 'test_url_param' response = sg.client.suppression.blocks._(email).delete puts response.status_code puts response.body @@ -80,7 +78,7 @@ # Retrieve a Bounce # # GET /suppression/bounces/{email} # -email = "test_url_param" +email = 'test_url_param' response = sg.client.suppression.bounces._(email).get puts response.status_code puts response.body @@ -91,7 +89,7 @@ # DELETE /suppression/bounces/{email} # params = JSON.parse('{"email_address": "example@example.com"}') -email = "test_url_param" +email = 'test_url_param' response = sg.client.suppression.bounces._(email).delete(query_params: params) puts response.status_code puts response.body @@ -127,7 +125,7 @@ # Retrieve a specific invalid email # # GET /suppression/invalid_emails/{email} # -email = "test_url_param" +email = 'test_url_param' response = sg.client.suppression.invalid_emails._(email).get puts response.status_code puts response.body @@ -137,7 +135,7 @@ # Delete a specific invalid email # # DELETE /suppression/invalid_emails/{email} # -email = "test_url_param" +email = 'test_url_param' response = sg.client.suppression.invalid_emails._(email).delete puts response.status_code puts response.body @@ -147,8 +145,8 @@ # Retrieve a specific spam report # # GET /suppression/spam_report/{email} # -email = "test_url_param" -response = sg.client.suppression.spam_report._(email).get() +email = 'test_url_param' +response = sg.client.suppression.spam_report._(email).get puts response.status_code puts response.body puts response.headers @@ -157,8 +155,8 @@ # Delete a specific spam report # # DELETE /suppression/spam_report/{email} # -email = "test_url_param" -response = sg.client.suppression.spam_reports._(email).delete() +email = 'test_url_param' +response = sg.client.suppression.spam_reports._(email).delete puts response.status_code puts response.body puts response.headers @@ -198,4 +196,3 @@ puts response.status_code puts response.body puts response.headers - diff --git a/examples/templates/templates.rb b/examples/templates/templates.rb index 3c4338a3..49c16ffc 100644 --- a/examples/templates/templates.rb +++ b/examples/templates/templates.rb @@ -30,7 +30,7 @@ data = JSON.parse('{ "name": "new_example_name" }') -template_id = "test_url_param" +template_id = 'test_url_param' response = sg.client.templates._(template_id).patch(request_body: data) puts response.status_code puts response.body @@ -40,7 +40,7 @@ # Retrieve a single transactional template. # # GET /templates/{template_id} # -template_id = "test_url_param" +template_id = 'test_url_param' response = sg.client.templates._(template_id).get puts response.status_code puts response.body @@ -50,7 +50,7 @@ # Delete a template. # # DELETE /templates/{template_id} # -template_id = "test_url_param" +template_id = 'test_url_param' response = sg.client.templates._(template_id).delete puts response.status_code puts response.body @@ -68,7 +68,7 @@ "subject": "<%subject%>", "template_id": "ddb96bbc-9b92-425e-8979-99464621b543" }') -template_id = "test_url_param" +template_id = 'test_url_param' response = sg.client.templates._(template_id).versions.post(request_body: data) puts response.status_code puts response.body @@ -85,8 +85,8 @@ "plain_content": "<%body%>", "subject": "<%subject%>" }') -template_id = "test_url_param" -version_id = "test_url_param" +template_id = 'test_url_param' +version_id = 'test_url_param' response = sg.client.templates._(template_id).versions._(version_id).patch(request_body: data) puts response.status_code puts response.body @@ -96,8 +96,8 @@ # Retrieve a specific transactional template version. # # GET /templates/{template_id}/versions/{version_id} # -template_id = "test_url_param" -version_id = "test_url_param" +template_id = 'test_url_param' +version_id = 'test_url_param' response = sg.client.templates._(template_id).versions._(version_id).get puts response.status_code puts response.body @@ -107,8 +107,8 @@ # Delete a transactional template version. # # DELETE /templates/{template_id}/versions/{version_id} # -template_id = "test_url_param" -version_id = "test_url_param" +template_id = 'test_url_param' +version_id = 'test_url_param' response = sg.client.templates._(template_id).versions._(version_id).delete puts response.status_code puts response.body @@ -118,8 +118,8 @@ # Activate a transactional template version. # # POST /templates/{template_id}/versions/{version_id}/activate # -template_id = "test_url_param" -version_id = "test_url_param" +template_id = 'test_url_param' +version_id = 'test_url_param' response = sg.client.templates._(template_id).versions._(version_id).activate.post puts response.status_code puts response.body diff --git a/examples/user/user.rb b/examples/user/user.rb index 8ada0e05..0f8f4f3f 100644 --- a/examples/user/user.rb +++ b/examples/user/user.rb @@ -106,7 +106,7 @@ data = JSON.parse('{ "status": "pause" }') -batch_id = "test_url_param" +batch_id = 'test_url_param' response = sg.client.user.scheduled_sends._(batch_id).patch(request_body: data) puts response.status_code puts response.body @@ -116,7 +116,7 @@ # Retrieve scheduled send # # GET /user/scheduled_sends/{batch_id} # -batch_id = "test_url_param" +batch_id = 'test_url_param' response = sg.client.user.scheduled_sends._(batch_id).get puts response.status_code puts response.body @@ -126,7 +126,7 @@ # Delete a cancellation or pause of a scheduled send # # DELETE /user/scheduled_sends/{batch_id} # -batch_id = "test_url_param" +batch_id = 'test_url_param' response = sg.client.user.scheduled_sends._(batch_id).delete puts response.status_code puts response.body @@ -253,7 +253,7 @@ "spam_check": false, "url": "http://newdomain.com/parse" }') -hostname = "test_url_param" +hostname = 'test_url_param' response = sg.client.user.webhooks.parse.settings._(hostname).patch(request_body: data) puts response.status_code puts response.body @@ -263,7 +263,7 @@ # Retrieve a specific parse setting # # GET /user/webhooks/parse/settings/{hostname} # -hostname = "test_url_param" +hostname = 'test_url_param' response = sg.client.user.webhooks.parse.settings._(hostname).get puts response.status_code puts response.body @@ -273,7 +273,7 @@ # Delete a parse setting # # DELETE /user/webhooks/parse/settings/{hostname} # -hostname = "test_url_param" +hostname = 'test_url_param' response = sg.client.user.webhooks.parse.settings._(hostname).delete puts response.status_code puts response.body diff --git a/lib/rack/sendgrid_webhook_verification.rb b/lib/rack/sendgrid_webhook_verification.rb index d9faa450..cf952d60 100644 --- a/lib/rack/sendgrid_webhook_verification.rb +++ b/lib/rack/sendgrid_webhook_verification.rb @@ -27,6 +27,7 @@ def initialize(app, public_key, *paths) def call(env) return @app.call(env) unless env['PATH_INFO'].match(@path_regex) + request = Rack::Request.new(env) event_webhook = SendGrid::EventWebhook.new @@ -39,9 +40,9 @@ def call(env) ) if verified - return @app.call(env) + @app.call(env) else - return [ + [ 403, { 'Content-Type' => 'text/plain' }, ['SendGrid Request Verification Failed.'] diff --git a/lib/sendgrid/base_interface.rb b/lib/sendgrid/base_interface.rb index c333f175..c288e632 100644 --- a/lib/sendgrid/base_interface.rb +++ b/lib/sendgrid/base_interface.rb @@ -17,7 +17,7 @@ class BaseInterface def initialize(auth:, host:, request_headers: nil, version: nil, impersonate_subuser: nil) @auth = auth @host = host - @version = version ? version : 'v3' + @version = version || 'v3' @impersonate_subuser = impersonate_subuser @user_agent = "sendgrid/#{SendGrid::VERSION};ruby" @request_headers = JSON.parse(' diff --git a/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb b/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb index 2596dcf7..3ea3f137 100644 --- a/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb +++ b/lib/sendgrid/helpers/eventwebhook/eventwebhook.rb @@ -25,15 +25,13 @@ def verify_signature(public_key, payload, signature, timestamp) payload_digest = Digest::SHA256.digest(timestamped_playload) decoded_signature = Base64.decode64(signature) public_key.dsa_verify_asn1(payload_digest, decoded_signature) - rescue + rescue StandardError false end def verify_engine # JRuby does not fully support ECDSA: https://github.com/jruby/jruby-openssl/issues/193 - if RUBY_PLATFORM == "java" - raise NotSupportedError, "Event Webhook verification is not supported by JRuby" - end + raise NotSupportedError, "Event Webhook verification is not supported by JRuby" if RUBY_PLATFORM == "java" end class Error < ::RuntimeError @@ -46,7 +44,7 @@ class NotSupportedError < Error # This class lists headers that get posted to the webhook. Read the docs for # more details: https://sendgrid.com/docs/for-developers/tracking-events/event class EventWebhookHeader - SIGNATURE = "HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_SIGNATURE" - TIMESTAMP = "HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_TIMESTAMP" + SIGNATURE = "HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_SIGNATURE".freeze + TIMESTAMP = "HTTP_X_TWILIO_EMAIL_EVENT_WEBHOOK_TIMESTAMP".freeze end end diff --git a/lib/sendgrid/helpers/ip_management/ip_management.rb b/lib/sendgrid/helpers/ip_management/ip_management.rb index d6007ffd..1112fcad 100644 --- a/lib/sendgrid/helpers/ip_management/ip_management.rb +++ b/lib/sendgrid/helpers/ip_management/ip_management.rb @@ -11,7 +11,7 @@ def initialize(sendgrid_client:) def unassigned response = @sendgrid_client.ips.get ips = JSON.parse(response.body) - ips.select {|ip| ip.subusers.empty?} + ips.select { |ip| ip.subusers.empty? } end end end diff --git a/lib/sendgrid/helpers/mail/attachment.rb b/lib/sendgrid/helpers/mail/attachment.rb index e669ded7..0386fc75 100644 --- a/lib/sendgrid/helpers/mail/attachment.rb +++ b/lib/sendgrid/helpers/mail/attachment.rb @@ -20,16 +20,16 @@ def content=(content) def content return @encoded_content if @encoded_content - if @content.respond_to?(:read) - @encoded_content = encode @content - else - @encoded_content = @content - end + @encoded_content = if @content.respond_to?(:read) + encode @content + else + @content + end end def to_json(*) { - 'content' => self.content, + 'content' => content, 'type' => type, 'filename' => filename, 'disposition' => disposition, diff --git a/lib/sendgrid/helpers/mail/email.rb b/lib/sendgrid/helpers/mail/email.rb index 030339e6..6d1e30a9 100644 --- a/lib/sendgrid/helpers/mail/email.rb +++ b/lib/sendgrid/helpers/mail/email.rb @@ -2,7 +2,6 @@ module SendGrid class Email - attr_accessor :email, :name def initialize(email: nil, name: nil) diff --git a/lib/sendgrid/helpers/mail/header.rb b/lib/sendgrid/helpers/mail/header.rb index d104dfaf..c9a7227f 100644 --- a/lib/sendgrid/helpers/mail/header.rb +++ b/lib/sendgrid/helpers/mail/header.rb @@ -11,7 +11,7 @@ def initialize(key: nil, value: nil) def to_json(*) { - 'header' => self.header + 'header' => header }.delete_if { |_, value| value.to_s.strip == '' } end end diff --git a/lib/sendgrid/helpers/mail/mail.rb b/lib/sendgrid/helpers/mail/mail.rb index 6230919e..2b32af80 100644 --- a/lib/sendgrid/helpers/mail/mail.rb +++ b/lib/sendgrid/helpers/mail/mail.rb @@ -4,7 +4,6 @@ module SendGrid class Mail - attr_accessor :subject, :ip_pool_name, :template_id, :send_at, :batch_id attr_reader :personalizations, :contents, :attachments, :categories, :sections, :headers, :custom_args attr_writer :from, :asm, :mail_settings, :tracking_settings, :reply_to @@ -28,14 +27,14 @@ def initialize(from_email = nil, subj = nil, to_email = nil, cont = nil) @tracking_settings = nil @reply_to = nil - unless from_email.nil? && subj.nil? && to_email.nil? && cont.nil? - self.from = from_email - self.subject = subj - personalization = Personalization.new - personalization.add_to(to_email) - add_personalization(personalization) - add_content(cont) - end + return if from_email.nil? && subj.nil? && to_email.nil? && cont.nil? + + self.from = from_email + self.subject = subj + personalization = Personalization.new + personalization.add_to(to_email) + add_personalization(personalization) + add_content(cont) end def from @@ -53,7 +52,7 @@ def add_content(content) def check_for_secrets(patterns) contents = @contents.map { |content| content['value'] }.join(' ') patterns.each do |pattern| - raise SecurityError.new('Content contains sensitive information.') if contents.match(pattern) + raise SecurityError, 'Content contains sensitive information.' if contents.match(pattern) end end diff --git a/lib/sendgrid/helpers/mail/mail_settings.rb b/lib/sendgrid/helpers/mail/mail_settings.rb index 8b764203..875c4859 100644 --- a/lib/sendgrid/helpers/mail/mail_settings.rb +++ b/lib/sendgrid/helpers/mail/mail_settings.rb @@ -16,7 +16,6 @@ def sandbox_mode @sandbox_mode.nil? ? nil : @sandbox_mode.to_json end - def bypass_list_management @bypass_list_management.nil? ? nil : @bypass_list_management.to_json end diff --git a/lib/sendgrid/helpers/mail/personalization.rb b/lib/sendgrid/helpers/mail/personalization.rb index 70383e9f..bc1ee13a 100644 --- a/lib/sendgrid/helpers/mail/personalization.rb +++ b/lib/sendgrid/helpers/mail/personalization.rb @@ -2,7 +2,6 @@ module SendGrid class Personalization - attr_reader :tos, :ccs, :bccs, :headers, :substitutions, :custom_args, :dynamic_template_data diff --git a/lib/sendgrid/helpers/mail/substitution.rb b/lib/sendgrid/helpers/mail/substitution.rb index 92222c4e..738f4f5b 100644 --- a/lib/sendgrid/helpers/mail/substitution.rb +++ b/lib/sendgrid/helpers/mail/substitution.rb @@ -11,7 +11,7 @@ def initialize(key: nil, value: nil) def to_json(*) { - 'substitution' => self.substitution + 'substitution' => substitution }.delete_if { |_, value| value.to_s.strip == '' } end end diff --git a/lib/sendgrid/helpers/permissions/scope.rb b/lib/sendgrid/helpers/permissions/scope.rb index 944ab4d2..c7bd3ba9 100644 --- a/lib/sendgrid/helpers/permissions/scope.rb +++ b/lib/sendgrid/helpers/permissions/scope.rb @@ -4,7 +4,7 @@ module SendGrid class Scope SCOPES = YAML.load_file(File.dirname(__FILE__) + '/scopes.yml').freeze - + class << self def admin_permissions SCOPES.values.map(&:values).flatten diff --git a/lib/sendgrid/sendgrid.rb b/lib/sendgrid/sendgrid.rb index be4dc895..8207a389 100644 --- a/lib/sendgrid/sendgrid.rb +++ b/lib/sendgrid/sendgrid.rb @@ -12,7 +12,7 @@ class API < BaseInterface # def initialize(api_key:, host: nil, request_headers: nil, version: nil, impersonate_subuser: nil) auth = "Bearer #{api_key}" - host = 'https://api.sendgrid.com' unless host + host ||= 'https://api.sendgrid.com' super(auth: auth, host: host, request_headers: request_headers, version: version, impersonate_subuser: impersonate_subuser) end diff --git a/lib/sendgrid/twilio_email.rb b/lib/sendgrid/twilio_email.rb index 13c5cbdb..0d8ab0a6 100644 --- a/lib/sendgrid/twilio_email.rb +++ b/lib/sendgrid/twilio_email.rb @@ -13,7 +13,7 @@ class API < BaseInterface # def initialize(username:, password:, host: nil, request_headers: nil, version: nil, impersonate_subuser: nil) auth = "Basic #{Base64.strict_encode64("#{username}:#{password}")}" - host = 'https://email.twilio.com' unless host + host ||= 'https://email.twilio.com' super(auth: auth, host: host, request_headers: request_headers, version: version, impersonate_subuser: impersonate_subuser) end diff --git a/mail_helper_v3.md b/mail_helper_v3.md index 1b58570b..23b509dc 100644 --- a/mail_helper_v3.md +++ b/mail_helper_v3.md @@ -263,7 +263,7 @@ attachments = [ 'base64 encoded content', 'image/png', 'inline', - 'Banner 2'), + 'Banner 2'), ] msg.add_attachments(attachments) @@ -279,7 +279,7 @@ msg.set_global_headers(global_headers) msg.add_section('%section1%', 'Substitution for Section 1 Tag') sections = [ '%section2%' => 'Substitution for Section 2 Tag', - '%section3%' => 'Substitution for Section 3 Tag' + '%section3%' => 'Substitution for Section 3 Tag' ] msg.add_sections(sections) diff --git a/sendgrid-ruby.gemspec b/sendgrid-ruby.gemspec index 8c65b77c..279d0c39 100644 --- a/sendgrid-ruby.gemspec +++ b/sendgrid-ruby.gemspec @@ -1,5 +1,4 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'sendgrid/version' @@ -20,13 +19,13 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(/^(test|spec|features)/) spec.require_paths = ['lib'] spec.add_dependency 'ruby_http_client', '~> 3.4' - spec.add_development_dependency 'sinatra', '>= 1.4.7', '< 3' - spec.add_development_dependency 'rake', '~> 13.0' - spec.add_development_dependency 'rspec' - spec.add_development_dependency 'pry' spec.add_development_dependency 'faker' - spec.add_development_dependency 'rubocop' spec.add_development_dependency 'minitest', '~> 5.9' + spec.add_development_dependency 'pry' 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/spec/fixtures/event_webhook.rb b/spec/fixtures/event_webhook.rb index 05236df4..9195129c 100644 --- a/spec/fixtures/event_webhook.rb +++ b/spec/fixtures/event_webhook.rb @@ -2,21 +2,21 @@ module Fixtures module EventWebhook - PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE83T4O/n84iotIvIW4mdBgQ/7dAfSmpqIM8kF9mN1flpVKS3GRqe62gw+2fNNRaINXvVpiglSI8eNEc6wEA3F+g==' - FAILING_PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqTxd43gyp8IOEto2LdIfjRQrIbsd4SXZkLW6jDutdhXSJCWHw8REntlo7aNDthvj+y7GjUuFDb/R1NGe1OPzpA==' - SIGNATURE = 'MEUCIGHQVtGj+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiEAyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM=' - FAILING_SIGNATURE = 'MEUCIQCtIHJeH93Y+qpYeWrySphQgpNGNr/U+UyUlBkU6n7RAwIgJTz2C+8a8xonZGi6BpSzoQsbVRamr2nlxFDWYNH3j/0=' - TIMESTAMP = '1600112502' + PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE83T4O/n84iotIvIW4mdBgQ/7dAfSmpqIM8kF9mN1flpVKS3GRqe62gw+2fNNRaINXvVpiglSI8eNEc6wEA3F+g=='.freeze + FAILING_PUBLIC_KEY = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEqTxd43gyp8IOEto2LdIfjRQrIbsd4SXZkLW6jDutdhXSJCWHw8REntlo7aNDthvj+y7GjUuFDb/R1NGe1OPzpA=='.freeze + SIGNATURE = 'MEUCIGHQVtGj+Y3LkG9fLcxf3qfI10QysgDWmMOVmxG0u6ZUAiEAyBiXDWzM+uOe5W0JuG+luQAbPIqHh89M15TluLtEZtM='.freeze + FAILING_SIGNATURE = 'MEUCIQCtIHJeH93Y+qpYeWrySphQgpNGNr/U+UyUlBkU6n7RAwIgJTz2C+8a8xonZGi6BpSzoQsbVRamr2nlxFDWYNH3j/0='.freeze + TIMESTAMP = '1600112502'.freeze PAYLOAD = [ - { - email: 'hello@world.com', - event: 'dropped', - reason: 'Bounced Address', - sg_event_id: 'ZHJvcC0xMDk5NDkxOS1MUnpYbF9OSFN0T0doUTRrb2ZTbV9BLTA', - sg_message_id: 'LRzXl_NHStOGhQ4kofSm_A.filterdrecv-p3mdw1-756b745b58-kmzbl-18-5F5FC76C-9.0', - 'smtp-id': '', - timestamp: 1600112492, - } + { + email: 'hello@world.com', + event: 'dropped', + reason: 'Bounced Address', + sg_event_id: 'ZHJvcC0xMDk5NDkxOS1MUnpYbF9OSFN0T0doUTRrb2ZTbV9BLTA', + sg_message_id: 'LRzXl_NHStOGhQ4kofSm_A.filterdrecv-p3mdw1-756b745b58-kmzbl-18-5F5FC76C-9.0', + 'smtp-id': '', + timestamp: 1_600_112_492 + } ].to_json + "\r\n" # Be sure to include the trailing carriage return and newline! end end diff --git a/spec/rack/sendgrid_webhook_verification_spec.rb b/spec/rack/sendgrid_webhook_verification_spec.rb index 4cd45604..11bfd0b1 100644 --- a/spec/rack/sendgrid_webhook_verification_spec.rb +++ b/spec/rack/sendgrid_webhook_verification_spec.rb @@ -12,19 +12,19 @@ describe 'new' do it 'should initialize with an app, public key and a path' do expect do - Rack::SendGridWebhookVerification.new(@app, 'ABC', /\/email/) + Rack::SendGridWebhookVerification.new(@app, 'ABC', %r{/email}) end.not_to raise_error end it 'should initialize with an app, public key and paths' do expect do - Rack::SendGridWebhookVerification.new(@app, 'ABC', /\/email/, /\/event/) + Rack::SendGridWebhookVerification.new(@app, 'ABC', %r{/email}, %r{/event}) end.not_to raise_error end end describe 'calling against one path' do - let(:middleware) { Rack::SendGridWebhookVerification.new(@app, public_key, /\/email/) } + let(:middleware) { Rack::SendGridWebhookVerification.new(@app, public_key, %r{/email}) } it "should not intercept when the path doesn't match" do expect(SendGrid::EventWebhook).to_not receive(:new) @@ -81,7 +81,7 @@ end describe 'calling with multiple paths' do - let(:middleware) { Rack::SendGridWebhookVerification.new(@app, public_key, /\/email/, /\/events/) } + let(:middleware) { Rack::SendGridWebhookVerification.new(@app, public_key, %r{/email}, %r{/events}) } it "should not intercept when the path doesn't match" do expect(SendGrid::EventWebhook).to_not receive(:new) diff --git a/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb b/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb index 32d39950..1d928e82 100644 --- a/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb +++ b/spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb @@ -6,77 +6,79 @@ it 'verifies a valid signature' do unless skip_jruby expect(verify( - Fixtures::EventWebhook::PUBLIC_KEY, - Fixtures::EventWebhook::PAYLOAD, - Fixtures::EventWebhook::SIGNATURE, - Fixtures::EventWebhook::TIMESTAMP - )).to be true + Fixtures::EventWebhook::PUBLIC_KEY, + Fixtures::EventWebhook::PAYLOAD, + Fixtures::EventWebhook::SIGNATURE, + Fixtures::EventWebhook::TIMESTAMP + )).to be true end end it 'rejects a bad key' do unless skip_jruby expect(verify( - Fixtures::EventWebhook::FAILING_PUBLIC_KEY, - Fixtures::EventWebhook::PAYLOAD, - Fixtures::EventWebhook::SIGNATURE, - Fixtures::EventWebhook::TIMESTAMP - )).to be false + Fixtures::EventWebhook::FAILING_PUBLIC_KEY, + Fixtures::EventWebhook::PAYLOAD, + Fixtures::EventWebhook::SIGNATURE, + Fixtures::EventWebhook::TIMESTAMP + )).to be false end end it 'rejects a bad payload' do unless skip_jruby expect(verify( - Fixtures::EventWebhook::PUBLIC_KEY, - 'payload', - Fixtures::EventWebhook::SIGNATURE, - Fixtures::EventWebhook::TIMESTAMP - )).to be false + Fixtures::EventWebhook::PUBLIC_KEY, + 'payload', + Fixtures::EventWebhook::SIGNATURE, + Fixtures::EventWebhook::TIMESTAMP + )).to be false end end it 'rejects a bad signature' do unless skip_jruby expect(verify( - Fixtures::EventWebhook::PUBLIC_KEY, - Fixtures::EventWebhook::PAYLOAD, - Fixtures::EventWebhook::FAILING_SIGNATURE, - Fixtures::EventWebhook::TIMESTAMP - )).to be false + Fixtures::EventWebhook::PUBLIC_KEY, + Fixtures::EventWebhook::PAYLOAD, + Fixtures::EventWebhook::FAILING_SIGNATURE, + Fixtures::EventWebhook::TIMESTAMP + )).to be false end end it 'rejects a bad timestamp' do unless skip_jruby expect(verify( - Fixtures::EventWebhook::PUBLIC_KEY, - Fixtures::EventWebhook::PAYLOAD, - Fixtures::EventWebhook::SIGNATURE, - 'timestamp' - )).to be false + Fixtures::EventWebhook::PUBLIC_KEY, + Fixtures::EventWebhook::PAYLOAD, + Fixtures::EventWebhook::SIGNATURE, + 'timestamp' + )).to be false end end it 'rejects a missing signature' do unless skip_jruby expect(verify( - Fixtures::EventWebhook::PUBLIC_KEY, - Fixtures::EventWebhook::PAYLOAD, - nil, - Fixtures::EventWebhook::TIMESTAMP - )).to be false + Fixtures::EventWebhook::PUBLIC_KEY, + Fixtures::EventWebhook::PAYLOAD, + nil, + Fixtures::EventWebhook::TIMESTAMP + )).to be false end end it 'throws an error when using jruby' do if skip_jruby - expect{ verify( - Fixtures::EventWebhook::PUBLIC_KEY, - Fixtures::EventWebhook::PAYLOAD, - Fixtures::EventWebhook::SIGNATURE, - Fixtures::EventWebhook::TIMESTAMP - )}.to raise_error(SendGrid::EventWebhook::NotSupportedError) + expect do + verify( + Fixtures::EventWebhook::PUBLIC_KEY, + Fixtures::EventWebhook::PAYLOAD, + Fixtures::EventWebhook::SIGNATURE, + Fixtures::EventWebhook::TIMESTAMP + ) + end .to raise_error(SendGrid::EventWebhook::NotSupportedError) end end end diff --git a/spec/sendgrid/helpers/settings/settings_spec.rb b/spec/sendgrid/helpers/settings/settings_spec.rb index 543ebc89..640be2a3 100644 --- a/spec/sendgrid/helpers/settings/settings_spec.rb +++ b/spec/sendgrid/helpers/settings/settings_spec.rb @@ -18,7 +18,7 @@ describe '.update_bcc' do it 'updates bcc' do - bcc_response = settings.update_bcc(enabled: true, email: "email@example.com") + bcc_response = settings.update_bcc(enabled: true, email: 'email@example.com') expect(bcc_response).to be_a SendGrid::Response end end diff --git a/spec/sendgrid/helpers/stats/email_stats_spec.rb b/spec/sendgrid/helpers/stats/email_stats_spec.rb index 8c8cba0f..e9c6c633 100644 --- a/spec/sendgrid/helpers/stats/email_stats_spec.rb +++ b/spec/sendgrid/helpers/stats/email_stats_spec.rb @@ -7,26 +7,26 @@ let(:sample_response) do [{ - "date" => "2017-10-01", - "stats" => [ - { "metrics" => + 'date' => '2017-10-01', + 'stats' => [ + { 'metrics' => { - "blocks" => 101, - "bounce_drops" => 102, - "bounces" => 103, - "clicks" => 104, - "deferred" => 105, - "delivered" => 106, - "invalid_emails" => 107, - "opens" => 108, - "processed" => 109, - "requests" => 110, - "spam_report_drops" => 111, - "spam_reports" => 112, - "unique_clicks" => 113, - "unique_opens" => 114, - "unsubscribe_drops" => 115, - "unsubscribes" => 116 + 'blocks' => 101, + 'bounce_drops' => 102, + 'bounces' => 103, + 'clicks' => 104, + 'deferred' => 105, + 'delivered' => 106, + 'invalid_emails' => 107, + 'opens' => 108, + 'processed' => 109, + 'requests' => 110, + 'spam_report_drops' => 111, + 'spam_reports' => 112, + 'unique_clicks' => 113, + 'unique_opens' => 114, + 'unsubscribe_drops' => 115, + 'unsubscribes' => 116 } } ] }] @@ -34,9 +34,9 @@ let(:error_response) do { - "errors" => [ + 'errors' => [ { - "message" => "end_date should be a YYYY-MM-DD formatted date" + 'message' => 'end_date should be a YYYY-MM-DD formatted date' } ] } diff --git a/spec/sendgrid/helpers/stats/metrics_spec.rb b/spec/sendgrid/helpers/stats/metrics_spec.rb index fb53b7e8..b7a121b4 100644 --- a/spec/sendgrid/helpers/stats/metrics_spec.rb +++ b/spec/sendgrid/helpers/stats/metrics_spec.rb @@ -3,23 +3,23 @@ describe SendGrid::Metrics do let(:params) do { - "date" => "2017-10-01", - "blocks" => 101, - "bounce_drops" => 102, - "bounces" => 103, - "clicks" => 104, - "deferred" => 105, - "delivered" => 106, - "invalid_emails" => 107, - "opens" => 108, - "processed" => 109, - "requests" => 110, - "spam_report_drops" => 111, - "spam_reports" => 112, - "unique_clicks" => 113, - "unique_opens" => 114, - "unsubscribe_drops" => 115, - "unsubscribes" => 116 + 'date' => '2017-10-01', + 'blocks' => 101, + 'bounce_drops' => 102, + 'bounces' => 103, + 'clicks' => 104, + 'deferred' => 105, + 'delivered' => 106, + 'invalid_emails' => 107, + 'opens' => 108, + 'processed' => 109, + 'requests' => 110, + 'spam_report_drops' => 111, + 'spam_reports' => 112, + 'unique_clicks' => 113, + 'unique_opens' => 114, + 'unsubscribe_drops' => 115, + 'unsubscribes' => 116 } end diff --git a/spec/sendgrid/helpers/stats/stats_response_spec.rb b/spec/sendgrid/helpers/stats/stats_response_spec.rb index d6a3d30d..c3b99cbe 100644 --- a/spec/sendgrid/helpers/stats/stats_response_spec.rb +++ b/spec/sendgrid/helpers/stats/stats_response_spec.rb @@ -3,26 +3,26 @@ describe SendGrid::StatsResponse do let(:params) do [{ - "date" => "2017-10-01", - "stats" => [ - { "metrics" => + 'date' => '2017-10-01', + 'stats' => [ + { 'metrics' => { - "blocks" => 101, - "bounce_drops" => 102, - "bounces" => 103, - "clicks" => 104, - "deferred" => 105, - "delivered" => 106, - "invalid_emails" => 107, - "opens" => 108, - "processed" => 109, - "requests" => 110, - "spam_report_drops" => 111, - "spam_reports" => 112, - "unique_clicks" => 113, - "unique_opens" => 114, - "unsubscribe_drops" => 115, - "unsubscribes" => 116 + 'blocks' => 101, + 'bounce_drops' => 102, + 'bounces' => 103, + 'clicks' => 104, + 'deferred' => 105, + 'delivered' => 106, + 'invalid_emails' => 107, + 'opens' => 108, + 'processed' => 109, + 'requests' => 110, + 'spam_report_drops' => 111, + 'spam_reports' => 112, + 'unique_clicks' => 113, + 'unique_opens' => 114, + 'unsubscribe_drops' => 115, + 'unsubscribes' => 116 } } ] }] @@ -50,9 +50,9 @@ context 'errors' do let(:error_params) do { - "errors" => [ + 'errors' => [ { - "message" => "end_date should be a YYYY-MM-DD formatted date" + 'message' => 'end_date should be a YYYY-MM-DD formatted date' } ] } diff --git a/test/sendgrid/helpers/mail/test_attachment.rb b/test/sendgrid/helpers/mail/test_attachment.rb index f66ebb16..0fecca00 100644 --- a/test/sendgrid/helpers/mail/test_attachment.rb +++ b/test/sendgrid/helpers/mail/test_attachment.rb @@ -1,19 +1,17 @@ -# coding: utf-8 require_relative "../../../../lib/sendgrid/helpers/mail/attachment" include SendGrid require "json" require "minitest/autorun" class TestAttachment < Minitest::Test - SAMPLE_INPUT = """Es blüht so grün wie Blüten blüh'n im Frühling + SAMPLE_INPUT = "Es blüht so grün wie Blüten blüh'n im Frühling Es blüht so grün wie Blüten blüh'n im Frühling Es blüht so grün wie Blüten blüh'n im Frühling Es blüht so grün wie Blüten blüh'n im Frühling Es blüht so grün wie Blüten blüh'n im Frühling -""".force_encoding('UTF-8').encode - - def setup - end +".force_encoding('UTF-8').encode + + def setup; end def test_io_enocding attachment = Attachment.new diff --git a/test/sendgrid/helpers/mail/test_email.rb b/test/sendgrid/helpers/mail/test_email.rb index 182c0d03..28f5c2ce 100644 --- a/test/sendgrid/helpers/mail/test_email.rb +++ b/test/sendgrid/helpers/mail/test_email.rb @@ -5,27 +5,27 @@ class TestEmail < Minitest::Test include SendGrid def test_split_email_full_email - @email = Email.new(email: "Example User ") + @email = Email.new(email: 'Example User ') expected_json = { - "email" => "test1@example.com", - "name" => "Example User" + 'email' => 'test1@example.com', + 'name' => 'Example User' } assert_equal @email.to_json, expected_json end def test_split_email_only_email - @email = Email.new(email: "test1@example.com") + @email = Email.new(email: 'test1@example.com') expected_json = { - "email" => "test1@example.com" + 'email' => 'test1@example.com' } assert_equal @email.to_json, expected_json end def test_split_email_name_and_email - @email = Email.new(name: "Example User", email: "test1@example.com") + @email = Email.new(name: 'Example User', email: 'test1@example.com') expected_json = { - "email" => "test1@example.com", - "name" => "Example User" + 'email' => 'test1@example.com', + 'name' => 'Example User' } assert_equal @email.to_json, expected_json end diff --git a/test/sendgrid/helpers/mail/test_mail.rb b/test/sendgrid/helpers/mail/test_mail.rb index e63b2d4a..ec44153a 100644 --- a/test/sendgrid/helpers/mail/test_mail.rb +++ b/test/sendgrid/helpers/mail/test_mail.rb @@ -1,7 +1,7 @@ -require_relative "../../../../lib/sendgrid/helpers/mail/mail" -require_relative "../../../../lib/sendgrid/sendgrid" +require_relative '../../../../lib/sendgrid/helpers/mail/mail' +require_relative '../../../../lib/sendgrid/sendgrid' include SendGrid -require "json" +require 'json' require 'minitest/autorun' class TestMail < Minitest::Test @@ -19,100 +19,100 @@ def test_hello_world def test_kitchen_sink mail = SendGrid::Mail.new - mail.from = Email.new(email: "test@example.com") - mail.subject = "Hello World from the Twilio SendGrid Ruby Library" + mail.from = Email.new(email: 'test@example.com') + mail.subject = 'Hello World from the Twilio SendGrid Ruby Library' personalization = Personalization.new - personalization.add_to(Email.new(email: "test@example.com", name: "Example User")) - personalization.add_to(Email.new(email: "test@example.com", name: "Example User")) - personalization.add_cc(Email.new(email: "test@example.com", name: "Example User")) - personalization.add_cc(Email.new(email: "test@example.com", name: "Example User")) - personalization.add_bcc(Email.new(email: "test@example.com", name: "Example User")) - personalization.add_bcc(Email.new(email: "test@example.com", name: "Example User")) - personalization.subject = "Hello World from the Personalized Twilio SendGrid Ruby Library" - personalization.add_header(Header.new(key: "X-Test", value: "True")) - personalization.add_header(Header.new(key: "X-Mock", value: "False")) - personalization.add_substitution(Substitution.new(key: "%name%", value: "Example User")) - personalization.add_substitution(Substitution.new(key: "%city%", value: "Denver")) - personalization.add_custom_arg(CustomArg.new(key: "user_id", value: "343")) - personalization.add_custom_arg(CustomArg.new(key: "type", value: "marketing")) - personalization.send_at = 1443636843 + personalization.add_to(Email.new(email: 'test@example.com', name: 'Example User')) + personalization.add_to(Email.new(email: 'test@example.com', name: 'Example User')) + personalization.add_cc(Email.new(email: 'test@example.com', name: 'Example User')) + personalization.add_cc(Email.new(email: 'test@example.com', name: 'Example User')) + personalization.add_bcc(Email.new(email: 'test@example.com', name: 'Example User')) + personalization.add_bcc(Email.new(email: 'test@example.com', name: 'Example User')) + personalization.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library' + personalization.add_header(Header.new(key: 'X-Test', value: 'True')) + personalization.add_header(Header.new(key: 'X-Mock', value: 'False')) + personalization.add_substitution(Substitution.new(key: '%name%', value: 'Example User')) + personalization.add_substitution(Substitution.new(key: '%city%', value: 'Denver')) + personalization.add_custom_arg(CustomArg.new(key: 'user_id', value: '343')) + personalization.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing')) + personalization.send_at = 1_443_636_843 mail.add_personalization(personalization) personalization2 = Personalization.new - personalization2.add_to(Email.new(email: "test@example.com", name: "Example User")) - personalization2.add_to(Email.new(email: "test@example.com", name: "Example User")) - personalization2.add_cc(Email.new(email: "test@example.com", name: "Example User")) - personalization2.add_cc(Email.new(email: "test@example.com", name: "Example User")) - personalization2.add_bcc(Email.new(email: "test@example.com", name: "Example User")) - personalization2.add_bcc(Email.new(email: "test@example.com", name: "Example User")) - personalization2.subject = "Hello World from the Personalized Twilio SendGrid Ruby Library" - personalization2.add_header(Header.new(key: "X-Test", value: "True")) - personalization2.add_header(Header.new(key: "X-Mock", value: "False")) - personalization2.add_substitution(Substitution.new(key: "%name%", value: "Example User")) - personalization2.add_substitution(Substitution.new(key: "%city%", value: "Denver")) - personalization2.add_custom_arg(CustomArg.new(key: "user_id", value: "343")) - personalization2.add_custom_arg(CustomArg.new(key: "type", value: "marketing")) - personalization2.send_at = 1443636843 + personalization2.add_to(Email.new(email: 'test@example.com', name: 'Example User')) + personalization2.add_to(Email.new(email: 'test@example.com', name: 'Example User')) + personalization2.add_cc(Email.new(email: 'test@example.com', name: 'Example User')) + personalization2.add_cc(Email.new(email: 'test@example.com', name: 'Example User')) + personalization2.add_bcc(Email.new(email: 'test@example.com', name: 'Example User')) + personalization2.add_bcc(Email.new(email: 'test@example.com', name: 'Example User')) + personalization2.subject = 'Hello World from the Personalized Twilio SendGrid Ruby Library' + personalization2.add_header(Header.new(key: 'X-Test', value: 'True')) + personalization2.add_header(Header.new(key: 'X-Mock', value: 'False')) + personalization2.add_substitution(Substitution.new(key: '%name%', value: 'Example User')) + personalization2.add_substitution(Substitution.new(key: '%city%', value: 'Denver')) + personalization2.add_custom_arg(CustomArg.new(key: 'user_id', value: '343')) + personalization2.add_custom_arg(CustomArg.new(key: 'type', value: 'marketing')) + personalization2.send_at = 1_443_636_843 mail.add_personalization(personalization2) - mail.add_content(Content.new(type: "text/plain", value: "some text here")) - mail.add_content(Content.new(type: "text/html", value: "some text here")) + mail.add_content(Content.new(type: 'text/plain', value: 'some text here')) + mail.add_content(Content.new(type: 'text/html', value: 'some text here')) attachment = Attachment.new - attachment.content = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12" - attachment.type = "application/pdf" - attachment.filename = "balance_001.pdf" - attachment.disposition = "attachment" - attachment.content_id = "Balance Sheet" + attachment.content = 'TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12' + attachment.type = 'application/pdf' + attachment.filename = 'balance_001.pdf' + attachment.disposition = 'attachment' + attachment.content_id = 'Balance Sheet' mail.add_attachment(attachment) attachment2 = Attachment.new - attachment2.content = "BwdW" - attachment2.type = "image/png" - attachment2.filename = "banner.png" - attachment2.disposition = "inline" - attachment2.content_id = "Banner" + attachment2.content = 'BwdW' + attachment2.type = 'image/png' + attachment2.filename = 'banner.png' + attachment2.disposition = 'inline' + attachment2.content_id = 'Banner' mail.add_attachment(attachment2) - mail.template_id = "13b8f94f-bcae-4ec6-b752-70d6cb59f932" + mail.template_id = '13b8f94f-bcae-4ec6-b752-70d6cb59f932' - mail.add_section(Section.new(key: "%section1%", value: "Substitution Text for Section 1")) - mail.add_section(Section.new(key: "%section2%", value: "Substitution Text for Section 2")) + mail.add_section(Section.new(key: '%section1%', value: 'Substitution Text for Section 1')) + mail.add_section(Section.new(key: '%section2%', value: 'Substitution Text for Section 2')) - mail.add_header(Header.new(key: "X-Test3", value: "test3")) - mail.add_header(Header.new(key: "X-Test4", value: "test4")) + mail.add_header(Header.new(key: 'X-Test3', value: 'test3')) + mail.add_header(Header.new(key: 'X-Test4', value: 'test4')) - mail.add_category(Category.new(name: "May")) - mail.add_category(Category.new(name: "2016")) + mail.add_category(Category.new(name: 'May')) + mail.add_category(Category.new(name: '2016')) - mail.add_custom_arg(CustomArg.new(key: "campaign", value: "welcome")) - mail.add_custom_arg(CustomArg.new(key: "weekday", value: "morning")) + mail.add_custom_arg(CustomArg.new(key: 'campaign', value: 'welcome')) + mail.add_custom_arg(CustomArg.new(key: 'weekday', value: 'morning')) - mail.send_at = 1443636842 + mail.send_at = 1_443_636_842 - mail.batch_id = "sendgrid_batch_id" + mail.batch_id = 'sendgrid_batch_id' mail.asm = ASM.new(group_id: 99, groups_to_display: [4, 5, 6, 7, 8]) - mail.ip_pool_name = "23" + mail.ip_pool_name = '23' mail_settings = MailSettings.new - mail_settings.bcc = BccSettings.new(enable: true, email: "test@example.com") + mail_settings.bcc = BccSettings.new(enable: true, email: 'test@example.com') mail_settings.bypass_list_management = BypassListManagement.new(enable: true) - mail_settings.footer = Footer.new(enable: true, text: "Footer Text", html: "Footer Text") + mail_settings.footer = Footer.new(enable: true, text: 'Footer Text', html: 'Footer Text') mail_settings.sandbox_mode = SandBoxMode.new(enable: true) - mail_settings.spam_check = SpamCheck.new(enable: true, threshold: 1, post_to_url: "https://spamcatcher.sendgrid.com") + mail_settings.spam_check = SpamCheck.new(enable: true, threshold: 1, post_to_url: 'https://spamcatcher.sendgrid.com') mail.mail_settings = mail_settings tracking_settings = TrackingSettings.new tracking_settings.click_tracking = ClickTracking.new(enable: false, enable_text: false) - tracking_settings.open_tracking = OpenTracking.new(enable: true, substitution_tag: "Optional tag to replace with the open image in the body of the message") - tracking_settings.subscription_tracking = SubscriptionTracking.new(enable: true, text: "text to insert into the text/plain portion of the message", html: "html to insert into the text/html portion of the message", substitution_tag: "Optional tag to replace with the open image in the body of the message") - tracking_settings.ganalytics = Ganalytics.new(enable: true, utm_source: "some source", utm_medium: "some medium", utm_term: "some term", utm_content: "some content", utm_campaign: "some campaign") + tracking_settings.open_tracking = OpenTracking.new(enable: true, substitution_tag: 'Optional tag to replace with the open image in the body of the message') + tracking_settings.subscription_tracking = SubscriptionTracking.new(enable: true, text: 'text to insert into the text/plain portion of the message', html: 'html to insert into the text/html portion of the message', substitution_tag: 'Optional tag to replace with the open image in the body of the message') + tracking_settings.ganalytics = Ganalytics.new(enable: true, utm_source: 'some source', utm_medium: 'some medium', utm_term: 'some term', utm_content: 'some content', utm_campaign: 'some campaign') mail.tracking_settings = tracking_settings - mail.reply_to = Email.new(email: "test@example.com") + mail.reply_to = Email.new(email: 'test@example.com') assert_equal(mail.to_json, JSON.parse('{"asm":{"group_id":99,"groups_to_display":[4,5,6,7,8]},"attachments":[{"content":"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12","content_id":"Balance Sheet","disposition":"attachment","filename":"balance_001.pdf","type":"application/pdf"},{"content":"BwdW","content_id":"Banner","disposition":"inline","filename":"banner.png","type":"image/png"}],"batch_id":"sendgrid_batch_id","categories":["May","2016"],"content":[{"type":"text/plain","value":"some text here"},{"type":"text/html","value":"some text here"}],"custom_args":{"campaign":"welcome","weekday":"morning"},"from":{"email":"test@example.com"},"headers":{"X-Test3":"test3","X-Test4":"test4"},"ip_pool_name":"23","mail_settings":{"bcc":{"email":"test@example.com","enable":true},"bypass_list_management":{"enable":true},"footer":{"enable":true,"html":"Footer Text","text":"Footer Text"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"post_to_url":"https://spamcatcher.sendgrid.com","threshold":1}},"personalizations":[{"bcc":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}],"cc":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}],"custom_args":{"type":"marketing","user_id":"343"},"headers":{"X-Mock":"False","X-Test":"True"},"send_at":1443636843,"subject":"Hello World from the Personalized Twilio SendGrid Ruby Library","substitutions":{"%city%":"Denver","%name%":"Example User"},"to":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}]},{"bcc":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}],"cc":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}],"custom_args":{"type":"marketing","user_id":"343"},"headers":{"X-Mock":"False","X-Test":"True"},"send_at":1443636843,"subject":"Hello World from the Personalized Twilio SendGrid Ruby Library","substitutions":{"%city%":"Denver","%name%":"Example User"},"to":[{"email":"test@example.com","name":"Example User"},{"email":"test@example.com","name":"Example User"}]}],"reply_to":{"email":"test@example.com"},"sections":{"%section1%":"Substitution Text for Section 1","%section2%":"Substitution Text for Section 2"},"send_at":1443636842,"subject":"Hello World from the Twilio SendGrid Ruby Library","template_id":"13b8f94f-bcae-4ec6-b752-70d6cb59f932","tracking_settings":{"click_tracking":{"enable":false,"enable_text":false},"ganalytics":{"enable":true,"utm_campaign":"some campaign","utm_content":"some content","utm_medium":"some medium","utm_source":"some source","utm_term":"some term"},"open_tracking":{"enable":true,"substitution_tag":"Optional tag to replace with the open image in the body of the message"},"subscription_tracking":{"enable":true,"html":"html to insert into the text/html portion of the message","substitution_tag":"Optional tag to replace with the open image in the body of the message","text":"text to insert into the text/plain portion of the message"}}}')) end @@ -153,16 +153,16 @@ def test_add_section mail = SendGrid::Mail.new mail.add_section(Section.new(key: '%section1%', value: 'Substitution Text for Section 1')) expected_json = { - "sections" => { - "%section1%" => "Substitution Text for Section 1" + 'sections' => { + '%section1%' => 'Substitution Text for Section 1' } } assert_equal mail.to_json, expected_json mail.add_section(Section.new(key: '%section2%', value: 'Substitution Text for Section 2')) expected_json = { - "sections" => { - "%section1%" => "Substitution Text for Section 1", - "%section2%" => "Substitution Text for Section 2" + 'sections' => { + '%section1%' => 'Substitution Text for Section 1', + '%section2%' => 'Substitution Text for Section 2' } } assert_equal mail.to_json, expected_json @@ -172,16 +172,16 @@ def test_add_header mail = SendGrid::Mail.new mail.add_header(Header.new(key: 'X-Test3', value: 'test3')) expected_json = { - "headers" => { - "X-Test3" => "test3" + 'headers' => { + 'X-Test3' => 'test3' } } assert_equal mail.to_json, expected_json mail.add_header(Header.new(key: 'X-Test4', value: 'test4')) expected_json = { - "headers" => { - "X-Test3" => "test3", - "X-Test4" => "test4" + 'headers' => { + 'X-Test3' => 'test3', + 'X-Test4' => 'test4' } } assert_equal mail.to_json, expected_json @@ -191,16 +191,16 @@ def test_add_custom_arg mail = SendGrid::Mail.new mail.add_custom_arg(CustomArg.new(key: 'campaign 1', value: 'welcome 1')) expected_json = { - "custom_args" => { - "campaign 1" => "welcome 1" + 'custom_args' => { + 'campaign 1' => 'welcome 1' } } assert_equal mail.to_json, expected_json mail.add_custom_arg(CustomArg.new(key: 'campaign 2', value: 'welcome 2')) expected_json = { - "custom_args" => { - "campaign 1" => "welcome 1", - "campaign 2" => "welcome 2" + 'custom_args' => { + 'campaign 1' => 'welcome 1', + 'campaign 2' => 'welcome 2' } } assert_equal mail.to_json, expected_json @@ -208,14 +208,14 @@ def test_add_custom_arg def test_add_non_string_custom_arg mail = Mail.new - mail.add_custom_arg(CustomArg.new(key: "Integer", value: 1)) - mail.add_custom_arg(CustomArg.new(key: "Array", value: [1, "a", true])) - mail.add_custom_arg(CustomArg.new(key: "Hash", value: { "a" => 1, "b" => 2 })) + mail.add_custom_arg(CustomArg.new(key: 'Integer', value: 1)) + mail.add_custom_arg(CustomArg.new(key: 'Array', value: [1, 'a', true])) + mail.add_custom_arg(CustomArg.new(key: 'Hash', value: { 'a' => 1, 'b' => 2 })) expected_json = { - "custom_args" => { - "Integer" => "1", - "Array" => "[1, \"a\", true]", - "Hash" => "{\"a\"=>1, \"b\"=>2}" + 'custom_args' => { + 'Integer' => '1', + 'Array' => '[1, "a", true]', + 'Hash' => '{"a"=>1, "b"=>2}' } } assert_equal mail.to_json, expected_json @@ -236,11 +236,9 @@ def test_add_valid_category def test_add_more_than_1_valid_category mail = SendGrid::Mail.new - category_1 = Category.new(name: 'foo') - category_2 = Category.new(name: 'bar') - mail.add_category(category_1) - mail.add_category(category_2) - assert_equal(['foo', 'bar'], mail.categories) + mail.add_category(Category.new(name: 'foo')) + mail.add_category(Category.new(name: 'bar')) + assert_equal(%w[foo bar], mail.categories) end def test_add_invalid_category diff --git a/test/sendgrid/helpers/mail/test_personalizations.rb b/test/sendgrid/helpers/mail/test_personalizations.rb index b6517e86..3b8c0efe 100644 --- a/test/sendgrid/helpers/mail/test_personalizations.rb +++ b/test/sendgrid/helpers/mail/test_personalizations.rb @@ -9,14 +9,14 @@ def test_add_to @personalization.add_to(Email.new(email: 'test1@example.com', name: 'Example User')) @personalization.add_to(Email.new(email: 'test2@example.com', name: 'Example User 2')) expected_json = { - "to" => [ + 'to' => [ { - "email" => "test1@example.com", - "name" => "Example User" + 'email' => 'test1@example.com', + 'name' => 'Example User' }, { - "email" => "test2@example.com", - "name" => "Example User 2" + 'email' => 'test2@example.com', + 'name' => 'Example User 2' } ] } @@ -28,14 +28,14 @@ def test_add_cc @personalization.add_cc(Email.new(email: 'test1@example.com', name: 'Example User')) @personalization.add_cc(Email.new(email: 'test2@example.com', name: 'Example User 2')) expected_json = { - "cc" => [ + 'cc' => [ { - "email" => "test1@example.com", - "name" => "Example User" + 'email' => 'test1@example.com', + 'name' => 'Example User' }, { - "email" => "test2@example.com", - "name" => "Example User 2" + 'email' => 'test2@example.com', + 'name' => 'Example User 2' } ] } @@ -47,14 +47,14 @@ def test_add_bcc @personalization.add_bcc(Email.new(email: 'test1@example.com', name: 'Example User')) @personalization.add_bcc(Email.new(email: 'test2@example.com', name: 'Example User 2')) expected_json = { - "bcc" => [ + 'bcc' => [ { - "email" => "test1@example.com", - "name" => "Example User" + 'email' => 'test1@example.com', + 'name' => 'Example User' }, { - "email" => "test2@example.com", - "name" => "Example User 2" + 'email' => 'test2@example.com', + 'name' => 'Example User 2' } ] } @@ -65,16 +65,16 @@ def test_add_header @personalization = Personalization.new @personalization.add_header(Header.new(key: 'X-Test', value: 'True')) expected_json = { - "headers" => { - "X-Test" => "True" + 'headers' => { + 'X-Test' => 'True' } } assert_equal @personalization.to_json, expected_json @personalization.add_header(Header.new(key: 'X-Test 1', value: 'False')) expected_json = { - "headers" => { - "X-Test" => "True", - "X-Test 1" => "False" + 'headers' => { + 'X-Test' => 'True', + 'X-Test 1' => 'False' } } assert_equal @personalization.to_json, expected_json @@ -84,16 +84,16 @@ def test_add_substitution @personalization = Personalization.new @personalization.add_substitution(Substitution.new(key: '%name%', value: 'Example User')) expected_json = { - "substitutions" => { - "%name%" => "Example User" + 'substitutions' => { + '%name%' => 'Example User' } } assert_equal @personalization.to_json, expected_json @personalization.add_substitution(Substitution.new(key: '%name 1%', value: 'Example User 1')) expected_json = { - "substitutions" => { - "%name%" => "Example User", - "%name 1%" => "Example User 1" + 'substitutions' => { + '%name%' => 'Example User', + '%name 1%' => 'Example User 1' } } assert_equal @personalization.to_json, expected_json @@ -103,16 +103,16 @@ def test_add_custom_arg @personalization = Personalization.new @personalization.add_custom_arg(CustomArg.new(key: 'user_id', value: '343')) expected_json = { - "custom_args" => { - "user_id" => "343" + 'custom_args' => { + 'user_id' => '343' } } assert_equal @personalization.to_json, expected_json @personalization.add_custom_arg(CustomArg.new(key: 'city', value: 'denver')) expected_json = { - "custom_args" => { - "user_id" => "343", - "city" => "denver" + 'custom_args' => { + 'user_id' => '343', + 'city' => 'denver' } } assert_equal @personalization.to_json, expected_json @@ -121,13 +121,13 @@ def test_add_custom_arg def test_add_dynamic_template_data @personalization = Personalization.new @personalization.add_dynamic_template_data( - "name" => "Example User", - "city" => "Denver" + 'name' => 'Example User', + 'city' => 'Denver' ) expected_json = { - "dynamic_template_data" => { - "name" => "Example User", - "city" => "Denver" + 'dynamic_template_data' => { + 'name' => 'Example User', + 'city' => 'Denver' } } assert_equal @personalization.to_json, expected_json diff --git a/test/sendgrid/permissions/test_scopes.rb b/test/sendgrid/permissions/test_scopes.rb index 2d5eefb3..a299ce25 100644 --- a/test/sendgrid/permissions/test_scopes.rb +++ b/test/sendgrid/permissions/test_scopes.rb @@ -2,7 +2,6 @@ require 'minitest/autorun' class TestCategory < Minitest::Test - include SendGrid # usecases @@ -34,5 +33,4 @@ def test_read_only_and_full_access_from_file assert_equal Scope.send("#{endpoint}_full_access_permissions"), @scopes_from_yaml[endpoint].values.flatten end end - end diff --git a/test/sendgrid/test_sendgrid-ruby.rb b/test/sendgrid/test_sendgrid-ruby.rb index e5357174..a0ef10e4 100644 --- a/test/sendgrid/test_sendgrid-ruby.rb +++ b/test/sendgrid/test_sendgrid-ruby.rb @@ -6,46 +6,45 @@ require 'minitest/unit' class TestAPI < MiniTest::Test - - def setup - @sg = SendGrid::API.new(api_key: "SENDGRID_API_KEY") - end - - def test_init - headers = JSON.parse(' - { - "X-Test": "test" - } - ') - subuser = 'test_user' - sg = SendGrid::API.new(api_key: "SENDGRID_API_KEY", host: "https://api.test.com", request_headers: headers, version: "v3", impersonate_subuser: subuser) - - assert_equal("https://api.test.com", sg.host) - user_agent = "sendgrid/#{SendGrid::VERSION};ruby" - test_headers = JSON.parse(' - { - "Authorization": "Bearer SENDGRID_API_KEY", - "Accept": "application/json", - "X-Test": "test", - "User-Agent": "' + user_agent + '", - "On-Behalf-Of": "' + subuser + '" - } - ') - assert_equal(test_headers, sg.request_headers) - assert_equal("v3", sg.version) - assert_equal(subuser, sg.impersonate_subuser) - assert_equal("6.3.4", SendGrid::VERSION) - assert_instance_of(SendGrid::Client, sg.client) - end - - def test_init_when_impersonate_subuser_is_not_given - sg = SendGrid::API.new(api_key: "SENDGRID_API_KEY", host: "https://api.test.com", version: "v3") - refute_includes(sg.request_headers, 'On-Behalf-Of') - end - - def test_access_settings_activity_get - params = JSON.parse('{"limit": 1}') - headers = JSON.parse('{"X-Mock": 200}') + def setup + @sg = SendGrid::API.new(api_key: 'SENDGRID_API_KEY') + end + + def test_init + headers = JSON.parse(' + { + "X-Test": "test" + } + ') + subuser = 'test_user' + sg = SendGrid::API.new(api_key: 'SENDGRID_API_KEY', host: 'https://api.test.com', request_headers: headers, version: 'v3', impersonate_subuser: subuser) + + assert_equal('https://api.test.com', sg.host) + user_agent = "sendgrid/#{SendGrid::VERSION};ruby" + test_headers = JSON.parse(' + { + "Authorization": "Bearer SENDGRID_API_KEY", + "Accept": "application/json", + "X-Test": "test", + "User-Agent": "' + user_agent + '", + "On-Behalf-Of": "' + subuser + '" + } + ') + assert_equal(test_headers, sg.request_headers) + assert_equal('v3', sg.version) + assert_equal(subuser, sg.impersonate_subuser) + assert_equal('6.3.4', SendGrid::VERSION) + assert_instance_of(SendGrid::Client, sg.client) + end + + def test_init_when_impersonate_subuser_is_not_given + sg = SendGrid::API.new(api_key: 'SENDGRID_API_KEY', host: 'https://api.test.com', version: 'v3') + refute_includes(sg.request_headers, 'On-Behalf-Of') + end + + def test_access_settings_activity_get + params = JSON.parse('{"limit": 1}') + headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.access_settings.activity.get(query_params: params, request_headers: headers) @@ -97,7 +96,7 @@ def test_access_settings_whitelist_delete end def test_access_settings_whitelist__rule_id__get - rule_id = "test_url_param" + rule_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.access_settings.whitelist._(rule_id).get(request_headers: headers) @@ -106,7 +105,7 @@ def test_access_settings_whitelist__rule_id__get end def test_access_settings_whitelist__rule_id__delete - rule_id = "test_url_param" + rule_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.access_settings.whitelist._(rule_id).delete(request_headers: headers) @@ -139,7 +138,7 @@ def test_alerts__alert_id__patch data = JSON.parse('{ "email_to": "example@example.com" }') - alert_id = "test_url_param" + alert_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.alerts._(alert_id).patch(request_body: data, request_headers: headers) @@ -148,7 +147,7 @@ def test_alerts__alert_id__patch end def test_alerts__alert_id__get - alert_id = "test_url_param" + alert_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.alerts._(alert_id).get(request_headers: headers) @@ -157,7 +156,7 @@ def test_alerts__alert_id__get end def test_alerts__alert_id__delete - alert_id = "test_url_param" + alert_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.alerts._(alert_id).delete(request_headers: headers) @@ -199,7 +198,7 @@ def test_api_keys__api_key_id__put "user.profile.update" ] }') - api_key_id = "test_url_param" + api_key_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.api_keys._(api_key_id).put(request_body: data, request_headers: headers) @@ -211,7 +210,7 @@ def test_api_keys__api_key_id__patch data = JSON.parse('{ "name": "A New Hope" }') - api_key_id = "test_url_param" + api_key_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.api_keys._(api_key_id).patch(request_body: data, request_headers: headers) @@ -220,7 +219,7 @@ def test_api_keys__api_key_id__patch end def test_api_keys__api_key_id__get - api_key_id = "test_url_param" + api_key_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.api_keys._(api_key_id).get(request_headers: headers) @@ -229,7 +228,7 @@ def test_api_keys__api_key_id__get end def test_api_keys__api_key_id__delete - api_key_id = "test_url_param" + api_key_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.api_keys._(api_key_id).delete(request_headers: headers) @@ -265,7 +264,7 @@ def test_asm_groups__group_id__patch "id": 103, "name": "Item Suggestions" }') - group_id = "test_url_param" + group_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 201}') response = @sg.client.asm.groups._(group_id).patch(request_body: data, request_headers: headers) @@ -274,7 +273,7 @@ def test_asm_groups__group_id__patch end def test_asm_groups__group_id__get - group_id = "test_url_param" + group_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.asm.groups._(group_id).get(request_headers: headers) @@ -283,7 +282,7 @@ def test_asm_groups__group_id__get end def test_asm_groups__group_id__delete - group_id = "test_url_param" + group_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.asm.groups._(group_id).delete(request_headers: headers) @@ -298,7 +297,7 @@ def test_asm_groups__group_id__suppressions_post "test2@example.com" ] }') - group_id = "test_url_param" + group_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 201}') response = @sg.client.asm.groups._(group_id).suppressions.post(request_body: data, request_headers: headers) @@ -307,7 +306,7 @@ def test_asm_groups__group_id__suppressions_post end def test_asm_groups__group_id__suppressions_get - group_id = "test_url_param" + group_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.asm.groups._(group_id).suppressions.get(request_headers: headers) @@ -323,7 +322,7 @@ def test_asm_groups__group_id__suppressions_search_post "doesnotexists@example.com" ] }') - group_id = "test_url_param" + group_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.asm.groups._(group_id).suppressions.search.post(request_body: data, request_headers: headers) @@ -332,8 +331,8 @@ def test_asm_groups__group_id__suppressions_search_post end def test_asm_groups__group_id__suppressions__email__delete - group_id = "test_url_param" - email = "test_url_param" + group_id = 'test_url_param' + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.asm.groups._(group_id).suppressions._(email).delete(request_headers: headers) @@ -364,7 +363,7 @@ def test_asm_suppressions_global_post end def test_asm_suppressions_global__email__get - email = "test_url_param" + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.asm.suppressions.global._(email).get(request_headers: headers) @@ -373,7 +372,7 @@ def test_asm_suppressions_global__email__get end def test_asm_suppressions_global__email__delete - email = "test_url_param" + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.asm.suppressions.global._(email).delete(request_headers: headers) @@ -382,7 +381,7 @@ def test_asm_suppressions_global__email__delete end def test_asm_suppressions__email__get - email = "test_url_param" + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.asm.suppressions._(email).get(request_headers: headers) @@ -446,7 +445,7 @@ def test_campaigns__campaign_id__patch "subject": "New Products for Summer!", "title": "May Newsletter" }') - campaign_id = "test_url_param" + campaign_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.campaigns._(campaign_id).patch(request_body: data, request_headers: headers) @@ -455,7 +454,7 @@ def test_campaigns__campaign_id__patch end def test_campaigns__campaign_id__get - campaign_id = "test_url_param" + campaign_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.campaigns._(campaign_id).get(request_headers: headers) @@ -464,7 +463,7 @@ def test_campaigns__campaign_id__get end def test_campaigns__campaign_id__delete - campaign_id = "test_url_param" + campaign_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.campaigns._(campaign_id).delete(request_headers: headers) @@ -476,7 +475,7 @@ def test_campaigns__campaign_id__schedules_patch data = JSON.parse('{ "send_at": 1489451436 }') - campaign_id = "test_url_param" + campaign_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.campaigns._(campaign_id).schedules.patch(request_body: data, request_headers: headers) @@ -488,7 +487,7 @@ def test_campaigns__campaign_id__schedules_post data = JSON.parse('{ "send_at": 1489771528 }') - campaign_id = "test_url_param" + campaign_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 201}') response = @sg.client.campaigns._(campaign_id).schedules.post(request_body: data, request_headers: headers) @@ -497,7 +496,7 @@ def test_campaigns__campaign_id__schedules_post end def test_campaigns__campaign_id__schedules_get - campaign_id = "test_url_param" + campaign_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.campaigns._(campaign_id).schedules.get(request_headers: headers) @@ -506,7 +505,7 @@ def test_campaigns__campaign_id__schedules_get end def test_campaigns__campaign_id__schedules_delete - campaign_id = "test_url_param" + campaign_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.campaigns._(campaign_id).schedules.delete(request_headers: headers) @@ -515,7 +514,7 @@ def test_campaigns__campaign_id__schedules_delete end def test_campaigns__campaign_id__schedules_now_post - campaign_id = "test_url_param" + campaign_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 201}') response = @sg.client.campaigns._(campaign_id).schedules.now.post(request_headers: headers) @@ -527,7 +526,7 @@ def test_campaigns__campaign_id__schedules_test_post data = JSON.parse('{ "to": "your.email@example.com" }') - campaign_id = "test_url_param" + campaign_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.campaigns._(campaign_id).schedules.test.post(request_body: data, request_headers: headers) @@ -573,7 +572,7 @@ def test_clients_stats_get def test_clients__client_type__stats_get params = JSON.parse('{"aggregated_by": "day", "start_date": "2016-01-01", "end_date": "2016-04-01"}') - client_type = "test_url_param" + client_type = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.clients._(client_type).stats.get(query_params: params, request_headers: headers) @@ -602,7 +601,7 @@ def test_contactdb_custom_fields_get end def test_contactdb_custom_fields__custom_field_id__get - custom_field_id = "test_url_param" + custom_field_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.contactdb.custom_fields._(custom_field_id).get(request_headers: headers) @@ -611,7 +610,7 @@ def test_contactdb_custom_fields__custom_field_id__get end def test_contactdb_custom_fields__custom_field_id__delete - custom_field_id = "test_url_param" + custom_field_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 202}') response = @sg.client.contactdb.custom_fields._(custom_field_id).delete(request_headers: headers) @@ -657,7 +656,7 @@ def test_contactdb_lists__list_id__patch "name": "newlistname" }') params = JSON.parse('{"list_id": 1}') - list_id = "test_url_param" + list_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.contactdb.lists._(list_id).patch(request_body: data, query_params: params, request_headers: headers) @@ -667,7 +666,7 @@ def test_contactdb_lists__list_id__patch def test_contactdb_lists__list_id__get params = JSON.parse('{"list_id": 1}') - list_id = "test_url_param" + list_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.contactdb.lists._(list_id).get(query_params: params, request_headers: headers) @@ -677,7 +676,7 @@ def test_contactdb_lists__list_id__get def test_contactdb_lists__list_id__delete params = JSON.parse('{"delete_contacts": "true"}') - list_id = "test_url_param" + list_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 202}') response = @sg.client.contactdb.lists._(list_id).delete(query_params: params, request_headers: headers) @@ -690,7 +689,7 @@ def test_contactdb_lists__list_id__recipients_post "recipient_id1", "recipient_id2" ]') - list_id = "test_url_param" + list_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 201}') response = @sg.client.contactdb.lists._(list_id).recipients.post(request_body: data, request_headers: headers) @@ -700,7 +699,7 @@ def test_contactdb_lists__list_id__recipients_post def test_contactdb_lists__list_id__recipients_get params = JSON.parse('{"page": 1, "page_size": 1, "list_id": 1}') - list_id = "test_url_param" + list_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.contactdb.lists._(list_id).recipients.get(query_params: params, request_headers: headers) @@ -709,8 +708,8 @@ def test_contactdb_lists__list_id__recipients_get end def test_contactdb_lists__list_id__recipients__recipient_id__post - list_id = "test_url_param" - recipient_id = "test_url_param" + list_id = 'test_url_param' + recipient_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 201}') response = @sg.client.contactdb.lists._(list_id).recipients._(recipient_id).post(request_headers: headers) @@ -720,8 +719,8 @@ def test_contactdb_lists__list_id__recipients__recipient_id__post def test_contactdb_lists__list_id__recipients__recipient_id__delete params = JSON.parse('{"recipient_id": 1, "list_id": 1}') - list_id = "test_url_param" - recipient_id = "test_url_param" + list_id = 'test_url_param' + recipient_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.contactdb.lists._(list_id).recipients._(recipient_id).delete(query_params: params, request_headers: headers) @@ -804,7 +803,7 @@ def test_contactdb_recipients_count_get end def test_contactdb_recipients_search_get - params = { field_name: "test_string" } + params = { field_name: 'test_string' } headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.contactdb.recipients.search.get(query_params: params, request_headers: headers) @@ -813,7 +812,7 @@ def test_contactdb_recipients_search_get end def test_contactdb_recipients__recipient_id__get - recipient_id = "test_url_param" + recipient_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.contactdb.recipients._(recipient_id).get(request_headers: headers) @@ -822,7 +821,7 @@ def test_contactdb_recipients__recipient_id__get end def test_contactdb_recipients__recipient_id__delete - recipient_id = "test_url_param" + recipient_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.contactdb.recipients._(recipient_id).delete(request_headers: headers) @@ -831,7 +830,7 @@ def test_contactdb_recipients__recipient_id__delete end def test_contactdb_recipients__recipient_id__lists_get - recipient_id = "test_url_param" + recipient_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.contactdb.recipients._(recipient_id).lists.get(request_headers: headers) @@ -901,7 +900,7 @@ def test_contactdb_segments__segment_id__patch "name": "The Millers" }') params = JSON.parse('{"segment_id": "test_string"}') - segment_id = "test_url_param" + segment_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.contactdb.segments._(segment_id).patch(request_body: data, query_params: params, request_headers: headers) @@ -911,7 +910,7 @@ def test_contactdb_segments__segment_id__patch def test_contactdb_segments__segment_id__get params = JSON.parse('{"segment_id": 1}') - segment_id = "test_url_param" + segment_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.contactdb.segments._(segment_id).get(query_params: params, request_headers: headers) @@ -921,7 +920,7 @@ def test_contactdb_segments__segment_id__get def test_contactdb_segments__segment_id__delete params = JSON.parse('{"delete_contacts": "true"}') - segment_id = "test_url_param" + segment_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.contactdb.segments._(segment_id).delete(query_params: params, request_headers: headers) @@ -931,7 +930,7 @@ def test_contactdb_segments__segment_id__delete def test_contactdb_segments__segment_id__recipients_get params = JSON.parse('{"page": 1, "page_size": 1}') - segment_id = "test_url_param" + segment_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.contactdb.segments._(segment_id).recipients.get(query_params: params, request_headers: headers) @@ -997,7 +996,7 @@ def test_ips_pools__pool_name__put data = JSON.parse('{ "name": "new_pool_name" }') - pool_name = "test_url_param" + pool_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.ips.pools._(pool_name).put(request_body: data, request_headers: headers) @@ -1006,7 +1005,7 @@ def test_ips_pools__pool_name__put end def test_ips_pools__pool_name__get - pool_name = "test_url_param" + pool_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.ips.pools._(pool_name).get(request_headers: headers) @@ -1015,7 +1014,7 @@ def test_ips_pools__pool_name__get end def test_ips_pools__pool_name__delete - pool_name = "test_url_param" + pool_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.ips.pools._(pool_name).delete(request_headers: headers) @@ -1027,7 +1026,7 @@ def test_ips_pools__pool_name__ips_post data = JSON.parse('{ "ip": "0.0.0.0" }') - pool_name = "test_url_param" + pool_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 201}') response = @sg.client.ips.pools._(pool_name).ips.post(request_body: data, request_headers: headers) @@ -1036,8 +1035,8 @@ def test_ips_pools__pool_name__ips_post end def test_ips_pools__pool_name__ips__ip__delete - pool_name = "test_url_param" - ip = "test_url_param" + pool_name = 'test_url_param' + ip = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.ips.pools._(pool_name).ips._(ip).delete(request_headers: headers) @@ -1065,7 +1064,7 @@ def test_ips_warmup_get end def test_ips_warmup__ip_address__get - ip_address = "test_url_param" + ip_address = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.ips.warmup._(ip_address).get(request_headers: headers) @@ -1074,7 +1073,7 @@ def test_ips_warmup__ip_address__get end def test_ips_warmup__ip_address__delete - ip_address = "test_url_param" + ip_address = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.ips.warmup._(ip_address).delete(request_headers: headers) @@ -1083,7 +1082,7 @@ def test_ips_warmup__ip_address__delete end def test_ips__ip_address__get - ip_address = "test_url_param" + ip_address = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.ips._(ip_address).get(request_headers: headers) @@ -1100,7 +1099,7 @@ def test_mail_batch_post end def test_mail_batch__batch_id__get - batch_id = "test_url_param" + batch_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.mail.batch._(batch_id).get(request_headers: headers) @@ -1249,7 +1248,7 @@ def test_mail_send_post }') headers = JSON.parse('{"X-Mock": 202}') - response = @sg.client.mail._("send").post(request_body: data, request_headers: headers) + response = @sg.client.mail._('send').post(request_body: data, request_headers: headers) assert_equal('202', response.status_code) end @@ -1515,13 +1514,13 @@ def test_senders_post }') headers = JSON.parse('{"X-Mock": 201}') response = @sg.client.senders.post(request_body: data, request_headers: headers) - assert_equal(response.status_code, "201") + assert_equal(response.status_code, '201') end def test_senders_get headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.senders.get(request_headers: headers) - assert_equal(response.status_code, "200") + assert_equal(response.status_code, '200') end def test_senders__sender_id__patch @@ -1542,31 +1541,31 @@ def test_senders__sender_id__patch "state": "Colorado", "zip": "80202" }') - sender_id = "test_url_param" + sender_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.senders._(sender_id).patch(request_body: data, request_headers: headers) - assert_equal(response.status_code, "200") + assert_equal(response.status_code, '200') end def test_senders__sender_id__get - sender_id = "test_url_param" + sender_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.senders._(sender_id).get(request_headers: headers) - assert_equal(response.status_code, "200") + assert_equal(response.status_code, '200') end def test_senders__sender_id__delete - sender_id = "test_url_param" + sender_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.senders._(sender_id).delete(request_headers: headers) - assert_equal(response.status_code, "204") + assert_equal(response.status_code, '204') end def test_senders__sender_id__resend_verification_post - sender_id = "test_url_param" + sender_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.senders._(sender_id).resend_verification.post(request_headers: headers) - assert_equal(response.status_code, "204") + assert_equal(response.status_code, '204') end def test_stats_get @@ -1644,7 +1643,7 @@ def test_subusers__subuser_name__patch data = JSON.parse('{ "disabled": false }') - subuser_name = "test_url_param" + subuser_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.subusers._(subuser_name).patch(request_body: data, request_headers: headers) @@ -1653,7 +1652,7 @@ def test_subusers__subuser_name__patch end def test_subusers__subuser_name__delete - subuser_name = "test_url_param" + subuser_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.subusers._(subuser_name).delete(request_headers: headers) @@ -1665,7 +1664,7 @@ def test_subusers__subuser_name__ips_put data = JSON.parse('[ "127.0.0.1" ]') - subuser_name = "test_url_param" + subuser_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.subusers._(subuser_name).ips.put(request_body: data, request_headers: headers) @@ -1678,7 +1677,7 @@ def test_subusers__subuser_name__monitor_put "email": "example@example.com", "frequency": 500 }') - subuser_name = "test_url_param" + subuser_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.subusers._(subuser_name).monitor.put(request_body: data, request_headers: headers) @@ -1691,7 +1690,7 @@ def test_subusers__subuser_name__monitor_post "email": "example@example.com", "frequency": 50000 }') - subuser_name = "test_url_param" + subuser_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.subusers._(subuser_name).monitor.post(request_body: data, request_headers: headers) @@ -1700,7 +1699,7 @@ def test_subusers__subuser_name__monitor_post end def test_subusers__subuser_name__monitor_get - subuser_name = "test_url_param" + subuser_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.subusers._(subuser_name).monitor.get(request_headers: headers) @@ -1709,7 +1708,7 @@ def test_subusers__subuser_name__monitor_get end def test_subusers__subuser_name__monitor_delete - subuser_name = "test_url_param" + subuser_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.subusers._(subuser_name).monitor.delete(request_headers: headers) @@ -1719,7 +1718,7 @@ def test_subusers__subuser_name__monitor_delete def test_subusers__subuser_name__stats_monthly_get params = JSON.parse('{"date": "test_string", "sort_by_direction": "asc", "limit": 1, "sort_by_metric": "test_string", "offset": 1}') - subuser_name = "test_url_param" + subuser_name = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.subusers._(subuser_name).stats.monthly.get(query_params: params, request_headers: headers) @@ -1752,7 +1751,7 @@ def test_suppression_blocks_delete end def test_suppression_blocks__email__get - email = "test_url_param" + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.suppression.blocks._(email).get(request_headers: headers) @@ -1761,7 +1760,7 @@ def test_suppression_blocks__email__get end def test_suppression_blocks__email__delete - email = "test_url_param" + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.suppression.blocks._(email).delete(request_headers: headers) @@ -1794,7 +1793,7 @@ def test_suppression_bounces_delete end def test_suppression_bounces__email__get - email = "test_url_param" + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.suppression.bounces._(email).get(request_headers: headers) @@ -1804,7 +1803,7 @@ def test_suppression_bounces__email__get def test_suppression_bounces__email__delete params = JSON.parse('{"email_address": "example@example.com"}') - email = "test_url_param" + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.suppression.bounces._(email).delete(query_params: params, request_headers: headers) @@ -1837,7 +1836,7 @@ def test_suppression_invalid_emails_delete end def test_suppression_invalid_emails__email__get - email = "test_url_param" + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.suppression.invalid_emails._(email).get(request_headers: headers) @@ -1846,7 +1845,7 @@ def test_suppression_invalid_emails__email__get end def test_suppression_invalid_emails__email__delete - email = "test_url_param" + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.suppression.invalid_emails._(email).delete(request_headers: headers) @@ -1855,7 +1854,7 @@ def test_suppression_invalid_emails__email__delete end def test_suppression_spam_report__email__get - email = "test_url_param" + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.suppression.spam_reports._(email).get(request_headers: headers) @@ -1864,10 +1863,10 @@ def test_suppression_spam_report__email__get end def test_suppression_spam_report__email__delete - email = "test_url_param" + email = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') - response = @sg.client.suppression.spam_reports._(email).delete(request_headers: headers) + response = @sg.client.suppression.spam_reports._(email).delete(request_headers: headers) assert_equal('204', response.status_code) end @@ -1928,7 +1927,7 @@ def test_templates__template_id__patch data = JSON.parse('{ "name": "new_example_name" }') - template_id = "test_url_param" + template_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.templates._(template_id).patch(request_body: data, request_headers: headers) @@ -1937,7 +1936,7 @@ def test_templates__template_id__patch end def test_templates__template_id__get - template_id = "test_url_param" + template_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.templates._(template_id).get(request_headers: headers) @@ -1946,7 +1945,7 @@ def test_templates__template_id__get end def test_templates__template_id__delete - template_id = "test_url_param" + template_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.templates._(template_id).delete(request_headers: headers) @@ -1963,7 +1962,7 @@ def test_templates__template_id__versions_post "subject": "<%subject%>", "template_id": "ddb96bbc-9b92-425e-8979-99464621b543" }') - template_id = "test_url_param" + template_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 201}') response = @sg.client.templates._(template_id).versions.post(request_body: data, request_headers: headers) @@ -1979,8 +1978,8 @@ def test_templates__template_id__versions__version_id__patch "plain_content": "<%body%>", "subject": "<%subject%>" }') - template_id = "test_url_param" - version_id = "test_url_param" + template_id = 'test_url_param' + version_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.templates._(template_id).versions._(version_id).patch(request_body: data, request_headers: headers) @@ -1989,8 +1988,8 @@ def test_templates__template_id__versions__version_id__patch end def test_templates__template_id__versions__version_id__get - template_id = "test_url_param" - version_id = "test_url_param" + template_id = 'test_url_param' + version_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.templates._(template_id).versions._(version_id).get(request_headers: headers) @@ -1999,8 +1998,8 @@ def test_templates__template_id__versions__version_id__get end def test_templates__template_id__versions__version_id__delete - template_id = "test_url_param" - version_id = "test_url_param" + template_id = 'test_url_param' + version_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.templates._(template_id).versions._(version_id).delete(request_headers: headers) @@ -2009,8 +2008,8 @@ def test_templates__template_id__versions__version_id__delete end def test_templates__template_id__versions__version_id__activate_post - template_id = "test_url_param" - version_id = "test_url_param" + template_id = 'test_url_param' + version_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.templates._(template_id).versions._(version_id).activate.post(request_headers: headers) @@ -2205,7 +2204,7 @@ def test_user_scheduled_sends__batch_id__patch data = JSON.parse('{ "status": "pause" }') - batch_id = "test_url_param" + batch_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.user.scheduled_sends._(batch_id).patch(request_body: data, request_headers: headers) @@ -2214,7 +2213,7 @@ def test_user_scheduled_sends__batch_id__patch end def test_user_scheduled_sends__batch_id__get - batch_id = "test_url_param" + batch_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.user.scheduled_sends._(batch_id).get(request_headers: headers) @@ -2223,7 +2222,7 @@ def test_user_scheduled_sends__batch_id__get end def test_user_scheduled_sends__batch_id__delete - batch_id = "test_url_param" + batch_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.user.scheduled_sends._(batch_id).delete(request_headers: headers) @@ -2340,7 +2339,7 @@ def test_user_webhooks_parse_settings__hostname__patch "spam_check": false, "url": "http://newdomain.com/parse" }') - hostname = "test_url_param" + hostname = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.user.webhooks.parse.settings._(hostname).patch(request_body: data, request_headers: headers) @@ -2349,7 +2348,7 @@ def test_user_webhooks_parse_settings__hostname__patch end def test_user_webhooks_parse_settings__hostname__get - hostname = "test_url_param" + hostname = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.user.webhooks.parse.settings._(hostname).get(request_headers: headers) @@ -2358,7 +2357,7 @@ def test_user_webhooks_parse_settings__hostname__get end def test_user_webhooks_parse_settings__hostname__delete - hostname = "test_url_param" + hostname = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.user.webhooks.parse.settings._(hostname).delete(request_headers: headers) @@ -2433,7 +2432,7 @@ def test_whitelabel_domains__domain_id__patch "custom_spf": true, "default": false }') - domain_id = "test_url_param" + domain_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.whitelabel.domains._(domain_id).patch(request_body: data, request_headers: headers) @@ -2442,7 +2441,7 @@ def test_whitelabel_domains__domain_id__patch end def test_whitelabel_domains__domain_id__get - domain_id = "test_url_param" + domain_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.whitelabel.domains._(domain_id).get(request_headers: headers) @@ -2451,7 +2450,7 @@ def test_whitelabel_domains__domain_id__get end def test_whitelabel_domains__domain_id__delete - domain_id = "test_url_param" + domain_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.whitelabel.domains._(domain_id).delete(request_headers: headers) @@ -2463,7 +2462,7 @@ def test_whitelabel_domains__domain_id__subuser_post data = JSON.parse('{ "username": "jane@example.com" }') - domain_id = "test_url_param" + domain_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 201}') response = @sg.client.whitelabel.domains._(domain_id).subuser.post(request_body: data, request_headers: headers) @@ -2475,7 +2474,7 @@ def test_whitelabel_domains__id__ips_post data = JSON.parse('{ "ip": "192.168.0.1" }') - id = "test_url_param" + id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.whitelabel.domains._(id).ips.post(request_body: data, request_headers: headers) @@ -2484,8 +2483,8 @@ def test_whitelabel_domains__id__ips_post end def test_whitelabel_domains__id__ips__ip__delete - id = "test_url_param" - ip = "test_url_param" + id = 'test_url_param' + ip = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.whitelabel.domains._(id).ips._(ip).delete(request_headers: headers) @@ -2494,7 +2493,7 @@ def test_whitelabel_domains__id__ips__ip__delete end def test_whitelabel_domains__id__validate_post - id = "test_url_param" + id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.whitelabel.domains._(id).validate.post(request_headers: headers) @@ -2525,7 +2524,7 @@ def test_whitelabel_ips_get end def test_whitelabel_ips__id__get - id = "test_url_param" + id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.whitelabel.ips._(id).get(request_headers: headers) @@ -2534,7 +2533,7 @@ def test_whitelabel_ips__id__get end def test_whitelabel_ips__id__delete - id = "test_url_param" + id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.whitelabel.ips._(id).delete(request_headers: headers) @@ -2543,7 +2542,7 @@ def test_whitelabel_ips__id__delete end def test_whitelabel_ips__id__validate_post - id = "test_url_param" + id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.whitelabel.ips._(id).validate.post(request_headers: headers) @@ -2605,7 +2604,7 @@ def test_whitelabel_links__id__patch data = JSON.parse('{ "default": true }') - id = "test_url_param" + id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.whitelabel.links._(id).patch(request_body: data, request_headers: headers) @@ -2614,7 +2613,7 @@ def test_whitelabel_links__id__patch end def test_whitelabel_links__id__get - id = "test_url_param" + id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.whitelabel.links._(id).get(request_headers: headers) @@ -2623,7 +2622,7 @@ def test_whitelabel_links__id__get end def test_whitelabel_links__id__delete - id = "test_url_param" + id = 'test_url_param' headers = JSON.parse('{"X-Mock": 204}') response = @sg.client.whitelabel.links._(id).delete(request_headers: headers) @@ -2632,7 +2631,7 @@ def test_whitelabel_links__id__delete end def test_whitelabel_links__id__validate_post - id = "test_url_param" + id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.whitelabel.links._(id).validate.post(request_headers: headers) @@ -2644,7 +2643,7 @@ def test_whitelabel_links__link_id__subuser_post data = JSON.parse('{ "username": "jane@example.com" }') - link_id = "test_url_param" + link_id = 'test_url_param' headers = JSON.parse('{"X-Mock": 200}') response = @sg.client.whitelabel.links._(link_id).subuser.post(request_body: data, request_headers: headers) @@ -2655,7 +2654,7 @@ def test_whitelabel_links__link_id__subuser_post def test_license_file_year # Read the third line from the license file year = IO.readlines('./LICENSE.md')[2].gsub(/[^\d]/, '') - self.assert_equal("#{Time.now.year}", year) + assert_equal(Time.now.year.to_s, year) end def test_env_sample_exists