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/object.rb
CHANGED
@@ -1,119 +1,119 @@
|
|
1
|
-
require 'set'
|
2
|
-
|
3
|
-
module ChartMogul
|
4
|
-
class Object
|
5
|
-
class << self
|
6
|
-
def attributes
|
7
|
-
@attributes ||= Set.new
|
8
|
-
end
|
9
|
-
|
10
|
-
def writeable_attributes
|
11
|
-
@writeable_attributes ||= Set.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def readonly_attr(attribute, options = {})
|
15
|
-
attributes << attribute.to_sym
|
16
|
-
define_reader(attribute, options[:default])
|
17
|
-
define_private_writer(attribute, options[:type])
|
18
|
-
end
|
19
|
-
|
20
|
-
def writeable_attr(attribute, options = {})
|
21
|
-
attributes << attribute.to_sym
|
22
|
-
writeable_attributes << attribute.to_sym
|
23
|
-
|
24
|
-
define_reader(attribute, options[:default])
|
25
|
-
define_writer(attribute)
|
26
|
-
define_private_writer(attribute, options[:type])
|
27
|
-
end
|
28
|
-
|
29
|
-
def define_reader(attribute, default)
|
30
|
-
define_method(attribute) do
|
31
|
-
if instance_variable_defined?("@#{attribute}")
|
32
|
-
instance_variable_get("@#{attribute}")
|
33
|
-
else
|
34
|
-
instance_variable_set("@#{attribute}", default)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
def define_private_writer(attribute, type)
|
40
|
-
if type == :time
|
41
|
-
define_method("set_#{attribute}") do |value|
|
42
|
-
instance_variable_set("@#{attribute}", value && Time.parse(value))
|
43
|
-
end
|
44
|
-
elsif type == :date
|
45
|
-
define_method("set_#{attribute}") do |value|
|
46
|
-
instance_variable_set("@#{attribute}", value && Date.strptime(value, '%Y-%m-%d'))
|
47
|
-
end
|
48
|
-
else
|
49
|
-
define_method("set_#{attribute}") do |value|
|
50
|
-
instance_variable_set("@#{attribute}", value)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
private "set_#{attribute}"
|
54
|
-
end
|
55
|
-
|
56
|
-
def define_writer(attribute)
|
57
|
-
define_method("#{attribute}=") do |value|
|
58
|
-
instance_variable_set("@#{attribute}", value)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def initialize(attributes = {})
|
64
|
-
assign_writeable_attributes(attributes)
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.new_from_json(attributes={})
|
68
|
-
self.new.tap do |resource|
|
69
|
-
resource.assign_all_attributes(attributes)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def instance_attributes
|
74
|
-
self.class.attributes.each_with_object({}) do |attribute, hash|
|
75
|
-
hash[attribute] = send(attribute)
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def assign_writeable_attributes(new_values)
|
80
|
-
self.class.writeable_attributes.each do |attr, value|
|
81
|
-
self.send("#{attr}=", new_values[attr]) if new_values.key?(attr)
|
82
|
-
end
|
83
|
-
|
84
|
-
self
|
85
|
-
end
|
86
|
-
|
87
|
-
def assign_all_attributes(new_values)
|
88
|
-
self.class.attributes.each do |attr|
|
89
|
-
self.send("set_#{attr}", new_values[attr]) if new_values.key?(attr)
|
90
|
-
end
|
91
|
-
|
92
|
-
self
|
93
|
-
end
|
94
|
-
|
95
|
-
def serialize_for_write
|
96
|
-
self.class.writeable_attributes.each_with_object({}) do |attr, attrs|
|
97
|
-
serialized_value = serialized_value_for_attr(attr)
|
98
|
-
attrs[attr] = serialized_value if allowed_for_write?(serialized_value)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def allowed_for_write?(serialized_value)
|
103
|
-
return false if serialized_value.is_a?(Array) && serialized_value.empty?
|
104
|
-
return false if serialized_value.nil?
|
105
|
-
|
106
|
-
true
|
107
|
-
end
|
108
|
-
|
109
|
-
def serialized_value_for_attr(attr)
|
110
|
-
serialize_method_name = "serialize_#{attr}"
|
111
|
-
|
112
|
-
if respond_to?(serialize_method_name)
|
113
|
-
send(serialize_method_name)
|
114
|
-
else
|
115
|
-
send(attr)
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module ChartMogul
|
4
|
+
class Object
|
5
|
+
class << self
|
6
|
+
def attributes
|
7
|
+
@attributes ||= Set.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def writeable_attributes
|
11
|
+
@writeable_attributes ||= Set.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def readonly_attr(attribute, options = {})
|
15
|
+
attributes << attribute.to_sym
|
16
|
+
define_reader(attribute, options[:default])
|
17
|
+
define_private_writer(attribute, options[:type])
|
18
|
+
end
|
19
|
+
|
20
|
+
def writeable_attr(attribute, options = {})
|
21
|
+
attributes << attribute.to_sym
|
22
|
+
writeable_attributes << attribute.to_sym
|
23
|
+
|
24
|
+
define_reader(attribute, options[:default])
|
25
|
+
define_writer(attribute)
|
26
|
+
define_private_writer(attribute, options[:type])
|
27
|
+
end
|
28
|
+
|
29
|
+
def define_reader(attribute, default)
|
30
|
+
define_method(attribute) do
|
31
|
+
if instance_variable_defined?("@#{attribute}")
|
32
|
+
instance_variable_get("@#{attribute}")
|
33
|
+
else
|
34
|
+
instance_variable_set("@#{attribute}", default)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def define_private_writer(attribute, type)
|
40
|
+
if type == :time
|
41
|
+
define_method("set_#{attribute}") do |value|
|
42
|
+
instance_variable_set("@#{attribute}", value && Time.parse(value))
|
43
|
+
end
|
44
|
+
elsif type == :date
|
45
|
+
define_method("set_#{attribute}") do |value|
|
46
|
+
instance_variable_set("@#{attribute}", value && Date.strptime(value, '%Y-%m-%d'))
|
47
|
+
end
|
48
|
+
else
|
49
|
+
define_method("set_#{attribute}") do |value|
|
50
|
+
instance_variable_set("@#{attribute}", value)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
private "set_#{attribute}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def define_writer(attribute)
|
57
|
+
define_method("#{attribute}=") do |value|
|
58
|
+
instance_variable_set("@#{attribute}", value)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def initialize(attributes = {})
|
64
|
+
assign_writeable_attributes(attributes)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.new_from_json(attributes={})
|
68
|
+
self.new.tap do |resource|
|
69
|
+
resource.assign_all_attributes(attributes)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def instance_attributes
|
74
|
+
self.class.attributes.each_with_object({}) do |attribute, hash|
|
75
|
+
hash[attribute] = send(attribute)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def assign_writeable_attributes(new_values)
|
80
|
+
self.class.writeable_attributes.each do |attr, value|
|
81
|
+
self.send("#{attr}=", new_values[attr]) if new_values.key?(attr)
|
82
|
+
end
|
83
|
+
|
84
|
+
self
|
85
|
+
end
|
86
|
+
|
87
|
+
def assign_all_attributes(new_values)
|
88
|
+
self.class.attributes.each do |attr|
|
89
|
+
self.send("set_#{attr}", new_values[attr]) if new_values.key?(attr)
|
90
|
+
end
|
91
|
+
|
92
|
+
self
|
93
|
+
end
|
94
|
+
|
95
|
+
def serialize_for_write
|
96
|
+
self.class.writeable_attributes.each_with_object({}) do |attr, attrs|
|
97
|
+
serialized_value = serialized_value_for_attr(attr)
|
98
|
+
attrs[attr] = serialized_value if allowed_for_write?(serialized_value)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def allowed_for_write?(serialized_value)
|
103
|
+
return false if serialized_value.is_a?(Array) && serialized_value.empty?
|
104
|
+
return false if serialized_value.nil?
|
105
|
+
|
106
|
+
true
|
107
|
+
end
|
108
|
+
|
109
|
+
def serialized_value_for_attr(attr)
|
110
|
+
serialize_method_name = "serialize_#{attr}"
|
111
|
+
|
112
|
+
if respond_to?(serialize_method_name)
|
113
|
+
send(serialize_method_name)
|
114
|
+
else
|
115
|
+
send(attr)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/lib/chartmogul/ping.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
class Ping < APIResource
|
3
|
-
set_resource_name 'Ping'
|
4
|
-
set_resource_path '/v1/ping'
|
5
|
-
|
6
|
-
readonly_attr :data
|
7
|
-
|
8
|
-
include API::Actions::Custom
|
9
|
-
|
10
|
-
def self.ping()
|
11
|
-
custom!(:get, '/v1/ping')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
1
|
+
module ChartMogul
|
2
|
+
class Ping < APIResource
|
3
|
+
set_resource_name 'Ping'
|
4
|
+
set_resource_path '/v1/ping'
|
5
|
+
|
6
|
+
readonly_attr :data
|
7
|
+
|
8
|
+
include API::Actions::Custom
|
9
|
+
|
10
|
+
def self.ping()
|
11
|
+
custom!(:get, '/v1/ping')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/chartmogul/plan.rb
CHANGED
@@ -1,41 +1,41 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
class Plan < APIResource
|
3
|
-
set_resource_name 'Plan'
|
4
|
-
set_resource_path '/v1/plans'
|
5
|
-
|
6
|
-
readonly_attr :uuid
|
7
|
-
|
8
|
-
writeable_attr :name
|
9
|
-
writeable_attr :interval_count
|
10
|
-
writeable_attr :interval_unit
|
11
|
-
writeable_attr :external_id
|
12
|
-
|
13
|
-
writeable_attr :data_source_uuid
|
14
|
-
|
15
|
-
include API::Actions::Create
|
16
|
-
include API::Actions::Update
|
17
|
-
include API::Actions::Destroy
|
18
|
-
include API::Actions::Custom
|
19
|
-
|
20
|
-
def self.retrieve(uuid)
|
21
|
-
custom!(:get, "/v1/plans/#{uuid}")
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.all(options = {})
|
25
|
-
Plans.all(options)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
class Plans < APIResource
|
31
|
-
set_resource_name 'Plans'
|
32
|
-
set_resource_path '/v1/plans'
|
33
|
-
|
34
|
-
set_resource_root_key :plans
|
35
|
-
|
36
|
-
include Concerns::Entries
|
37
|
-
include Concerns::Pageable2
|
38
|
-
|
39
|
-
set_entry_class Plan
|
40
|
-
end
|
41
|
-
end
|
1
|
+
module ChartMogul
|
2
|
+
class Plan < APIResource
|
3
|
+
set_resource_name 'Plan'
|
4
|
+
set_resource_path '/v1/plans'
|
5
|
+
|
6
|
+
readonly_attr :uuid
|
7
|
+
|
8
|
+
writeable_attr :name
|
9
|
+
writeable_attr :interval_count
|
10
|
+
writeable_attr :interval_unit
|
11
|
+
writeable_attr :external_id
|
12
|
+
|
13
|
+
writeable_attr :data_source_uuid
|
14
|
+
|
15
|
+
include API::Actions::Create
|
16
|
+
include API::Actions::Update
|
17
|
+
include API::Actions::Destroy
|
18
|
+
include API::Actions::Custom
|
19
|
+
|
20
|
+
def self.retrieve(uuid)
|
21
|
+
custom!(:get, "/v1/plans/#{uuid}")
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.all(options = {})
|
25
|
+
Plans.all(options)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
class Plans < APIResource
|
31
|
+
set_resource_name 'Plans'
|
32
|
+
set_resource_path '/v1/plans'
|
33
|
+
|
34
|
+
set_resource_root_key :plans
|
35
|
+
|
36
|
+
include Concerns::Entries
|
37
|
+
include Concerns::Pageable2
|
38
|
+
|
39
|
+
set_entry_class Plan
|
40
|
+
end
|
41
|
+
end
|
@@ -1,42 +1,42 @@
|
|
1
|
-
require 'uri'
|
2
|
-
|
3
|
-
module ChartMogul
|
4
|
-
class ResourcePath
|
5
|
-
attr_reader :path
|
6
|
-
attr_reader :named_params
|
7
|
-
|
8
|
-
class RequiredParameterMissing < StandardError; end
|
9
|
-
|
10
|
-
def initialize(path)
|
11
|
-
@path = path
|
12
|
-
@named_params = path.scan(/:\w+/).each_with_object({}) do |named_param, hash|
|
13
|
-
hash[named_param] = named_param.gsub(':', '').to_sym
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def apply(params = {})
|
18
|
-
apply_named_params(params)
|
19
|
-
end
|
20
|
-
|
21
|
-
# For path = '/hello/:hello_id/say' & params = { hello_id: 1, search: 'cat' }
|
22
|
-
# it will return '/hello/1/say?search=cat'
|
23
|
-
|
24
|
-
def apply_with_get_params(params = {})
|
25
|
-
base_path = apply_named_params(params)
|
26
|
-
get_params = params.reject { |param_name| named_params.values.include?(param_name) }
|
27
|
-
|
28
|
-
get_params.empty? ? base_path : "#{base_path}?#{URI.encode_www_form(get_params)}"
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def apply_named_params(params)
|
34
|
-
path.dup.tap do |path|
|
35
|
-
named_params.each do |named_param, param_key|
|
36
|
-
raise(RequiredParameterMissing, "#{named_param} is required") unless params.key?(param_key)
|
37
|
-
path.gsub!(named_param, params[param_key].to_s)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module ChartMogul
|
4
|
+
class ResourcePath
|
5
|
+
attr_reader :path
|
6
|
+
attr_reader :named_params
|
7
|
+
|
8
|
+
class RequiredParameterMissing < StandardError; end
|
9
|
+
|
10
|
+
def initialize(path)
|
11
|
+
@path = path
|
12
|
+
@named_params = path.scan(/:\w+/).each_with_object({}) do |named_param, hash|
|
13
|
+
hash[named_param] = named_param.gsub(':', '').to_sym
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def apply(params = {})
|
18
|
+
apply_named_params(params)
|
19
|
+
end
|
20
|
+
|
21
|
+
# For path = '/hello/:hello_id/say' & params = { hello_id: 1, search: 'cat' }
|
22
|
+
# it will return '/hello/1/say?search=cat'
|
23
|
+
|
24
|
+
def apply_with_get_params(params = {})
|
25
|
+
base_path = apply_named_params(params)
|
26
|
+
get_params = params.reject { |param_name| named_params.values.include?(param_name) }
|
27
|
+
|
28
|
+
get_params.empty? ? base_path : "#{base_path}?#{URI.encode_www_form(get_params)}"
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def apply_named_params(params)
|
34
|
+
path.dup.tap do |path|
|
35
|
+
named_params.each do |named_param, param_key|
|
36
|
+
raise(RequiredParameterMissing, "#{named_param} is required") unless params.key?(param_key)
|
37
|
+
path.gsub!(named_param, params[param_key].to_s)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,48 +1,48 @@
|
|
1
|
-
module ChartMogul
|
2
|
-
class Subscription < APIResource
|
3
|
-
set_resource_name 'Subscription'
|
4
|
-
set_resource_path '/v1/import/customers/:customer_uuid/subscriptions'
|
5
|
-
|
6
|
-
readonly_attr :uuid
|
7
|
-
readonly_attr :external_id
|
8
|
-
readonly_attr :cancellation_dates, default: []
|
9
|
-
|
10
|
-
readonly_attr :plan_uuid
|
11
|
-
readonly_attr :data_source_uuid
|
12
|
-
|
13
|
-
include API::Actions::Custom
|
14
|
-
|
15
|
-
def set_cancellation_dates(cancellation_dates_array)
|
16
|
-
@cancellation_dates = cancellation_dates_array.map do |cancellation_date|
|
17
|
-
Time.parse(cancellation_date)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def cancel(cancelled_at)
|
22
|
-
custom!(:patch, "/v1/import/subscriptions/#{uuid}", cancelled_at: cancelled_at)
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.all(customer_uuid, options = {})
|
26
|
-
Subscriptions.all(customer_uuid, options)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class Subscriptions < APIResource
|
31
|
-
readonly_attr :customer_uuid
|
32
|
-
|
33
|
-
set_resource_name 'Subscriptions'
|
34
|
-
set_resource_path '/v1/import/customers/:customer_uuid/subscriptions'
|
35
|
-
|
36
|
-
set_resource_root_key :subscriptions
|
37
|
-
|
38
|
-
include Concerns::Entries
|
39
|
-
include Concerns::Pageable2
|
40
|
-
|
41
|
-
set_entry_class Subscription
|
42
|
-
|
43
|
-
def self.all(customer_uuid, options = {})
|
44
|
-
super(options.merge(customer_uuid: customer_uuid))
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
1
|
+
module ChartMogul
|
2
|
+
class Subscription < APIResource
|
3
|
+
set_resource_name 'Subscription'
|
4
|
+
set_resource_path '/v1/import/customers/:customer_uuid/subscriptions'
|
5
|
+
|
6
|
+
readonly_attr :uuid
|
7
|
+
readonly_attr :external_id
|
8
|
+
readonly_attr :cancellation_dates, default: []
|
9
|
+
|
10
|
+
readonly_attr :plan_uuid
|
11
|
+
readonly_attr :data_source_uuid
|
12
|
+
|
13
|
+
include API::Actions::Custom
|
14
|
+
|
15
|
+
def set_cancellation_dates(cancellation_dates_array)
|
16
|
+
@cancellation_dates = cancellation_dates_array.map do |cancellation_date|
|
17
|
+
Time.parse(cancellation_date)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def cancel(cancelled_at)
|
22
|
+
custom!(:patch, "/v1/import/subscriptions/#{uuid}", cancelled_at: cancelled_at)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.all(customer_uuid, options = {})
|
26
|
+
Subscriptions.all(customer_uuid, options)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Subscriptions < APIResource
|
31
|
+
readonly_attr :customer_uuid
|
32
|
+
|
33
|
+
set_resource_name 'Subscriptions'
|
34
|
+
set_resource_path '/v1/import/customers/:customer_uuid/subscriptions'
|
35
|
+
|
36
|
+
set_resource_root_key :subscriptions
|
37
|
+
|
38
|
+
include Concerns::Entries
|
39
|
+
include Concerns::Pageable2
|
40
|
+
|
41
|
+
set_entry_class Subscription
|
42
|
+
|
43
|
+
def self.all(customer_uuid, options = {})
|
44
|
+
super(options.merge(customer_uuid: customer_uuid))
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|