chartmogul-ruby 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af78d54ace12411026ce9ee9a25248f092428f2c
4
- data.tar.gz: 4fd3512f3b39ee8df129f94cf2994f7cc0983fdc
3
+ metadata.gz: dd14d80ca5ef6ec9a672747aa43aa42c3c2273d6
4
+ data.tar.gz: eff41878d6cdf81a006ab2870389aae11846651b
5
5
  SHA512:
6
- metadata.gz: 1b317b68430c609ba27240dd6fdd12f7ab92293b72d11dd45813e937af7d509e71ddc185d19964bf199be02433001a00dba04d4d4a6c9f95467c65fdf53b3a91
7
- data.tar.gz: 60ef9540f2486f9ee9cad87a327df056e12c300a04e44a7051d04bfcf21e3e0e33a6d31be863e657f437abeb9c08db235b64aab1933654dbfd04266ded1438e0
6
+ metadata.gz: 786c4423ba62345bf5c66a71e8c13ca68a2dbd0fc5349ebf78b943e3fcc04df4f8a269efe1723821922add7c0912f35bdc0b8ca2c33926800d3b1b98eafe1d78
7
+ data.tar.gz: 97e57e5a0590f2ec2cdda4219980e6686c567e6555dde5358089b30018a9358370dd032dd450cc34f00850a4c7a5a122eea0ab308b35f133ed68c2def84ebb5a
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.chartmogul.com/v1/customers/search?email=adam%40smith.com&page=2&per_page=1
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{}'
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Content-Type:
13
+ - application/json
14
+ Authorization:
15
+ - Basic MDFiNzI2YzI0ZjNiYjhlOTc0MmEwNGZiMDhhZmE3NzQ6NzJlNGMxYTdlZTFiYzlkNGZjMDBlZWUwNWIyN2QzMGY=
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ server:
22
+ - nginx/1.9.10
23
+ date:
24
+ - Wed, 29 Jun 2016 12:47:11 GMT
25
+ content-type:
26
+ - application/json
27
+ content-length:
28
+ - '740'
29
+ connection:
30
+ - close
31
+ status:
32
+ - 200 OK
33
+ access-control-allow-credentials:
34
+ - 'true'
35
+ body:
36
+ encoding: UTF-8
37
+ string: '{"entries":[{"id":20268060,"uuid":"cus_07393ece-aab1-4255-8bcd-0ef11e24b047","external_id":"cus_0001","name":"Adam
38
+ Smith","email":"adam@smith.com","status":"Cancelled","customer-since":"2016-05-01T12:00:00+00:00","attributes":{"tags":["another-tag"],"custom":{"string_key":"Another
39
+ String Value","integer_key":"5678","timestamp_key":"2016-02-01 00:00:00 UTC","boolean_key":"f"}},"address":{"country":"United
40
+ States","state":null,"city":"New York","address_line1":null,"address_line2":null,"address_zip":""},"mrr":0,"arr":0,"billing-system-url":null,"chartmogul-url":"https://app.chartmogul.com/#customers/cus_07393ece-aab1-4255-8bcd-0ef11e24b047-Adam_Smith","billing-system-type":"ImportApi","currency":"USD","currency-sign":"$"}],"has_more":false,"per_page":1,"page":2}'
41
+ http_version:
42
+ recorded_at: Wed, 29 Jun 2016 12:47:11 GMT
43
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,101 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.chartmogul.com/v1/import/customers/cus_510b1395-4fe8-4d35-ae23-0e61f9a51e33/subscriptions?page=1&per_page=2
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.2
12
+ Content-Type:
13
+ - application/json
14
+ Authorization:
15
+ - Basic YmIzN2I0Njk5NjNlMjhlYjY2MjA1ZWYzZmU1MWQ1NmM6ZmM1YjQxYzM3YTNlZTcwYjQyN2UwYzU1ODg2NzA2ZmQ=
16
+ response:
17
+ status:
18
+ code: 200
19
+ message:
20
+ headers:
21
+ server:
22
+ - nginx/1.9.10
23
+ date:
24
+ - Thu, 23 Jun 2016 20:46:07 GMT
25
+ content-type:
26
+ - application/json; charset=utf-8
27
+ transfer-encoding:
28
+ - chunked
29
+ connection:
30
+ - close
31
+ x-frame-options:
32
+ - SAMEORIGIN
33
+ x-xss-protection:
34
+ - 1; mode=block
35
+ x-content-type-options:
36
+ - nosniff
37
+ etag:
38
+ - W/"797037ae5a33dcae7de46e23dfdd4ec7"
39
+ cache-control:
40
+ - max-age=0, private, must-revalidate
41
+ x-request-id:
42
+ - efa1a67e-37e8-4ac3-bce7-8d11f33d0e8c
43
+ x-runtime:
44
+ - '0.026716'
45
+ strict-transport-security:
46
+ - max-age=15768000
47
+ body:
48
+ encoding: UTF-8
49
+ string: '{"customer_uuid":"cus_510b1395-4fe8-4d35-ae23-0e61f9a51e33","subscriptions":[{"uuid":"sub_9b3ccf25-4613-4af6-84b3-12026cfa4b7c","external_id":"test_cus_sub_ext_id","cancellation_dates":[],"plan_uuid":"pl_06ea83a9-f8c8-4ddd-a980-9ceffd27f107","data_source_uuid":"ds_55ab11fb-53e6-4468-aa95-bd582f14cac6"}],"current_page":1,"total_pages":1}'
50
+ http_version:
51
+ recorded_at: Thu, 23 Jun 2016 20:46:07 GMT
52
+ - request:
53
+ method: get
54
+ uri: https://api.chartmogul.com/v1/import/customers/cus_510b1395-4fe8-4d35-ae23-0e61f9a51e33/subscriptions?page=2&per_page=1
55
+ body:
56
+ encoding: US-ASCII
57
+ string: ''
58
+ headers:
59
+ User-Agent:
60
+ - Faraday v0.9.2
61
+ Content-Type:
62
+ - application/json
63
+ Authorization:
64
+ - Basic YmIzN2I0Njk5NjNlMjhlYjY2MjA1ZWYzZmU1MWQ1NmM6ZmM1YjQxYzM3YTNlZTcwYjQyN2UwYzU1ODg2NzA2ZmQ=
65
+ response:
66
+ status:
67
+ code: 200
68
+ message:
69
+ headers:
70
+ server:
71
+ - nginx/1.9.10
72
+ date:
73
+ - Thu, 23 Jun 2016 20:46:07 GMT
74
+ content-type:
75
+ - application/json; charset=utf-8
76
+ transfer-encoding:
77
+ - chunked
78
+ connection:
79
+ - close
80
+ x-frame-options:
81
+ - SAMEORIGIN
82
+ x-xss-protection:
83
+ - 1; mode=block
84
+ x-content-type-options:
85
+ - nosniff
86
+ etag:
87
+ - W/"797037ae5a33dcae7de46e23dfdd4ec7"
88
+ cache-control:
89
+ - max-age=0, private, must-revalidate
90
+ x-request-id:
91
+ - efa1a67e-37e8-4ac3-bce7-8d11f33d0e8c
92
+ x-runtime:
93
+ - '0.026716'
94
+ strict-transport-security:
95
+ - max-age=15768000
96
+ body:
97
+ encoding: UTF-8
98
+ string: '{"customer_uuid":"cus_510b1395-4fe8-4d35-ae23-0e61f9a51e33","subscriptions":[{"uuid":"sub_9b3ccf25-4613-4af6-84b3-12026cfa4b7c","external_id":"test_cus_sub_ext_id","cancellation_dates":[],"plan_uuid":"pl_06ea83a9-f8c8-4ddd-a980-9ceffd27f107","data_source_uuid":"ds_55ab11fb-53e6-4468-aa95-bd582f14cac6"}],"current_page":2,"total_pages":2}'
99
+ http_version:
100
+ recorded_at: Thu, 23 Jun 2016 20:46:07 GMT
101
+ recorded_with: VCR 3.0.3
@@ -14,12 +14,7 @@ module ChartMogul
14
14
  end
