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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50f98ff0c8672795e594ce60423c90321c157373
4
- data.tar.gz: 8d96dd0cb5eb27611827e0db47e712344465c8fe
3
+ metadata.gz: e7ad064432c9e4fecaf637584b5d34052e76055d
4
+ data.tar.gz: c54868e20a9715858c983033c6919f585883de3d
5
5
  SHA512:
6
- metadata.gz: 9b9936e6898bc049c6d0a3d87d315a3c9a3edee35b28a9af7bfdd88b40aac34c6c2ea70d3bd20238a3ae79255a8265ef3412cbf434a022fa196caf451a2f2656
7
- data.tar.gz: f1db11b939b4946bdd9e3386acdd6576be5c2f98edc3680517b8d69e0d4ceea466990156b70f59e849a458a7e12447ec4e9fe80921b8a03d2786c2d286f7f9b9
6
+ metadata.gz: 09dd03962421da8a7f03e1d11f9317541f5e616e4d45c5f63b52c549d0c6f715c10696281104ad936ee0c1c3418aa0052ae8343f7923694eaebaef1dd1b3cd7e
7
+ data.tar.gz: 9246cc2c80a01bbec3fa24f205351bdb1293d44ccd8c9fb6c2cd270c432d2a2ba109bd951f0284aa509e3be0df6c83dcf57cf8cf3a73f82b2c6d4a8cdb004586
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "chartmogul"
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 "irb"
13
+ require 'irb'
14
14
  IRB.start
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'chartmogul/version'
data/lib/chartmogul.rb CHANGED
@@ -2,70 +2,71 @@ require 'time'
2
2
  require 'json'
3
3
  require 'faraday'
4
4
 
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/not_found_error"
13
- require "chartmogul/errors/resource_invalid_error"
14
- require "chartmogul/errors/schema_invalid_error"
15
- require "chartmogul/errors/unauthorized_error"
16
-
17
- require "chartmogul/config_attributes"
18
- require "chartmogul/configuration"
19
-
20
- require "chartmogul/object"
21
- require "chartmogul/resource_path"
22
- require "chartmogul/api_resource"
23
- require "chartmogul/summary"
24
-
25
- require "chartmogul/api/actions/all"
26
- require "chartmogul/api/actions/create"
27
- require "chartmogul/api/actions/custom"
28
- require "chartmogul/api/actions/destroy"
29
- require "chartmogul/api/actions/retrieve"
30
- require "chartmogul/api/actions/update"
31
-
32
- require "chartmogul/line_items/one_time"
33
- require "chartmogul/line_items/subscription"
34
-
35
- require "chartmogul/transactions/payment"
36
- require "chartmogul/transactions/refund"
37
-
38
- require "chartmogul/concerns/entries"
39
- require "chartmogul/concerns/summary"
40
- require "chartmogul/concerns/pageable"
41
- require "chartmogul/concerns/pageable2"
42
-
43
- require "chartmogul/subscription"
44
- require "chartmogul/invoice"
45
- require "chartmogul/customer_invoices"
46
- require "chartmogul/customer"
47
- require "chartmogul/data_source"
48
- require "chartmogul/ping"
49
- require "chartmogul/plan"
50
-
51
- require "chartmogul/metrics/arpa"
52
- require "chartmogul/metrics/arr"
53
- require "chartmogul/metrics/asp"
54
- require "chartmogul/metrics/customer_churn_rate"
55
- require "chartmogul/metrics/customer_count"
56
- require "chartmogul/metrics/ltv"
57
- require "chartmogul/metrics/mrr"
58
- require "chartmogul/metrics/mrr_churn_rate"
59
- require "chartmogul/metrics/all_key_metrics"
60
- require "chartmogul/metrics/base"
61
-
62
- require "chartmogul/metrics/activity"
63
- require "chartmogul/metrics/subscription"
64
-
65
- require "chartmogul/enrichment/customer"
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(self.instance_attributes)) do |req|
11
+ connection.post(resource_path.apply(instance_attributes)) do |req|
12
12
  req.headers['Content-Type'] = 'application/json'
13
- req.body = JSON.dump(self.serialize_for_write)
13
+ req.body = JSON.dump(serialize_for_write)
14
14
  end
15
15
  end
16
16
  json = ChartMogul::Utils::JSONParser.parse(resp.body)
@@ -8,7 +8,7 @@ module ChartMogul
8
8
 
9
9
  def destroy!
10
10
  handling_errors do
11
- connection.delete("#{resource_path.apply(self.instance_attributes)}/#{uuid}")
11
+ connection.delete("#{resource_path.apply(instance_attributes)}/#{uuid}")
12
12
  end
13
13
  true
14
14
  end
@@ -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(self.instance_attributes)}/#{uuid}") do |req|
7
+ connection.patch("#{resource_path.apply(instance_attributes)}/#{uuid}") do |req|
8
8
  req.headers['Content-Type'] = 'application/json'
