mailchimp_api_v3 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b131d5f8ea61376b71ae54ad06e55ba4d1b4ad2
4
- data.tar.gz: 761823e4d92f3d25340294ad43eb30c0398358e9
3
+ metadata.gz: c5bd68d37be74e00ba3cc25767c6eb284dacbfb6
4
+ data.tar.gz: 38fdd51235a7defcdc13a26da6f9a062299cd42b
5
5
  SHA512:
6
- metadata.gz: 74c51582f8b6c2c12b5909120b92bd2e9341ee9fda650373ad26fcdb5bbc3934caf21d4a0aa58303c91ab30f61043f79c2a8a84fe6b0f4b0bf20ab331cd7028d
7
- data.tar.gz: 3e7dec641e3cb9f0b4a8502984af84b79c1dcd4857f08ce3e59679ecc4b698c454c2bed44ce6f3ffefdf9581b6c0be09d52e1c7c2b5fcdbfd1076d8b332b146b
6
+ metadata.gz: da6e188a8a5664611e1d78f3dc046455818d204bc4979d5243421825d9844a872b625dd7e1f854c24e822baac9514a59d9134d18b181aab6c894ef4c00e9aaf7
7
+ data.tar.gz: 497263a595bfeef764a482f809a096d4af6d5b5cc4dd0afdd1a6c85cebe7b8d1c2e25d66c219b68bc73322157494e10318f7a47a081e05a5d31d2c0b7962f0d1
@@ -38,6 +38,6 @@ class String
38
38
  end
39
39
 
40
40
  def convert_to_id
41
- OpenSSL::Digest.digest('MD5', self.downcase).unpack('H*').first
41
+ OpenSSL::Digest.digest('MD5', downcase).unpack('H*').first
42
42
  end
43
43
  end
@@ -23,7 +23,7 @@ module Mailchimp
23
23
  def initialize(api_key = nil, extra_headers = {})
24
24
  @api_key = api_key || ENV['MAILCHIMP_API_KEY']
25
25
 
26
- fail(
26
+ raise(
27
27
  Mailchimp::Exception::APIKeyError,
28
28
  'detail' => "Invalid API key format: #{@api_key}"
29
29
  ) unless api_key_valid?
@@ -22,7 +22,7 @@ module Mailchimp
22
22
 
23
23
  private
24
24
 
25
- RETRY_EXCEPTIONS = [SocketError]
25
+ RETRY_EXCEPTIONS = [SocketError].freeze
26
26
 
27
27
  def managed_remote(path, method = :get, options = {}, payload = nil)
28
28
  headers_and_params = headers.merge params_from(options)
@@ -40,11 +40,11 @@ module Mailchimp
40
40
  exception_class_name = e.class.to_s
41
41
 
42
42
  if Mailchimp::Exception::MAPPED_EXCEPTIONS.key? exception_class_name
43
- fail Mailchimp::Exception::MAPPED_EXCEPTIONS[exception_class_name], data
43
+ raise Mailchimp::Exception::MAPPED_EXCEPTIONS[exception_class_name], data
44
44
  elsif exception_class_name == 'RestClient::BadRequest'
45
45
  Mailchimp::Exception.parse_invalid_resource_exception data
46
46
  else
47
- fail e
47
+ raise e
48
48
  end
49
49
  end
50
50
 
@@ -3,13 +3,9 @@ module Mailchimp
3
3
  def self.parse_invalid_resource_exception(data)
4
4
  detail = data['detail']
5
5
 
6
- if detail.include? 'already'
7
- fail Duplicate, data
8
- elsif detail.include? 'can\'t be blank'
9
- fail MissingField, data
10
- else
11
- fail BadRequest, data
12
- end
6
+ raise Duplicate, data if detail.include? 'already'
7
+ raise MissingField, data if detail.include? 'can\'t be blank'
8
+ raise BadRequest, data
13
9
  end
14
10
 
15
11
  class DataException < RuntimeError
@@ -19,7 +15,11 @@ module Mailchimp
19
15
  end
20
16
 
21
17
  def method_missing(symbol)
22
- @data[symbol.id2name]
18
+ symbol.is_a?(Symbol) ? @data[symbol.id2name] : super
19
+ end
20
+
21
+ def respond_to_missing?(symbol)
22
+ symbol.is_a?(Symbol)
23
23
  end
24
24
  end
25
25
 
@@ -35,6 +35,6 @@ module Mailchimp
35
35
  MAPPED_EXCEPTIONS = {
36
36
  'RestClient::ResourceNotFound' => NotFound,
37
37
  'RestClient::Unauthorized' => APIKeyError
38
- }
38
+ }.freeze
39
39
  end