15
15
  end
16
16
  json = ChartMogul::Utils::JSONParser.parse(resp.body)
17
-
18
- if resource_root_key && json.key?(resource_root_key)
19
- json[resource_root_key].map { |attributes| new_from_json(attributes) }
20
- else
21
- new_from_json(json)
22
- end
17
+ new_from_json(json)
23
18
  end
24
19
  end
25
20
  end
@@ -28,12 +28,7 @@ module ChartMogul
28
28
 
29
29
  def custom!(http_method, http_path, body_data = {})
30
30
  json = custom_without_assign!(http_method, http_path, body_data)
31
-
32
- if resource_root_key && json.key?(resource_root_key)
33
- json[resource_root_key].map { |attributes| new_from_json(attributes) }
34
- else
35
- new_from_json(json)
36
- end
31
+ new_from_json(json)
37
32
  end
38
33
  end
39
34
  end
@@ -17,7 +17,7 @@ module ChartMogul
17
17
  def self.set_resource_root_key(root_key)
18
18
  @resource_root_key = root_key
19
19
  end
20
-
20
+
21
21
  def self.connection
22
22
  @connection ||= Faraday.new(url: ChartMogul::API_BASE) do |faraday|
23
23
  faraday.use Faraday::Request::BasicAuthentication, ChartMogul.account_token, ChartMogul.secret_key
