chartmogul-ruby 1.7.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +44 -0
  3. data/.rspec +0 -0
  4. data/2.0-Upgrade.md +9 -0
  5. data/README.md +8 -2
  6. data/changelog.md +14 -0
  7. data/chartmogul-ruby.gemspec +1 -1
  8. data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/correctly_interracts_with_the_API.yml +67 -119
  9. data/fixtures/vcr_cassettes/ChartMogul_Metrics_ActivitiesExport/get_activities_export.yml +43 -0
  10. data/fixtures/vcr_cassettes/ChartMogul_Metrics_ActivitiesExport/post_activities_export.yml +83 -0
  11. data/fixtures/vcr_cassettes/ChartMogul_Metrics_Activity.yml +37 -0
  12. data/fixtures/vcr_cassettes/ChartMogul_Metrics_Activity/behaves_like_PageableWithAnchor/should_be_pageable.yml +44 -0
  13. data/fixtures/vcr_cassettes/ChartMogul_Metrics_Activity/should_have_Activity_entries.yml +17 -14
  14. data/fixtures/vcr_cassettes/{ChartMogul_Metrics_Activity → ChartMogul_Metrics_Customers_Activity}/behaves_like_Pageable/should_be_pageable.yml +0 -0
  15. data/fixtures/vcr_cassettes/ChartMogul_Metrics_Customers_Activity/should_have_Activity_entries.yml +41 -0
  16. data/fixtures/vcr_cassettes/{ChartMogul_Metrics_Subscription → ChartMogul_Metrics_Customers_Subscription}/behaves_like_Pageable/should_be_pageable.yml +0 -0
  17. data/fixtures/vcr_cassettes/{ChartMogul_Metrics_Subscription → ChartMogul_Metrics_Customers_Subscription}/should_have_Subscription_entries.yml +0 -0
  18. data/lib/chartmogul.rb +10 -3
  19. data/lib/chartmogul/api/actions/all.rb +1 -1
  20. data/lib/chartmogul/api/actions/create.rb +2 -2
  21. data/lib/chartmogul/api/actions/custom.rb +1 -1
  22. data/lib/chartmogul/api/actions/retrieve.rb +2 -1
  23. data/lib/chartmogul/api/actions/update.rb +2 -2
  24. data/lib/chartmogul/api_resource.rb +8 -4
  25. data/lib/chartmogul/concerns/pageable_with_anchor.rb +14 -0
  26. data/lib/chartmogul/config_attributes.rb +17 -1
  27. data/lib/chartmogul/customer.rb +2 -2
  28. data/lib/chartmogul/metrics/activities_export.rb +38 -0
  29. data/lib/chartmogul/metrics/activity.rb +12 -8
  30. data/lib/chartmogul/metrics/customers/activity.rb +38 -0
  31. data/lib/chartmogul/metrics/customers/subscription.rb +41 -0
  32. data/lib/chartmogul/utils/hash_snake_caser.rb +9 -2
  33. data/lib/chartmogul/utils/json_parser.rb +2 -4
  34. data/lib/chartmogul/version.rb +1 -1
  35. data/pre-commit.example +0 -0
  36. metadata +18 -9
  37. data/.travis.yml +0 -25
  38. data/lib/chartmogul/metrics/subscription.rb +0 -39
@@ -4,7 +4,7 @@ module ChartMogul
4
4
  class Customer < APIResource
5
5
  set_resource_name 'Customer'
6
6
  set_resource_path '/v1/customers'
7
- set_skip_case_conversion true
7
+ set_immutable_keys([:attributes, :custom])
8
8
 
9
9
  readonly_attr :uuid
10
10
  readonly_attr :id
@@ -132,7 +132,7 @@ module ChartMogul
132
132
  class Customers < APIResource
133
133
  set_resource_name 'Customers'
134
134
  set_resource_path '/v1/customers'
135
- set_skip_case_conversion true
135
+ set_immutable_keys([:attributes, :custom])
136
136
 
137
137
  include Concerns::Entries
138
138
  include API::Actions::Custom
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChartMogul
4
+ module Metrics
5
+ class ActivitiesExport < APIResource
6
+ set_resource_name 'ActivitiesExport'
7
+ set_resource_path '/v1/activities_export'
8
+
9
+ readonly_attr :id
10
+ readonly_attr :status
11
+ readonly_attr :file_url
12
+ readonly_attr :params
13
+ readonly_attr :expires_at
14
+ readonly_attr :created_at
15
+
16
+ writeable_attr :start_date
17
+ writeable_attr :end_date
18
+ writeable_attr :type
19
+
20
+ include API::Actions::Retrieve
21
+ include API::Actions::Create
22
+
23
+ def serialize_for_write
24
+ super.tap do |attributes|
25
+ attributes.clone.each do |k, v|
26
+ attributes[preprocess_attributes(k)] = attributes.delete(k)
27
+ end
28
+ end
29
+ end
30
+
31
+ def preprocess_attributes(attribute)
32
+ return attribute unless %i[start_date end_date].include?(attribute)
33
+
34
+ attribute.to_s.tr('_', '-')
35
+ end
36
+ end
37
+ end
38
+ end
@@ -3,7 +3,6 @@
3
3
  module ChartMogul
