recurly 2.18.24 → 3.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +158 -110
  8. data/Rakefile +6 -0
  9. data/bin/bundle +105 -0
  10. data/bin/coderay +29 -0
  11. data/bin/console +14 -0
  12. data/bin/htmldiff +29 -0
  13. data/bin/ldiff +29 -0
  14. data/bin/pry +29 -0
  15. data/bin/rake +29 -0
  16. data/bin/rspec +29 -0
  17. data/bin/setup +8 -0
  18. data/bin/yard +29 -0
  19. data/bin/yardoc +29 -0
  20. data/bin/yri +29 -0
  21. data/lib/data/ca-certificates.crt +31 -0
  22. data/lib/recurly/client/operations.rb +935 -0
  23. data/lib/recurly/client.rb +198 -0
  24. data/lib/recurly/errors/api_errors.rb +35 -0
  25. data/lib/recurly/errors/network_errors.rb +8 -0
  26. data/lib/recurly/errors.rb +34 -0
  27. data/lib/recurly/pager.rb +119 -0
  28. data/lib/recurly/request.rb +30 -0
  29. data/lib/recurly/requests/account_acquisition_updatable.rb +22 -0
  30. data/lib/recurly/requests/account_create_only.rb +18 -0
  31. data/lib/recurly/requests/account_updatable.rb +50 -0
  32. data/lib/recurly/requests/add_on_create.rb +38 -0
  33. data/lib/recurly/requests/add_on_update.rb +38 -0
  34. data/lib/recurly/requests/address.rb +42 -0
  35. data/lib/recurly/requests/billing_info_create.rb +58 -0
  36. data/lib/recurly/requests/coupon_create_only.rb +66 -0
  37. data/lib/recurly/requests/coupon_updatable.rb +30 -0
  38. data/lib/recurly/requests/create_account.rb +62 -0
  39. data/lib/recurly/requests/create_coupon.rb +90 -0
  40. data/lib/recurly/requests/invoice_create.rb +42 -0
  41. data/lib/recurly/requests/invoice_refund.rb +30 -0
  42. data/lib/recurly/requests/line_item_create.rb +46 -0
  43. data/lib/recurly/requests/plan_create.rb +66 -0
  44. data/lib/recurly/requests/plan_update.rb +70 -0
  45. data/lib/recurly/requests/shipping_address_create.rb +58 -0
  46. data/lib/recurly/requests/shipping_address_update.rb +62 -0
  47. data/lib/recurly/requests/subscription_add_on_create.rb +22 -0
  48. data/lib/recurly/requests/subscription_change_create.rb +42 -0
  49. data/lib/recurly/requests/subscription_create.rb +86 -0
  50. data/lib/recurly/requests/subscription_update.rb +42 -0
  51. data/lib/recurly/requests/update_coupon.rb +30 -0
  52. data/lib/recurly/resource.rb +16 -1112
  53. data/lib/recurly/resources/account.rb +86 -0
  54. data/lib/recurly/resources/account_acquisition.rb +42 -0
  55. data/lib/recurly/resources/account_balance.rb +22 -0
  56. data/lib/recurly/resources/account_note.rb +30 -0
  57. data/lib/recurly/resources/add_on.rb +62 -0
  58. data/lib/recurly/resources/address.rb +42 -0
  59. data/lib/recurly/resources/billing_info.rb +62 -0
  60. data/lib/recurly/resources/coupon.rb +110 -0
  61. data/lib/recurly/resources/coupon_discount.rb +22 -0
  62. data/lib/recurly/resources/coupon_redemption.rb +46 -0
  63. data/lib/recurly/resources/credit_payment.rb +62 -0
  64. data/lib/recurly/resources/error.rb +18 -0
  65. data/lib/recurly/resources/error_may_have_transaction.rb +22 -0
  66. data/lib/recurly/resources/invoice.rb +138 -0
  67. data/lib/recurly/resources/invoice_collection.rb +18 -0
  68. data/lib/recurly/resources/line_item.rb +166 -0
  69. data/lib/recurly/resources/plan.rb +86 -0
  70. data/lib/recurly/resources/settings.rb +18 -0
  71. data/lib/recurly/resources/shipping_address.rb +74 -0
  72. data/lib/recurly/resources/site.rb +46 -0
  73. data/lib/recurly/resources/subscription.rb +134 -0
  74. data/lib/recurly/resources/subscription_add_on.rb +42 -0
  75. data/lib/recurly/resources/subscription_change.rb +54 -0
  76. data/lib/recurly/resources/tax_info.rb +18 -0
  77. data/lib/recurly/resources/transaction.rb +146 -0
  78. data/lib/recurly/resources/unique_coupon_code.rb +38 -0
  79. data/lib/recurly/resources/user.rb +38 -0
  80. data/lib/recurly/schema/json_deserializer.rb +53 -0
  81. data/lib/recurly/schema/json_parser.rb +71 -0
  82. data/lib/recurly/schema/request_caster.rb +66 -0
  83. data/lib/recurly/schema/schema_factory.rb +50 -0
  84. data/lib/recurly/schema/schema_validator.rb +125 -0
  85. data/lib/recurly/schema.rb +114 -0
  86. data/lib/recurly/version.rb +1 -10
  87. data/lib/recurly.rb +14 -151
  88. data/recurly.gemspec +32 -0
  89. data/scripts/build +4 -0
  90. data/scripts/clean +6 -0
  91. data/scripts/test +3 -0
  92. metadata +129 -179
  93. data/lib/recurly/account.rb +0 -214
  94. data/lib/recurly/account_acquisition.rb +0 -27
  95. data/lib/recurly/account_balance.rb +0 -22
  96. data/lib/recurly/add_on.rb +0 -51
  97. data/lib/recurly/address.rb +0 -25
  98. data/lib/recurly/adjustment.rb +0 -84
  99. data/lib/recurly/api/errors.rb +0 -208
  100. data/lib/recurly/api/net_http_adapter.rb +0 -111
  101. data/lib/recurly/api.rb +0 -110
  102. data/lib/recurly/billing_info.rb +0 -114
  103. data/lib/recurly/coupon.rb +0 -136
  104. data/lib/recurly/credit_payment.rb +0 -32
  105. data/lib/recurly/currency_percentage_tier.rb +0 -17
  106. data/lib/recurly/custom_field.rb +0 -15
  107. data/lib/recurly/delivery.rb +0 -19
  108. data/lib/recurly/dunning_campaign.rb +0 -30
  109. data/lib/recurly/dunning_cycle.rb +0 -18
  110. data/lib/recurly/error.rb +0 -13
  111. data/lib/recurly/gift_card.rb +0 -85
  112. data/lib/recurly/helper.rb +0 -51
  113. data/lib/recurly/invoice.rb +0 -305
  114. data/lib/recurly/invoice_collection.rb +0 -14
  115. data/lib/recurly/invoice_template.rb +0 -14
  116. data/lib/recurly/item.rb +0 -36
  117. data/lib/recurly/js.rb +0 -14
  118. data/lib/recurly/juris_detail.rb +0 -15
  119. data/lib/recurly/measured_unit.rb +0 -16
  120. data/lib/recurly/money.rb +0 -120
  121. data/lib/recurly/note.rb +0 -14
  122. data/lib/recurly/percentage_tier.rb +0 -17
  123. data/lib/recurly/plan.rb +0 -44
  124. data/lib/recurly/purchase.rb +0 -238
  125. data/lib/recurly/redemption.rb +0 -46
  126. data/lib/recurly/resource/association.rb +0 -16
  127. data/lib/recurly/resource/errors.rb +0 -20
  128. data/lib/recurly/resource/pager.rb +0 -313
  129. data/lib/recurly/shipping_address.rb +0 -26
  130. data/lib/recurly/shipping_fee.rb +0 -17
  131. data/lib/recurly/shipping_method.rb +0 -13
  132. data/lib/recurly/sub_add_on_percentage_tier.rb +0 -17
  133. data/lib/recurly/subscription/add_ons.rb +0 -82
  134. data/lib/recurly/subscription.rb +0 -367
  135. data/lib/recurly/subscription_add_on.rb +0 -63
  136. data/lib/recurly/tax_detail.rb +0 -18
  137. data/lib/recurly/tax_type.rb +0 -13
  138. data/lib/recurly/tier.rb +0 -18
  139. data/lib/recurly/transaction/errors.rb +0 -115
  140. data/lib/recurly/transaction.rb +0 -131
  141. data/lib/recurly/usage.rb +0 -28
  142. data/lib/recurly/verify.rb +0 -12
  143. data/lib/recurly/webhook/account_notification.rb +0 -13
  144. data/lib/recurly/webhook/billing_info_update_failed_notification.rb +0 -6
  145. data/lib/recurly/webhook/billing_info_updated_notification.rb +0 -6
  146. data/lib/recurly/webhook/canceled_account_notification.rb +0 -6
  147. data/lib/recurly/webhook/canceled_gift_card_notification.rb +0 -6
  148. data/lib/recurly/webhook/canceled_subscription_notification.rb +0 -6
  149. data/lib/recurly/webhook/closed_credit_invoice_notification.rb +0 -6
  150. data/lib/recurly/webhook/closed_invoice_notification.rb +0 -6
  151. data/lib/recurly/webhook/credit_payment_notification.rb +0 -12
  152. data/lib/recurly/webhook/deactivated_item_notification.rb +0 -6
  153. data/lib/recurly/webhook/deleted_shipping_address_notification.rb +0 -6
  154. data/lib/recurly/webhook/dunning_notification.rb +0 -14
  155. data/lib/recurly/webhook/expired_subscription_notification.rb +0 -6
  156. data/lib/recurly/webhook/failed_charge_invoice_notification.rb +0 -6
  157. data/lib/recurly/webhook/failed_payment_notification.rb +0 -6
  158. data/lib/recurly/webhook/fraud_info_updated_notification.rb +0 -6
  159. data/lib/recurly/webhook/gift_card_notification.rb +0 -8
  160. data/lib/recurly/webhook/invoice_notification.rb +0 -12
  161. data/lib/recurly/webhook/item_notification.rb +0 -7
  162. data/lib/recurly/webhook/low_balance_gift_card_notification.rb +0 -6
  163. data/lib/recurly/webhook/new_account_notification.rb +0 -6
  164. data/lib/recurly/webhook/new_charge_invoice_notification.rb +0 -6
  165. data/lib/recurly/webhook/new_credit_invoice_notification.rb +0 -6
  166. data/lib/recurly/webhook/new_credit_payment_notification.rb +0 -6
  167. data/lib/recurly/webhook/new_dunning_event_notification.rb +0 -6
  168. data/lib/recurly/webhook/new_invoice_notification.rb +0 -6
  169. data/lib/recurly/webhook/new_item_notification.rb +0 -6
  170. data/lib/recurly/webhook/new_shipping_address_notification.rb +0 -6
  171. data/lib/recurly/webhook/new_subscription_notification.rb +0 -6
  172. data/lib/recurly/webhook/new_usage_notification.rb +0 -8
  173. data/lib/recurly/webhook/notification.rb +0 -18
  174. data/lib/recurly/webhook/paid_charge_invoice_notification.rb +0 -6
  175. data/lib/recurly/webhook/past_due_charge_invoice_notification.rb +0 -6
  176. data/lib/recurly/webhook/past_due_invoice_notification.rb +0 -6
  177. data/lib/recurly/webhook/paused_subscription_renewal_notification.rb +0 -6
  178. data/lib/recurly/webhook/prerenewal_notification.rb +0 -6
  179. data/lib/recurly/webhook/processing_charge_invoice_notification.rb +0 -6
  180. data/lib/recurly/webhook/processing_credit_invoice_notification.rb +0 -6
  181. data/lib/recurly/webhook/processing_invoice_notification.rb +0 -6
  182. data/lib/recurly/webhook/processing_payment_notification.rb +0 -6
  183. data/lib/recurly/webhook/purchased_gift_card_notification.rb +0 -7
  184. data/lib/recurly/webhook/reactivated_account_notification.rb +0 -6
  185. data/lib/recurly/webhook/reactivated_item_notification.rb +0 -6
  186. data/lib/recurly/webhook/redeemed_gift_card_notification.rb +0 -7
  187. data/lib/recurly/webhook/regenerated_gift_card_notification.rb +0 -6
  188. data/lib/recurly/webhook/renewed_subscription_notification.rb +0 -6
  189. data/lib/recurly/webhook/reopened_charge_invoice_notification.rb +0 -6
  190. data/lib/recurly/webhook/reopened_credit_invoice_notification.rb +0 -6
  191. data/lib/recurly/webhook/scheduled_payment_notification.rb +0 -6
  192. data/lib/recurly/webhook/scheduled_subscription_pause_notification.rb +0 -6
  193. data/lib/recurly/webhook/scheduled_subscription_update_notification.rb +0 -6
  194. data/lib/recurly/webhook/subscription_notification.rb +0 -12
  195. data/lib/recurly/webhook/subscription_pause_canceled_notification.rb +0 -6
  196. data/lib/recurly/webhook/subscription_pause_modified_notification.rb +0 -6
  197. data/lib/recurly/webhook/subscription_paused_notification.rb +0 -6
  198. data/lib/recurly/webhook/subscription_resumed_notification.rb +0 -6
  199. data/lib/recurly/webhook/successful_payment_notification.rb +0 -6
  200. data/lib/recurly/webhook/successful_refund_notification.rb +0 -6
  201. data/lib/recurly/webhook/transaction_authorized_notification.rb +0 -6
  202. data/lib/recurly/webhook/transaction_notification.rb +0 -12
  203. data/lib/recurly/webhook/transaction_status_updated_notification.rb +0 -6
  204. data/lib/recurly/webhook/updated_account_notification.rb +0 -6
  205. data/lib/recurly/webhook/updated_balance_gift_card_notification.rb +0 -7
  206. data/lib/recurly/webhook/updated_gift_card_notification.rb +0 -6
  207. data/lib/recurly/webhook/updated_invoice_notification.rb +0 -6
  208. data/lib/recurly/webhook/updated_item_notification.rb +0 -6
  209. data/lib/recurly/webhook/updated_shipping_address_notification.rb +0 -6
  210. data/lib/recurly/webhook/updated_subscription_notification.rb +0 -6
  211. data/lib/recurly/webhook/void_payment_notification.rb +0 -6
  212. data/lib/recurly/webhook/voided_credit_invoice_notification.rb +0 -6
  213. data/lib/recurly/webhook/voided_credit_payment_notification.rb +0 -6
  214. data/lib/recurly/webhook.rb +0 -113
  215. data/lib/recurly/xml/nokogiri.rb +0 -60
  216. data/lib/recurly/xml/rexml.rb +0 -52
  217. data/lib/recurly/xml.rb +0 -122
