Skip to content

Commit 8d0e363

Browse files
committed
Add RuboCop linting and use frozen_string_literal everywhere
1 parent efdfa9c commit 8d0e363

File tree

8 files changed

+69
-48
lines changed

8 files changed

+69
-48
lines changed

.rubocop.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Layout/LineLength:
2+
Max: 120
3+
4+
Style/StringLiterals:
5+
EnforcedStyle: double_quotes

hubspot-mailer.gemspec

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
1+
# frozen_string_literal: true
2+
13
Gem::Specification.new do |s|
2-
s.name = "hubspot-mailer".freeze
4+
s.name = "hubspot-mailer"
35
s.version = "0.0.2"
4-
s.licenses = ['MIT']
5-
s.date = "2018-12-09".freeze
6-
s.description = "Create beautiful transactional emails right within HubSpot using the email editor with all the benefits of smart content, personalization and templates - just like regular HubSpot emails. Create beautiful transactional emails right within HubSpot using the email editor with all the benefits of smart content, personalization and templates - just like regular HubSpot emails. Create beautiful transactional emails right within HubSpot using the email editor with all the benefits of smart content, personalization and templates - just like regular HubSpot emails.".freeze
7-
s.summary = "HubSpot Single Send API SDK for use with Ruby on Rails".freeze
8-
s.authors = ["heaven".freeze]
9-
s.email = ["hello@codeart.us".freeze]
10-
s.homepage = "https://github.com/heaven/hubspot-mailer".freeze
6+
s.licenses = ["MIT"]
7+
s.date = "2018-12-09"
8+
s.description = "Create beautiful transactional emails right within HubSpot using the email editor with all the benefits of smart content, personalization and templates - just like regular HubSpot emails. Create beautiful transactional emails right within HubSpot using the email editor with all the benefits of smart content, personalization and templates - just like regular HubSpot emails. Create beautiful transactional emails right within HubSpot using the email editor with all the benefits of smart content, personalization and templates - just like regular HubSpot emails."
9+
s.summary = "HubSpot Single Send API SDK for use with Ruby on Rails"
10+
s.authors = ["heaven"]
11+
s.email = ["hello@codeart.us"]
12+
s.homepage = "https://github.com/heaven/hubspot-mailer"
1113
s.files = [
1214
"lib/hubspot-mailer.rb",
1315
"lib/hubspot/mailer.rb",
1416
"lib/hubspot/mailer/delivery.rb",
1517
"lib/hubspot/mailer/exceptions.rb",
1618
"lib/hubspot/mailer/hubspot_preview_interceptor.rb",
17-
"lib/hubspot/mailer/message.rb",
19+
"lib/hubspot/mailer/message.rb"
1820
]
1921
s.require_paths = ["lib"]
2022

2123
if s.respond_to? :specification_version
2224
s.specification_version = 3
2325

24-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0')
25-
s.add_runtime_dependency(%q<hubspot-ruby>.freeze, ["~> 0.4"])
26-
s.add_runtime_dependency(%q<actionmailer>.freeze, ["~> 5.1"])
27-
s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
26+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("1.2.0")
27+
s.add_runtime_dependency("actionmailer", ["~> 5.1"])
28+
s.add_runtime_dependency("hubspot-ruby", ["~> 0.4"])
29+
s.add_development_dependency("bundler", ["~> 1.0"])
2830
else
29-
s.add_dependency(%q<hubspot-ruby>.freeze, ["~> 0.4"])
30-
s.add_dependency(%q<actionmailer>.freeze, ["~> 5.1"])
31-
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
31+
s.add_dependency("actionmailer", ["~> 5.1"])
32+
s.add_dependency("bundler", ["~> 1.0"])
33+
s.add_dependency("hubspot-ruby", ["~> 0.4"])
3234
end
3335
else
34-
s.add_dependency(%q<hubspot-ruby>.freeze, ["~> 0.4"])
35-
s.add_dependency(%q<actionmailer>.freeze, ["~> 5.1"])
36-
s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
36+
s.add_dependency("actionmailer", ["~> 5.1"])
37+
s.add_dependency("bundler", ["~> 1.0"])
38+
s.add_dependency("hubspot-ruby", ["~> 0.4"])
3739
end
3840
end

lib/hubspot-mailer.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
require 'action_mailer'
2-
require 'hubspot-ruby'
3-
require 'hubspot/mailer/delivery'
4-
require 'hubspot/mailer/exceptions'
5-
require 'hubspot/mailer/hubspot_preview_interceptor'
6-
require 'hubspot/mailer/message'
7-
require 'hubspot/mailer'
1+
# frozen_string_literal: true
82

3+
require "action_mailer"
4+
require "hubspot-ruby"
5+
require "hubspot/mailer/delivery"
6+
require "hubspot/mailer/exceptions"
7+
require "hubspot/mailer/hubspot_preview_interceptor"
8+
require "hubspot/mailer/message"
9+
require "hubspot/mailer"

lib/hubspot/mailer.rb

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Hubspot
24
class Mailer < ActionMailer::Base
35
abstract!
@@ -15,7 +17,7 @@ class Mailer < ActionMailer::Base
1517

1618
self.default_params = {}.freeze
1719

18-
SINGLE_SEND_PATH = '/email/public/v1/singleEmail/send'.freeze
20+
SINGLE_SEND_PATH = "/email/public/v1/singleEmail/send"
1921

