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
@@ -1,44 +1,44 @@
|
|
1
|
-
require 'forwardable'
|
2
|
-
|
3
|
-
module ChartMogul
|
4
|
-
class CustomerInvoices < APIResource
|
5
|
-
extend Forwardable
|
6
|
-
include Enumerable
|
7
|
-
|
8
|
-
set_resource_name 'Invoices'
|
9
|
-
set_resource_path '/v1/import/customers/:customer_uuid/invoices'
|
10
|
-
|
11
|
-
writeable_attr :invoices, default: []
|
12
|
-
|
13
|
-
writeable_attr :customer_uuid
|
14
|
-
|
15
|
-
include API::Actions::All
|
16
|
-
include API::Actions::Create
|
17
|
-
include Concerns::Pageable2
|
18
|
-
|
19
|
-
def serialize_invoices
|
20
|
-
map(&:serialize_for_write)
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.all(customer_uuid, options = {})
|
24
|
-
super(options.merge(customer_uuid: customer_uuid))
|
25
|
-
end
|
26
|
-
|
27
|
-
def_delegators :invoices, :each, :[], :<<, :size, :length, :empty?, :first
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
# TODO: replace with Entries concern?
|
32
|
-
def set_invoices(invoices_attributes)
|
33
|
-
@invoices = invoices_attributes.map.with_index do |invoice_attributes, index|
|
34
|
-
existing_invoice = invoices[index]
|
35
|
-
|
36
|
-
if existing_invoice
|
37
|
-
existing_invoice.assign_all_attributes(invoice_attributes)
|
38
|
-
else
|
39
|
-
Invoice.new_from_json(invoice_attributes)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module ChartMogul
|
4
|
+
class CustomerInvoices < APIResource
|
5
|
+
extend Forwardable
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
set_resource_name 'Invoices'
|
9
|
+
set_resource_path '/v1/import/customers/:customer_uuid/invoices'
|
10
|
+
|
11
|
+
writeable_attr :invoices, default: []
|
12
|
+
|
13
|
+
writeable_attr :customer_uuid
|
14
|
+
|
15
|
+
include API::Actions::All
|
16
|
+
include API::Actions::Create
|
17
|
+
include Concerns::Pageable2
|
18
|
+
|
19
|
+
def serialize_invoices
|
20
|
+
map(&:serialize_for_write)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.all(customer_uuid, options = {})
|
24
|
+
super(options.merge(customer_uuid: customer_uuid))
|
25
|
+
end
|
26
|
+
|
27
|
+
def_delegators :invoices, :each, :[], :<<, :size, :length, :empty?, :first
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# TODO: replace with Entries concern?
|
32
|
+
def set_invoices(invoices_attributes)
|
33
|
+
@invoices = invoices_attributes.map.with_index do |invoice_attributes, index|
|
34
|
+
existing_invoice = invoices[index]
|
35
|
+
|
36
|
+
if existing_invoice
|
37
|
+
existing_invoice.assign_all_attributes(invoice_attributes)
|
38
|
+
else
|
39
|
+
Invoice.new_from_json(invoice_attributes)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
class DataSource < APIResource
|
3
|
-
set_resource_name 'Data Source'
|
4
|
-
set_resource_path '/v1/data_sources'
|
5
|
-
|
6
|
-
readonly_attr :uuid
|
7
|
-
readonly_attr :status
|
8
|
-
readonly_attr :system
|
9
|
-
readonly_attr :created_at, type: :time
|
10
|
-
|
11
|
-
writeable_attr :name
|
12
|
-
|
13
|
-
include API::Actions::All
|
14
|
-
include API::Actions::Create
|
15
|
-
include API::Actions::Destroy
|
16
|
-
include API::Actions::Custom
|
17
|
-
|
18
|
-
def self.retrieve(uuid)
|
19
|
-
custom!(:get, "/v1/data_sources/#{uuid}")
|
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
|
37
|
-
end
|
38
|
-
end
|
1
|
+
module ChartMogul
|
2
|
+
class DataSource < APIResource
|
3
|
+
set_resource_name 'Data Source'
|
4
|
+
set_resource_path '/v1/data_sources'
|
5
|
+
|
6
|
+
readonly_attr :uuid
|
7
|
+
readonly_attr :status
|
8
|
+
readonly_attr :system
|
9
|
+
readonly_attr :created_at, type: :time
|
10
|
+
|
11
|
+
writeable_attr :name
|
12
|
+
|
13
|
+
include API::Actions::All
|
14
|
+
include API::Actions::Create
|
15
|
+
include API::Actions::Destroy
|
16
|
+
include API::Actions::Custom
|
17
|
+
|
18
|
+
def self.retrieve(uuid)
|
19
|
+
custom!(:get, "/v1/data_sources/#{uuid}")
|
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
|
37
|
+
end
|
38
|
+
end
|
@@ -1,141 +1,141 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
module Enrichment
|
3
|
-
|
4
|
-
# <b>DEPRECATED:</b> Please use <tt>ChartMogul/Customer</tt> instead.
|
5
|
-
class DeprecatedCustomer < APIResource
|
6
|
-
|
7
|
-
set_resource_name 'Customer'
|
8
|
-
set_resource_path '/v1/customers'
|
9
|
-
|
10
|
-
readonly_attr :id
|
11
|
-
readonly_attr :uuid
|
12
|
-
readonly_attr :external_id
|
13
|
-
readonly_attr :status
|
14
|
-
readonly_attr :customer_since, type: :time
|
15
|
-
readonly_attr :address
|
16
|
-
readonly_attr :mrr
|
17
|
-
readonly_attr :arr
|
18
|
-
readonly_attr :billing_system_url
|
19
|
-
readonly_attr :chartmogul_url
|
20
|
-
readonly_attr :billing_system_type
|
21
|
-
readonly_attr :currency
|
22
|
-
readonly_attr :currency_sign
|
23
|
-
|
24
|
-
writeable_attr :name
|
25
|
-
writeable_attr :email
|
26
|
-
writeable_attr :company
|
27
|
-
writeable_attr :country
|
28
|
-
writeable_attr :state
|
29
|
-
writeable_attr :city
|
30
|
-
writeable_attr :lead_created_at
|
31
|
-
writeable_attr :free_trial_started_at
|
32
|
-
writeable_attr :attributes
|
33
|
-
|
34
|
-
include API::Actions::Custom
|
35
|
-
include API::Actions::Update
|
36
|
-
|
37
|
-
def tags
|
38
|
-
@attributes[:tags]
|
39
|
-
end
|
40
|
-
|
41
|
-
def custom_attributes
|
42
|
-
@attributes[:custom]
|
43
|
-
end
|
44
|
-
|
45
|
-
def add_tags!(*tags)
|
46
|
-
self.tags = custom_without_assign!(:post,
|
47
|
-
"/v1/customers/#{uuid}/attributes/tags",
|
48
|
-
tags: tags)[:tags]
|
49
|
-
end
|
50
|
-
|
51
|
-
def remove_tags!(*tags)
|
52
|
-
self.tags = custom_without_assign!(:delete,
|
53
|
-
"/v1/customers/#{uuid}/attributes/tags",
|
54
|
-
tags: tags)[:tags]
|
55
|
-
end
|
56
|
-
|
57
|
-
def add_custom_attributes!(*custom_attrs)
|
58
|
-
self.custom_attributes = custom_without_assign!(:post,
|
59
|
-
"/v1/customers/#{uuid}/attributes/custom",
|
60
|
-
custom: custom_attrs)[:custom]
|
61
|
-
end
|
62
|
-
|
63
|
-
def update_custom_attributes!(custom_attrs = {})
|
64
|
-
self.custom_attributes = custom_without_assign!(:put,
|
65
|
-
"/v1/customers/#{uuid}/attributes/custom",
|
66
|
-
custom: custom_attrs)[:custom]
|
67
|
-
end
|
68
|
-
|
69
|
-
def remove_custom_attributes!(*custom_attrs)
|
70
|
-
self.custom_attributes = custom_without_assign!(:delete,
|
71
|
-
"/v1/customers/#{uuid}/attributes/custom",
|
72
|
-
custom: custom_attrs)[:custom]
|
73
|
-
end
|
74
|
-
|
75
|
-
def merge_into!(other_customer)
|
76
|
-
options = {
|
77
|
-
from: { customer_uuid: uuid },
|
78
|
-
into: { customer_uuid: other_customer.uuid }
|
79
|
-
}
|
80
|
-
custom!(:post, '/v1/customers/merges', options)
|
81
|
-
true
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.retrieve(uuid)
|
85
|
-
custom!(:get, "/v1/customers/#{uuid}")
|
86
|
-
end
|
87
|
-
|
88
|
-
def self.all(options = {})
|
89
|
-
Customers.all(options)
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.search(email)
|
93
|
-
Customers.search(email)
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
def tags=(tags)
|
99
|
-
@attributes[:tags] = tags
|
100
|
-
end
|
101
|
-
|
102
|
-
def custom_attributes=(custom_attributes = {})
|
103
|
-
@attributes[:custom] = typecast_custom_attributes(custom_attributes)
|
104
|
-
end
|
105
|
-
|
106
|
-
def set_attributes(attributes_attributes)
|
107
|
-
@attributes = attributes_attributes
|
108
|
-
@attributes[:custom] = typecast_custom_attributes(attributes_attributes[:custom])
|
109
|
-
end
|
110
|
-
|
111
|
-
def typecast_custom_attributes(custom_attributes)
|
112
|
-
return {} unless custom_attributes
|
113
|
-
custom_attributes.each_with_object({}) do |(key, value), hash|
|
114
|
-
hash[key] = value.instance_of?(String) ? (Time.parse(value) rescue value) : value
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
def self.const_missing(const_name)
|
120
|
-
super unless const_name == :Customer
|
121
|
-
warn "DEPRECATION WARNING: the class ChartMogul::Enrichment::Customer is deprecated. Use ChartMogul::Customer instead."
|
122
|
-
DeprecatedCustomer
|
123
|
-
end
|
124
|
-
|
125
|
-
class Customers < APIResource
|
126
|
-
set_resource_name 'Customers'
|
127
|
-
set_resource_path '/v1/customers'
|
128
|
-
|
129
|
-
include Concerns::Entries
|
130
|
-
include API::Actions::Custom
|
131
|
-
include Concerns::Pageable
|
132
|
-
|
133
|
-
set_entry_class DeprecatedCustomer
|
134
|
-
|
135
|
-
def self.search(email)
|
136
|
-
path = ChartMogul::ResourcePath.new('/v1/customers/search')
|
137
|
-
custom!(:get, path.apply_with_get_params(email: email))
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
1
|
+
module ChartMogul
|
2
|
+
module Enrichment
|
3
|
+
|
4
|
+
# <b>DEPRECATED:</b> Please use <tt>ChartMogul/Customer</tt> instead.
|
5
|
+
class DeprecatedCustomer < APIResource
|
6
|
+
|
7
|
+
set_resource_name 'Customer'
|
8
|
+
set_resource_path '/v1/customers'
|
9
|
+
|
10
|
+
readonly_attr :id
|
11
|
+
readonly_attr :uuid
|
12
|
+
readonly_attr :external_id
|
13
|
+
readonly_attr :status
|
14
|
+
readonly_attr :customer_since, type: :time
|
15
|
+
readonly_attr :address
|
16
|
+
readonly_attr :mrr
|
17
|
+
readonly_attr :arr
|
18
|
+
readonly_attr :billing_system_url
|
19
|
+
readonly_attr :chartmogul_url
|
20
|
+
readonly_attr :billing_system_type
|
21
|
+
readonly_attr :currency
|
22
|
+
readonly_attr :currency_sign
|
23
|
+
|
24
|
+
writeable_attr :name
|
25
|
+
writeable_attr :email
|
26
|
+
writeable_attr :company
|
27
|
+
writeable_attr :country
|
28
|
+
writeable_attr :state
|
29
|
+
writeable_attr :city
|
30
|
+
writeable_attr :lead_created_at
|
31
|
+
writeable_attr :free_trial_started_at
|
32
|
+
writeable_attr :attributes
|
33
|
+
|
34
|
+
include API::Actions::Custom
|
35
|
+
include API::Actions::Update
|
36
|
+
|
37
|
+
def tags
|
38
|
+
@attributes[:tags]
|
39
|
+
end
|
40
|
+
|
41
|
+
def custom_attributes
|
42
|
+
@attributes[:custom]
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_tags!(*tags)
|
46
|
+
self.tags = custom_without_assign!(:post,
|
47
|
+
"/v1/customers/#{uuid}/attributes/tags",
|
48
|
+
tags: tags)[:tags]
|
49
|
+
end
|
50
|
+
|
51
|
+
def remove_tags!(*tags)
|
52
|
+
self.tags = custom_without_assign!(:delete,
|
53
|
+
"/v1/customers/#{uuid}/attributes/tags",
|
54
|
+
tags: tags)[:tags]
|
55
|
+
end
|
56
|
+
|
57
|
+
def add_custom_attributes!(*custom_attrs)
|
58
|
+
self.custom_attributes = custom_without_assign!(:post,
|
59
|
+
"/v1/customers/#{uuid}/attributes/custom",
|
60
|
+
custom: custom_attrs)[:custom]
|
61
|
+
end
|
62
|
+
|
63
|
+
def update_custom_attributes!(custom_attrs = {})
|
64
|
+
self.custom_attributes = custom_without_assign!(:put,
|
65
|
+
"/v1/customers/#{uuid}/attributes/custom",
|
66
|
+
custom: custom_attrs)[:custom]
|
67
|
+
end
|
68
|
+
|
69
|
+
def remove_custom_attributes!(*custom_attrs)
|
70
|
+
self.custom_attributes = custom_without_assign!(:delete,
|
71
|
+
"/v1/customers/#{uuid}/attributes/custom",
|
72
|
+
custom: custom_attrs)[:custom]
|
73
|
+
end
|
74
|
+
|
75
|
+
def merge_into!(other_customer)
|
76
|
+
options = {
|
77
|
+
from: { customer_uuid: uuid },
|
78
|
+
into: { customer_uuid: other_customer.uuid }
|
79
|
+
}
|
80
|
+
custom!(:post, '/v1/customers/merges', options)
|
81
|
+
true
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.retrieve(uuid)
|
85
|
+
custom!(:get, "/v1/customers/#{uuid}")
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.all(options = {})
|
89
|
+
Customers.all(options)
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.search(email)
|
93
|
+
Customers.search(email)
|
94
|
+
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
def tags=(tags)
|
99
|
+
@attributes[:tags] = tags
|
100
|
+
end
|
101
|
+
|
102
|
+
def custom_attributes=(custom_attributes = {})
|
103
|
+
@attributes[:custom] = typecast_custom_attributes(custom_attributes)
|
104
|
+
end
|
105
|
+
|
106
|
+
def set_attributes(attributes_attributes)
|
107
|
+
@attributes = attributes_attributes
|
108
|
+
@attributes[:custom] = typecast_custom_attributes(attributes_attributes[:custom])
|
109
|
+
end
|
110
|
+
|
111
|
+
def typecast_custom_attributes(custom_attributes)
|
112
|
+
return {} unless custom_attributes
|
113
|
+
custom_attributes.each_with_object({}) do |(key, value), hash|
|
114
|
+
hash[key] = value.instance_of?(String) ? (Time.parse(value) rescue value) : value
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.const_missing(const_name)
|
120
|
+
super unless const_name == :Customer
|
121
|
+
warn "DEPRECATION WARNING: the class ChartMogul::Enrichment::Customer is deprecated. Use ChartMogul::Customer instead."
|
122
|
+
DeprecatedCustomer
|
123
|
+
end
|
124
|
+
|
125
|
+
class Customers < APIResource
|
126
|
+
set_resource_name 'Customers'
|
127
|
+
set_resource_path '/v1/customers'
|
128
|
+
|
129
|
+
include Concerns::Entries
|
130
|
+
include API::Actions::Custom
|
131
|
+
include Concerns::Pageable
|
132
|
+
|
133
|
+
set_entry_class DeprecatedCustomer
|
134
|
+
|
135
|
+
def self.search(email)
|
136
|
+
path = ChartMogul::ResourcePath.new('/v1/customers/search')
|
137
|
+
custom!(:get, path.apply_with_get_params(email: email))
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
class ChartMogulError < StandardError
|
3
|
-
attr_accessor :message
|
4
|
-
attr_accessor :response
|
5
|
-
attr_accessor :http_status
|
6
|
-
|
7
|
-
def initialize(message, http_status:nil, response:nil)
|
8
|
-
@message = message
|
9
|
-
@http_status = http_status
|
10
|
-
@response = response
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_s
|
14
|
-
status = @http_status ? " (HTTP Status: #{@http_status.to_s})" : ''
|
15
|
-
response = @response ? "\nResponse: #{@response.to_s}" : ''
|
16
|
-
"#{message}#{status}#{response}"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
1
|
+
module ChartMogul
|
2
|
+
class ChartMogulError < StandardError
|
3
|
+
attr_accessor :message
|
4
|
+
attr_accessor :response
|
5
|
+
attr_accessor :http_status
|
6
|
+
|
7
|
+
def initialize(message, http_status:nil, response:nil)
|
8
|
+
@message = message
|
9
|
+
@http_status = http_status
|
10
|
+
@response = response
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
status = @http_status ? " (HTTP Status: #{@http_status.to_s})" : ''
|
15
|
+
response = @response ? "\nResponse: #{@response.to_s}" : ''
|
16
|
+
"#{message}#{status}#{response}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|