4
4
  module Metrics
5
5
  class Activity < ChartMogul::Object
6
- readonly_attr :id
7
6
  readonly_attr :description
8
7
  readonly_attr :type
9
8
  readonly_attr :date, type: :time
@@ -11,25 +10,30 @@ module ChartMogul
11
10
  readonly_attr :activity_mrr
12
11
  readonly_attr :activity_mrr_movement
13
12
  readonly_attr :currency
14
- readonly_attr :currency_sign
15
13
  readonly_attr :subscription_external_id
14
+ readonly_attr :plan_external_id
15
+ readonly_attr :customer_name
16
+ readonly_attr :customer_uuid
17
+ readonly_attr :customer_external_id
18
+ readonly_attr :billing_connector_uuid
19
+ readonly_attr :uuid
16
20
 
17
- def self.all(customer_uuid, options = {})
18
- ChartMogul::Metrics::Activities.all(customer_uuid, options)
21
+ def self.all(options = {})
22
+ ChartMogul::Metrics::Activities.all(options)
19
23
  end
20
24
  end
21
25
 
22
26
  class Activities < APIResource
23
27
  set_resource_name 'Activities'
24
- set_resource_path '/v1/customers/:customer_uuid/activities'
28
+ set_resource_path '/v1/activities'
25
29
 
26
30
  include Concerns::Entries
27
- include Concerns::Pageable
31
+ include Concerns::PageableWithAnchor
28
32
 
29
33
  set_entry_class Activity
30
34
 
31
- def self.all(customer_uuid, options = {})
32
- super(options.merge(customer_uuid: customer_uuid))
35
+ def self.all(options = {})
36
+ super(options)
33
37
  end
34
38
  end
35
39
  end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChartMogul
4
+ module Metrics
5
+ module Customers
6
+ class Activity < ChartMogul::Object
7
+ readonly_attr :id
8
+ readonly_attr :description
9
+ readonly_attr :type
10
+ readonly_attr :date, type: :time
11
+ readonly_attr :activity_arr
12
+ readonly_attr :activity_mrr
13
+ readonly_attr :activity_mrr_movement
14
+ readonly_attr :currency
15
+ readonly_attr :currency_sign
16
+ readonly_attr :subscription_external_id
17
+
18
+ def self.all(customer_uuid, options = {})
19
+ ChartMogul::Metrics::Customers::Activities.all(customer_uuid, options)
20
+ end
21
+ end
22
+
23
+ class Activities < APIResource
24
+ set_resource_name 'Activities'
25
+ set_resource_path '/v1/customers/:customer_uuid/activities'
26
+
27
+ include Concerns::Entries
28
+ include Concerns::Pageable
29
+
30
+ set_entry_class Activity
31
+
32
+ def self.all(customer_uuid, options = {})
33
+ super(options.merge(customer_uuid: customer_uuid))
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ChartMogul
4
+ module Metrics
5
+ module Customers
6
+ class Subscription < ChartMogul::Object
7
+ readonly_attr :id
8
+ readonly_attr :external_id
9
+ readonly_attr :plan
10
+ readonly_attr :quantity
11
+ readonly_attr :mrr
12
+ readonly_attr :arr
13
+ readonly_attr :status
14
+ readonly_attr :billing_cycle
15
+ readonly_attr :billing_cycle_count
16
+ readonly_attr :start_date, type: :time
17
+ readonly_attr :end_date, type: :time
18
+ readonly_attr :currency
19
+ readonly_attr :currency_sign
20
+
21
+ def self.all(customer_uuid, options = {})
22
+ ChartMogul::Metrics::Customers::Subscriptions.all(customer_uuid, options)
23
+ end
24
+ end
25
+
26
+ class Subscriptions < APIResource
27
+ set_resource_name 'Subscriptions'
28
+ set_resource_path '/v1/customers/:customer_uuid/subscriptions'
29
+
30
+ include Concerns::Entries
31
+ include Concerns::Pageable
32
+
33
+ set_entry_class Subscription
34
+
35
+ def self.all(customer_uuid, options = {})
36
+ super(options.merge(customer_uuid: customer_uuid))
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -8,8 +8,9 @@ module ChartMogul
8
8
  # Rubyish snake_case, suitable for use during instantiation of Ruby
9
9
  # model attributes.
10
10
  #
11
- def initialize(hash)
11
+ def initialize(hash, immutable_keys: [])
12
12
  @hash = hash
