recurly 2.19.7 → 3.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) 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 -1113
  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 -164
  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 -192
  93. data/lib/recurly/account.rb +0 -230
  94. data/lib/recurly/account_acquisition.rb +0 -27
  95. data/lib/recurly/account_balance.rb +0 -23
  96. data/lib/recurly/add_on.rb +0 -52
  97. data/lib/recurly/address.rb +0 -25
  98. data/lib/recurly/adjustment.rb +0 -98
  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 -133
  103. data/lib/recurly/business_entity.rb +0 -30
  104. data/lib/recurly/coupon.rb +0 -136
  105. data/lib/recurly/credit_payment.rb +0 -32
  106. data/lib/recurly/currency_percentage_tier.rb +0 -17
  107. data/lib/recurly/custom_field.rb +0 -15
  108. data/lib/recurly/custom_field_definition.rb +0 -14
  109. data/lib/recurly/customer_permission.rb +0 -10
  110. data/lib/recurly/delivery.rb +0 -19
  111. data/lib/recurly/dunning_campaign.rb +0 -30
  112. data/lib/recurly/dunning_cycle.rb +0 -18
  113. data/lib/recurly/entitlement.rb +0 -19
  114. data/lib/recurly/error.rb +0 -13
  115. data/lib/recurly/external_account.rb +0 -17
  116. data/lib/recurly/external_charge.rb +0 -20
  117. data/lib/recurly/external_invoice.rb +0 -26
  118. data/lib/recurly/external_product.rb +0 -34
  119. data/lib/recurly/external_product_reference.rb +0 -18
  120. data/lib/recurly/external_subscription.rb +0 -36
  121. data/lib/recurly/gateway_attribute.rb +0 -10
  122. data/lib/recurly/gift_card.rb +0 -85
  123. data/lib/recurly/helper.rb +0 -51
  124. data/lib/recurly/invoice.rb +0 -322
  125. data/lib/recurly/invoice_collection.rb +0 -14
  126. data/lib/recurly/invoice_template.rb +0 -14
  127. data/lib/recurly/item.rb +0 -36
  128. data/lib/recurly/js.rb +0 -14
  129. data/lib/recurly/juris_detail.rb +0 -15
  130. data/lib/recurly/measured_unit.rb +0 -16
  131. data/lib/recurly/money.rb +0 -120
  132. data/lib/recurly/note.rb +0 -14
  133. data/lib/recurly/percentage_tier.rb +0 -17
  134. data/lib/recurly/plan.rb +0 -56
  135. data/lib/recurly/plan_ramp_interval.rb +0 -10
  136. data/lib/recurly/purchase.rb +0 -238
  137. data/lib/recurly/redemption.rb +0 -46
  138. data/lib/recurly/resource/association.rb +0 -16
  139. data/lib/recurly/resource/errors.rb +0 -20
  140. data/lib/recurly/resource/pager.rb +0 -313
  141. data/lib/recurly/shipping_address.rb +0 -26
  142. data/lib/recurly/shipping_fee.rb +0 -17
  143. data/lib/recurly/shipping_method.rb +0 -13
  144. data/lib/recurly/sub_add_on_percentage_tier.rb +0 -17
  145. data/lib/recurly/subscription/add_ons.rb +0 -82
  146. data/lib/recurly/subscription.rb +0 -371
  147. data/lib/recurly/subscription_add_on.rb +0 -64
  148. data/lib/recurly/subscription_ramp_interval.rb +0 -10
  149. data/lib/recurly/tax_detail.rb +0 -18
  150. data/lib/recurly/tax_type.rb +0 -13
  151. data/lib/recurly/tier.rb +0 -18
  152. data/lib/recurly/transaction/errors.rb +0 -119
  153. data/lib/recurly/transaction.rb +0 -131
  154. data/lib/recurly/usage.rb +0 -29
  155. data/lib/recurly/verify.rb +0 -12
  156. data/lib/recurly/webhook/account_notification.rb +0 -13
  157. data/lib/recurly/webhook/billing_info_update_failed_notification.rb +0 -6
  158. data/lib/recurly/webhook/billing_info_updated_notification.rb +0 -6
  159. data/lib/recurly/webhook/canceled_account_notification.rb +0 -6
  160. data/lib/recurly/webhook/canceled_gift_card_notification.rb +0 -6
  161. data/lib/recurly/webhook/canceled_subscription_notification.rb +0 -6
  162. data/lib/recurly/webhook/closed_credit_invoice_notification.rb +0 -6
  163. data/lib/recurly/webhook/closed_invoice_notification.rb +0 -6
  164. data/lib/recurly/webhook/credit_payment_notification.rb +0 -12
  165. data/lib/recurly/webhook/deactivated_item_notification.rb +0 -6
  166. data/lib/recurly/webhook/deleted_shipping_address_notification.rb +0 -6
  167. data/lib/recurly/webhook/dunning_notification.rb +0 -14
  168. data/lib/recurly/webhook/expired_subscription_notification.rb +0 -6
  169. data/lib/recurly/webhook/failed_charge_invoice_notification.rb +0 -6
  170. data/lib/recurly/webhook/failed_payment_notification.rb +0 -6
  171. data/lib/recurly/webhook/fraud_info_updated_notification.rb +0 -6
  172. data/lib/recurly/webhook/gift_card_notification.rb +0 -8
  173. data/lib/recurly/webhook/invoice_notification.rb +0 -12
  174. data/lib/recurly/webhook/item_notification.rb +0 -7
  175. data/lib/recurly/webhook/low_balance_gift_card_notification.rb +0 -6
  176. data/lib/recurly/webhook/new_account_notification.rb +0 -6
  177. data/lib/recurly/webhook/new_charge_invoice_notification.rb +0 -6
  178. data/lib/recurly/webhook/new_credit_invoice_notification.rb +0 -6
  179. data/lib/recurly/webhook/new_credit_payment_notification.rb +0 -6
  180. data/lib/recurly/webhook/new_dunning_event_notification.rb +0 -6
  181. data/lib/recurly/webhook/new_invoice_notification.rb +0 -6
  182. data/lib/recurly/webhook/new_item_notification.rb +0 -6
  183. data/lib/recurly/webhook/new_shipping_address_notification.rb +0 -6
  184. data/lib/recurly/webhook/new_subscription_notification.rb +0 -6
  185. data/lib/recurly/webhook/new_usage_notification.rb +0 -8
  186. data/lib/recurly/webhook/notification.rb +0 -18
  187. data/lib/recurly/webhook/paid_charge_invoice_notification.rb +0 -6
  188. data/lib/recurly/webhook/past_due_charge_invoice_notification.rb +0 -6
  189. data/lib/recurly/webhook/past_due_invoice_notification.rb +0 -6
  190. data/lib/recurly/webhook/paused_subscription_renewal_notification.rb +0 -6
  191. data/lib/recurly/webhook/prerenewal_notification.rb +0 -6
  192. data/lib/recurly/webhook/processing_charge_invoice_notification.rb +0 -6
  193. data/lib/recurly/webhook/processing_credit_invoice_notification.rb +0 -6
  194. data/lib/recurly/webhook/processing_invoice_notification.rb +0 -6
  195. data/lib/recurly/webhook/processing_payment_notification.rb +0 -6
  196. data/lib/recurly/webhook/purchased_gift_card_notification.rb +0 -7
  197. data/lib/recurly/webhook/reactivated_account_notification.rb +0 -6
  198. data/lib/recurly/webhook/reactivated_item_notification.rb +0 -6
  199. data/lib/recurly/webhook/redeemed_gift_card_notification.rb +0 -7
  200. data/lib/recurly/webhook/regenerated_gift_card_notification.rb +0 -6
  201. data/lib/recurly/webhook/renewed_subscription_notification.rb +0 -6
  202. data/lib/recurly/webhook/reopened_charge_invoice_notification.rb +0 -6
  203. data/lib/recurly/webhook/reopened_credit_invoice_notification.rb +0 -6
  204. data/lib/recurly/webhook/scheduled_payment_notification.rb +0 -6
  205. data/lib/recurly/webhook/scheduled_subscription_pause_notification.rb +0 -6
  206. data/lib/recurly/webhook/scheduled_subscription_update_notification.rb +0 -6
  207. data/lib/recurly/webhook/subscription_notification.rb +0 -12
  208. data/lib/recurly/webhook/subscription_pause_canceled_notification.rb +0 -6
  209. data/lib/recurly/webhook/subscription_pause_modified_notification.rb +0 -6
  210. data/lib/recurly/webhook/subscription_paused_notification.rb +0 -6
  211. data/lib/recurly/webhook/subscription_resumed_notification.rb +0 -6
  212. data/lib/recurly/webhook/successful_payment_notification.rb +0 -6
  213. data/lib/recurly/webhook/successful_refund_notification.rb +0 -6
  214. data/lib/recurly/webhook/transaction_authorized_notification.rb +0 -6
  215. data/lib/recurly/webhook/transaction_notification.rb +0 -12
  216. data/lib/recurly/webhook/transaction_status_updated_notification.rb +0 -6
  217. data/lib/recurly/webhook/updated_account_notification.rb +0 -6
  218. data/lib/recurly/webhook/updated_balance_gift_card_notification.rb +0 -7
  219. data/lib/recurly/webhook/updated_gift_card_notification.rb +0 -6
  220. data/lib/recurly/webhook/updated_invoice_notification.rb +0 -6
  221. data/lib/recurly/webhook/updated_item_notification.rb +0 -6
  222. data/lib/recurly/webhook/updated_shipping_address_notification.rb +0 -6
  223. data/lib/recurly/webhook/updated_subscription_notification.rb +0 -6
  224. data/lib/recurly/webhook/void_payment_notification.rb +0 -6
  225. data/lib/recurly/webhook/voided_credit_invoice_notification.rb +0 -6
  226. data/lib/recurly/webhook/voided_credit_payment_notification.rb +0 -6
  227. data/lib/recurly/webhook.rb +0 -113
  228. data/lib/recurly/xml/nokogiri.rb +0 -60
  229. data/lib/recurly/xml/rexml.rb +0 -52
  230. 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.19.7"
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,166 +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/gateway_attribute'
9
- require 'recurly/billing_info'
10
- require 'recurly/custom_field'
11
- require 'recurly/account_acquisition'
12
- require 'recurly/account'
13
- require 'recurly/account_balance'
14
- require 'recurly/add_on'
15
- require 'recurly/address'
16
- require 'recurly/business_entity'
17
- require 'recurly/tax_detail'
18
- require 'recurly/tax_type'
19
- require 'recurly/juris_detail'
20
- require 'recurly/adjustment'
21
- require 'recurly/coupon'
22
- require 'recurly/credit_payment'
23
- require 'recurly/customer_permission'
24
- require 'recurly/entitlement'
25
- require 'recurly/external_account'
26
- require 'recurly/external_charge'
27
- require 'recurly/external_invoice'
28
- require 'recurly/external_product'
29
- require 'recurly/external_product_reference'
30
- require 'recurly/external_subscription'
31
- require 'recurly/helper'
32
- require 'recurly/invoice'
33
- require 'recurly/invoice_collection'
34
- require 'recurly/item'
35
- require 'recurly/js'
36
- require 'recurly/money'
37
- require 'recurly/measured_unit'
38
- require 'recurly/note'
39
- require 'recurly/plan'
40
- require 'recurly/plan_ramp_interval'
41
- require 'recurly/redemption'
42
- require 'recurly/shipping_fee'
43
- require 'recurly/shipping_method'
44
- require 'recurly/subscription'
45
- require 'recurly/subscription_add_on'
46
- require 'recurly/subscription_ramp_interval'
47
- require 'recurly/transaction'
48
- require 'recurly/usage'
49
- require 'recurly/version'
50
- require 'recurly/xml'
51
- require 'recurly/delivery'
52
- require 'recurly/gift_card'
53
- require 'recurly/purchase'
54
- require 'recurly/webhook'
55
- require 'recurly/verify'
56
- require 'recurly/tier'
57
- require 'recurly/dunning_campaign'
58
- require 'recurly/dunning_cycle'
59
- require 'recurly/invoice_template'
60
- require 'recurly/percentage_tier'
61
- require 'recurly/currency_percentage_tier'
62
- require 'recurly/sub_add_on_percentage_tier'
63
- require 'recurly/custom_field_definition'
64
-
65
- @subdomain = nil
66
-
67
- # This exception is raised if Recurly has not been configured.
68
- class ConfigurationError < Error
69
- end
70
-
71
- class << self
72
- # Set a config based on current thread context.
73
- # Any default set will say in effect unless overwritten in the config_params.
74
- # Call this method with out any arguments to have it unset the thread context config values.
75
- # @param config_params - Hash with the following keys: subdomain, api_key, default_currency
76
- def config(config_params = nil)
77
- Thread.current[:recurly_config] = config_params
78
- end
79
-
80
- # @return [String] A subdomain.
81
- def subdomain
82
- if Thread.current[:recurly_config] && Thread.current[:recurly_config][:subdomain]
83
- return Thread.current[:recurly_config][:subdomain]
84
- end
85
- @subdomain || 'api'
86
- end
87
- attr_writer :subdomain
88
-
89
- # @return [String] An API key.
90
- # @raise [ConfigurationError] If not configured.
91
- def api_key
92
- if Thread.current[:recurly_config] && Thread.current[:recurly_config][:api_key]
93
- return Thread.current[:recurly_config][:api_key]
94
- end
95
-
96
- defined? @api_key and @api_key or raise(
97
- ConfigurationError, "Recurly.api_key not configured"
98
- )
99
- end
100
- attr_writer :api_key
101
-
102
- # @return [String, nil] A default currency.
103
- def default_currency
104
- if Thread.current[:recurly_config] && Thread.current[:recurly_config][:default_currency]
105
- return Thread.current[:recurly_config][:default_currency]
106
- 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"
107
14
 
108
- return @default_currency if defined? @default_currency
109
- @default_currency = 'USD'
110
- end
111
- attr_writer :default_currency
112
-
113
- # @return [JS] The Recurly.js module.
114
- def js
115
- JS
116
- end
117
-
118
- # Assigns a logger to log requests/responses and more.
119
- # The logger can only be set if the environment variable
120
- # `RECURLY_INSECURE_DEBUG` equals `true`.
121
- #
122
- # @return [Logger, nil]
123
- # @example
124
- # require 'logger'
125
- # Recurly.logger = Logger.new STDOUT
126
- # @example Rails applications automatically log to the Rails log:
127
- # Recurly.logger = Rails.logger
128
- # @example Turn off logging entirely:
129
- # Recurly.logger = nil # Or Recurly.logger = Logger.new nil
130
- attr_accessor :logger
131
-
132
- def logger=(logger)
133
- if ENV['RECURLY_INSECURE_DEBUG'].to_s.downcase == 'true'
134
- @logger = logger
135
- puts <<-MSG
136
- [WARNING] Recurly logger enabled. The logger has the potential to leak
137
- PII and should never be used in production environments.
138
- MSG
139
- else
140
- puts <<-MSG
141
- [WARNING] Recurly logger has been disabled. If you wish to use it,
142
- only do so in a non-production environment and make sure
143
- the `RECURLY_INSECURE_DEBUG` environment variable is set to `true`.
144
- MSG
145
- end
146
- end
147
-
148
- # Convenience logging method includes a Logger#progname dynamically.
149
- # @return [true, nil]
150
- def log level, message
151
- logger.send(level, name) { message }
152
- end
153
-
154
- if RUBY_VERSION <= "1.9.0"
155
- def const_defined? sym, inherit = false
156
- raise ArgumentError, "inherit must be false" if inherit
157
- super sym
158
- end
159
-
160
- def const_get sym, inherit = false
161
- raise ArgumentError, "inherit must be false" if inherit
162
- super sym
163
- end
164
- end
165
- end
15
+ module Recurly
166
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