chartmogul-ruby 1.1.1 → 1.1.2
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 +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,39 +1,39 @@
|
|
|
1
|
-
module ChartMogul
|
|
2
|
-
module Concerns
|
|
3
|
-
module Entries
|
|
4
|
-
def self.included(base)
|
|
5
|
-
base.extend ClassMethods
|
|
6
|
-
|
|
7
|
-
base.instance_eval do
|
|
8
|
-
if @resource_root_key.nil?
|
|
9
|
-
@resource_root_key = :entries
|
|
10
|
-
end
|
|
11
|
-
readonly_attr @resource_root_key, default: []
|
|
12
|
-
|
|
13
|
-
include API::Actions::All
|
|
14
|
-
|
|
15
|
-
include Enumerable
|
|
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
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
module ClassMethods
|
|
29
|
-
def set_entry_class(klass)
|
|
30
|
-
instance_variable_set("@entry_class", klass)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def get_entry_class
|
|
34
|
-
instance_variable_get("@entry_class")
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
1
|
+
module ChartMogul
|
|
2
|
+
module Concerns
|
|
3
|
+
module Entries
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.extend ClassMethods
|
|
6
|
+
|
|
7
|
+
base.instance_eval do
|
|
8
|
+
if @resource_root_key.nil?
|
|
9
|
+
@resource_root_key = :entries
|
|
10
|
+
end
|
|
11
|
+
readonly_attr @resource_root_key, default: []
|
|
12
|
+
|
|
13
|
+
include API::Actions::All
|
|
14
|
+
|
|
15
|
+
include Enumerable
|
|
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
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
module ClassMethods
|
|
29
|
+
def set_entry_class(klass)
|
|
30
|
+
instance_variable_set("@entry_class", klass)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def get_entry_class
|
|
34
|
+
instance_variable_get("@entry_class")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
module ChartMogul
|
|
2
|
-
module Concerns
|
|
3
|
-
module Pageable
|
|
4
|
-
def self.included(base)
|
|
5
|
-
base.instance_eval do
|
|
6
|
-
readonly_attr :has_more
|
|
7
|
-
readonly_attr :per_page
|
|
8
|
-
readonly_attr :page
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
1
|
+
module ChartMogul
|
|
2
|
+
module Concerns
|
|
3
|
+
module Pageable
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.instance_eval do
|
|
6
|
+
readonly_attr :has_more
|
|
7
|
+
readonly_attr :per_page
|
|
8
|
+
readonly_attr :page
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
module ChartMogul
|
|
2
|
-
module Concerns
|
|
3
|
-
module Pageable2
|
|
4
|
-
def self.included(base)
|
|
5
|
-
base.instance_eval do
|
|
6
|
-
readonly_attr :current_page
|
|
7
|
-
readonly_attr :total_pages
|
|
8
|
-
end
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|
|
1
|
+
module ChartMogul
|
|
2
|
+
module Concerns
|
|
3
|
+
module Pageable2
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.instance_eval do
|
|
6
|
+
readonly_attr :current_page
|
|
7
|
+
readonly_attr :total_pages
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
module ChartMogul
|
|
2
|
-
module Concerns
|
|
3
|
-
module Summary
|
|
4
|
-
def self.included(base)
|
|
5
|
-
base.send :prepend, InstanceMethods
|
|
6
|
-
|
|
7
|
-
base.instance_eval do
|
|
8
|
-
readonly_attr :summary
|
|
9
|
-
end
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
module InstanceMethods
|
|
13
|
-
def set_summary(summary_attributes)
|
|
14
|
-
@summary = ChartMogul::Summary.new_from_json(summary_attributes)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
1
|
+
module ChartMogul
|
|
2
|
+
module Concerns
|
|
3
|
+
module Summary
|
|
4
|
+
def self.included(base)
|
|
5
|
+
base.send :prepend, InstanceMethods
|
|
6
|
+
|
|
7
|
+
base.instance_eval do
|
|
8
|
+
readonly_attr :summary
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module InstanceMethods
|
|
13
|
+
def set_summary(summary_attributes)
|
|
14
|
+
@summary = ChartMogul::Summary.new_from_json(summary_attributes)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
module ChartMogul
|
|
2
|
-
module ConfigAttributes
|
|
3
|
-
def config_accessor(attribute)
|
|
4
|
-
define_method(attribute) do
|
|
5
|
-
attr = config.send(attribute)
|
|
6
|
-
raise ConfigurationError.new("Configuration for #{attribute} not set") if attr.nil?
|
|
7
|
-
attr
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
define_method("#{attribute}=") do |val|
|
|
11
|
-
config.send("#{attribute}=", val)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
1
|
+
module ChartMogul
|
|
2
|
+
module ConfigAttributes
|
|
3
|
+
def config_accessor(attribute)
|
|
4
|
+
define_method(attribute) do
|
|
5
|
+
attr = config.send(attribute)
|
|
6
|
+
raise ConfigurationError.new("Configuration for #{attribute} not set") if attr.nil?
|
|
7
|
+
attr
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
define_method("#{attribute}=") do |val|
|
|
11
|
+
config.send("#{attribute}=", val)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
module ChartMogul
|
|
2
|
-
class Configuration
|
|
3
|
-
attr_accessor :account_token
|
|
4
|
-
attr_accessor :secret_key
|
|
5
|
-
end
|
|
6
|
-
end
|
|
1
|
+
module ChartMogul
|
|
2
|
+
class Configuration
|
|
3
|
+
attr_accessor :account_token
|
|
4
|
+
attr_accessor :secret_key
|
|
5
|
+
end
|
|
6
|
+
end
|
data/lib/chartmogul/customer.rb
CHANGED
|
@@ -1,155 +1,155 @@
|
|
|
1
|
-
module ChartMogul
|
|
2
|
-
class Customer < APIResource
|
|
3
|
-
set_resource_name 'Customer'
|
|
4
|
-
set_resource_path '/v1/customers'
|
|
5
|
-
|
|
6
|
-
readonly_attr :uuid
|
|
7
|
-
readonly_attr :id
|
|
8
|
-
|
|
9
|
-
readonly_attr :status
|
|
10
|
-
readonly_attr :customer_since, type: :time
|
|
11
|
-
readonly_attr :address
|
|
12
|
-
readonly_attr :mrr
|
|
13
|
-
readonly_attr :arr
|
|
14
|
-
readonly_attr :billing_system_url
|
|
15
|
-
readonly_attr :chartmogul_url
|
|
16
|
-
readonly_attr :billing_system_type
|
|
17
|
-
readonly_attr :currency
|
|
18
|
-
readonly_attr :currency_sign
|
|
19
|
-
readonly_attr :data_source_uuids
|
|
20
|
-
readonly_attr :external_ids
|
|
21
|
-
|
|
22
|
-
writeable_attr :attributes
|
|
23
|
-
writeable_attr :external_id
|
|
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 :zip
|
|
31
|
-
writeable_attr :data_source_uuid
|
|
32
|
-
writeable_attr :lead_created_at, type: :time
|
|
33
|
-
writeable_attr :free_trial_started_at, type: :time
|
|
34
|
-
|
|
35
|
-
include API::Actions::Create
|
|
36
|
-
include API::Actions::Update
|
|
37
|
-
include API::Actions::Custom
|
|
38
|
-
include API::Actions::Destroy
|
|
39
|
-
|
|
40
|
-
def self.all(options = {})
|
|
41
|
-
Customers.all(options)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
def self.retrieve(uuid)
|
|
45
|
-
custom!(:get, "/v1/customers/#{uuid}")
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def self.search(email, options = {})
|
|
49
|
-
Customers.search(email, options)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def self.find_by_external_id(external_id)
|
|
53
|
-
all(external_id: external_id).first
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def subscriptions(options = {})
|
|
57
|
-
@subscriptions ||= ChartMogul::Subscription.all(uuid, options)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def invoices(options = {})
|
|
61
|
-
@invoices ||= ChartMogul::CustomerInvoices.all(uuid, options)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def invoices=(invoices_array)
|
|
65
|
-
@invoices = ChartMogul::CustomerInvoices.new(customer_uuid: uuid, invoices: invoices_array)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
# Enrichment
|
|
69
|
-
def tags
|
|
70
|
-
@attributes[:tags]
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def custom_attributes
|
|
74
|
-
@attributes[:custom]
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def add_tags!(*tags)
|
|
78
|
-
self.tags = custom_without_assign!(:post,
|
|
79
|
-
"/v1/customers/#{uuid}/attributes/tags",
|
|
80
|
-
tags: tags)[:tags]
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def remove_tags!(*tags)
|
|
84
|
-
self.tags = custom_without_assign!(:delete,
|
|
85
|
-
"/v1/customers/#{uuid}/attributes/tags",
|
|
86
|
-
tags: tags)[:tags]
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def add_custom_attributes!(*custom_attrs)
|
|
90
|
-
self.custom_attributes = custom_without_assign!(:post,
|
|
91
|
-
"/v1/customers/#{uuid}/attributes/custom",
|
|
92
|
-
custom: custom_attrs)[:custom]
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def update_custom_attributes!(custom_attrs = {})
|
|
96
|
-
self.custom_attributes = custom_without_assign!(:put,
|
|
97
|
-
"/v1/customers/#{uuid}/attributes/custom",
|
|
98
|
-
custom: custom_attrs)[:custom]
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def remove_custom_attributes!(*custom_attrs)
|
|
102
|
-
self.custom_attributes = custom_without_assign!(:delete,
|
|
103
|
-
"/v1/customers/#{uuid}/attributes/custom",
|
|
104
|
-
custom: custom_attrs)[:custom]
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def merge_into!(other_customer)
|
|
108
|
-
options = {
|
|
109
|
-
from: { customer_uuid: uuid },
|
|
110
|
-
into: { customer_uuid: other_customer.uuid }
|
|
111
|
-
}
|
|
112
|
-
custom!(:post, '/v1/customers/merges', options)
|
|
113
|
-
true
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
private
|
|
117
|
-
|
|
118
|
-
def tags=(tags)
|
|
119
|
-
@attributes[:tags] = tags
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def custom_attributes=(custom_attributes = {})
|
|
123
|
-
@attributes[:custom] = typecast_custom_attributes(custom_attributes)
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
def set_attributes(attributes_attributes)
|
|
127
|
-
@attributes = attributes_attributes
|
|
128
|
-
@attributes[:custom] = typecast_custom_attributes(attributes_attributes[:custom])
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def typecast_custom_attributes(custom_attributes)
|
|
132
|
-
return {} unless custom_attributes
|
|
133
|
-
custom_attributes.each_with_object({}) do |(key, value), hash|
|
|
134
|
-
hash[key] = value.instance_of?(String) ? (Time.parse(value) rescue value) : value
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
|
|
139
|
-
class Customers < APIResource
|
|
140
|
-
set_resource_name 'Customers'
|
|
141
|
-
set_resource_path '/v1/customers'
|
|
142
|
-
|
|
143
|
-
include Concerns::Entries
|
|
144
|
-
include API::Actions::Custom
|
|
145
|
-
include Concerns::Pageable
|
|
146
|
-
include Concerns::Pageable2
|
|
147
|
-
|
|
148
|
-
set_entry_class Customer
|
|
149
|
-
|
|
150
|
-
def self.search(email, options = {})
|
|
151
|
-
path = ChartMogul::ResourcePath.new('/v1/customers/search')
|
|
152
|
-
custom!(:get, path.apply_with_get_params(options.merge(email: email)))
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
1
|
+
module ChartMogul
|
|
2
|
+
class Customer < APIResource
|
|
3
|
+
set_resource_name 'Customer'
|
|
4
|
+
set_resource_path '/v1/customers'
|
|
5
|
+
|
|
6
|
+
readonly_attr :uuid
|
|
7
|
+
readonly_attr :id
|
|
8
|
+
|
|
9
|
+
readonly_attr :status
|
|
10
|
+
readonly_attr :customer_since, type: :time
|
|
11
|
+
readonly_attr :address
|
|
12
|
+
readonly_attr :mrr
|
|
13
|
+
readonly_attr :arr
|
|
14
|
+
readonly_attr :billing_system_url
|
|
15
|
+
readonly_attr :chartmogul_url
|
|
16
|
+
readonly_attr :billing_system_type
|
|
17
|
+
readonly_attr :currency
|
|
18
|
+
readonly_attr :currency_sign
|
|
19
|
+
readonly_attr :data_source_uuids
|
|
20
|
+
readonly_attr :external_ids
|
|
21
|
+
|
|
22
|
+
writeable_attr :attributes
|
|
23
|
+
writeable_attr :external_id
|
|
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 :zip
|
|
31
|
+
writeable_attr :data_source_uuid
|
|
32
|
+
writeable_attr :lead_created_at, type: :time
|
|
33
|
+
writeable_attr :free_trial_started_at, type: :time
|
|
34
|
+
|
|
35
|
+
include API::Actions::Create
|
|
36
|
+
include API::Actions::Update
|
|
37
|
+
include API::Actions::Custom
|
|
38
|
+
include API::Actions::Destroy
|
|
39
|
+
|
|
40
|
+
def self.all(options = {})
|
|
41
|
+
Customers.all(options)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.retrieve(uuid)
|
|
45
|
+
custom!(:get, "/v1/customers/#{uuid}")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.search(email, options = {})
|
|
49
|
+
Customers.search(email, options)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.find_by_external_id(external_id)
|
|
53
|
+
all(external_id: external_id).first
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def subscriptions(options = {})
|
|
57
|
+
@subscriptions ||= ChartMogul::Subscription.all(uuid, options)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def invoices(options = {})
|
|
61
|
+
@invoices ||= ChartMogul::CustomerInvoices.all(uuid, options)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def invoices=(invoices_array)
|
|
65
|
+
@invoices = ChartMogul::CustomerInvoices.new(customer_uuid: uuid, invoices: invoices_array)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Enrichment
|
|
69
|
+
def tags
|
|
70
|
+
@attributes[:tags]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def custom_attributes
|
|
74
|
+
@attributes[:custom]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def add_tags!(*tags)
|
|
78
|
+
self.tags = custom_without_assign!(:post,
|
|
79
|
+
"/v1/customers/#{uuid}/attributes/tags",
|
|
80
|
+
tags: tags)[:tags]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def remove_tags!(*tags)
|
|
84
|
+
self.tags = custom_without_assign!(:delete,
|
|
85
|
+
"/v1/customers/#{uuid}/attributes/tags",
|
|
86
|
+
tags: tags)[:tags]
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def add_custom_attributes!(*custom_attrs)
|
|
90
|
+
self.custom_attributes = custom_without_assign!(:post,
|
|
91
|
+
"/v1/customers/#{uuid}/attributes/custom",
|
|
92
|
+
custom: custom_attrs)[:custom]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def update_custom_attributes!(custom_attrs = {})
|
|
96
|
+
self.custom_attributes = custom_without_assign!(:put,
|
|
97
|
+
"/v1/customers/#{uuid}/attributes/custom",
|
|
98
|
+
custom: custom_attrs)[:custom]
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def remove_custom_attributes!(*custom_attrs)
|
|
102
|
+
self.custom_attributes = custom_without_assign!(:delete,
|
|
103
|
+
"/v1/customers/#{uuid}/attributes/custom",
|
|
104
|
+
custom: custom_attrs)[:custom]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def merge_into!(other_customer)
|
|
108
|
+
options = {
|
|
109
|
+
from: { customer_uuid: uuid },
|
|
110
|
+
into: { customer_uuid: other_customer.uuid }
|
|
111
|
+
}
|
|
112
|
+
custom!(:post, '/v1/customers/merges', options)
|
|
113
|
+
true
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
private
|
|
117
|
+
|
|
118
|
+
def tags=(tags)
|
|
119
|
+
@attributes[:tags] = tags
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def custom_attributes=(custom_attributes = {})
|
|
123
|
+
@attributes[:custom] = typecast_custom_attributes(custom_attributes)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def set_attributes(attributes_attributes)
|
|
127
|
+
@attributes = attributes_attributes
|
|
128
|
+
@attributes[:custom] = typecast_custom_attributes(attributes_attributes[:custom])
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def typecast_custom_attributes(custom_attributes)
|
|
132
|
+
return {} unless custom_attributes
|
|
133
|
+
custom_attributes.each_with_object({}) do |(key, value), hash|
|
|
134
|
+
hash[key] = value.instance_of?(String) ? (Time.parse(value) rescue value) : value
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
class Customers < APIResource
|
|
140
|
+
set_resource_name 'Customers'
|
|
141
|
+
set_resource_path '/v1/customers'
|
|
142
|
+
|
|
143
|
+
include Concerns::Entries
|
|
144
|
+
include API::Actions::Custom
|
|
145
|
+
include Concerns::Pageable
|
|
146
|
+
include Concerns::Pageable2
|
|
147
|
+
|
|
148
|
+
set_entry_class Customer
|
|
149
|
+
|
|
150
|
+
def self.search(email, options = {})
|
|
151
|
+
path = ChartMogul::ResourcePath.new('/v1/customers/search')
|
|
152
|
+
custom!(:get, path.apply_with_get_params(options.merge(email: email)))
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|