diff --git a/Rakefile b/Rakefile index 701a88d..4153bfd 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,9 @@ -require "bundler/gem_tasks" +# frozen_string_literal: true + +require 'bundler/gem_tasks' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new('spec') # If you want to make this the default task -task default: :spec \ No newline at end of file +task default: :spec diff --git a/lib/mailup.rb b/lib/mailup.rb index bcc57ec..344245e 100644 --- a/lib/mailup.rb +++ b/lib/mailup.rb @@ -1,8 +1,8 @@ require 'oauth2' require 'multi_json' -require "net/https" +require 'net/https' require 'json' -require "uri" +require 'uri' require 'mailup/version' require 'mailup/errors' @@ -48,19 +48,21 @@ class API # } # mailup = MailUp::API.new(credentials) # - def initialize(credentials=nil, debug=false) + def initialize(credentials = nil, debug = false) @debug = debug @host = 'https://services.mailup.com' @path = '' @credentials = credentials # Validate the credentials - raise Error.new, 'MailUp credentials missing' if credentials.nil? or !credentials.is_a?(Hash) - [:client_id, :client_secret, :oauth].each do |key| - raise Error.new, "MailUp credentials must include a #{key.to_s} key" unless credentials.has_key?(key) + raise Error.new, 'MailUp credentials missing' if credentials.nil? || !credentials.is_a?(Hash) + + %i[client_id client_secret oauth].each do |key| + raise Error.new, "MailUp credentials must include a #{key} key" unless credentials.has_key?(key) end raise Error.new, 'MailUp credentials :oauth must be a hash' unless credentials[:oauth].is_a?(Hash) - [:token, :refresh_token, :expires_at].each do |key| + + %i[token refresh_token expires_at].each do |key| raise Error.new, "MailUp credentials :oauth hash must include a #{key.to_s} key" unless credentials[:oauth].has_key?(key) end @@ -69,8 +71,8 @@ def initialize(credentials=nil, debug=false) credentials[:client_id], credentials[:client_secret], site: @host, - authorize_url: "/Authorization/OAuth/LogOn", - token_url: "/Authorization/OAuth/Token", + authorize_url: '/Authorization/OAuth/LogOn', + token_url: '/Authorization/OAuth/Token', raise_errors: @debug ) @@ -92,19 +94,19 @@ def initialize(credentials=nil, debug=false) # @param [Hash] opts the options to make the request with # def request(method, path, opts={}, &block) # :nodoc: - unless @access_token == nil - # Refresh token if needed - @access_token = @access_token.refresh! if @access_token.expired? - # Ensure the body is JSON - opts[:body] = MultiJson.dump(opts[:body]) if opts[:body] - # Set the headers - opts[:headers] ||= {} - opts[:headers].merge!(headers) - # Make the request - req = @access_token.send(method, path, opts) - # Handle the response - handle_response(req) - end + return if @access_token.nil? + + # Refresh token if needed + @access_token = @access_token.refresh! if @access_token.expired? + # Ensure the body is JSON + opts[:body] = MultiJson.dump(opts[:body]) if opts[:body] + # Set the headers + opts[:headers] ||= {} + opts[:headers].merge!(headers) + # Make the request + req = @access_token.send(method, path, opts) + # Handle the response + handle_response(req) end # Make a request with for Provisioning Calls. @@ -119,7 +121,7 @@ def provisioning_request(path, body = nil) # :nodoc: http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER - req = Net::HTTP::Post.new(path, initheader = {'Content-Type' =>'application/json'}) + req = Net::HTTP::Post.new(path, initheader = { 'Content-Type' => 'application/json' }) req.basic_auth @credentials[:client_id], @credentials[:client_secret] req.body = body.to_json @@ -224,6 +226,5 @@ def public def stats Stats::Base.new self end - end -end \ No newline at end of file +end diff --git a/lib/mailup/console/base.rb b/lib/mailup/console/base.rb index bba0ee0..7e87118 100644 --- a/lib/mailup/console/base.rb +++ b/lib/mailup/console/base.rb @@ -1,16 +1,18 @@ +# frozen_string_literal: true + module MailUp module Console class Base attr_accessor :api def initialize(api) # :nodoc: - @api = api - @api.path = "/API/v#{MailUp::API_VERSION}/Rest/ConsoleService.svc/Console" + @api = api + @api.path = "/API/v#{MailUp::API_VERSION}/Rest/ConsoleService.svc/Console" end # Create an email object # - # @return [MailUp::Console::Email] + # @return [MailUp::Console::Email] # # @example # @@ -21,10 +23,10 @@ def email end # Create a group object - # + # # @param [Integer] id The group_id of the group to access. # - # @return [MailUp::Console::Group] + # @return [MailUp::Console::Group] # # @example # @@ -36,7 +38,7 @@ def group(id) # Create an images object # - # @return [MailUp::Console::Images] + # @return [MailUp::Console::Images] # # @example # @@ -45,12 +47,12 @@ def group(id) def images Images.new @api end - + # Create an import object - # + # # @param [Integer] idImport The ID of the import process. # - # @return [MailUp::Console::Import] + # @return [MailUp::Console::Import] # # @example # @@ -61,10 +63,10 @@ def import(id) end # Create a list object - # + # # @param [Integer] id The list_id of the list to access. # - # @return [MailUp::Console::List] + # @return [MailUp::Console::List] # # @example # @@ -76,7 +78,7 @@ def list(id) # Create a public methods object # - # @return [MailUp::Console::List] + # @return [MailUp::Console::List] # # @example # @@ -88,7 +90,7 @@ def public # Create a recipient object # - # @return [MailUp::Console::Recipient] + # @return [MailUp::Console::Recipient] # # @example # @@ -100,7 +102,7 @@ def recipient # Create a user object # - # @return [MailUp::Console::User] + # @return [MailUp::Console::User] # # @example # @@ -109,7 +111,6 @@ def recipient def user User.new @api end - end end -end \ No newline at end of file +end diff --git a/lib/mailup/console/email.rb b/lib/mailup/console/email.rb index 5c2b26f..b482fd3 100644 --- a/lib/mailup/console/email.rb +++ b/lib/mailup/console/email.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MailUp module Console class Email @@ -27,7 +29,7 @@ def initialize(api) # => 1 # def send(message_id, email) - @api.post("#{@api.path}/Email/Send", body: {:idMessage => message_id, :Email => email}) + @api.post("#{@api.path}/Email/Send", body: { idMessage: message_id, Email: email }) end # Schedules a mailing for immediate sending @@ -35,8 +37,8 @@ def send(message_id, email) # @param [Integer] Id Sending. # def send_immediate_confirmation(sending_id) - @api.post("#{@api.path}/Email/Sendings/#{sending_id}/Immediate") - end + @api.post("#{@api.path}/Email/Sendings/#{sending_id}/Immediate") + end # Retrieves the earliest date to schedule the given sending task. # @@ -52,7 +54,7 @@ def get_deferred_confirmation_date(sending_id) # @param [String] :Date date/time for a deferred sending(should be UTC). # def send_deferred_confirmation(sending_id, date = nil) - @api.post("#{@api.path}/Email/Sendings/#{sending_id}/Deferred", body: {'Date' => date}) + @api.post("#{@api.path}/Email/Sendings/#{sending_id}/Deferred", body: { 'Date' => date }) end # Retrieves the list of email messages that are currently queued up for "immediate sending". @@ -77,4 +79,4 @@ def get_undefined_confirmation_queque end end end -end \ No newline at end of file +end diff --git a/lib/mailup/console/group.rb b/lib/mailup/console/group.rb index ba1361c..aed5bfc 100644 --- a/lib/mailup/console/group.rb +++ b/lib/mailup/console/group.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MailUp module Console class Group @@ -119,7 +121,6 @@ def unsubscribe(recipient_id) def send_message(message_id, params = {}) @api.post("#{@api.path}/Group/#{@id}/Email/#{message_id}/Send", params: params) end - end end -end \ No newline at end of file +end diff --git a/lib/mailup/console/images.rb b/lib/mailup/console/images.rb index df338ae..67ee96f 100644 --- a/lib/mailup/console/images.rb +++ b/lib/mailup/console/images.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + module MailUp module Console class Images attr_accessor :api def initialize(api) - @api = api + @api = api end # Get the list of all shared images for the current console. @@ -12,7 +14,7 @@ def initialize(api) # @return [Array] An array of Image strings. # # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetSharedImages - # + # # @example # # images = mailup.console.images.list @@ -22,7 +24,7 @@ def initialize(api) def list @api.get("#{@api.path}/Images") end - + # Add a new image to the shared images list. # # @param [Hash] image A hash of image attributes: @@ -32,7 +34,7 @@ def list # @return [Array] An array of Image strings. # # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-AddSharedImage - # + # # @example # # image = { @@ -44,9 +46,9 @@ def list # => 51 # def add_image(image) - @api.post("#{@api.path}/Images", body:image) + @api.post("#{@api.path}/Images", body: image) end - + # Delete the image corresponding to the provided full path name. # # @param [String] path The path of the image to delete. @@ -54,7 +56,7 @@ def add_image(image) # @return [Boolean] `true` if successful. # # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-DeleteImage - # + # # @example # # delete = mailup.console.images.delete_image("#{image_path}") @@ -63,7 +65,6 @@ def add_image(image) def delete_image(path) @api.delete("#{@api.path}/Images", body: path.to_s) end - end end -end \ No newline at end of file +end diff --git a/lib/mailup/console/import.rb b/lib/mailup/console/import.rb index 56d5661..f5b51ea 100644 --- a/lib/mailup/console/import.rb +++ b/lib/mailup/console/import.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MailUp module Console class Import @@ -40,7 +42,6 @@ def status def confirmation_email_id @api.get("#{@api.path}/Import/#{@id}/Sending") end - end end -end \ No newline at end of file +end diff --git a/lib/mailup/console/list.rb b/lib/mailup/console/list.rb index 4c154e9..2edca58 100644 --- a/lib/mailup/console/list.rb +++ b/lib/mailup/console/list.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MailUp module Console class List @@ -907,7 +909,6 @@ def update_list(params={}) update_params['IdList'] = @id @api.put("#{@api.path}/User/List/#{@id}", body: update_params) end - end end -end \ No newline at end of file +end diff --git a/lib/mailup/console/recipient.rb b/lib/mailup/console/recipient.rb index d79ffde..ea0f969 100644 --- a/lib/mailup/console/recipient.rb +++ b/lib/mailup/console/recipient.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + module MailUp module Console class Recipient attr_accessor :api def initialize(api) - @api = api + @api = api end # Update a recipient with the specified details into address book. - # + # # @param [Hash] recipient A hash of recipient attributes: # @option recipient [String] :Name of the recipient (required). # @option recipient [String] :Email of the recipient (required). @@ -25,7 +27,7 @@ def initialize(api) # * Fields [Array] # # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-UpdateRecipientDetail - # + # # @example # # recipient = { @@ -40,9 +42,9 @@ def initialize(api) def update(recipient) @api.put("#{@api.path}/Recipient/Detail", body: recipient) end - + # Retrieve recipient dynamic field definitions. - # + # # @return [JSON] Results and data including: # * IsPaginated [Boolean] # * Items [Array] @@ -52,7 +54,7 @@ def update(recipient) # * TotalElementsCount [Integer] # # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetDynamicFields - # + # # @example # # fields = mailup.console.recipient.fields @@ -64,7 +66,6 @@ def update(recipient) def fields(params = {}) @api.get("#{@api.path}/Recipient/DynamicFields", params: params) end - end end -end \ No newline at end of file +end diff --git a/lib/mailup/console/user.rb b/lib/mailup/console/user.rb index e947744..6d34c0b 100644 --- a/lib/mailup/console/user.rb +++ b/lib/mailup/console/user.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + module MailUp module Console class User attr_accessor :api def initialize(api) - @api = api + @api = api end # Retrieve the admin console lists for the current user. - # + # # @param [Hash] params Optional params or filters: # @option params [Integer] :pageNumber The page number to return. # @option params [Integer] :pageSize The number of results to per page. @@ -39,9 +41,9 @@ def initialize(api) def lists(params = {}) @api.get("#{@api.path}/User/Lists", params: params) end - + # Retrieve the email messages (cloned and not cloned) for the current user. - # + # # @param [Hash] params Optional params or filters: # @option params [Integer] :pageNumber The page number to return. # @option params [Integer] :pageSize The number of results to per page. @@ -68,10 +70,9 @@ def lists(params = {}) # # emails = mailup.console.user.emails(pageNumber: 0, pageSize: 1) # - def emails(params={}) + def emails(params = {}) @api.get("#{@api.path}/User/Emails", params: params) end - end end -end \ No newline at end of file +end diff --git a/lib/mailup/errors.rb b/lib/mailup/errors.rb index d8f2e90..51f873b 100644 --- a/lib/mailup/errors.rb +++ b/lib/mailup/errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MailUp class Error < StandardError end @@ -15,4 +17,4 @@ class Unauthorized < Error end class Unavailable < Error end -end \ No newline at end of file +end diff --git a/lib/mailup/public/base.rb b/lib/mailup/public/base.rb index dc9daa4..6614db4 100644 --- a/lib/mailup/public/base.rb +++ b/lib/mailup/public/base.rb @@ -1,18 +1,19 @@ +# frozen_string_literal: true + module MailUp module Public class Base attr_accessor :api def initialize(api) # :nodoc: - @api = api - @api.path = "/API/v#{MailUp::API_VERSION}/Rest/PublicService.svc" + @api = api + @api.path = "/API/v#{MailUp::API_VERSION}/Rest/PublicService.svc" end # Resource nodes def console Console.new @api end - end end -end \ No newline at end of file +end diff --git a/lib/mailup/public/console.rb b/lib/mailup/public/console.rb index 2eb586b..dfe695b 100644 --- a/lib/mailup/public/console.rb +++ b/lib/mailup/public/console.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + module MailUp module Public class Console attr_accessor :api def initialize(api) - @api = api + @api = api end # Create a new trial console. - # + # # @param [Hash] account A hash of account attributes. # @option params [String] :NameAndSurname The company name. # @option params [String] :Email The email address for the trial account. @@ -43,7 +45,7 @@ def activate_trial(account = {}) end # Retrieve the information about current trial activation status. - # + # # @param [Hash] account A hash of account attributes. # @option params [String] :Hash The Hash of the trial activation request. # @option params [Integer] :Id The Id of the trial activation request. @@ -69,7 +71,6 @@ def activate_trial(account = {}) def status(account = {}) @api.provisioning_request("#{@api.path}/Console/TrialActivationStatus", account) end - end end -end \ No newline at end of file +end diff --git a/lib/mailup/stats/base.rb b/lib/mailup/stats/base.rb index f628ced..486853d 100644 --- a/lib/mailup/stats/base.rb +++ b/lib/mailup/stats/base.rb @@ -1,18 +1,20 @@ +# frozen_string_literal: true + module MailUp module Stats class Base attr_accessor :api def initialize(api) # :nodoc: - @api = api - @api.path = "/API/v#{MailUp::API_VERSION}/Rest/MailStatisticsService.svc" + @api = api + @api.path = "/API/v#{MailUp::API_VERSION}/Rest/MailStatisticsService.svc" end # Create a message object - # + # # @param [Integer] id The message_id of the message to access. # - # @return [MailUp::Stats::Message] + # @return [MailUp::Stats::Message] # # @example # @@ -23,10 +25,10 @@ def message(id) end # Create a recipient object - # + # # @param [Integer] id The recipient_id of the recipient to access. # - # @return [MailUp::Stats::Recipient] + # @return [MailUp::Stats::Recipient] # # @example # @@ -35,7 +37,6 @@ def message(id) def recipient(id) Recipient.new id, @api end - end end -end \ No newline at end of file +end diff --git a/lib/mailup/stats/message.rb b/lib/mailup/stats/message.rb index 2eace06..1bc97f0 100644 --- a/lib/mailup/stats/message.rb +++ b/lib/mailup/stats/message.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + module MailUp module Stats class Message attr_accessor :api def initialize(id, api) - @api = api - @id = id + @api = api + @id = id end # Paged list of recipients who received the specified email. @@ -37,7 +39,7 @@ def initialize(id, api) def recipients(params = {}) @api.get("#{@api.path}/Message/#{@id}/List/Recipients", params: params) end - + # Count of recipients who received the specified email. # # @@ -54,7 +56,7 @@ def recipients_count @api.get("#{@api.path}/Message/#{@id}/Count/Recipients") end alias_method :received_count, :recipients_count - + # Paged list of views of the specified email. # # @param [Hash] params Optional params or filters: @@ -82,7 +84,7 @@ def recipients_count def views(params = {}) @api.get("#{@api.path}/Message/#{@id}/List/Views", params: params) end - + # Count of views of the specified email. # # @@ -98,7 +100,7 @@ def views(params = {}) def views_count @api.get("#{@api.path}/Message/#{@id}/Count/Views") end - + # Paged list of bounces from the specified email. # # @param [Hash] params Optional params or filters: @@ -126,7 +128,7 @@ def views_count def bounces(params = {}) @api.get("#{@api.path}/Message/#{@id}/List/Bounces", params: params) end - + # Count of bounces from the specified mail. # # @@ -142,7 +144,7 @@ def bounces(params = {}) def bounces_count @api.get("#{@api.path}/Message/#{@id}/Count/Bounces") end - + # Paged list of unsubscriptions from the specified email. # # @param [Hash] params Optional params or filters: @@ -170,7 +172,7 @@ def bounces_count def unsubscribes(params = {}) @api.get("#{@api.path}/Message/#{@id}/List/Unsubscriptions", params: params) end - + # Count of unsubscriptions from the specified email. # # @@ -186,7 +188,7 @@ def unsubscribes(params = {}) def unsubscribes_count @api.get("#{@api.path}/Message/#{@id}/Count/Unsubscriptions") end - + # Paged list of clicks on a link in the specified email. # # @param [Hash] params Optional params or filters: @@ -216,7 +218,7 @@ def unsubscribes_count def clicks(params = {}) @api.get("#{@api.path}/Message/#{@id}/List/Clicks", params: params) end - + # Count of clicks on a link in the specified email. # # @@ -262,7 +264,7 @@ def clicks_count def url_clicks(params = {}) @api.get("#{@api.path}/Message/#{@id}/List/UrlClicks", params: params) end - + # Count of clicks on a link in the specified email. # # @@ -281,4 +283,4 @@ def url_clicks_count end end -end \ No newline at end of file +end diff --git a/lib/mailup/stats/recipient.rb b/lib/mailup/stats/recipient.rb index 3413ed6..5eb58ac 100644 --- a/lib/mailup/stats/recipient.rb +++ b/lib/mailup/stats/recipient.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + module MailUp module Stats class Recipient attr_accessor :api def initialize(id, api) - @api = api - @id = id + @api = api + @id = id end # Paged list of messages received by the specified recipient. @@ -37,7 +39,7 @@ def initialize(id, api) def deliveries(params = {}) @api.get("#{@api.path}/Recipient/#{@id}/List/Deliveries", params: params) end - + # Count of messages received by the specified recipient. # # @@ -53,7 +55,7 @@ def deliveries(params = {}) def deliveries_count @api.get("#{@api.path}/Recipient/#{@id}/Count/Deliveries") end - + # Paged list of messages viewed by the specified recipient. # # @param [Hash] params Optional params or filters: @@ -83,7 +85,7 @@ def deliveries_count def views(params = {}) @api.get("#{@api.path}/Recipient/#{@id}/List/Views", params: params) end - + # Count of messages viewed by the specified recipient. # # @@ -99,7 +101,7 @@ def views(params = {}) def views_count @api.get("#{@api.path}/Recipient/#{@id}/Count/Views") end - + # Paged list of bounces with details returned by the specified recipient. # # @param [Hash] params Optional params or filters: @@ -159,7 +161,7 @@ def bounces_details(params = {}) def bounces(params = {}) @api.get("#{@api.path}/Recipient/#{@id}/List/Bounces", params: params) end - + # Count of bounces returned by the specified recipient. # # @@ -175,7 +177,7 @@ def bounces(params = {}) def bounces_count @api.get("#{@api.path}/Recipient/#{@id}/Count/Bounces") end - + # Paged list of unsubscriptions done by the specified recipient. # # @param [Hash] params Optional params or filters: @@ -205,7 +207,7 @@ def bounces_count def unsubscribes(params = {}) @api.get("#{@api.path}/Recipient/#{@id}/List/Unsubscriptions", params: params) end - + # Count of unsubscriptions done by the specified recipient. # # @@ -251,7 +253,7 @@ def unsubscribes_count def clicks_details(params = {}) @api.get("#{@api.path}/Recipient/#{@id}/List/ClicksDetails", params: params) end - + # Paged list of message clicks on a link done by the specified recipient. # # @param [Hash] params Optional params or filters: @@ -281,7 +283,7 @@ def clicks_details(params = {}) def clicks(params = {}) @api.get("#{@api.path}/Recipient/#{@id}/List/Clicks", params: params) end - + # Count of clicks on a link in the specified email. # # @@ -297,7 +299,6 @@ def clicks(params = {}) def clicks_count @api.get("#{@api.path}/Recipient/#{@id}/Count/Clicks") end - end end -end \ No newline at end of file +end diff --git a/lib/mailup/version.rb b/lib/mailup/version.rb index afaa727..5d68c8a 100644 --- a/lib/mailup/version.rb +++ b/lib/mailup/version.rb @@ -1,4 +1,6 @@ +# frozen_string_literal: true + module MailUp - API_VERSION = "1.1" - VERSION = "1.2.0" + API_VERSION = '1.1' + VERSION = '1.2.0' end diff --git a/mailup.gemspec b/mailup.gemspec index 3166ad6..0f7845a 100644 --- a/mailup.gemspec +++ b/mailup.gemspec @@ -1,27 +1,29 @@ -# -*- encoding: utf-8 -*- -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) +# lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'mailup/version' Gem::Specification.new do |gem| - gem.name = "mailup" + gem.name = 'mailup' gem.version = MailUp::VERSION gem.platform = Gem::Platform::RUBY - gem.authors = ["Brian Getting", "Rocco Galluzzo"] - gem.email = ["brian@tatem.ae"] - gem.homepage = "https://github.com/mailup/mailup-ruby" - gem.summary = "Ruby wrapper for the MailUp REST API" - gem.description = "A Ruby gem for interacting with the MailUp REST API." - gem.licenses = ['MIT'] + gem.authors = ['Brian Getting', 'Rocco Galluzzo'] + gem.email = ['brian@tatem.ae'] + gem.homepage = 'https://github.com/mailup/mailup-ruby' + gem.summary = 'Ruby wrapper for the MailUp REST API' + gem.description = 'A Ruby gem for interacting with the MailUp REST API.' + gem.licenses = ['MIT'] - gem.files = `git ls-files`.split($/) - gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } + gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) + gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) - gem.require_paths = ["lib"] + gem.require_paths = ['lib'] - gem.add_runtime_dependency 'oauth2', '~> 0.9', '>= 0.9.2' + gem.add_runtime_dependency 'oauth2', '~> 1.4', '>= 1.4' - gem.add_development_dependency "rspec" - gem.add_development_dependency "rake" - gem.add_development_dependency "coveralls" + gem.add_development_dependency 'coveralls' + gem.add_development_dependency 'rake' + gem.add_development_dependency 'rspec' end diff --git a/rails/init.rb b/rails/init.rb index d031f84..4ac019c 100644 --- a/rails/init.rb +++ b/rails/init.rb @@ -1 +1,3 @@ -require 'mailup' \ No newline at end of file +# frozen_string_literal: true + +require 'mailup' diff --git a/spec/mailup/console/base_spec.rb b/spec/mailup/console/base_spec.rb index bdb74ca..15e89c0 100644 --- a/spec/mailup/console/base_spec.rb +++ b/spec/mailup/console/base_spec.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'spec_helper' # Console API Methods describe MailUp::Console do - before(:each){ init_mailup } + before(:each) { init_mailup } it 'should return a console base object' do @mailup.console.should be_an_instance_of(MailUp::Console::Base) @@ -12,22 +14,21 @@ @mailup.console.api.path.should eq("/API/v#{MailUp::API_VERSION}/Rest/ConsoleService.svc/Console") end - %w(email images recipient user).each do |resource| + %w[email images recipient user].each do |resource| context resource do it "should return a #{resource} object" do test = @mailup.console.send(resource.to_sym) - test.should be_an_instance_of(Object.const_get("MailUp").const_get("Console").const_get("#{resource.capitalize}")) + test.should be_an_instance_of(Object.const_get('MailUp').const_get('Console').const_get(resource.capitalize.to_s)) end end end - %w(group import list).each do |resource| + %w[group import list].each do |resource| context resource do it "should return a #{resource} object" do test = @mailup.console.send(resource.to_sym, 1) - test.should be_an_instance_of(Object.const_get("MailUp").const_get("Console").const_get("#{resource.capitalize}")) + test.should be_an_instance_of(Object.const_get('MailUp').const_get('Console').const_get(resource.capitalize.to_s)) end end end - -end \ No newline at end of file +end diff --git a/spec/mailup/console/email_spec.rb b/spec/mailup/console/email_spec.rb index 3294f68..693d257 100644 --- a/spec/mailup/console/email_spec.rb +++ b/spec/mailup/console/email_spec.rb @@ -1,19 +1,20 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailUp::Console::Email do - before(:each){ init_mailup } - - %w(send).each do |method| + before(:each) { init_mailup } + + %w[send].each do |method| it "should have a #{method} method" do @mailup.console.email.should respond_to(method.to_sym) end end - it "should fire the correct POST request for send" do - email = "test@email.com" + it 'should fire the correct POST request for send' do + email = 'test@email.com' id = rand(100).abs - @mailup.console.email.api.should_receive(:post).with("#{@mailup.console.email.api.path}/Email/Send", {body: {:idMessage => id, :Email => email}}) + @mailup.console.email.api.should_receive(:post).with("#{@mailup.console.email.api.path}/Email/Send", body: { idMessage: id, Email: email }) @mailup.console.email.send(id, email) end - -end \ No newline at end of file +end diff --git a/spec/mailup/console/group_spec.rb b/spec/mailup/console/group_spec.rb index 145e037..5d7bc82 100644 --- a/spec/mailup/console/group_spec.rb +++ b/spec/mailup/console/group_spec.rb @@ -1,48 +1,49 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailUp::Console::Group do before(:each) { init_mailup } - %w(add_recipients recipients subscribe unsubscribe send_message).each do |method| + %w[add_recipients recipients subscribe unsubscribe send_message].each do |method| it "should have a #{method} method" do @mailup.console.group(1).should respond_to(method.to_sym) end end - it "should fire the correct POST request for add_recipients" do - payload = Date._jisx0301("empty hash, please") - @mailup.console.group(1).api.should_receive(:post).with("#{@mailup.console.group(1).api.path}/Group/1/Recipients", {body: payload, params: {}}) + it 'should fire the correct POST request for add_recipients' do + payload = Date._jisx0301('empty hash, please') + @mailup.console.group(1).api.should_receive(:post).with("#{@mailup.console.group(1).api.path}/Group/1/Recipients", body: payload, params: {}) @mailup.console.group(1).add_recipients(payload) end - it "should fire the correct POST request for add_recipient" do - payload = Date._jisx0301("empty hash, please") - @mailup.console.group(1).api.should_receive(:post).with("#{@mailup.console.group(1).api.path}/Group/1/Recipient", {body: payload, params: {}}) + it 'should fire the correct POST request for add_recipient' do + payload = Date._jisx0301('empty hash, please') + @mailup.console.group(1).api.should_receive(:post).with("#{@mailup.console.group(1).api.path}/Group/1/Recipient", body: payload, params: {}) @mailup.console.group(1).add_recipient(payload) end - it "should fire the correct GET request for recipients" do - payload = Date._jisx0301("empty hash, please") - @mailup.console.group(1).api.should_receive(:get).with("#{@mailup.console.group(1).api.path}/Group/1/Recipients", {params: {}}) + it 'should fire the correct GET request for recipients' do + payload = Date._jisx0301('empty hash, please') + @mailup.console.group(1).api.should_receive(:get).with("#{@mailup.console.group(1).api.path}/Group/1/Recipients", params: {}) @mailup.console.group(1).recipients end - it "should fire the correct POST request for subscribe" do + it 'should fire the correct POST request for subscribe' do id = rand(100).abs @mailup.console.group(1).api.should_receive(:post).with("#{@mailup.console.group(1).api.path}/Group/1/Subscribe/#{id}") @mailup.console.group(1).subscribe(id) end - it "should fire the correct DELETE request for unsubscribe" do + it 'should fire the correct DELETE request for unsubscribe' do id = rand(100).abs @mailup.console.group(1).api.should_receive(:delete).with("#{@mailup.console.group(1).api.path}/Group/1/Unsubscribe/#{id}") @mailup.console.group(1).unsubscribe(id) end - it "should fire the correct POST request for send_message" do + it 'should fire the correct POST request for send_message' do id = rand(100).abs - @mailup.console.group(1).api.should_receive(:post).with("#{@mailup.console.group(1).api.path}/Group/1/Email/#{id}/Send", {params: {}}) + @mailup.console.group(1).api.should_receive(:post).with("#{@mailup.console.group(1).api.path}/Group/1/Email/#{id}/Send", params: {}) @mailup.console.group(1).send_message(id) end - -end \ No newline at end of file +end diff --git a/spec/mailup/console/images_spec.rb b/spec/mailup/console/images_spec.rb index 4031e06..a2337a7 100644 --- a/spec/mailup/console/images_spec.rb +++ b/spec/mailup/console/images_spec.rb @@ -1,29 +1,30 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailUp::Console::Images do before(:each) { init_mailup } - %w(add_image delete_image list).each do |method| + %w[add_image delete_image list].each do |method| it "should have a #{method} method" do @mailup.console.images.should respond_to(method.to_sym) end end - it "should fire the correct GET request for list" do + it 'should fire the correct GET request for list' do @mailup.console.images.api.should_receive(:get).with("#{@mailup.console.images.api.path}/Images") @mailup.console.images.list end - it "should fire the correct POST request for add_image" do - payload = Date._jisx0301("empty hash, please") - @mailup.console.images.api.should_receive(:post).with("#{@mailup.console.images.api.path}/Images", {body: payload}) + it 'should fire the correct POST request for add_image' do + payload = Date._jisx0301('empty hash, please') + @mailup.console.images.api.should_receive(:post).with("#{@mailup.console.images.api.path}/Images", body: payload) @mailup.console.images.add_image(payload) end - it "should fire the correct DELETE request for delete_image" do - path = "/Test/Image/Path" - @mailup.console.images.api.should_receive(:delete).with("#{@mailup.console.images.api.path}/Images", {body: path}) + it 'should fire the correct DELETE request for delete_image' do + path = '/Test/Image/Path' + @mailup.console.images.api.should_receive(:delete).with("#{@mailup.console.images.api.path}/Images", body: path) @mailup.console.images.delete_image(path) end - -end \ No newline at end of file +end diff --git a/spec/mailup/console/import_spec.rb b/spec/mailup/console/import_spec.rb index f2211bc..e5106ec 100644 --- a/spec/mailup/console/import_spec.rb +++ b/spec/mailup/console/import_spec.rb @@ -1,23 +1,25 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailUp::Console::Import do before(:each) { init_mailup } - %w(status confirmation_email_id).each do |method| + %w[status confirmation_email_id].each do |method| it "should have a #{method} method" do @mailup.console.import(1).should respond_to(method.to_sym) end end - it "should fire the correct GET request for status" do + it 'should fire the correct GET request for status' do id = rand(100).abs @mailup.console.import(id).api.should_receive(:get).with("#{@mailup.console.import(id).api.path}/Import/#{id}") @mailup.console.import(id).status end - it "should fire the correct GET request for confirmation_email_id" do + it 'should fire the correct GET request for confirmation_email_id' do id = rand(100).abs @mailup.console.import(id).api.should_receive(:get).with("#{@mailup.console.import(id).api.path}/Import/#{id}/Sending") @mailup.console.import(id).confirmation_email_id end -end \ No newline at end of file +end diff --git a/spec/mailup/console/list_spec.rb b/spec/mailup/console/list_spec.rb index 6edf5b4..be41dd6 100644 --- a/spec/mailup/console/list_spec.rb +++ b/spec/mailup/console/list_spec.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailUp::Console::List do before(:each) { init_mailup } - %w(groups add_group update_group delete_group recipient_groups pending subscribed unsubscribed import_recipients subscribe unsubscribe tags add_tag update_tag delete_tag attachments add_attachment delete_attachment images add_image add_message_from_template add_message update_message update_message_visibility delete_message message_details emails online_emails archived_emails send_history send_message templates template_details).each do |method| + %w[groups add_group update_group delete_group recipient_groups pending subscribed unsubscribed import_recipients subscribe unsubscribe tags add_tag update_tag delete_tag attachments add_attachment delete_attachment images add_image add_message_from_template add_message update_message update_message_visibility delete_message message_details emails online_emails archived_emails send_history send_message templates template_details].each do |method| it "should have a #{method} method" do @mailup.console.list(1).should respond_to(method.to_sym) end @@ -11,156 +13,156 @@ # GET requests - %w(groups tags images emails templates).each do |method| + %w[groups tags images emails templates].each do |method| it "should fire the correct GET request for #{method}" do - @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/#{method.capitalize}", {params: {}}) + @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/#{method.capitalize}", { params: {} }) @mailup.console.list(1).send(method.to_sym) end end - %w(pending subscribed unsubscribed).each do |method| + %w[pending subscribed unsubscribed].each do |method| it "should fire the correct GET request for #{method}" do - @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/Recipients/#{method.capitalize}", {params: {}}) + @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/Recipients/#{method.capitalize}", { params: {} }) @mailup.console.list(1).send(method.to_sym) end end - %w(online_emails archived_emails).each do |method| + %w[online_emails archived_emails].each do |method| it "should fire the correct GET request for #{method}" do - @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/#{method.split('_').first.capitalize}/Emails", {params: {}}) + @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/#{method.split('_').first.capitalize}/Emails", { params: {} }) @mailup.console.list(1).send(method.to_sym) end end - it "should fire the correct GET request for recipient_groups" do - @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/Recipient/2/Groups", {params: {}}) + it 'should fire the correct GET request for recipient_groups' do + @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/Recipient/2/Groups", { params: {} }) @mailup.console.list(1).recipient_groups(2) end - it "should fire the correct GET request for attachments" do - @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/Email/2/Attachment", {params: {}}) + it 'should fire the correct GET request for attachments' do + @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/Email/2/Attachment", { params: {} }) @mailup.console.list(1).attachments(2) end - it "should fire the correct GET request for message_details" do + it 'should fire the correct GET request for message_details' do @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/Email/2") @mailup.console.list(1).message_details(2) end - it "should fire the correct GET request for send_history" do - @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/Email/2/SendHistory", {params: {}}) + it 'should fire the correct GET request for send_history' do + @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/Email/2/SendHistory", { params: {} }) @mailup.console.list(1).send_history(2) end - it "should fire the correct GET request for template_details" do + it 'should fire the correct GET request for template_details' do @mailup.console.list(1).api.should_receive(:get).with("#{@mailup.console.list(1).api.path}/List/1/Templates/2") @mailup.console.list(1).template_details(2) end # POST requests - %w(add_group).each do |method| + %w[add_group].each do |method| it "should fire the correct POST request for #{method}" do - payload = Date._jisx0301("empty hash, please") - @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/#{method.split('_').last.capitalize}", {body: payload}) + payload = Date._jisx0301('empty hash, please') + @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/#{method.split('_').last.capitalize}", { body: payload }) @mailup.console.list(1).send(method.to_sym, payload) end end - it "should fire the correct POST request for import_recipients" do - payload = Date._jisx0301("empty hash, please") - @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Recipients", {body: payload, params: {}}) + it 'should fire the correct POST request for import_recipients' do + payload = Date._jisx0301('empty hash, please') + @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Recipients", { body: payload, params: {} }) @mailup.console.list(1).send(:import_recipients, payload) end - it "should fire the correct POST request for import_recipient" do - payload = Date._jisx0301("empty hash, please") - @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Recipient", {body: payload, params: {}}) + it 'should fire the correct POST request for import_recipient' do + payload = Date._jisx0301('empty hash, please') + @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Recipient", { body: payload, params: {} }) @mailup.console.list(1).send(:import_recipient, payload) end - it "should fire the correct POST request for import_recipients and email optin" do - payload = Date._jisx0301("empty hash, please") + it 'should fire the correct POST request for import_recipients and email optin' do + payload = Date._jisx0301('empty hash, please') @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Recipients", - {body: payload, params: {ConfirmEmail: true}}) - @mailup.console.list(1).send(:import_recipients, payload, {ConfirmEmail: true}) + { body: payload, params: { ConfirmEmail: true } }) + @mailup.console.list(1).send(:import_recipients, payload, { ConfirmEmail: true }) end - it "should fire the correct POST request for subscribe" do + it 'should fire the correct POST request for subscribe' do payload = rand(100).abs @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Subscribe/#{payload}") @mailup.console.list(1).subscribe(payload) end - it "should fire the correct POST request for add_tag" do - payload = "Tag Name" + it 'should fire the correct POST request for add_tag' do + payload = 'Tag Name' @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Tag", {body: payload}) @mailup.console.list(1).add_tag(payload) end - it "should fire the correct POST request for add_attachment" do + it 'should fire the correct POST request for add_attachment' do message = slot = rand(100).abs - payload = Date._jisx0301("empty hash, please") - @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Email/#{message}/Attachment/#{slot}", {body: payload}) + payload = Date._jisx0301('empty hash, please') + @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Email/#{message}/Attachment/#{slot}", { body: payload }) @mailup.console.list(1).add_attachment(message, slot, payload) end - it "should fire the correct POST request for add_image" do - payload = Date._jisx0301("empty hash, please") - @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Images", {body: payload}) + it 'should fire the correct POST request for add_image' do + payload = Date._jisx0301('empty hash, please') + @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Images", { body: payload }) @mailup.console.list(1).add_image(payload) end - it "should fire the correct POST request for add_message_from_template" do + it 'should fire the correct POST request for add_message_from_template' do payload = rand(100).abs @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Email/Template/#{payload}") @mailup.console.list(1).add_message_from_template(payload) end - it "should fire the correct POST request for add_message" do - payload = Date._jisx0301("empty hash, please") - @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Email", {body: payload}) + it 'should fire the correct POST request for add_message' do + payload = Date._jisx0301('empty hash, please') + @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Email", { body: payload }) @mailup.console.list(1).add_message(payload) end - it "should fire the correct POST request for send_message" do + it 'should fire the correct POST request for send_message' do payload = rand(100).abs - @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Email/#{payload}/Send", {params: {}}) + @mailup.console.list(1).api.should_receive(:post).with("#{@mailup.console.list(1).api.path}/List/1/Email/#{payload}/Send", { params: {} }) @mailup.console.list(1).send_message(payload) end # PUT requests - it "should fire the correct PUT request for update_group" do + it 'should fire the correct PUT request for update_group' do id = rand(100).abs - payload = Date._jisx0301("empty hash, please") - @mailup.console.list(1).api.should_receive(:put).with("#{@mailup.console.list(1).api.path}/List/1/Group/#{id}", {body: payload}) + payload = Date._jisx0301('empty hash, please') + @mailup.console.list(1).api.should_receive(:put).with("#{@mailup.console.list(1).api.path}/List/1/Group/#{id}", { body: payload }) @mailup.console.list(1).update_group(id, payload) end - it "should fire the correct PUT request for update_tag" do + it 'should fire the correct PUT request for update_tag' do id = rand(100).abs - payload = Date._jisx0301("empty hash, please") - @mailup.console.list(1).api.should_receive(:put).with("#{@mailup.console.list(1).api.path}/List/1/Tag/#{id}", {body: payload}) + payload = Date._jisx0301('empty hash, please') + @mailup.console.list(1).api.should_receive(:put).with("#{@mailup.console.list(1).api.path}/List/1/Tag/#{id}", { body: payload }) @mailup.console.list(1).update_tag(id, payload) end - it "should fire the correct PUT request for update_message" do + it 'should fire the correct PUT request for update_message' do id = rand(100).abs - payload = Date._jisx0301("empty hash, please") - @mailup.console.list(1).api.should_receive(:put).with("#{@mailup.console.list(1).api.path}/List/1/Email/#{id}", {body: payload}) + payload = Date._jisx0301('empty hash, please') + @mailup.console.list(1).api.should_receive(:put).with("#{@mailup.console.list(1).api.path}/List/1/Email/#{id}", { body: payload }) @mailup.console.list(1).update_message(id, payload) end - it "should fire the correct PUT request for update_message_visibility" do + it 'should fire the correct PUT request for update_message_visibility' do id = rand(100).abs - @mailup.console.list(1).api.should_receive(:put).with("#{@mailup.console.list(1).api.path}/List/1/Email/#{id}/Online/Visibility", {body: true}) + @mailup.console.list(1).api.should_receive(:put).with("#{@mailup.console.list(1).api.path}/List/1/Email/#{id}/Online/Visibility", { body: true }) @mailup.console.list(1).update_message_visibility(id, true) end # DELETE requests - %w(delete_group unsubscribe delete_tag).each do |method| + %w[delete_group unsubscribe delete_tag].each do |method| it "should fire the correct DELETE request for #{method}" do id = rand(100).abs @mailup.console.list(1).api.should_receive(:delete).with("#{@mailup.console.list(1).api.path}/List/1/#{method.split('_').last.capitalize}/#{id}") @@ -168,16 +170,15 @@ end end - it "should fire the correct DELETE request for delete_attachment" do + it 'should fire the correct DELETE request for delete_attachment' do id = slot = rand(100).abs @mailup.console.list(1).api.should_receive(:delete).with("#{@mailup.console.list(1).api.path}/List/1/Email/#{id}/#{slot}") @mailup.console.list(1).delete_attachment(id, slot) end - it "should fire the correct DELETE request for delete_message" do + it 'should fire the correct DELETE request for delete_message' do id = slot = rand(100).abs @mailup.console.list(1).api.should_receive(:delete).with("#{@mailup.console.list(1).api.path}/List/1/Email/#{id}") @mailup.console.list(1).delete_message(id) end - -end \ No newline at end of file +end diff --git a/spec/mailup/console/recipient_spec.rb b/spec/mailup/console/recipient_spec.rb index 61885bb..c1ff2b6 100644 --- a/spec/mailup/console/recipient_spec.rb +++ b/spec/mailup/console/recipient_spec.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailUp::Console::Recipient do before(:each) { init_mailup } - %w(update fields).each do |method| + %w[update fields].each do |method| it "should have a #{method} method" do @mailup.console.recipient.should respond_to(method.to_sym) end end -end \ No newline at end of file +end diff --git a/spec/mailup/console/user_spec.rb b/spec/mailup/console/user_spec.rb index ef598a0..decbc05 100644 --- a/spec/mailup/console/user_spec.rb +++ b/spec/mailup/console/user_spec.rb @@ -1,16 +1,18 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailUp::Console::User do before(:each) { init_mailup } - %w(emails lists).each do |method| + %w[emails lists].each do |method| it "should have a #{method} method" do @mailup.console.user.should respond_to(method.to_sym) end it "should fire the correct GET request for #{method}" do - @mailup.console.user.api.should_receive(:get).with("#{@mailup.console.user.api.path}/User/#{method.capitalize}", {params: {}}) + @mailup.console.user.api.should_receive(:get).with("#{@mailup.console.user.api.path}/User/#{method.capitalize}", params: {}) @mailup.console.user.send(method.to_sym) end end -end \ No newline at end of file +end diff --git a/spec/mailup/mailup_spec.rb b/spec/mailup/mailup_spec.rb index 78f2494..e369c88 100644 --- a/spec/mailup/mailup_spec.rb +++ b/spec/mailup/mailup_spec.rb @@ -1,33 +1,35 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailUp::API do context 'initialization' do # Make sure a hash is provided it 'requires credentials' do - expect{ MailUp::API.new }.to raise_error(MailUp::Error, 'MailUp credentials missing') + expect { MailUp::API.new }.to raise_error(MailUp::Error, 'MailUp credentials missing') end # Validate the credentials hash keys - [:client_id, :client_secret, :oauth].each do |key| + %i[client_id client_secret oauth].each do |key| it "requires credentials to have a '#{key}' key" do - @credentials.delete_if{ |k,v| k == key } - expect{ MailUp::API.new(@credentials) }.to raise_error(MailUp::Error, "MailUp credentials must include a #{key} key") + @credentials.delete_if { |k, _v| k == key } + expect { MailUp::API.new(@credentials) }.to raise_error(MailUp::Error, "MailUp credentials must include a #{key} key") end end # Make sure the oauth key is a hash it 'requires credentials to have an oauth hash' do @credentials[:oauth] = nil - expect{ MailUp::API.new(@credentials).merge!(token: true) }.to raise_error(MailUp::Error, "MailUp credentials :oauth must be a hash") + expect { MailUp::API.new(@credentials).merge!(token: true) }.to raise_error(MailUp::Error, 'MailUp credentials :oauth must be a hash') end # Validate the oauth hash keys - [:token, :refresh_token, :expires_at].each do |key| + %i[token refresh_token expires_at].each do |key| it "requires credentials with an oauth hash containing a '#{key}' key" do - @credentials[:oauth].delete_if{ |k,v| k == key } - expect{ MailUp::API.new(@credentials) }.to raise_error(MailUp::Error, "MailUp credentials :oauth hash must include a #{key} key") + @credentials[:oauth].delete_if { |k, _v| k == key } + expect { MailUp::API.new(@credentials) }.to raise_error(MailUp::Error, "MailUp credentials :oauth hash must include a #{key} key") end - end + end end # Add a context for sending a request diff --git a/spec/mailup/public/base_spec.rb b/spec/mailup/public/base_spec.rb index 4b70119..cd0305b 100644 --- a/spec/mailup/public/base_spec.rb +++ b/spec/mailup/public/base_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailUp::Public do - before(:each){ init_mailup } + before(:each) { init_mailup } it 'should return a public base object' do @mailup.public.should be_an_instance_of(MailUp::Public::Base) @@ -11,12 +13,12 @@ @mailup.public.api.path.should eq("/API/v#{MailUp::API_VERSION}/Rest/PublicService.svc") end - %w(console).each do |resource| + %w[console].each do |resource| context resource do it "should return a #{resource} object" do test = @mailup.public.send(resource.to_sym) - test.should be_an_instance_of(Object.const_get("MailUp").const_get("Public").const_get("#{resource.capitalize}")) + test.should be_an_instance_of(Object.const_get('MailUp').const_get('Public').const_get(resource.capitalize.to_s)) end end end -end \ No newline at end of file +end diff --git a/spec/mailup/public/console_spec.rb b/spec/mailup/public/console_spec.rb index d5659da..b36b7ed 100644 --- a/spec/mailup/public/console_spec.rb +++ b/spec/mailup/public/console_spec.rb @@ -1,24 +1,25 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailUp::Public::Console do before(:each) { init_mailup } - %w(activate_trial status).each do |method| + %w[activate_trial status].each do |method| it "should have a #{method} method" do @mailup.public.console.should respond_to(method.to_sym) end end - it "should fire the correct POST request for activate_trial" do - payload = Date._jisx0301("empty hash, please") + it 'should fire the correct POST request for activate_trial' do + payload = Date._jisx0301('empty hash, please') @mailup.public.console.api.should_receive(:provisioning_request).with("#{@mailup.public.console.api.path}/Console/TrialActivation", payload) @mailup.public.console.activate_trial(payload) end - it "should fire the correct POST request for status" do - payload = Date._jisx0301("empty hash, please") + it 'should fire the correct POST request for status' do + payload = Date._jisx0301('empty hash, please') @mailup.public.console.api.should_receive(:provisioning_request).with("#{@mailup.public.console.api.path}/Console/TrialActivationStatus", payload) @mailup.public.console.status(payload) end - -end \ No newline at end of file +end diff --git a/spec/mailup/stats/base_spec.rb b/spec/mailup/stats/base_spec.rb index a7292a1..4a89b84 100644 --- a/spec/mailup/stats/base_spec.rb +++ b/spec/mailup/stats/base_spec.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + require 'spec_helper' describe MailUp::Stats do - before(:each){ init_mailup } + before(:each) { init_mailup } it 'should return a stats base object' do @mailup.stats.should be_an_instance_of(MailUp::Stats::Base) @@ -11,12 +13,12 @@ @mailup.stats.api.path.should eq("/API/v#{MailUp::API_VERSION}/Rest/MailStatisticsService.svc") end - %w(message recipient).each do |resource| + %w[message recipient].each do |resource| context resource do it "should return a #{resource} object" do test = @mailup.stats.send(resource.to_sym, 1) - test.should be_an_instance_of(Object.const_get("MailUp").const_get("Stats").const_get("#{resource.capitalize}")) + test.should be_an_instance_of(Object.const_get('MailUp').const_get('Stats').const_get(resource.capitalize.to_s)) end end end -end \ No newline at end of file +end diff --git a/spec/mailup/stats/message_spec.rb b/spec/mailup/stats/message_spec.rb index 85e87d1..5a99dfc 100644 --- a/spec/mailup/stats/message_spec.rb +++ b/spec/mailup/stats/message_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'spec_helper' # Stats::Message Methods describe MailUp::Stats::Message do - before(:each){ init_mailup } + before(:each) { init_mailup } - %w(recipients recipients_count views views_count bounces bounces_count unsubscribes unsubscribes_count clicks clicks_count url_clicks url_clicks_count).each do |method| + %w[recipients recipients_count views views_count bounces bounces_count unsubscribes unsubscribes_count clicks clicks_count url_clicks url_clicks_count].each do |method| it "should have a #{method} method" do @mailup.stats.message(1).should respond_to(method.to_sym) end @@ -12,24 +14,24 @@ # List methods - %w(recipients views bounces clicks url_clicks).each do |method| + %w[recipients views bounces clicks url_clicks].each do |method| it "should fire the correct GET request for #{method}" do - @mailup.stats.message(1).api.should_receive(:get).with("#{@mailup.stats.message(1).api.path}/Message/1/List/#{method.split('_').collect(&:capitalize).join}", {params: {}}) + @mailup.stats.message(1).api.should_receive(:get).with("#{@mailup.stats.message(1).api.path}/Message/1/List/#{method.split('_').collect(&:capitalize).join}", params: {}) @mailup.stats.message(1).send(method.to_sym) end end # Count methods - %w(recipients_count views_count bounces_count clicks_count).each do |method| + %w[recipients_count views_count bounces_count clicks_count].each do |method| it "should fire the correct GET request for #{method}" do @mailup.stats.message(1).api.should_receive(:get).with("#{@mailup.stats.message(1).api.path}/Message/1/Count/#{method.split('_').first.capitalize}") @mailup.stats.message(1).send(method.to_sym) end end - it "should fire the correct GET request for url_clicks_count" do + it 'should fire the correct GET request for url_clicks_count' do @mailup.stats.message(1).api.should_receive(:get).with("#{@mailup.stats.message(1).api.path}/Message/1/Count/UrlClicks") @mailup.stats.message(1).url_clicks_count end -end \ No newline at end of file +end diff --git a/spec/mailup/stats/recipient_spec.rb b/spec/mailup/stats/recipient_spec.rb index 7edf811..bbc7292 100644 --- a/spec/mailup/stats/recipient_spec.rb +++ b/spec/mailup/stats/recipient_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'spec_helper' # Stats::Recipient Methods describe MailUp::Stats::Recipient do before(:each) { init_mailup } - %w(deliveries deliveries_count views views_count bounces_details bounces bounces_count unsubscribes unsubscribes_count clicks_details clicks clicks_count).each do |method| + %w[deliveries deliveries_count views views_count bounces_details bounces bounces_count unsubscribes unsubscribes_count clicks_details clicks clicks_count].each do |method| it "should have a #{method} method" do @mailup.stats.recipient(1).should respond_to(method.to_sym) end @@ -12,29 +14,29 @@ # List methods - %w(deliveries views bounces_details bounces clicks_details clicks).each do |method| + %w[deliveries views bounces_details bounces clicks_details clicks].each do |method| it "should fire the correct GET request for #{method}" do - @mailup.stats.recipient(1).api.should_receive(:get).with("#{@mailup.stats.recipient(1).api.path}/Recipient/1/List/#{method.split('_').collect(&:capitalize).join}", {params: {}}) + @mailup.stats.recipient(1).api.should_receive(:get).with("#{@mailup.stats.recipient(1).api.path}/Recipient/1/List/#{method.split('_').collect(&:capitalize).join}", params: {}) @mailup.stats.recipient(1).send(method.to_sym) end end - it "should fire the correct GET request for unsubscribes" do - @mailup.stats.recipient(1).api.should_receive(:get).with("#{@mailup.stats.recipient(1).api.path}/Recipient/1/List/Unsubscriptions", {params: {}}) + it 'should fire the correct GET request for unsubscribes' do + @mailup.stats.recipient(1).api.should_receive(:get).with("#{@mailup.stats.recipient(1).api.path}/Recipient/1/List/Unsubscriptions", params: {}) @mailup.stats.recipient(1).unsubscribes end # Count methods - %w(deliveries_count views_count bounces_count clicks_count).each do |method| + %w[deliveries_count views_count bounces_count clicks_count].each do |method| it "should fire the correct GET request for #{method}" do @mailup.stats.recipient(1).api.should_receive(:get).with("#{@mailup.stats.recipient(1).api.path}/Recipient/1/Count/#{method.split('_').first.capitalize}") @mailup.stats.recipient(1).send(method.to_sym) end end - it "should fire the correct GET request for unsubscribes_count" do + it 'should fire the correct GET request for unsubscribes_count' do @mailup.stats.recipient(1).api.should_receive(:get).with("#{@mailup.stats.recipient(1).api.path}/Recipient/1/Count/Unsubscriptions") @mailup.stats.recipient(1).unsubscribes_count end -end \ No newline at end of file +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6eed199..6f9e6bb 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rubygems' require 'bundler/setup' require 'mailup' @@ -17,24 +19,24 @@ config.order = 'random' # Global hooks - config.before(:each) { init_credentials} + config.before(:each) { init_credentials } config.mock_with :rspec do |c| - c.syntax = [:should, :expect] + c.syntax = %i[should expect] end config.expect_with :rspec do |c| - c.syntax = [:should, :expect] + c.syntax = %i[should expect] end end # Create Credentials Hash def init_credentials @credentials = { - client_id: "1234", - client_secret: "1234", + client_id: '1234', + client_secret: '1234', oauth: { - token: "123", - refresh_token: "123", + token: '123', + refresh_token: '123', expires_at: 123 } }