13
+ @immutable_keys = immutable_keys
13
14
  end
14
15
 
15
16
  def to_snake_keys(value = @hash)
@@ -26,7 +27,13 @@ module ChartMogul
26
27
  private
27
28
 
28
29
  def snake_hash(value)
29
- Hash[value.map { |k, v| [underscore_key(k), to_snake_keys(v)] }]
30
+ Hash[value.map { |k, v| [underscore_key(k), immutable_check(k, v)] }]
31
+ end
32
+
33
+ def immutable_check(k,v)
34
+ return v if @immutable_keys.include?(k)
35
+
36
+ to_snake_keys(v)
30
37
  end
31
38
 
32
39
  def underscore_key(k)
@@ -4,11 +4,9 @@ module ChartMogul
4
4
  module Utils
5
5
  class JSONParser
6
6
  class << self
7
- def parse(json_string, skip_case_conversion: false)
7
+ def parse(json_string, immutable_keys: [])
8
8
  hash = JSON.parse(json_string, symbolize_names: true)
9
- return hash if skip_case_conversion
10
-
11
- HashSnakeCaser.new(hash).to_snake_keys
9
+ HashSnakeCaser.new(hash, immutable_keys: immutable_keys).to_snake_keys
12
10
  end
13
11
 
14
12
  def typecast_custom_attributes(custom_attributes)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChartMogul
4
- VERSION = '1.7.1'
4
+ VERSION = '2.1.0'
5
5
  end
data/pre-commit.example CHANGED
File without changes
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.7.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petr Kopac
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-12 00:00:00.000000000 Z
11
+ date: 2021-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.0
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.0.0
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -171,9 +171,10 @@ executables: []
171
171
  extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
+ - ".github/workflows/test.yml"
174
175
  - ".gitignore"
175
176
  - ".rspec"
176
- - ".travis.yml"
177
+ - 2.0-Upgrade.md
177
178
  - Gemfile
178
179
  - LICENSE.txt
179
180
  - README.md
@@ -221,21 +222,26 @@ files:
221
222
  - fixtures/vcr_cassettes/ChartMogul_Metrics_ARR/behaves_like_Metrics_API_resource/should_have_entries.yml
222
223
  - fixtures/vcr_cassettes/ChartMogul_Metrics_ASP/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml
223
224
  - fixtures/vcr_cassettes/ChartMogul_Metrics_ASP/behaves_like_Metrics_API_resource/should_have_entries.yml
224
- - fixtures/vcr_cassettes/ChartMogul_Metrics_Activity/behaves_like_Pageable/should_be_pageable.yml
225
+ - fixtures/vcr_cassettes/ChartMogul_Metrics_ActivitiesExport/get_activities_export.yml
226
+ - fixtures/vcr_cassettes/ChartMogul_Metrics_ActivitiesExport/post_activities_export.yml
227
+ - fixtures/vcr_cassettes/ChartMogul_Metrics_Activity.yml
228
+ - fixtures/vcr_cassettes/ChartMogul_Metrics_Activity/behaves_like_PageableWithAnchor/should_be_pageable.yml
225
229
  - fixtures/vcr_cassettes/ChartMogul_Metrics_Activity/should_have_Activity_entries.yml
226
230
  - fixtures/vcr_cassettes/ChartMogul_Metrics_AllKeyMetric/should_have_entries.yml
227
231
  - fixtures/vcr_cassettes/ChartMogul_Metrics_CustomerChurnRate/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml
228
232
  - fixtures/vcr_cassettes/ChartMogul_Metrics_CustomerChurnRate/behaves_like_Metrics_API_resource/should_have_entries.yml
229
233
  - fixtures/vcr_cassettes/ChartMogul_Metrics_CustomerCount/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml
230
234
  - fixtures/vcr_cassettes/ChartMogul_Metrics_CustomerCount/behaves_like_Metrics_API_resource/should_have_entries.yml
235
+ - fixtures/vcr_cassettes/ChartMogul_Metrics_Customers_Activity/behaves_like_Pageable/should_be_pageable.yml
236
+ - fixtures/vcr_cassettes/ChartMogul_Metrics_Customers_Activity/should_have_Activity_entries.yml
237
+ - fixtures/vcr_cassettes/ChartMogul_Metrics_Customers_Subscription/behaves_like_Pageable/should_be_pageable.yml
238
+ - fixtures/vcr_cassettes/ChartMogul_Metrics_Customers_Subscription/should_have_Subscription_entries.yml
231
239
  - fixtures/vcr_cassettes/ChartMogul_Metrics_LTV/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml
232
240
  - fixtures/vcr_cassettes/ChartMogul_Metrics_LTV/behaves_like_Metrics_API_resource/should_have_entries.yml