@@ -3,15 +3,25 @@ module ChartMogul
3
3
  module Entries
4
4
  def self.included(base)
5
5
  base.extend ClassMethods
6
- base.send :prepend, InstanceMethods
7
6
 
8
7
  base.instance_eval do
9
- readonly_attr :entries, default: []
8
+ if @resource_root_key.nil?
9
+ @resource_root_key = :entries
10
+ end
11
+ readonly_attr @resource_root_key, default: []
10
12
 
11
13
  include API::Actions::All
12
14
 
13
15
  include Enumerable
14
- def_delegators :entries, :each, :[], :<<, :size, :length
16
+ def_delegators @resource_root_key, :each, :[], :<<, :size, :length, :empty?, :first
17
+
18
+ resource_root_key = @resource_root_key.to_s
19
+ base.send :define_method, "set_" + resource_root_key do |entries|
20
+ objects = entries.map do |entity|
21
+ self.class.get_entry_class.new_from_json(entity)
22
+ end
23
+ self.instance_variable_set "@#{resource_root_key}", objects
24
+ end
15
25
  end
16
26
  end
17
27
 
@@ -24,14 +34,6 @@ module ChartMogul
24
34
  instance_variable_get("@entry_class")
25
35
  end
26
36
  end
27
-
28
- module InstanceMethods
29
- def set_entries(entries_attributes)
30
- @entries = entries_attributes.map do |entity|
31
- self.class.get_entry_class.new_from_json(entity)
32
- end
33
- end
34
- end
35
37
  end
36
38
  end
37
39
  end
@@ -45,8 +45,8 @@ module ChartMogul
45
45
  custom!(:get, "/v1/customers/#{uuid}")
46
46
  end
47
47
 
48
- def self.search(email)
49
- Customers.search(email)
48
+ def self.search(email, options = {})
49
+ Customers.search(email, options)
50
50
  end
51
51
 
52
52
  def self.find_by_external_id(external_id)
@@ -147,9 +147,9 @@ module ChartMogul
147
147
 
148
148
  set_entry_class Customer
149
149
 
150
- def self.search(email)
150
+ def self.search(email, options = {})
151
151
  path = ChartMogul::ResourcePath.new('/v1/customers/search')
152
- custom!(:get, path.apply_with_get_params(email: email))
152
+ custom!(:get, path.apply_with_get_params(options.merge(email: email)))
153
153
  end
154
154
  end
155
155
  end
@@ -14,6 +14,7 @@ module ChartMogul
14
14
 
15
15
  include API::Actions::All
16
16
  include API::Actions::Create
17
+ include Concerns::Pageable2
17
18
 
18
19
  def serialize_invoices
19
20
  map(&:serialize_for_write)
@@ -23,10 +24,11 @@ module ChartMogul
23
24
  super(options.merge(customer_uuid: customer_uuid))
24
25
  end
25
26
 
26
- def_delegators :invoices, :each, :[], :<<, :size, :length
27
+ def_delegators :invoices, :each, :[], :<<, :size, :length, :empty?, :first
27
28
 
28
29
  private
29
30
 
31
+ # TODO: replace with Entries concern?
30
32
  def set_invoices(invoices_attributes)
31
33
  @invoices = invoices_attributes.map.with_index do |invoice_attributes, index|
32
34
  existing_invoice = invoices[index]
@@ -2,7 +2,6 @@ module ChartMogul
2
2
  class DataSource < APIResource
3
3
  set_resource_name 'Data Source'
4
4
  set_resource_path '/v1/data_sources'
5
- set_resource_root_key :data_sources
6
5
 
7
6
  readonly_attr :uuid
8
7
  readonly_attr :status
@@ -19,5 +18,21 @@ module ChartMogul
19
18
  def self.retrieve(uuid)
20
19
  custom!(:get, "/v1/data_sources/#{uuid}")
21
20
  end
21
+
22
+ def self.all(options = {})
23
+ DataSources.all(options)
24
+ end
25
+ end
26
+
27
+
28
+ class DataSources < APIResource
29
+ set_resource_name 'Data Sources'
30
+ set_resource_path '/v1/data_sources'
31
+
32
+ set_resource_root_key :data_sources
33
+
34
+ include Concerns::Entries
35
+
36
+ set_entry_class DataSource
22
37
  end
23
38
  end
@@ -2,6 +2,7 @@ module ChartMogul
2
2
  module Metrics