9
- req.body = JSON.dump(self.serialize_for_write)
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 = "The requested action is forbidden."
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.new(exception.message)
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, "set_" + resource_root_key do |entries|
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
- self.instance_variable_set "@#{resource_root_key}", objects
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("@entry_class", klass)
28
+ instance_variable_set('@entry_class', klass)
31
29
  end
32
30
 
33
31
  def get_entry_class
34
- instance_variable_get("@entry_class")
32
+ instance_variable_get('@entry_class')
35
33
  end
36
34
  end
37
35
  end
@@ -17,4 +17,3 @@ module ChartMogul
17
17
  end
18
18
  end
19
19
  end
20
-
@@ -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.new("Configuration for #{attribute} not set") if attr.nil?
6
+ raise ConfigurationError, "Configuration for #{attribute} not set" if attr.nil?
7
7
  attr
8
8
  end
9
9
 
@@ -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) ? (Time.parse(value) rescue value) : value
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
@@ -21,7 +21,6 @@ module ChartMogul
21
21
  end
22
22
  end
23
23
 
24
-
25
24
  class DataSources < APIResource
26
25
  set_resource_name 'Data Sources'
27
26
  set_resource_path '/v1/data_sources'
@@ -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) ? (Time.parse(value) rescue value) : value
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 "DEPRECATION WARNING: the class ChartMogul::Enrichment::Customer is deprecated. Use ChartMogul::Customer instead."
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.to_s})" : ''
15
- response = @response ? "\nResponse: #{@response.to_s}" : ''
14
+ status = @http_status ? " (HTTP Status: #{@http_status})" : ''
15
+ response = @response ? "\nResponse: #{@response}" : ''
16
16
  "#{message}#{status}#{response}"
17
17
  end
18
18
  end
@@ -31,4 +31,3 @@ module ChartMogul
31
31
  end
32
32
  end
33
33
  end
34
-
@@ -22,4 +22,3 @@ module ChartMogul
22
22
  end
23
23
  end
24
24
  end
25
-
@@ -16,4 +16,3 @@ module ChartMogul
16
16
  end
17
17
  end
18
18
  end
19
-
@@ -16,4 +16,3 @@ module ChartMogul
16
16
  end
17
17
  end
18
18
  end
19
-
@@ -16,4 +16,3 @@ module ChartMogul
16
16
  end
17
17
  end
18
18
  end
19
-
@@ -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
- [:start_date, :end_date].each do |param_name|
44
- options[param_name.to_s.gsub('_', '-')] = options.delete(param_name) if options[param_name]
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
- [:geo, :plans].each do |param_name|
48
- if options[param_name] && options[param_name].kind_of?(Array)
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
-
@@ -16,4 +16,3 @@ module ChartMogul
16
16
  end
17
17
  end
18
18
  end
19
-
@@ -16,4 +16,3 @@ module ChartMogul
16
16
  end
17
17
  end
18
18
  end
19
-
@@ -16,4 +16,3 @@ module ChartMogul
16
16
  end
17
17
  end
18
18
  end
19
-
@@ -16,4 +16,3 @@ module ChartMogul
16
16
  end
17
17
  end
18
18
  end
19
-
@@ -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
- self.new.tap do |resource|
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, value|
81
- self.send("#{attr}=", new_values[attr]) if new_values.key?(attr)
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
- self.send("set_#{attr}", new_values[attr]) if new_values.key?(attr)
89
+ send("set_#{attr}", new_values[attr]) if new_values.key?(attr)
90
90
  end
91
91
 
92
92
  self
@@ -7,7 +7,7 @@ module ChartMogul
7
7
 
8
8
  include API::Actions::Custom
9
9
 
10
- def self.ping()
10
+ def self.ping
11
11
  custom!(:get, '/v1/ping')
12
12
  end
13
13
  end
@@ -23,7 +23,6 @@ module ChartMogul
23
23
  end
24
24
  end
25
25
 
26
-
27
26
  class Plans < APIResource
28
27
  set_resource_name 'Plans'
29
28
  set_resource_path '/v1/plans'
@@ -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.gsub(':', '').to_sym
13
+ hash[named_param] = named_param.delete(':').to_sym
14
14
  end
15
15
  end
16
16
 
@@ -43,6 +43,5 @@ module ChartMogul
43
43
  def self.all(customer_uuid, options = {})
44
44
  super(options.merge(customer_uuid: customer_uuid))
45
45
  end
46
-
47
46
  end
48
47
  end
@@ -39,12 +39,11 @@ module ChartMogul
39
39
 
40
40
  def underscore(string)
41
41
  string.gsub(/::/, '/')
42
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
43
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
44
- .tr('-', '_')
45
- .downcase
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
-
@@ -8,4 +8,3 @@ module ChartMogul
8
8
  end
9
9
  end
10
10
  end
11
-
@@ -1,3 +1,3 @@
1
1
  module ChartMogul
2
- VERSION = "1.1.4"
2
+ VERSION = '1.1.5'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chartmogul-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
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-06-09 00:00:00.000000000 Z
11
+ date: 2017-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday