chartmogul-ruby 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/.rspec +2 -2
- data/.travis.yml +4 -4
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +111 -111
- data/Rakefile +6 -6
- data/bin/console +14 -14
- data/bin/setup +9 -9
- data/changelog.md +27 -27
- data/chartmogul-ruby.gemspec +29 -29
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/adds_custom_attributes.yml +80 -80
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/adds_required_tags.yml +79 -79
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/can_page_through_search_endpoint.yml +43 -43
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/correctly_handles_a_422_response.yml +50 -50
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/correctly_interracts_with_the_API.yml +244 -244
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/merges_customers.yml +185 -185
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/raises_401_if_invalid_credentials.yml +38 -38
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/raises_404_if_no_customers_found.yml +38 -38
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/raises_422_for_update_with_invalid_data.yml +86 -86
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/removes_custom_attributes.yml +80 -80
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/removes_tags.yml +80 -80
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/returns_all_customers_through_list_all_endpoint.yml +47 -47
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/returns_customer_through_retrieve_endpoint.yml +42 -42
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/returns_right_customers_through_search_endpoint.yml +43 -43
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/updates_custom_attributes.yml +82 -82
- data/fixtures/vcr_cassettes/ChartMogul_Customer/API_Interactions/updates_customer.yml +139 -139
- data/fixtures/vcr_cassettes/ChartMogul_Customer/_find_by_external_id/when_external_id_is_provided/returns_matching_user_if_exists.yml +102 -102
- data/fixtures/vcr_cassettes/ChartMogul_Customer/_find_by_external_id/when_external_id_is_provided/returns_nil_if_customer_does_not_exist.yml +101 -101
- data/fixtures/vcr_cassettes/ChartMogul_CustomerInvoices/API_Interactions/correctly_interracts_with_the_API.yml +298 -298
- data/fixtures/vcr_cassettes/ChartMogul_DataSource/API_Interactions/correctly_interracts_with_the_API.yml +189 -189
- data/fixtures/vcr_cassettes/ChartMogul_DataSource/API_Interactions/correctly_raises_errors_on_404.yml +46 -46
- data/fixtures/vcr_cassettes/ChartMogul_DataSource/API_Interactions/correctly_raises_errors_on_422.yml +48 -48
- data/fixtures/vcr_cassettes/ChartMogul_DataSource/API_Interactions/retrieves_existing_data_source_matching_uuid.yml +101 -101
- data/fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/deletes_an_invoice.yml +37 -0
- data/fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/deletes_an_invoice_with_class_method.yml +37 -0
- data/fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/raises_error_on_deleting_non-existing_invoice.yml +42 -0
- data/fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/returns_all_invoices_through_list_all_endpoint.yml +46 -46
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_ARPA/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml +42 -42
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_ARPA/behaves_like_Metrics_API_resource/should_have_entries.yml +42 -42
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_ARR/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml +42 -42
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_ARR/behaves_like_Metrics_API_resource/should_have_entries.yml +42 -42
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_ASP/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml +40 -40
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_ASP/behaves_like_Metrics_API_resource/should_have_entries.yml +40 -40
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_Activity/behaves_like_Pageable/should_be_pageable.yml +41 -41
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_Activity/should_have_Activity_entries.yml +41 -41
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_AllKeyMetric/should_have_entries.yml +42 -42
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_CustomerChurnRate/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml +40 -40
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_CustomerChurnRate/behaves_like_Metrics_API_resource/should_have_entries.yml +40 -40
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_CustomerCount/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml +42 -42
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_CustomerCount/behaves_like_Metrics_API_resource/should_have_entries.yml +42 -42
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_LTV/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml +40 -40
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_LTV/behaves_like_Metrics_API_resource/should_have_entries.yml +40 -40
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_MRR/behaves_like_Summary/should_have_summary.yml +42 -42
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_MRR/should_have_entries.yml +42 -42
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_MRRChurnRate/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml +40 -40
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_MRRChurnRate/behaves_like_Metrics_API_resource/should_have_entries.yml +40 -40
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_Subscription/behaves_like_Pageable/should_be_pageable.yml +40 -40
- data/fixtures/vcr_cassettes/ChartMogul_Metrics_Subscription/should_have_Subscription_entries.yml +40 -40
- data/fixtures/vcr_cassettes/ChartMogul_Ping/pings/and_fails_on_incorrect_credentials.yml +38 -38
- data/fixtures/vcr_cassettes/ChartMogul_Ping/pings/when_credentials_correct.yml +38 -38
- data/fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/correctly_handles_a_422_error.yml +51 -51
- data/fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/correctly_interacts_with_the_API.yml +152 -152
- data/fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/deletes_existing_plan.yml +198 -198
- data/fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/retrieves_existing_plan_by_uuid.yml +151 -151
- data/fixtures/vcr_cassettes/ChartMogul_Plan/API_Interactions/updates_existing_plan.yml +198 -198
- data/fixtures/vcr_cassettes/ChartMogul_Subscription/API_Interactions/correctly_interracts_with_the_API.yml +340 -340
- data/fixtures/vcr_cassettes/ChartMogul_Subscription/API_Interactions/has_multiple_aliases.yml +101 -101
- data/fixtures/vcr_cassettes/ChartMogul_Transactions_Payment/API_Interactions/correctly_interracts_with_the_API.yml +243 -243
- data/lib/chartmogul.rb +79 -79
- data/lib/chartmogul/api/actions/all.rb +23 -23
- data/lib/chartmogul/api/actions/create.rb +39 -39
- data/lib/chartmogul/api/actions/custom.rb +37 -37
- data/lib/chartmogul/api/actions/destroy.rb +28 -14
- data/lib/chartmogul/api/actions/update.rb +19 -19
- data/lib/chartmogul/api_resource.rb +68 -68
- data/lib/chartmogul/concerns/entries.rb +39 -39
- data/lib/chartmogul/concerns/pageable.rb +13 -13
- data/lib/chartmogul/concerns/pageable2.rb +12 -12
- data/lib/chartmogul/concerns/summary.rb +20 -20
- data/lib/chartmogul/config_attributes.rb +15 -15
- data/lib/chartmogul/configuration.rb +6 -6
- data/lib/chartmogul/customer.rb +155 -155
- data/lib/chartmogul/customer_invoices.rb +44 -44
- data/lib/chartmogul/data_source.rb +38 -38
- data/lib/chartmogul/enrichment/customer.rb +141 -141
- data/lib/chartmogul/errors/chartmogul_error.rb +19 -19
- data/lib/chartmogul/errors/configuration_error.rb +4 -4
- data/lib/chartmogul/errors/forbidden_error.rb +4 -4
- data/lib/chartmogul/errors/not_found_error.rb +4 -4
- data/lib/chartmogul/errors/resource_invalid_error.rb +4 -4
- data/lib/chartmogul/errors/schema_invalid_error.rb +4 -4
- data/lib/chartmogul/errors/unauthorized_error.rb +4 -4
- data/lib/chartmogul/invoice.rb +83 -78
- data/lib/chartmogul/line_items/one_time.rb +23 -23
- data/lib/chartmogul/line_items/subscription.rb +29 -29
- data/lib/chartmogul/metrics/activity.rb +34 -34
- data/lib/chartmogul/metrics/all_key_metrics.rb +25 -25
- data/lib/chartmogul/metrics/arpa.rb +19 -19
- data/lib/chartmogul/metrics/arr.rb +19 -19
- data/lib/chartmogul/metrics/asp.rb +19 -19
- data/lib/chartmogul/metrics/base.rb +56 -56
- data/lib/chartmogul/metrics/customer_churn_rate.rb +19 -19
- data/lib/chartmogul/metrics/customer_count.rb +19 -19
- data/lib/chartmogul/metrics/ltv.rb +19 -19
- data/lib/chartmogul/metrics/mrr.rb +26 -26
- data/lib/chartmogul/metrics/mrr_churn_rate.rb +19 -19
- data/lib/chartmogul/metrics/subscription.rb +37 -37
- data/lib/chartmogul/object.rb +119 -119
- data/lib/chartmogul/ping.rb +14 -14
- data/lib/chartmogul/plan.rb +41 -41
- data/lib/chartmogul/resource_path.rb +42 -42
- data/lib/chartmogul/subscription.rb +48 -48
- data/lib/chartmogul/summary.rb +7 -7
- data/lib/chartmogul/transactions/payment.rb +24 -24
- data/lib/chartmogul/transactions/refund.rb +24 -24
- data/lib/chartmogul/utils/hash_snake_caser.rb +50 -50
- data/lib/chartmogul/utils/json_parser.rb +11 -11
- data/lib/chartmogul/version.rb +3 -3
- metadata +5 -2
data/lib/chartmogul/summary.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
class Summary < ChartMogul::Object
|
3
|
-
readonly_attr :current
|
4
|
-
readonly_attr :previous
|
5
|
-
readonly_attr :percentage_change
|
6
|
-
end
|
7
|
-
end
|
1
|
+
module ChartMogul
|
2
|
+
class Summary < ChartMogul::Object
|
3
|
+
readonly_attr :current
|
4
|
+
readonly_attr :previous
|
5
|
+
readonly_attr :percentage_change
|
6
|
+
end
|
7
|
+
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Transactions
|
3
|
-
class Payment < APIResource
|
4
|
-
set_resource_name 'Payment Transaction'
|
5
|
-
set_resource_path '/v1/import/invoices/:invoice_uuid/transactions'
|
6
|
-
|
7
|
-
readonly_attr :uuid
|
8
|
-
|
9
|
-
writeable_attr :type, default: 'payment'
|
10
|
-
writeable_attr :date, type: :time
|
11
|
-
writeable_attr :result
|
12
|
-
writeable_attr :external_id
|
13
|
-
|
14
|
-
writeable_attr :invoice_uuid
|
15
|
-
|
16
|
-
def initialize(attributes = {})
|
17
|
-
super(attributes)
|
18
|
-
@type = 'payment'
|
19
|
-
end
|
20
|
-
|
21
|
-
include API::Actions::Create
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
module ChartMogul
|
2
|
+
module Transactions
|
3
|
+
class Payment < APIResource
|
4
|
+
set_resource_name 'Payment Transaction'
|
5
|
+
set_resource_path '/v1/import/invoices/:invoice_uuid/transactions'
|
6
|
+
|
7
|
+
readonly_attr :uuid
|
8
|
+
|
9
|
+
writeable_attr :type, default: 'payment'
|
10
|
+
writeable_attr :date, type: :time
|
11
|
+
writeable_attr :result
|
12
|
+
writeable_attr :external_id
|
13
|
+
|
14
|
+
writeable_attr :invoice_uuid
|
15
|
+
|
16
|
+
def initialize(attributes = {})
|
17
|
+
super(attributes)
|
18
|
+
@type = 'payment'
|
19
|
+
end
|
20
|
+
|
21
|
+
include API::Actions::Create
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,24 +1,24 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Transactions
|
3
|
-
class Refund < APIResource
|
4
|
-
set_resource_name 'Refund Transaction'
|
5
|
-
set_resource_path '/v1/import/invoices/:invoice_uuid/transactions'
|
6
|
-
|
7
|
-
readonly_attr :uuid
|
8
|
-
|
9
|
-
writeable_attr :type, default: 'refund'
|
10
|
-
writeable_attr :date, type: :time
|
11
|
-
writeable_attr :result
|
12
|
-
writeable_attr :external_id
|
13
|
-
|
14
|
-
writeable_attr :invoice_uuid
|
15
|
-
|
16
|
-
def initialize(attributes = {})
|
17
|
-
super(attributes)
|
18
|
-
@type = 'refund'
|
19
|
-
end
|
20
|
-
|
21
|
-
include API::Actions::Create
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
module ChartMogul
|
2
|
+
module Transactions
|
3
|
+
class Refund < APIResource
|
4
|
+
set_resource_name 'Refund Transaction'
|
5
|
+
set_resource_path '/v1/import/invoices/:invoice_uuid/transactions'
|
6
|
+
|
7
|
+
readonly_attr :uuid
|
8
|
+
|
9
|
+
writeable_attr :type, default: 'refund'
|
10
|
+
writeable_attr :date, type: :time
|
11
|
+
writeable_attr :result
|
12
|
+
writeable_attr :external_id
|
13
|
+
|
14
|
+
writeable_attr :invoice_uuid
|
15
|
+
|
16
|
+
def initialize(attributes = {})
|
17
|
+
super(attributes)
|
18
|
+
@type = 'refund'
|
19
|
+
end
|
20
|
+
|
21
|
+
include API::Actions::Create
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,50 +1,50 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Utils
|
3
|
-
class HashSnakeCaser
|
4
|
-
#
|
5
|
-
# Recursively converts CamelCase and camelBack JSON-style hash keys to
|
6
|
-
# Rubyish snake_case, suitable for use during instantiation of Ruby
|
7
|
-
# model attributes.
|
8
|
-
#
|
9
|
-
def initialize(hash)
|
10
|
-
@hash = hash
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_snake_keys(value = @hash)
|
14
|
-
case value
|
15
|
-
when Array
|
16
|
-
value.map { |v| to_snake_keys(v) }
|
17
|
-
when Hash
|
18
|
-
snake_hash(value)
|
19
|
-
else
|
20
|
-
value
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def snake_hash(value)
|
27
|
-
Hash[value.map { |k, v| [underscore_key(k), to_snake_keys(v)] }]
|
28
|
-
end
|
29
|
-
|
30
|
-
def underscore_key(k)
|
31
|
-
if k.instance_of?(Symbol)
|
32
|
-
underscore(k.to_s).to_sym
|
33
|
-
elsif k.instance_of?(String)
|
34
|
-
underscore(k)
|
35
|
-
else
|
36
|
-
k # Can't snakify anything except strings and symbols
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def underscore(string)
|
41
|
-
string.gsub(/::/, '/')
|
42
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
43
|
-
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
44
|
-
.tr('-', '_')
|
45
|
-
.downcase
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
1
|
+
module ChartMogul
|
2
|
+
module Utils
|
3
|
+
class HashSnakeCaser
|
4
|
+
#
|
5
|
+
# Recursively converts CamelCase and camelBack JSON-style hash keys to
|
6
|
+
# Rubyish snake_case, suitable for use during instantiation of Ruby
|
7
|
+
# model attributes.
|
8
|
+
#
|
9
|
+
def initialize(hash)
|
10
|
+
@hash = hash
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_snake_keys(value = @hash)
|
14
|
+
case value
|
15
|
+
when Array
|
16
|
+
value.map { |v| to_snake_keys(v) }
|
17
|
+
when Hash
|
18
|
+
snake_hash(value)
|
19
|
+
else
|
20
|
+
value
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def snake_hash(value)
|
27
|
+
Hash[value.map { |k, v| [underscore_key(k), to_snake_keys(v)] }]
|
28
|
+
end
|
29
|
+
|
30
|
+
def underscore_key(k)
|
31
|
+
if k.instance_of?(Symbol)
|
32
|
+
underscore(k.to_s).to_sym
|
33
|
+
elsif k.instance_of?(String)
|
34
|
+
underscore(k)
|
35
|
+
else
|
36
|
+
k # Can't snakify anything except strings and symbols
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def underscore(string)
|
41
|
+
string.gsub(/::/, '/')
|
42
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
43
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
44
|
+
.tr('-', '_')
|
45
|
+
.downcase
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -1,11 +1,11 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Utils
|
3
|
-
class JSONParser
|
4
|
-
def self.parse(json_string)
|
5
|
-
hash = JSON.parse(json_string, symbolize_names: true)
|
6
|
-
HashSnakeCaser.new(hash).to_snake_keys
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
1
|
+
module ChartMogul
|
2
|
+
module Utils
|
3
|
+
class JSONParser
|
4
|
+
def self.parse(json_string)
|
5
|
+
hash = JSON.parse(json_string, symbolize_names: true)
|
6
|
+
HashSnakeCaser.new(hash).to_snake_keys
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
data/lib/chartmogul/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
VERSION = "1.1.
|
3
|
-
end
|
1
|
+
module ChartMogul
|
2
|
+
VERSION = "1.1.2"
|
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.1.
|
4
|
+
version: 1.1.2
|
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-05-
|
11
|
+
date: 2017-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -135,6 +135,9 @@ files:
|
|
135
135
|
- fixtures/vcr_cassettes/ChartMogul_DataSource/API_Interactions/correctly_raises_errors_on_404.yml
|
136
136
|
- fixtures/vcr_cassettes/ChartMogul_DataSource/API_Interactions/correctly_raises_errors_on_422.yml
|
137
137
|
- fixtures/vcr_cassettes/ChartMogul_DataSource/API_Interactions/retrieves_existing_data_source_matching_uuid.yml
|
138
|
+
- fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/deletes_an_invoice.yml
|
139
|
+
- fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/deletes_an_invoice_with_class_method.yml
|
140
|
+
- fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/raises_error_on_deleting_non-existing_invoice.yml
|
138
141
|
- fixtures/vcr_cassettes/ChartMogul_Invoice/API_Interactions/returns_all_invoices_through_list_all_endpoint.yml
|
139
142
|
- fixtures/vcr_cassettes/ChartMogul_Metrics_ARPA/behaves_like_Metrics_API_resource/behaves_like_Summary/should_have_summary.yml
|
140
143
|
- fixtures/vcr_cassettes/ChartMogul_Metrics_ARPA/behaves_like_Metrics_API_resource/should_have_entries.yml
|