@@ -0,0 +1,125 @@
1
+ module Recurly
2
+ class Schema
3
+ # This module is responsible for validating that the raw data
4
+ # passed in to *attributes* matches the schema belonging to this class.
5
+ # It should be mixed in to the Request class.
6
+ module SchemaValidator
7
+ # Validates the attributes and throws an error if something is wrong.
8
+ #
9
+ # @example
10
+ # Recurly::Requests::PlanCreate.new(code: 'plan123').validate!
11
+ # #=> {:code=>"plan123"}
12
+ # @example
13
+ # Recurly::Requests::PlanCreate.new(code: 3.14).validate!
14
+ # #=> ArgumentError: Attribute 'code' on the resource Recurly::Requests::PlanCreate is type Float but should be a String.
15
+ # @example
16
+ # Recurly::Requests::PlanCreate.new(kode: 'plan123').validate!
17
+ # #=> ArgumentError: Attribute 'kode' does not exist on request Recurly::Requests::PlanCreate. Did you mean 'code'?
18
+ #
19
+ # @raise [ArgumentError] if the attribute data does not match the schema.
20
+ def validate!
21
+ attributes.each do |attr_name, val|
22
+ schema_attr = schema.get_attribute(attr_name)
23
+ if schema_attr.nil?
24
+ err_msg = "Attribute '#{attr_name}' does not exist on request #{self.class.name}."
25
+ if did_you_mean = get_did_you_mean(schema, attr_name)
26
+ err_msg << " Did you mean '#{did_you_mean}'?"
27
+ raise ArgumentError, err_msg
28
+ end
29
+ elsif schema_attr.read_only?
30
+ raise ArgumentError, "Attribute '#{attr_name}' on resource #{self.class.name} is not writeable"
31
+ else
32
+ validate_attribute!(schema_attr, val)
33
+ end
34
+ end
35
+ end
36
+
37
+ # Validates an individual attribute
38
+ def validate_attribute!(schema_attr, val)
39
+ if !schema_attr.type.is_a?(Symbol) && val.class != schema_attr.type
40
+ expected = case schema_attr.type
41
+ when Array
42
+ "Array of #{schema_attr.type.item_type}s"
43
+ else
44
+ schema_attr.type
45
+ end
46
+
47
+ raise ArgumentError, "Attribute '#{schema_attr.name}' on the resource #{self.class.name} is type #{val.class} but should be a #{expected}"
48
+ end
49
+
50
+ # This is the convention for a recurly object
51
+ if schema_attr.type.is_a?(Symbol) && val.is_a?(Hash)
52
+ klazz = Schema.get_recurly_class(schema_attr.type)
53
+ # Using send because the initializer may be private
54
+ instance = klazz.send(:new, val)
55
+ instance.validate!
56
+ end
57
+ end
58
+
59
+ # Gets the closest term to the misspelled attribute
60
+ def get_did_you_mean(schema, misspelled_attr)
61
+ closest = schema.attributes.map(&:name).sort_by do |v|
62
+ levenshtein_distance(v, misspelled_attr)
63
+ end.first
64
+
65
+ if closest && levenshtein_distance(closest, misspelled_attr) <= 4
66
+ closest
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ # This code is copied directly from the did_you mean gem which is based
73
+ # directly on the Text gem implementation.
74
+ #
75
+ # did_you_mean: Copyright (c) 2014-2016 Yuki Nishijima.
76
+ # Text: Copyright (c) 2006-2013 Paul Battley, Michael Neumann, Tim Fletcher.
77
+ #
78
+ # Returns a value representing the "cost" of transforming str1 into str2
79
+ def levenshtein_distance(str1, str2)
80
+ str1 = str1.to_s unless str1.is_a? String
81
+ str2 = str2.to_s unless str2.is_a? String
82
+ n = str1.length
83
+ m = str2.length
84
+ return m if n.zero?
85
+ return n if m.zero?
86
+
87
+ d = (0..m).to_a
88
+ x = nil
89
+
90
+ # to avoid duplicating an enumerable object, create it outside of the loop
91
+ str2_codepoints = str2.codepoints
92
+
93
+ str1.each_codepoint.with_index(1) do |char1, i|
94
+ j = 0
95
+ while j < m
96
+ cost = (char1 == str2_codepoints[j]) ? 0 : 1
97
+ x = min3(
98
+ d[j+1] + 1, # insertion
99
+ i + 1, # deletion
100
+ d[j] + cost # substitution
101
+ )
102
+ d[j] = i
103
+ i = x
104
+
105
+ j += 1
106
+ end
107
+ d[m] = x
108
+ end
109
+
110
+ x
111
+ end
112
+
113
+ def min3(a, b, c)
114
+ if a < b && a < c
115
+ a
116
+ elsif b < c
117
+ b
118
+ else
119
+ c
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+
@@ -0,0 +1,114 @@
1
+ module Recurly
2
+ # The class responsible for describing a schema.
3
+ # This is used for requests and resources.
4
+ class Schema
5
+ # The attributes in the schema
6
+ # @return [Array<Attribute>]
7
+ attr_reader :attributes
8
+
9
+ def initialize
10
+ @attributes = []
11
+ end
12
+
13
+ # Adds an attribute to the schema definition
14
+ #
15
+ # @param name [Symbol] The name of the attribute
16
+ # @param type [Class,Symbol] The type of the attribute. Use capitalized symbol for Recurly class. Example: :Account.
17
+ # @param options [Hash] The attribute options. See {Attribute#options}
18
+ def add_attribute(name, type, options)
19
+ attribute = Attribute.new(name, type, options)
20
+ @attributes.push(attribute)
21
+ attribute
22
+ end
23
+
24
+ # Gets an attribute from this schema given a name
25
+ #
26
+ # @param name [String,Symbol] The name/key of the attribute
27
+ # @return [Attribute,nil] The found Attribute. nil if not found.
28
+ def get_attribute(name)
29
+ name = name.to_s
30
+ @attributes.find { |a| a.name.to_s == name }
31
+ end
32
+
33
+ # Gets a recurly class given a symbol name.
34
+ #
35
+ # @example
36
+ # Schema.get_recurly_class(:Account)
37
+ # #=> Recurly::Resources::Account
38
+ #
39
+ # @param type [Symbol] The name of the class you wish to find
40
+ # @return [Request,Resource]
41
+ # @raise ArgumentError If class can't be found.
42
+ def self.get_recurly_class(type)
43
+ raise ArgumentError, "#{type.inspect} must be a symbol but is a #{type.class}" unless type.is_a?(Symbol)
44
+
45
+ if Requests.const_defined?(type)
46
+ Requests.const_get(type)
47
+ elsif Resources.const_defined?(type)
48
+ Resources.const_get(type)
49
+ else
50
+ raise ArgumentError, "Recurly type '#{type}' is unknown"
51
+ end
52
+ end
53
+
54
+ # Describes a list attribute type
55
+ class List
56
+ # The type of the elements of the list
57
+ # @return [Symbol]
58
+ attr_accessor :item_type
59
+
60
+ def initialize(item_type)
61
+ @item_type = item_type
62
+ end
63
+
64
+ def to_s
65
+ "List<#{item_type}>"
66
+ end
67
+ end
68
+
69
+ # Describes and attribute for a schema.
70
+ class Attribute
71
+ # The name of the attribute.
72
+ # @return [Symbol]
73
+ attr_accessor :name
74
+
75
+ # The type of the attribute. Might be a class like `DateTime`
76
+ # or could be a Recurly object. In this case a symbol should be used.
77
+ # Example: :Account
78
+ # @return [Class,Symbol]
79
+ attr_accessor :type
80
+
81
+ # Options for the attribute.
82
+ # @return [Hash]
83
+ attr_accessor :options
84
+
85
+ # The description of the attribute for documentation.
86
+ # @return [String]
87
+ attr_accessor :description
88
+
89
+ def initialize(name, type, options={}, description=nil)
90
+ @name = name
91
+ @type = type
92
+ @options = options
93
+ @description = description
94
+ end
95
+
96
+ def read_only?
97
+ @options.fetch(:read_only, false)
98
+ end
99
+
100
+ def recurly_class
101
+ Schema.get_recurly_class(type == Array ? options[:item_type] : type)
102
+ end
103
+ end
104
+
105
+ private_constant :List
106
+ private_constant :Attribute
107
+ end
108
+
109
+
110
+ require_relative './schema/schema_factory'
111
+ require_relative './schema/schema_validator'
112
+ require_relative './schema/json_deserializer'
113
+ require_relative './schema/request_caster'
114
+ end
@@ -1,12 +1,3 @@
1
1
  module Recurly
