Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VSTS-3397 - Maropost Subscriptions #10

Merged
merged 2 commits into from
Oct 18, 2017
Merged

VSTS-3397 - Maropost Subscriptions #10

merged 2 commits into from
Oct 18, 2017

Conversation

jessedoyle
Copy link
Contributor

🐘

  • Add simplecov and set the minimum coverage to 100%.
  • Add a spec for Maropost.configure.
  • [breaking change] - Refactor Maropost::Contact to store
    subscriptions inside a lists hash (as opposed to unique
    instance accessors). This allows us to iterate subscriptions
    easily to simplify logic as well as allow for future updates.
  • Fix the DoNotMailList - previously, the user was not opted
    into the do not mail list when they had no subscriptions.
  • Make the .rspec file include spec_helper. Remove spec_helper
    inclusions in individual tests.
  • Fix awkward method call syntax in Maropost::Api.
  • Use class << self where possible - this allows for private
    class methods.

SEE: https://amaabca.visualstudio.com/membership_backlog/_queries?id=3397

* Add `simplecov` and set the minimum coverage to 100%.
* Add a spec for `Maropost.configure`.
* [**breaking change**] - Refactor `Maropost::Contact` to store
  subscriptions inside a `lists` hash (as opposed to unique
  instance accessors). This allows us to iterate subscriptions
  easily to simplify logic as well as allow for future updates.
* Fix the `DoNotMailList` - previously, the user was not opted
  into the do not mail list when they had no subscriptions.
* Make the `.rspec` file include `spec_helper`. Remove `spec_helper`
  inclusions in individual tests.
* Fix awkward method call syntax in `Maropost::Api`.
* Use `class << self` where possible - this allows for private
  class methods.

SEE: https://amaabca.visualstudio.com/membership_backlog/_queries?id=3397
@mvandenbeuken
Copy link
Member

📖

Copy link
Member

@mvandenbeuken mvandenbeuken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Just a few questions.

rescue RestClient::ResourceNotFound
nil
end
class << self
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you prefer this to keep class methods contained in a block?

Copy link
Contributor Author

@jessedoyle jessedoyle Oct 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer it because it allows private class-level methods:

class Foo

  private

  def self.bar
    'called!'
  end
end

Foo.bar # => "called!"

vs.

class Foo
  class << self
    private
    
    def bar
      'called!'
    end
  end
end

Foo.bar # => NoMethodError: private method `bar' called for Foo:Class

Though maybe there's an argument against the use of private class methods.

else
create(contact)
def update_subscriptions(contact)
if existing_contact = find(contact.email)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it worth doing the same kind of presence check on these methods as you have on the find method?

maropost_url('global_unsubscribes/email.json', "contact[email]=#{CGI.escape(contact.email)}")
)
JSON.parse(response.body)
response['id'].present?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

def request(method, url, payload = {})
RestClient::Request.logged_request(
method: method,
read_timeout: 10,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was going to say we could make this configurable, but we shouldn't have to bump the read_timeout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea it should be configuration. With a default.

@@ -0,0 +1,4 @@
SimpleCov.start do
SimpleCov.minimum_coverage 100.00
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be worth adding rubocop? how many violations would the current version of the gem have?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to. Let's give it a shot and see!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

lists
errors
).freeze
LISTS = %i(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. It makes it clearer what's a subscription vs a subscriber attribute. Too bad cell_phone_number is an outlier.

@jessedoyle
Copy link
Contributor Author

👋

__PR Review__

* Refactor common API handling code into a `Service` class. We no
  longer have to store state inside method call parameters.
* Add a request_id to every external request.
* Make the open_timeout and read_timeout configurable for the gem.
* Refactor query handling - use methods provided in RestClient to
  do the work for us.
* We must specify the `auth_token` parameter on `get` requests
  as per Maropost's documentation - this parameter is needed in the
  url.
* Implement rubocop and fix all warnings.

SEE: https://amaabca.visualstudio.com/membership_backlog/_queries?id=3397
@rubene
Copy link
Member

rubene commented Oct 18, 2017

📖


private

def initialize_lists(opts = {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@rubene
Copy link
Member

rubene commented Oct 18, 2017

🐘 🐘 🐘

@jessedoyle jessedoyle merged commit ec281f4 into master Oct 18, 2017
@jessedoyle jessedoyle deleted the vsts-3397 branch October 18, 2017 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants