chartmogul-ruby 1.6.1 → 1.6.7
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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/README.md +1 -1
- data/changelog.md +3 -0
- data/chartmogul-ruby.gemspec +14 -13
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/adds_custom_attributes.yml +2 -2
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/updates_custom_attributes.yml +2 -2
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/updates_customer_using_class_method.yml +53 -0
- data/fixtures/vcr_cassettes/ChartMogul_CustomerInvoices/API_Interactions/correctly_interracts_with_the_API.yml +148 -109
- data/fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/updates_existing_plan_using_class_method.yml +164 -0
- data/fixtures/vcr_cassettes/ChartMogul_PlanGroup/API_interactions/updates_existing_plan_group_name_via_class_method.yml +297 -0
- data/lib/chartmogul.rb +2 -1
- data/lib/chartmogul/api/actions/create.rb +2 -2
- data/lib/chartmogul/api/actions/custom.rb +1 -1
- data/lib/chartmogul/api/actions/retrieve.rb +1 -1
- data/lib/chartmogul/api/actions/update.rb +22 -1
- data/lib/chartmogul/api_resource.rb +9 -4
- data/lib/chartmogul/configuration.rb +1 -0
- data/lib/chartmogul/customer.rb +1 -0
- data/lib/chartmogul/customer_invoices.rb +9 -0
- data/lib/chartmogul/utils/json_parser.rb +12 -2
- data/lib/chartmogul/version.rb +1 -1
- metadata +9 -6
data/lib/chartmogul.rb
CHANGED
@@ -73,11 +73,11 @@ require 'chartmogul/enrichment/customer'
|
|
73
73
|
module ChartMogul
|
74
74
|
API_BASE = 'https://api.chartmogul.com'
|
75
75
|
MAX_RETRIES = 20
|
76
|
+
CONFIG_THREAD_KEY = 'chartmogul_ruby.config'
|
76
77
|
|
77
78
|
class << self
|
78
79
|
extend ConfigAttributes
|
79
80
|
|
80
|
-
CONFIG_THREAD_KEY = 'chartmogul_ruby.config'
|
81
81
|
|
82
82
|
def config
|
83
83
|
Thread.current[CONFIG_THREAD_KEY] = ChartMogul::Configuration.new if Thread.current[CONFIG_THREAD_KEY].nil?
|
@@ -87,5 +87,6 @@ module ChartMogul
|
|
87
87
|
config_accessor :account_token
|
88
88
|
config_accessor :secret_key
|
89
89
|
config_accessor :max_retries, MAX_RETRIES
|
90
|
+
config_accessor :api_base, API_BASE
|
90
91
|
end
|
91
92
|
end
|
@@ -15,7 +15,7 @@ module ChartMogul
|
|
15
15
|
req.body = JSON.dump(serialize_for_write)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
json = ChartMogul::Utils::JSONParser.parse(resp.body)
|
18
|
+
json = ChartMogul::Utils::JSONParser.parse(resp.body, skip_case_conversion: self.class.skip_case_conversion)
|
19
19
|
|
20
20
|
assign_all_attributes(json)
|
21
21
|
end
|
@@ -30,7 +30,7 @@ module ChartMogul
|
|
30
30
|
req.body = JSON.dump(resource.serialize_for_write)
|
31
31
|
end
|
32
32
|
end
|
33
|
-
json = ChartMogul::Utils::JSONParser.parse(resp.body)
|
33
|
+
json = ChartMogul::Utils::JSONParser.parse(resp.body, skip_case_conversion: skip_case_conversion)
|
34
34
|
|
35
35
|
new_from_json(json)
|
36
36
|
end
|
@@ -25,7 +25,7 @@ module ChartMogul
|
|
25
25
|
req.body = JSON.dump(body_data)
|
26
26
|
end
|
27
27
|
end
|
28
|
-
ChartMogul::Utils::JSONParser.parse(resp.body)
|
28
|
+
ChartMogul::Utils::JSONParser.parse(resp.body, skip_case_conversion: skip_case_conversion)
|
29
29
|
end
|
30
30
|
|
31
31
|
def custom!(http_method, http_path, body_data = {})
|
@@ -15,7 +15,7 @@ module ChartMogul
|
|
15
15
|
req.headers['Content-Type'] = 'application/json'
|
16
16
|
end
|
17
17
|
end
|
18
|
-
json = ChartMogul::Utils::JSONParser.parse(resp.body)
|
18
|
+
json = ChartMogul::Utils::JSONParser.parse(resp.body, skip_case_conversion: skip_case_conversion)
|
19
19
|
new_from_json(json)
|
20
20
|
end
|
21
21
|
end
|
@@ -4,6 +4,10 @@ module ChartMogul
|
|
4
4
|
module API
|
5
5
|
module Actions
|
6
6
|
module Update
|
7
|
+
def self.included(base)
|
8
|
+
base.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
7
11
|
def update!
|
8
12
|
resp = handling_errors do
|
9
13
|
connection.patch("#{resource_path.apply(instance_attributes)}/#{uuid}") do |req|
|
@@ -11,10 +15,27 @@ module ChartMogul
|
|
11
15
|
req.body = JSON.dump(serialize_for_write)
|
12
16
|
end
|
13
17
|
end
|
14
|
-
|
18
|
+
|
19
|
+
json = ChartMogul::Utils::JSONParser.parse(resp.body, skip_case_conversion: self.class.skip_case_conversion)
|
15
20
|
|
16
21
|
assign_all_attributes(json)
|
17
22
|
end
|
23
|
+
|
24
|
+
module ClassMethods
|
25
|
+
def update!(uuid, attributes = {})
|
26
|
+
resource = new(attributes)
|
27
|
+
|
28
|
+
resp = handling_errors do
|
29
|
+
connection.patch("#{resource_path.apply(attributes)}/#{uuid}") do |req|
|
30
|
+
req.headers['Content-Type'] = 'application/json'
|
31
|
+
req.body = JSON.dump(resource.serialize_for_write)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
json = ChartMogul::Utils::JSONParser.parse(resp.body, skip_case_conversion: skip_case_conversion)
|
35
|
+
|
36
|
+
new_from_json(json)
|
37
|
+
end
|
38
|
+
end
|
18
39
|
end
|
19
40
|
end
|
20
41
|
end
|
@@ -17,7 +17,7 @@ module ChartMogul
|
|
17
17
|
MAX_INTERVAL = 60
|
18
18
|
THREAD_CONNECTION_KEY = 'chartmogul_ruby.api_resource.connection'
|
19
19
|
|
20
|
-
class << self; attr_reader :resource_path, :resource_name, :resource_root_key end
|
20
|
+
class << self; attr_reader :resource_path, :resource_name, :resource_root_key, :skip_case_conversion end
|
21
21
|
|
22
22
|
def self.set_resource_path(path)
|
23
23
|
@resource_path = ChartMogul::ResourcePath.new(path)
|
@@ -31,13 +31,18 @@ module ChartMogul
|
|
31
31
|
@resource_root_key = root_key
|
32
32
|
end
|
33
33
|
|
34
|
+
# When true, response hash keys won't be converted to snake case
|
35
|
+
def self.set_skip_case_conversion(value)
|
36
|
+
@skip_case_conversion = value
|
37
|
+
end
|
38
|
+
|
34
39
|
def self.connection
|
35
40
|
Thread.current[THREAD_CONNECTION_KEY] ||= build_connection
|
36
41
|
end
|
37
42
|
|
38
43
|
def self.handling_errors
|
39
44
|
yield
|
40
|
-
rescue Faraday::ClientError => e
|
45
|
+
rescue Faraday::ClientError, Faraday::ServerError => e
|
41
46
|
e.response ? handle_request_error(e) : handle_other_error(e)
|
42
47
|
rescue StandardError => e
|
43
48
|
handle_other_error(e)
|
@@ -80,13 +85,13 @@ module ChartMogul
|
|
80
85
|
private
|
81
86
|
|
82
87
|
def self.build_connection
|
83
|
-
Faraday.new(url: ChartMogul
|
88
|
+
Faraday.new(url: ChartMogul.api_base) do |faraday|
|
84
89
|
faraday.use Faraday::Request::BasicAuthentication, ChartMogul.account_token, ChartMogul.secret_key
|
85
90
|
faraday.use Faraday::Response::RaiseError
|
86
91
|
faraday.request :retry, max: ChartMogul.max_retries, retry_statuses: RETRY_STATUSES,
|
87
92
|
max_interval: MAX_INTERVAL, backoff_factor: BACKOFF_FACTOR,
|
88
93
|
interval_randomness: INTERVAL_RANDOMNESS, interval: INTERVAL, exceptions: RETRY_EXCEPTIONS
|
89
|
-
faraday.
|
94
|
+
faraday.adapter Faraday::Adapter::NetHttp
|
90
95
|
end
|
91
96
|
end
|
92
97
|
end
|
data/lib/chartmogul/customer.rb
CHANGED
@@ -26,6 +26,15 @@ module ChartMogul
|
|
26
26
|
super(options.merge(customer_uuid: customer_uuid))
|
27
27
|
end
|
28
28
|
|
29
|
+
def self.destroy_all!(data_source_uuid, customer_uuid)
|
30
|
+
path = ChartMogul::ResourcePath.new('v1/data_sources/:data_source_uuid/customers/:customer_uuid/invoices')
|
31
|
+
handling_errors do
|
32
|
+
connection.delete(path.apply(data_source_uuid: data_source_uuid, customer_uuid: customer_uuid))
|
33
|
+
end
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
|
29
38
|
def_delegators :invoices, :each, :[], :<<, :size, :length, :empty?, :first
|
30
39
|
|
31
40
|
private
|
@@ -4,8 +4,10 @@ module ChartMogul
|
|
4
4
|
module Utils
|
5
5
|
class JSONParser
|
6
6
|
class << self
|
7
|
-
def parse(json_string)
|
7
|
+
def parse(json_string, skip_case_conversion: false)
|
8
8
|
hash = JSON.parse(json_string, symbolize_names: true)
|
9
|
+
return hash if skip_case_conversion
|
10
|
+
|
9
11
|
HashSnakeCaser.new(hash).to_snake_keys
|
10
12
|
end
|
11
13
|
|
@@ -20,7 +22,15 @@ module ChartMogul
|
|
20
22
|
def opt_string_to_time(value)
|
21
23
|
return value unless value.instance_of?(String)
|
22
24
|
|
23
|
-
|
25
|
+
parse_timestamp(value)
|
26
|
+
rescue ArgumentError
|
27
|
+
value
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_timestamp(value)
|
31
|
+
Time.iso8601(value)
|
32
|
+
rescue ArgumentError
|
33
|
+
Time.rfc2822(value)
|
24
34
|
end
|
25
35
|
end
|
26
36
|
end
|
data/lib/chartmogul/version.rb
CHANGED
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.6.
|
4
|
+
version: 1.6.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Petr Kopac
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-09-09 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: 0.
|
19
|
+
version: 1.0.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: 0.
|
26
|
+
version: 1.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/returns_right_customers_through_search_endpoint.yml
|
201
201
|
- fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/updates_custom_attributes.yml
|
202
202
|
- fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/updates_customer.yml
|
203
|
+
- fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/updates_customer_using_class_method.yml
|
203
204
|
- fixtures/vcr_cassettes/ChartMogul_Customer/_find_by_external_id/when_external_id_is_provided/returns_matching_user_if_exists.yml
|
204
205
|
- fixtures/vcr_cassettes/ChartMogul_Customer/_find_by_external_id/when_external_id_is_provided/returns_nil_if_customer_does_not_exist.yml
|
205
206
|
- fixtures/vcr_cassettes/ChartMogul_CustomerInvoices/API_Interactions/correctly_interracts_with_the_API.yml
|
@@ -242,11 +243,13 @@ files:
|
|
242
243
|
- fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/deletes_existing_plan.yml
|
243
244
|
- fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/retrieves_existing_plan_by_uuid.yml
|
244
245
|
- fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/updates_existing_plan.yml
|
246
|
+
- fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/updates_existing_plan_using_class_method.yml
|
245
247
|
- fixtures/vcr_cassettes/ChartMogul_PlanGroup/API_interactions/correctly_handles_a_422_error.yml
|
246
248
|
- fixtures/vcr_cassettes/ChartMogul_PlanGroup/API_interactions/deletes_a_plan_group.yml
|
247
249
|
- fixtures/vcr_cassettes/ChartMogul_PlanGroup/API_interactions/retrieves_existing_plan_group_by_uuid.yml
|
248
250
|
- fixtures/vcr_cassettes/ChartMogul_PlanGroup/API_interactions/returns_an_array_of_plan_groups.yml
|
249
251
|
- fixtures/vcr_cassettes/ChartMogul_PlanGroup/API_interactions/updates_existing_plan_group_name.yml
|
252
|
+
- fixtures/vcr_cassettes/ChartMogul_PlanGroup/API_interactions/updates_existing_plan_group_name_via_class_method.yml
|
250
253
|
- fixtures/vcr_cassettes/ChartMogul_PlanGroup/API_interactions/updates_existing_plan_group_plans.yml
|
251
254
|
- fixtures/vcr_cassettes/ChartMogul_PlanGroups_Plans/API_interactions/given_a_plan_group_uuid_returns_an_array_of_plans_in_the_plan_group.yml
|
252
255
|
- fixtures/vcr_cassettes/ChartMogul_Subscription/API_Interactions/connects_subscriptions.yml
|
@@ -324,14 +327,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
324
327
|
requirements:
|
325
328
|
- - ">="
|
326
329
|
- !ruby/object:Gem::Version
|
327
|
-
version: '
|
330
|
+
version: '2.3'
|
328
331
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
329
332
|
requirements:
|
330
333
|
- - ">="
|
331
334
|
- !ruby/object:Gem::Version
|
332
335
|
version: '0'
|
333
336
|
requirements: []
|
334
|
-
rubygems_version: 3.
|
337
|
+
rubygems_version: 3.1.4
|
335
338
|
signing_key:
|
336
339
|
specification_version: 4
|
337
340
|
summary: Chartmogul API Ruby Client
|