2
- module Version
3
- VERSION = "2.18.24"
4
-
5
- class << self
6
- def inspect
7
- VERSION.dup
8
- end
9
- alias to_s inspect
10
- end
11
- end
2
+ VERSION = "3.0.0.beta.1"
12
3
  end
data/lib/recurly.rb CHANGED
@@ -1,153 +1,16 @@
1
- # Recurly is a Ruby client for Recurly's REST API.
2
- module Recurly
3
- require 'recurly/error'
4
- require 'recurly/helper'
5
- require 'recurly/api'
6
- require 'recurly/resource'
7
- require 'recurly/shipping_address'
8
- require 'recurly/billing_info'
9
- require 'recurly/custom_field'
10
- require 'recurly/account_acquisition'
11
- require 'recurly/account'
12
- require 'recurly/account_balance'
13
- require 'recurly/add_on'
14
- require 'recurly/address'
15
- require 'recurly/tax_detail'
16
- require 'recurly/tax_type'
17
- require 'recurly/juris_detail'
18
- require 'recurly/adjustment'
19
- require 'recurly/coupon'
20
- require 'recurly/credit_payment'
21
- require 'recurly/helper'
22
- require 'recurly/invoice'
23
- require 'recurly/invoice_collection'
24
- require 'recurly/item'
25
- require 'recurly/js'
26
- require 'recurly/money'
27
- require 'recurly/measured_unit'
28
- require 'recurly/note'
29
- require 'recurly/plan'
30
- require 'recurly/redemption'
31
- require 'recurly/shipping_fee'
32
- require 'recurly/shipping_method'
33
- require 'recurly/subscription'
34
- require 'recurly/subscription_add_on'
35
- require 'recurly/transaction'
36
- require 'recurly/usage'
37
- require 'recurly/version'
38
- require 'recurly/xml'
39
- require 'recurly/delivery'
40
- require 'recurly/gift_card'
41
- require 'recurly/purchase'
42
- require 'recurly/webhook'
43
- require 'recurly/verify'
44
- require 'recurly/tier'
45
- require 'recurly/dunning_campaign'
46
- require 'recurly/dunning_cycle'
47
- require 'recurly/invoice_template'
48
- require 'recurly/percentage_tier'
49
- require 'recurly/currency_percentage_tier'
50
- require 'recurly/sub_add_on_percentage_tier'
51
-
52
- @subdomain = nil
53
-
54
- # This exception is raised if Recurly has not been configured.
55
- class ConfigurationError < Error
56
- end
57
-
58
- class << self
59
- # Set a config based on current thread context.
60
- # Any default set will say in effect unless overwritten in the config_params.
61
- # Call this method with out any arguments to have it unset the thread context config values.
62
- # @param config_params - Hash with the following keys: subdomain, api_key, default_currency
63
- def config(config_params = nil)
64
- Thread.current[:recurly_config] = config_params
65
- end
66
-
67
- # @return [String] A subdomain.
68
- def subdomain
69
- if Thread.current[:recurly_config] && Thread.current[:recurly_config][:subdomain]
70
- return Thread.current[:recurly_config][:subdomain]
71
- end
72
- @subdomain || 'api'
73
- end
74
- attr_writer :subdomain
75
-
76
- # @return [String] An API key.
77
- # @raise [ConfigurationError] If not configured.
78
- def api_key
79
- if Thread.current[:recurly_config] && Thread.current[:recurly_config][:api_key]
80
- return Thread.current[:recurly_config][:api_key]
81
- end
82
-
83
- defined? @api_key and @api_key or raise(
84
- ConfigurationError, "Recurly.api_key not configured"
85
- )
86
- end
87
- attr_writer :api_key
88
-
89
- # @return [String, nil] A default currency.
90
- def default_currency
91
- if Thread.current[:recurly_config] && Thread.current[:recurly_config][:default_currency]
92
- return Thread.current[:recurly_config][:default_currency]
93
- end
1
+ require "recurly/version"
2
+ require "recurly/schema"
3
+ require "recurly/request"
4
+ require "recurly/resource"
5
+ require "recurly/pager"
6
+ # Include all request files
7
+ resources = File.join(File.dirname(__FILE__), 'recurly', 'requests', '*.rb')
8
+ Dir.glob(resources, &method(:require))
9
+ # Include all resource files
10
+ resources = File.join(File.dirname(__FILE__), 'recurly', 'resources', '*.rb')
11
+ Dir.glob(resources, &method(:require))
12
+ require "recurly/errors"
13
+ require "recurly/client"
94
14
 
