chartmogul-ruby 1.1.4 → 1.1.5
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/Rakefile +3 -3
- data/bin/console +3 -3
- data/chartmogul-ruby.gemspec +1 -0
- data/lib/chartmogul.rb +63 -62
- data/lib/chartmogul/api/actions/create.rb +2 -2
- data/lib/chartmogul/api/actions/destroy.rb +1 -1
- data/lib/chartmogul/api/actions/update.rb +2 -2
- data/lib/chartmogul/api_resource.rb +3 -3
- data/lib/chartmogul/concerns/entries.rb +5 -7
- data/lib/chartmogul/concerns/summary.rb +0 -1
- data/lib/chartmogul/config_attributes.rb +1 -1
- data/lib/chartmogul/customer.rb +5 -2
- data/lib/chartmogul/data_source.rb +0 -1
- data/lib/chartmogul/enrichment/customer.rb +6 -4
- data/lib/chartmogul/errors/chartmogul_error.rb +3 -3
- data/lib/chartmogul/metrics/activity.rb +0 -1
- data/lib/chartmogul/metrics/all_key_metrics.rb +0 -1
- data/lib/chartmogul/metrics/arpa.rb +0 -1
- data/lib/chartmogul/metrics/arr.rb +0 -1
- data/lib/chartmogul/metrics/asp.rb +0 -1
- data/lib/chartmogul/metrics/base.rb +4 -6
- data/lib/chartmogul/metrics/customer_churn_rate.rb +0 -1
- data/lib/chartmogul/metrics/customer_count.rb +0 -1
- data/lib/chartmogul/metrics/ltv.rb +0 -1
- data/lib/chartmogul/metrics/mrr_churn_rate.rb +0 -1
- data/lib/chartmogul/object.rb +5 -5
- data/lib/chartmogul/ping.rb +1 -1
- data/lib/chartmogul/plan.rb +0 -1
- data/lib/chartmogul/resource_path.rb +1 -1
- data/lib/chartmogul/subscription.rb +0 -1
- data/lib/chartmogul/utils/hash_snake_caser.rb +4 -5
- data/lib/chartmogul/utils/json_parser.rb +0 -1
- data/lib/chartmogul/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7ad064432c9e4fecaf637584b5d34052e76055d
|
4
|
+
data.tar.gz: c54868e20a9715858c983033c6919f585883de3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09dd03962421da8a7f03e1d11f9317541f5e616e4d45c5f63b52c549d0c6f715c10696281104ad936ee0c1c3418aa0052ae8343f7923694eaebaef1dd1b3cd7e
|
7
|
+
data.tar.gz: 9246cc2c80a01bbec3fa24f205351bdb1293d44ccd8c9fb6c2cd270c432d2a2ba109bd951f0284aa509e3be0df6c83dcf57cf8cf3a73f82b2c6d4a8cdb004586
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'chartmogul'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "chartmogul"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/chartmogul-ruby.gemspec
CHANGED
data/lib/chartmogul.rb
CHANGED
@@ -2,70 +2,71 @@ require 'time'
|
|
2
2
|
require 'json'
|
3
3
|
require 'faraday'
|
4
4
|
|
5
|
-
require
|
6
|
-
|
7
|
-
require
|
8
|
-
require
|
9
|
-
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
15
|
-
require
|
16
|
-
|
17
|
-
|
18
|
-
require
|
19
|
-
|
20
|
-
|
21
|
-
require
|
22
|
-
require
|
23
|
-
require
|
24
|
-
|
25
|
-
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
|
32
|
-
|
33
|
-
require
|
34
|
-
|
35
|
-
|
36
|
-
require
|
37
|
-
|
38
|
-
|
39
|
-
require
|
40
|
-
require
|
41
|
-
require
|
42
|
-
|
43
|
-
|
44
|
-
require
|
45
|
-
require
|
46
|
-
require
|
47
|
-
require
|
48
|
-
require
|
49
|
-
require
|
50
|
-
|
51
|
-
|
52
|
-
require
|
53
|
-
require
|
54
|
-
require
|
55
|
-
require
|
56
|
-
require
|
57
|
-
require
|
58
|
-
require
|
59
|
-
require
|
60
|
-
require
|
61
|
-
|
62
|
-
|
63
|
-
require
|
64
|
-
|
65
|
-
|
5
|
+
require 'chartmogul/version'
|
6
|
+
|
7
|
+
require 'chartmogul/utils/hash_snake_caser'
|
8
|
+
require 'chartmogul/utils/json_parser'
|
9
|
+
|
10
|
+
require 'chartmogul/errors/chartmogul_error'
|
11
|
+
require 'chartmogul/errors/configuration_error'
|
12
|
+
require 'chartmogul/errors/forbidden_error'
|
13
|
+
require 'chartmogul/errors/not_found_error'
|
14
|
+
require 'chartmogul/errors/resource_invalid_error'
|
15
|
+
require 'chartmogul/errors/schema_invalid_error'
|
16
|
+
require 'chartmogul/errors/unauthorized_error'
|
17
|
+
|
18
|
+
require 'chartmogul/config_attributes'
|
19
|
+
require 'chartmogul/configuration'
|
20
|
+
|
21
|
+
require 'chartmogul/object'
|
22
|
+
require 'chartmogul/resource_path'
|
23
|
+
require 'chartmogul/api_resource'
|
24
|
+
require 'chartmogul/summary'
|
25
|
+
|
26
|
+
require 'chartmogul/api/actions/all'
|
27
|
+
require 'chartmogul/api/actions/create'
|
28
|
+
require 'chartmogul/api/actions/custom'
|
29
|
+
require 'chartmogul/api/actions/destroy'
|
30
|
+
require 'chartmogul/api/actions/retrieve'
|
31
|
+
require 'chartmogul/api/actions/update'
|
32
|
+
|
33
|
+
require 'chartmogul/line_items/one_time'
|
34
|
+
require 'chartmogul/line_items/subscription'
|
35
|
+
|
36
|
+
require 'chartmogul/transactions/payment'
|
37
|
+
require 'chartmogul/transactions/refund'
|
38
|
+
|
39
|
+
require 'chartmogul/concerns/entries'
|
40
|
+
require 'chartmogul/concerns/summary'
|
41
|
+
require 'chartmogul/concerns/pageable'
|
42
|
+
require 'chartmogul/concerns/pageable2'
|
43
|
+
|
44
|
+
require 'chartmogul/subscription'
|
45
|
+
require 'chartmogul/invoice'
|
46
|
+
require 'chartmogul/customer_invoices'
|
47
|
+
require 'chartmogul/customer'
|
48
|
+
require 'chartmogul/data_source'
|
49
|
+
require 'chartmogul/ping'
|
50
|
+
require 'chartmogul/plan'
|
51
|
+
|
52
|
+
require 'chartmogul/metrics/arpa'
|
53
|
+
require 'chartmogul/metrics/arr'
|
54
|
+
require 'chartmogul/metrics/asp'
|
55
|
+
require 'chartmogul/metrics/customer_churn_rate'
|
56
|
+
require 'chartmogul/metrics/customer_count'
|
57
|
+
require 'chartmogul/metrics/ltv'
|
58
|
+
require 'chartmogul/metrics/mrr'
|
59
|
+
require 'chartmogul/metrics/mrr_churn_rate'
|
60
|
+
require 'chartmogul/metrics/all_key_metrics'
|
61
|
+
require 'chartmogul/metrics/base'
|
62
|
+
|
63
|
+
require 'chartmogul/metrics/activity'
|
64
|
+
require 'chartmogul/metrics/subscription'
|
65
|
+
|
66
|
+
require 'chartmogul/enrichment/customer'
|
66
67
|
|
67
68
|
module ChartMogul
|
68
|
-
API_BASE = 'https://api.chartmogul.com'
|
69
|
+
API_BASE = 'https://api.chartmogul.com'.freeze
|
69
70
|
|
70
71
|
class << self
|
71
72
|
extend ConfigAttributes
|
@@ -8,9 +8,9 @@ module ChartMogul
|
|
8
8
|
|
9
9
|
def create!
|
10
10
|
resp = handling_errors do
|
11
|
-
connection.post(resource_path.apply(
|
11
|
+
connection.post(resource_path.apply(instance_attributes)) do |req|
|
12
12
|
req.headers['Content-Type'] = 'application/json'
|
13
|
-
req.body = JSON.dump(
|
13
|
+
req.body = JSON.dump(serialize_for_write)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
json = ChartMogul::Utils::JSONParser.parse(resp.body)
|
@@ -4,9 +4,9 @@ module ChartMogul
|
|
4
4
|
module Update
|
5
5
|
def update!
|
6
6
|
resp = handling_errors do
|
7
|
-
connection.patch("#{resource_path.apply(
|
7
|
+
connection.patch("#{resource_path.apply(instance_attributes)}/#{uuid}") do |req|
|
8
8
|
req.headers['Content-Type'] = 'application/json'
|
9
|
-
req.body = JSON.dump(
|
9
|
+
req.body = JSON.dump(serialize_for_write)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
json = ChartMogul::Utils::JSONParser.parse(resp.body)
|
@@ -17,7 +17,7 @@ module ChartMogul
|
|
17
17
|
def self.set_resource_root_key(root_key)
|
18
18
|
@resource_root_key = root_key
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def self.connection
|
22
22
|
@connection ||= Faraday.new(url: ChartMogul::API_BASE) do |faraday|
|
23
23
|
faraday.use Faraday::Request::BasicAuthentication, ChartMogul.account_token, ChartMogul.secret_key
|
@@ -45,7 +45,7 @@ module ChartMogul
|
|
45
45
|
message = 'No valid API key provided'
|
46
46
|
raise ChartMogul::UnauthorizedError.new(message, http_status: 401, response: response)
|
47
47
|
when 403
|
48
|
-
message =
|
48
|
+
message = 'The requested action is forbidden.'
|
49
49
|
raise ChartMogul::ForbiddenError.new(message, http_status: 403, response: response)
|
50
50
|
when 404
|
51
51
|
message = "The requested #{resource_name} could not be found."
|
@@ -60,7 +60,7 @@ module ChartMogul
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def self.handle_other_error(exception)
|
63
|
-
raise ChartMogul::ChartMogulError
|
63
|
+
raise ChartMogul::ChartMogulError, exception.message
|
64
64
|
end
|
65
65
|
|
66
66
|
def_delegators 'self.class', :resource_path, :resource_name, :resource_root_key, :connection, :handling_errors
|
@@ -5,9 +5,7 @@ module ChartMogul
|
|
5
5
|
base.extend ClassMethods
|
6
6
|
|
7
7
|
base.instance_eval do
|
8
|
-
if @resource_root_key.nil?
|
9
|
-
@resource_root_key = :entries
|
10
|
-
end
|
8
|
+
@resource_root_key = :entries if @resource_root_key.nil?
|
11
9
|
readonly_attr @resource_root_key, default: []
|
12
10
|
|
13
11
|
include API::Actions::All
|
@@ -16,22 +14,22 @@ module ChartMogul
|
|
16
14
|
def_delegators @resource_root_key, :each, :[], :<<, :size, :length, :empty?, :first
|
17
15
|
|
18
16
|
resource_root_key = @resource_root_key.to_s
|
19
|
-
base.send :define_method,
|
17
|
+
base.send :define_method, 'set_' + resource_root_key do |entries|
|
20
18
|
objects = entries.map do |entity|
|
21
19
|
self.class.get_entry_class.new_from_json(entity)
|
22
20
|
end
|
23
|
-
|
21
|
+
instance_variable_set "@#{resource_root_key}", objects
|
24
22
|
end
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
26
|
module ClassMethods
|
29
27
|
def set_entry_class(klass)
|
30
|
-
instance_variable_set(
|
28
|
+
instance_variable_set('@entry_class', klass)
|
31
29
|
end
|
32
30
|
|
33
31
|
def get_entry_class
|
34
|
-
instance_variable_get(
|
32
|
+
instance_variable_get('@entry_class')
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
@@ -3,7 +3,7 @@ module ChartMogul
|
|
3
3
|
def config_accessor(attribute)
|
4
4
|
define_method(attribute) do
|
5
5
|
attr = config.send(attribute)
|
6
|
-
raise ConfigurationError
|
6
|
+
raise ConfigurationError, "Configuration for #{attribute} not set" if attr.nil?
|
7
7
|
attr
|
8
8
|
end
|
9
9
|
|
data/lib/chartmogul/customer.rb
CHANGED
@@ -42,7 +42,6 @@ module ChartMogul
|
|
42
42
|
Customers.all(options)
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
45
|
def self.search(email, options = {})
|
47
46
|
Customers.search(email, options)
|
48
47
|
end
|
@@ -129,7 +128,11 @@ module ChartMogul
|
|
129
128
|
def typecast_custom_attributes(custom_attributes)
|
130
129
|
return {} unless custom_attributes
|
131
130
|
custom_attributes.each_with_object({}) do |(key, value), hash|
|
132
|
-
hash[key] = value.instance_of?(String) ? (
|
131
|
+
hash[key] = value.instance_of?(String) ? (begin
|
132
|
+
Time.parse(value)
|
133
|
+
rescue
|
134
|
+
value
|
135
|
+
end) : value
|
133
136
|
end
|
134
137
|
end
|
135
138
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
module ChartMogul
|
2
2
|
module Enrichment
|
3
|
-
|
4
3
|
# <b>DEPRECATED:</b> Please use <tt>ChartMogul/Customer</tt> instead.
|
5
4
|
class DeprecatedCustomer < APIResource
|
6
|
-
|
7
5
|
set_resource_name 'Customer'
|
8
6
|
set_resource_path '/v1/customers'
|
9
7
|
|
@@ -108,14 +106,18 @@ module ChartMogul
|
|
108
106
|
def typecast_custom_attributes(custom_attributes)
|
109
107
|
return {} unless custom_attributes
|
110
108
|
custom_attributes.each_with_object({}) do |(key, value), hash|
|
111
|
-
hash[key] = value.instance_of?(String) ? (
|
109
|
+
hash[key] = value.instance_of?(String) ? (begin
|
110
|
+
Time.parse(value)
|
111
|
+
rescue
|
112
|
+
value
|
113
|
+
end) : value
|
112
114
|
end
|
113
115
|
end
|
114
116
|
end
|
115
117
|
|
116
118
|
def self.const_missing(const_name)
|
117
119
|
super unless const_name == :Customer
|
118
|
-
warn
|
120
|
+
warn 'DEPRECATION WARNING: the class ChartMogul::Enrichment::Customer is deprecated. Use ChartMogul::Customer instead.'
|
119
121
|
DeprecatedCustomer
|
120
122
|
end
|
121
123
|
|
@@ -4,15 +4,15 @@ module ChartMogul
|
|
4
4
|
attr_accessor :response
|
5
5
|
attr_accessor :http_status
|
6
6
|
|
7
|
-
def initialize(message, http_status:nil, response:nil)
|
7
|
+
def initialize(message, http_status: nil, response: nil)
|
8
8
|
@message = message
|
9
9
|
@http_status = http_status
|
10
10
|
@response = response
|
11
11
|
end
|
12
12
|
|
13
13
|
def to_s
|
14
|
-
status = @http_status ? " (HTTP Status: #{@http_status
|
15
|
-
response = @response ? "\nResponse: #{@response
|
14
|
+
status = @http_status ? " (HTTP Status: #{@http_status})" : ''
|
15
|
+
response = @response ? "\nResponse: #{@response}" : ''
|
16
16
|
"#{message}#{status}#{response}"
|
17
17
|
end
|
18
18
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
module ChartMogul
|
2
2
|
module Metrics
|
3
|
-
|
4
3
|
def self.all(options = {})
|
5
4
|
ChartMogul::Metrics::AllKeyMetrics.all(preprocess_params(options))
|
6
5
|
end
|
@@ -40,12 +39,12 @@ module ChartMogul
|
|
40
39
|
private
|
41
40
|
|
42
41
|
def self.preprocess_params(options)
|
43
|
-
[
|
44
|
-
options[param_name.to_s.
|
42
|
+
%i[start_date end_date].each do |param_name|
|
43
|
+
options[param_name.to_s.tr('_', '-')] = options.delete(param_name) if options[param_name]
|
45
44
|
end
|
46
45
|
|
47
|
-
[
|
48
|
-
if options[param_name] && options[param_name].
|
46
|
+
%i[geo plans].each do |param_name|
|
47
|
+
if options[param_name] && options[param_name].is_a?(Array)
|
49
48
|
options[param_name] = options[param_name].join(',')
|
50
49
|
end
|
51
50
|
end
|
@@ -53,4 +52,3 @@ module ChartMogul
|
|
53
52
|
end
|
54
53
|
end
|
55
54
|
end
|
56
|
-
|
data/lib/chartmogul/object.rb
CHANGED
@@ -64,8 +64,8 @@ module ChartMogul
|
|
64
64
|
assign_writeable_attributes(attributes)
|
65
65
|
end
|
66
66
|
|
67
|
-
def self.new_from_json(attributes={})
|
68
|
-
|
67
|
+
def self.new_from_json(attributes = {})
|
68
|
+
new.tap do |resource|
|
69
69
|
resource.assign_all_attributes(attributes)
|
70
70
|
end
|
71
71
|
end
|
@@ -77,8 +77,8 @@ module ChartMogul
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def assign_writeable_attributes(new_values)
|
80
|
-
self.class.writeable_attributes.each do |attr,
|
81
|
-
|
80
|
+
self.class.writeable_attributes.each do |attr, _value|
|
81
|
+
send("#{attr}=", new_values[attr]) if new_values.key?(attr)
|
82
82
|
end
|
83
83
|
|
84
84
|
self
|
@@ -86,7 +86,7 @@ module ChartMogul
|
|
86
86
|
|
87
87
|
def assign_all_attributes(new_values)
|
88
88
|
self.class.attributes.each do |attr|
|
89
|
-
|
89
|
+
send("set_#{attr}", new_values[attr]) if new_values.key?(attr)
|
90
90
|
end
|
91
91
|
|
92
92
|
self
|
data/lib/chartmogul/ping.rb
CHANGED
data/lib/chartmogul/plan.rb
CHANGED
@@ -10,7 +10,7 @@ module ChartMogul
|
|
10
10
|
def initialize(path)
|
11
11
|
@path = path
|
12
12
|
@named_params = path.scan(/:\w+/).each_with_object({}) do |named_param, hash|
|
13
|
-
hash[named_param] = named_param.
|
13
|
+
hash[named_param] = named_param.delete(':').to_sym
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -39,12 +39,11 @@ module ChartMogul
|
|
39
39
|
|
40
40
|
def underscore(string)
|
41
41
|
string.gsub(/::/, '/')
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
43
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
44
|
+
.tr('-', '_')
|
45
|
+
.downcase
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
data/lib/chartmogul/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chartmogul-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
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-
|
11
|
+
date: 2017-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|