40
40
  end
@@ -59,6 +59,11 @@ module Mailchimp
59
59
  super
60
60
  end
61
61
 
62
+ def respond_to_missing?(symbol)
63
+ key = symbol.id2name
64
+ @data.key? key
65
+ end
66
+
62
67
  def subclass_instance_from(collection_class, id)
63
68
  child_path = "#{path}/#{collection_class::PATH_KEY}"
64
69
  collection_class::CHILD_CLASS.get @client, child_path, id
@@ -4,7 +4,7 @@ module Mailchimp
4
4
  Interest = Class.new(Instance)
5
5
 
6
6
  class Interests < Collection
7
- PATH_KEY = DATA_KEY = 'interests'
7
+ PATH_KEY = DATA_KEY = 'interests'.freeze
8
8
  CHILD_CLASS = Interest
9
9
  end
10
10
  end
@@ -9,9 +9,9 @@ module Mailchimp
9
9
  end
10
10
 
11
11
  class InterestCategories < Collection
12
- NAME_FIELD = 'title'
13
- PATH_KEY = 'interest-categories'
14
- DATA_KEY = 'categories'
12
+ NAME_FIELD = 'title'.freeze
13
+ PATH_KEY = 'interest-categories'.freeze
14
+ DATA_KEY = 'categories'.freeze
15
15
  CHILD_CLASS = InterestCategory
16
16
  end
17
17
  end
@@ -15,7 +15,7 @@ module Mailchimp
15
15
  end
16
16
 
17
17
  class Lists < Collection
18
- PATH_KEY = DATA_KEY = 'lists'
18
+ PATH_KEY = DATA_KEY = 'lists'.freeze
19
19
  CHILD_CLASS = List
20
20
  end
21
21
  end
@@ -56,7 +56,7 @@ module Mailchimp
56
56
  end
57
57
 
58
58
  class Members < Collection
59
- PATH_KEY = DATA_KEY = 'members'
59
+ PATH_KEY = DATA_KEY = 'members'.freeze
60
60
  CHILD_CLASS = Member
61
61
 
62
62
  def create(data)
@@ -1,3 +1,3 @@
1
1
  module Mailchimp
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'.freeze
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = 'A simple gem to interact with Mailchimp through their API v3'
11
11
  spec.summary = 'Example: mailchimp.lists("My first list").member("ann@example.com")'
12
12
  spec.homepage = 'https://github.com/Xenapto/mailchimp_api_v3'
13
- spec.license = 'BSD'
13
+ spec.license = 'BSD-2-Clause'
14
14
 
15
15
  spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16
16
  spec.executables = spec.files.grep(%r{^bin\/}) { |f| File.basename(f) }
@@ -40,7 +40,7 @@ describe Mailchimp::List::Member, vcr: { cassette_name: 'member' } do
40
40
  }
41
41
  }
42
42
 
43
- expect(member.update data).to have_attributes name: 'Ann Example'
43
+ expect(member.update(data)).to have_attributes name: 'Ann Example'
44
44
  end
45
45
  end
46
46
  end
@@ -82,12 +82,12 @@ describe Mailchimp::List::Members do
82
82
  # Update
83
83
  data = { first_name: 'Catherine', email_address: 'cat@sayers.cc', status: 'subscribed' }
84
84
  expect { members.create_or_update data }.not_to change { list.members.count }
85
- expect(members.create_or_update data).to have_attributes name: 'Catherine Sayers'
85
+ expect(members.create_or_update(data)).to have_attributes name: 'Catherine Sayers'
86
86
 
87
87
  # Unless we supply an id or equivalent, we won't end up updating anything
88
88
  data = { name: 'Catherine Sayers' }
89
89
  expect { members.create_or_update data }.not_to change { list.members.count }
90
- expect(members.create_or_update data).to have_attributes name: 'Catherine Sayers'
90
+ expect(members.create_or_update(data)).to have_attributes name: 'Catherine Sayers'
91
91
  end
92
92
  end
93
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailchimp_api_v3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xenapto
@@ -260,7 +260,7 @@ files:
260
260
  - spec/support/vcr_setup.rb
261
261
  homepage: https://github.com/Xenapto/mailchimp_api_v3
262
262
  licenses:
263
- - BSD
263
+ - BSD-2-Clause
264
264
  metadata: {}
265
265
  post_install_message:
266
266
  rdoc_options: []