2022
class << self
2123
# Wraps an email delivery inside of <tt>ActiveSupport::Notifications</tt> instrumentation.
@@ -82,19 +84,19 @@ def single_send_params(mail)
8284
end
8385

8486
# Copy subject from header to custom property
85-
if mail.subject.present? and not mail.custom_properties.try(:[], :subject)
87+
if mail.subject.present? && !mail.custom_properties.try(:[], :subject)
8688
mail.custom_properties ||= {}
8789
mail.custom_properties[:subject] = mail.subject
8890
end
8991

9092
if mail.contact_properties.present?
9193
data[:contactProperties] =
92-
Hubspot::Utils.hash_to_properties(mail.contact_properties, :key_name => :name)
94+
Hubspot::Utils.hash_to_properties(mail.contact_properties, key_name: :name)
9395
end
9496

9597
if mail.custom_properties.present?
9698
data[:customProperties] =
97-
Hubspot::Utils.hash_to_properties(mail.custom_properties, :key_name => :name)
99+
Hubspot::Utils.hash_to_properties(mail.custom_properties, key_name: :name)
98100
end
99101

100102
data
@@ -104,20 +106,21 @@ def parse_response(response)
104106
status_code = response["sendResult"]
105107

106108
case status_code
107-
when "SENT", "QUEUED"
108-
response["eventId"]
109-
when "INVALID_TO_ADDRESS"
110-
raise RecipientAddressError.new(response), "The TO address is invalid: #{status_code}"
111-
when "INVALID_FROM_ADDRESS"
112-
raise SenderAddressError.new(response), "The FROM address is invalid: #{status_code}"
113-
when "BLOCKED_DOMAIN", "PORTAL_SUSPENDED"
114-
raise SendingError.new(response), "Message can't be sent: #{status_code}"
115-
when "PREVIOUSLY_BOUNCED", "PREVIOUS_SPAM"
116-
raise DeliveryError.new(response), "Message can't be delivered: #{status_code}"
117-
when "MISSING_CONTENT"
118-
raise InvalidTemplateError.new(response), "The emailId is invalid, or the emailId is an email that is not set up for Single Send: #{status_code}"
119-
else
120-
raise UnknownResponseError.new(response), "Unrecognized status code: #{status_code}"
109+
when "SENT", "QUEUED"
110+
response["eventId"]
111+
when "INVALID_TO_ADDRESS"
112+
raise RecipientAddressError.new(response), "The TO address is invalid: #{status_code}"
113+
when "INVALID_FROM_ADDRESS"
114+
raise SenderAddressError.new(response), "The FROM address is invalid: #{status_code}"
115+
when "BLOCKED_DOMAIN", "PORTAL_SUSPENDED"
116+
raise SendingError.new(response), "Message can't be sent: #{status_code}"
117+
when "PREVIOUSLY_BOUNCED", "PREVIOUS_SPAM"
118+
raise DeliveryError.new(response), "Message can't be delivered: #{status_code}"
119+
when "MISSING_CONTENT"
120+
raise InvalidTemplateError.new(response),
121+
"The emailId is invalid, or the emailId is an email that is not set up for Single Send: #{status_code}"
122+
else
123+
raise UnknownResponseError.new(response), "Unrecognized status code: #{status_code}"
121124
end
122125
end
123126
end
@@ -173,7 +176,8 @@ def assign_attributes_to_message(message, headers)
173176

174177
def assign_headers_to_message(message, headers)
175178
headers.except(:parts_order, :content_type, :body, :template_name,
176-
:template_path, :delivery_method, :delivery_method_options).each { |k, v| message[k] = v }
179+
:template_path, :delivery_method, :delivery_method_options)
180+
.each { |k, v| message[k] = v }
177181
end
178182
end
179183
end

lib/hubspot/mailer/delivery.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
# frozen_string_literal: true
2+
13
module Hubspot
24
class Mailer < ActionMailer::Base
35
class Delivery
46
attr_accessor :settings
57

6-
DEFAULTS = {}
8+
DEFAULTS = {}.freeze
79

810
def initialize(values)
911
self.settings = DEFAULTS.merge(values)

lib/hubspot/mailer/exceptions.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Hubspot
24
class Mailer < ActionMailer::Base
35
class MissingTemplateError < StandardError; end

lib/hubspot/mailer/hubspot_preview_interceptor.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Hubspot
24
class Mailer < ActionMailer::Base
35
class HubspotPreviewInterceptor
@@ -21,7 +23,8 @@ def transform!
2123

2224
def build_preview
2325
if message.message.is_a?(Hubspot::Mailer::Message)
24-
html_part = "<b>Email ID (template)</b>: #{message.email_id}<br/><br/>"
26+
html_part = String.new
27+
html_part << "<b>Email ID (template)</b>: #{message.email_id}<br/><br/>"
2528

2629
html_part << list_properties("Contact Properties (use via {{contact.propertyname}})", message.contact_properties)
2730
html_part << list_properties("Custom Properties (use via {{custom.property_name}})", message.custom_properties)
@@ -33,7 +36,7 @@ def build_preview
3336
end
3437

3538
def list_properties(label, list)
36-
buffer = ""
39+
buffer = String.new
3740
return buffer unless list.present?
3841

3942
buffer << "<b>#{label}</b>:<ul>"

lib/hubspot/mailer/message.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module Hubspot
24
class Mailer < ActionMailer::Base
35
class Message < Mail::Message

0 commit comments

Comments
 (0)