3
3
  class Subscription < ChartMogul::Object
4
4
  readonly_attr :id
5
+ readonly_attr :external_id
5
6
  readonly_attr :plan
6
7
  readonly_attr :quantity
7
8
  readonly_attr :mrr
@@ -34,4 +35,3 @@ module ChartMogul
34
35
  end
35
36
  end
36
37
  end
37
-
@@ -2,7 +2,6 @@ module ChartMogul
2
2
  class Plan < APIResource
3
3
  set_resource_name 'Plan'
4
4
  set_resource_path '/v1/plans'
5
- set_resource_root_key :plans
6
5
 
7
6
  readonly_attr :uuid
8
7
 
@@ -13,7 +12,6 @@ module ChartMogul
13
12
 
14
13
  writeable_attr :data_source_uuid
15
14
 
16
- include API::Actions::All
17
15
  include API::Actions::Create
18
16
  include API::Actions::Update
19
17
  include API::Actions::Destroy
@@ -22,5 +20,22 @@ module ChartMogul
22
20
  def self.retrieve(uuid)
23
21
  custom!(:get, "/v1/plans/#{uuid}")
24
22
  end
23
+
24
+ def self.all(options = {})
25
+ Plans.all(options)
26
+ end
27
+ end
28
+
29
+
30
+ class Plans < APIResource
31
+ set_resource_name 'Plans'
32
+ set_resource_path '/v1/plans'
33
+
34
+ set_resource_root_key :plans
35
+
36
+ include Concerns::Entries
37
+ include Concerns::Pageable2
38
+
39
+ set_entry_class Plan
25
40
  end
26
41
  end
@@ -2,7 +2,6 @@ module ChartMogul
2
2
  class Subscription < APIResource
3
3
  set_resource_name 'Subscription'
4
4
  set_resource_path '/v1/import/customers/:customer_uuid/subscriptions'
5
- set_resource_root_key :subscriptions
6
5
 
7
6
  readonly_attr :uuid
8
7
  readonly_attr :external_id
@@ -11,7 +10,6 @@ module ChartMogul
11
10
  readonly_attr :plan_uuid
12
11
  readonly_attr :data_source_uuid
13
12
 
14
- include API::Actions::All
15
13
  include API::Actions::Custom
16
14
 
17
15
  def set_cancellation_dates(cancellation_dates_array)
@@ -24,8 +22,27 @@ module ChartMogul
24
22
  custom!(:patch, "/v1/import/subscriptions/#{uuid}", cancelled_at: cancelled_at)
25
23
  end
26
24
 
25
+ def self.all(customer_uuid, options = {})
26
+ Subscriptions.all(customer_uuid, options)
27
+ end
28
+ end
29
+
30
+ class Subscriptions < APIResource
31
+ readonly_attr :customer_uuid
32
+
33
+ set_resource_name 'Subscriptions'
34
+ set_resource_path '/v1/import/customers/:customer_uuid/subscriptions'
35
+
36
+ set_resource_root_key :subscriptions
37
+
38
+ include Concerns::Entries
39
+ include Concerns::Pageable2
40
+
41
+ set_entry_class Subscription
42
+
27
43
  def self.all(customer_uuid, options = {})
28
44
  super(options.merge(customer_uuid: customer_uuid))
29
45
  end
46
+
30
47
  end
31
48
  end
@@ -1,3 +1,3 @@
1
1
  module ChartMogul
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chartmogul-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Langenauer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-06 00:00:00.000000000 Z
11
+ date: 2017-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -114,6 +114,7 @@ files:
114
114
  - chartmogul-ruby.gemspec
115
115
  - fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/adds_custom_attributes.yml
116
116
  - fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/adds_required_tags.yml
117
+ - fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/can_page_through_search_endpoint.yml
117
118
  - fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/correctly_handles_a_422_response.yml
118
119
  - fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/correctly_interracts_with_the_API.yml
119
120
  - fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/merges_customers.yml
@@ -163,6 +164,7 @@ files:
163
164
  - fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/retrieves_existing_plan_by_uuid.yml
164
165
  - fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/updates_existing_plan.yml
165
166
  - fixtures/vcr_cassettes/ChartMogul_Subscription/API_Interactions/correctly_interracts_with_the_API.yml
167
+ - fixtures/vcr_cassettes/ChartMogul_Subscription/API_Interactions/has_multiple_aliases.yml
166
168
  - fixtures/vcr_cassettes/ChartMogul_Transactions_Payment/API_Interactions/correctly_interracts_with_the_API.yml
167
169
  - lib/chartmogul.rb
168
170
  - lib/chartmogul/api/actions/all.rb