233
241
  - fixtures/vcr_cassettes/ChartMogul_Metrics_MRR/behaves_like_Summary/should_have_summary.yml
234
242
  - fixtures/vcr_cassettes/ChartMogul_Metrics_MRR/should_have_entries.yml
235
243
  - fixtures/vcr_cassettes/ChartMogul_Metrics_MRRChurnRate/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml
236
244
  - fixtures/vcr_cassettes/ChartMogul_Metrics_MRRChurnRate/behaves_like_Metrics_API_resource/should_have_entries.yml
237
- - fixtures/vcr_cassettes/ChartMogul_Metrics_Subscription/behaves_like_Pageable/should_be_pageable.yml
238
- - fixtures/vcr_cassettes/ChartMogul_Metrics_Subscription/should_have_Subscription_entries.yml
239
245
  - fixtures/vcr_cassettes/ChartMogul_Ping/pings/and_fails_on_incorrect_credentials.yml
240
246
  - fixtures/vcr_cassettes/ChartMogul_Ping/pings/and_fails_with_500_internal_server_error.yml
241
247
  - fixtures/vcr_cassettes/ChartMogul_Ping/pings/and_fails_with_504_gateway_timeout_error.yml
@@ -274,6 +280,7 @@ files:
274
280
  - lib/chartmogul/concerns/entries.rb
275
281
  - lib/chartmogul/concerns/pageable.rb
276
282
  - lib/chartmogul/concerns/pageable2.rb
283
+ - lib/chartmogul/concerns/pageable_with_anchor.rb
277
284
  - lib/chartmogul/concerns/summary.rb
278
285
  - lib/chartmogul/config_attributes.rb
279
286
  - lib/chartmogul/configuration.rb
@@ -292,6 +299,7 @@ files:
292
299
  - lib/chartmogul/invoice.rb
293
300
  - lib/chartmogul/line_items/one_time.rb
294
301
  - lib/chartmogul/line_items/subscription.rb
302
+ - lib/chartmogul/metrics/activities_export.rb
295
303
  - lib/chartmogul/metrics/activity.rb
296
304
  - lib/chartmogul/metrics/all_key_metrics.rb
297
305
  - lib/chartmogul/metrics/arpa.rb
@@ -300,10 +308,11 @@ files:
300
308
  - lib/chartmogul/metrics/base.rb
301
309
  - lib/chartmogul/metrics/customer_churn_rate.rb
302
310
  - lib/chartmogul/metrics/customer_count.rb
311
+ - lib/chartmogul/metrics/customers/activity.rb
312
+ - lib/chartmogul/metrics/customers/subscription.rb
303
313
  - lib/chartmogul/metrics/ltv.rb
304
314
  - lib/chartmogul/metrics/mrr.rb
305
315
  - lib/chartmogul/metrics/mrr_churn_rate.rb
306
- - lib/chartmogul/metrics/subscription.rb
307
316
  - lib/chartmogul/object.rb
308
317
  - lib/chartmogul/ping.rb
309
318
  - lib/chartmogul/plan.rb
data/.travis.yml DELETED
@@ -1,25 +0,0 @@
1
- os: linux
2
- dist: bionic
3
-
4
- language: ruby
5
-
6
- rvm:
7
- - 2.3
8
- - 2.4
9
- - 2.5
10
- - 2.6
11
- - 2.7
12
-
13
- before_install: gem install bundler
14
-
15
- before_script:
16
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
17
- - chmod +x ./cc-test-reporter
18
- - ./cc-test-reporter before-build
19
-
20
- branches:
21
- only:
22
- - main
23
-
24
- after_script:
25
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ChartMogul
4
- module Metrics
5
- class Subscription < ChartMogul::Object
6
- readonly_attr :id
7
- readonly_attr :external_id
8
- readonly_attr :plan
9
- readonly_attr :quantity
10
- readonly_attr :mrr
11
- readonly_attr :arr
12
- readonly_attr :status
13
- readonly_attr :billing_cycle
14
- readonly_attr :billing_cycle_count
15
- readonly_attr :start_date, type: :time
16
- readonly_attr :end_date, type: :time
17
- readonly_attr :currency
18
- readonly_attr :currency_sign
19
-
20
- def self.all(customer_uuid, options = {})
21
- ChartMogul::Metrics::Subscriptions.all(customer_uuid, options)
22
- end
23
- end
24
-
25
- class Subscriptions < APIResource
26
- set_resource_name 'Subscriptions'
27
- set_resource_path '/v1/customers/:customer_uuid/subscriptions'
28
-
29
- include Concerns::Entries
30
- include Concerns::Pageable
31
-
32
- set_entry_class Subscription
33
-
34
- def self.all(customer_uuid, options = {})
35
- super(options.merge(customer_uuid: customer_uuid))
36
- end
37
- end
38
- end
39
- end