95
- return @default_currency if defined? @default_currency
96
- @default_currency = 'USD'
97
- end
98
- attr_writer :default_currency
99
-
100
- # @return [JS] The Recurly.js module.
101
- def js
102
- JS
103
- end
104
-
105
- # Assigns a logger to log requests/responses and more.
106
- # The logger can only be set if the environment variable
107
- # `RECURLY_INSECURE_DEBUG` equals `true`.
108
- #
109
- # @return [Logger, nil]
110
- # @example
111
- # require 'logger'
112
- # Recurly.logger = Logger.new STDOUT
113
- # @example Rails applications automatically log to the Rails log:
114
- # Recurly.logger = Rails.logger
115
- # @example Turn off logging entirely:
116
- # Recurly.logger = nil # Or Recurly.logger = Logger.new nil
117
- attr_accessor :logger
118
-
119
- def logger=(logger)
120
- if ENV['RECURLY_INSECURE_DEBUG'].to_s.downcase == 'true'
121
- @logger = logger
122
- puts <<-MSG
123
- [WARNING] Recurly logger enabled. The logger has the potential to leak
124
- PII and should never be used in production environments.
125
- MSG
126
- else
127
- puts <<-MSG
128
- [WARNING] Recurly logger has been disabled. If you wish to use it,
129
- only do so in a non-production environment and make sure
130
- the `RECURLY_INSECURE_DEBUG` environment variable is set to `true`.
131
- MSG
132
- end
133
- end
134
-
135
- # Convenience logging method includes a Logger#progname dynamically.
136
- # @return [true, nil]
137
- def log level, message
138
- logger.send(level, name) { message }
139
- end
140
-
141
- if RUBY_VERSION <= "1.9.0"
142
- def const_defined? sym, inherit = false
143
- raise ArgumentError, "inherit must be false" if inherit
144
- super sym
145
- end
146
-
147
- def const_get sym, inherit = false
148
- raise ArgumentError, "inherit must be false" if inherit
149
- super sym
150
- end
151
- end
152
- end
15
+ module Recurly
153
16
  end
data/recurly.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'recurly/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "recurly"
8
+ spec.version = Recurly::VERSION
9
+ spec.authors = ["Recurly"]
10
+ spec.email = ["support@recurly.com"]
11
+
12
+ spec.summary = "The ruby client for Recurly's Partner API"
13
+ spec.description = "The ruby client for Recurly's Partner API"
14
+ spec.homepage = "https://partner-docs.recurly.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ # spec.bindir = "exe"
21
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "faraday", "~> 0.13"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "yard", "~> 0.9"
30
+ spec.add_development_dependency "pry", "~> 0.10"
31
+ spec.add_development_dependency "simplecov", "~> 0.16"
32
+ end
data/scripts/build ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bundle install --binstubs --quiet
4
+ ./bin/yard --quiet
data/scripts/clean ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+
3
+ rm -f ./lib/recurly/resources/*
4
+ rm -f ./lib/recurly/requests/*
5
+ rm -f ./lib/recurly/errors/api_errors.rb
6
+ rm -f ./lib/recurly/client/operations.rb
data/scripts/test ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ ./bin/rspec