recurly 2.17.0 → 3.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. checksums.yaml +4 -4
  2. data/.bumpversion.cfg +15 -0
  3. data/.github/ISSUE_TEMPLATE/bug-report.md +30 -0
  4. data/.github/ISSUE_TEMPLATE/question-or-other.md +10 -0
  5. data/.github/workflows/docs.yml +28 -0
  6. data/.github_changelog_generator +8 -0
  7. data/.gitignore +15 -0
  8. data/.rspec +2 -0
  9. data/.travis.yml +13 -0
  10. data/.yardopts +2 -0
  11. data/CHANGELOG.md +313 -0
  12. data/CODE_OF_CONDUCT.md +130 -0
  13. data/CONTRIBUTING.md +106 -0
  14. data/GETTING_STARTED.md +319 -0
  15. data/Gemfile +4 -0
  16. data/LICENSE.txt +21 -0
  17. data/README.md +9 -153
  18. data/Rakefile +6 -0
  19. data/benchmark.rb +16 -0
  20. data/lib/data/ca-certificates.crt +3466 -0
  21. data/lib/recurly/client/operations.rb +3665 -0
  22. data/lib/recurly/client.rb +353 -0
  23. data/lib/recurly/connection_pool.rb +40 -0
  24. data/lib/recurly/errors/api_errors.rb +83 -0
  25. data/lib/recurly/errors/network_errors.rb +10 -0
  26. data/lib/recurly/errors.rb +68 -0
  27. data/lib/recurly/http.rb +50 -0
  28. data/lib/recurly/pager.rb +146 -0
  29. data/lib/recurly/request.rb +31 -0
  30. data/lib/recurly/requests/account_acquisition_cost.rb +18 -0
  31. data/lib/recurly/requests/account_acquisition_updatable.rb +26 -0
  32. data/lib/recurly/requests/account_create.rb +90 -0
  33. data/lib/recurly/requests/account_purchase.rb +90 -0
  34. data/lib/recurly/requests/account_update.rb +78 -0
  35. data/lib/recurly/requests/add_on_create.rb +94 -0
  36. data/lib/recurly/requests/add_on_pricing.rb +18 -0
  37. data/lib/recurly/requests/add_on_update.rb +74 -0
  38. data/lib/recurly/requests/address.rb +46 -0
  39. data/lib/recurly/requests/billing_info_create.rb +110 -0
  40. data/lib/recurly/requests/coupon_bulk_create.rb +14 -0
  41. data/lib/recurly/requests/coupon_create.rb +94 -0
  42. data/lib/recurly/requests/coupon_pricing.rb +18 -0
  43. data/lib/recurly/requests/coupon_redemption_create.rb +18 -0
  44. data/lib/recurly/requests/coupon_update.rb +34 -0
  45. data/lib/recurly/requests/custom_field.rb +18 -0
  46. data/lib/recurly/requests/external_refund.rb +22 -0
  47. data/lib/recurly/requests/external_transaction.rb +26 -0
  48. data/lib/recurly/requests/invoice_address.rb +54 -0
  49. data/lib/recurly/requests/invoice_collect.rb +18 -0
  50. data/lib/recurly/requests/invoice_create.rb +42 -0
  51. data/lib/recurly/requests/invoice_refund.rb +34 -0
  52. data/lib/recurly/requests/invoice_updatable.rb +34 -0
  53. data/lib/recurly/requests/item_create.rb +58 -0
  54. data/lib/recurly/requests/item_update.rb +58 -0
  55. data/lib/recurly/requests/line_item_create.rb +82 -0
  56. data/lib/recurly/requests/line_item_refund.rb +22 -0
  57. data/lib/recurly/requests/measured_unit_create.rb +22 -0
  58. data/lib/recurly/requests/measured_unit_update.rb +22 -0
  59. data/lib/recurly/requests/plan_create.rb +98 -0
  60. data/lib/recurly/requests/plan_hosted_pages.rb +26 -0
  61. data/lib/recurly/requests/plan_pricing.rb +22 -0
  62. data/lib/recurly/requests/plan_update.rb +94 -0
  63. data/lib/recurly/requests/pricing.rb +18 -0
  64. data/lib/recurly/requests/purchase_create.rb +74 -0
  65. data/lib/recurly/requests/shipping_address_create.rb +62 -0
  66. data/lib/recurly/requests/shipping_address_update.rb +66 -0
  67. data/lib/recurly/requests/shipping_fee_create.rb +22 -0
  68. data/lib/recurly/requests/shipping_method_create.rb +26 -0
  69. data/lib/recurly/requests/shipping_method_update.rb +26 -0
  70. data/lib/recurly/requests/shipping_purchase.rb +22 -0
  71. data/lib/recurly/requests/subscription_add_on_create.rb +38 -0
  72. data/lib/recurly/requests/subscription_add_on_tier.rb +18 -0
  73. data/lib/recurly/requests/subscription_add_on_update.rb +42 -0
  74. data/lib/recurly/requests/subscription_cancel.rb +14 -0
  75. data/lib/recurly/requests/subscription_change_create.rb +66 -0
  76. data/lib/recurly/requests/subscription_change_shipping_create.rb +22 -0
  77. data/lib/recurly/requests/subscription_create.rb +106 -0
  78. data/lib/recurly/requests/subscription_pause.rb +14 -0
  79. data/lib/recurly/requests/subscription_purchase.rb +66 -0
  80. data/lib/recurly/requests/subscription_shipping_create.rb +30 -0
  81. data/lib/recurly/requests/subscription_shipping_purchase.rb +22 -0
  82. data/lib/recurly/requests/subscription_shipping_update.rb +22 -0
  83. data/lib/recurly/requests/subscription_update.rb +58 -0
  84. data/lib/recurly/requests/tier.rb +18 -0
  85. data/lib/recurly/requests/usage_create.rb +26 -0
  86. data/lib/recurly/requests.rb +8 -0
  87. data/lib/recurly/resource.rb +23 -1082
  88. data/lib/recurly/resources/account.rb +130 -0
  89. data/lib/recurly/resources/account_acquisition.rb +46 -0
  90. data/lib/recurly/resources/account_acquisition_cost.rb +18 -0
  91. data/lib/recurly/resources/account_balance.rb +26 -0
  92. data/lib/recurly/resources/account_balance_amount.rb +18 -0
  93. data/lib/recurly/resources/account_mini.rb +46 -0
  94. data/lib/recurly/resources/account_note.rb +34 -0
  95. data/lib/recurly/resources/add_on.rb +114 -0
  96. data/lib/recurly/resources/add_on_mini.rb +54 -0
  97. data/lib/recurly/resources/add_on_pricing.rb +18 -0
  98. data/lib/recurly/resources/address.rb +46 -0
  99. data/lib/recurly/resources/billing_info.rb +66 -0
  100. data/lib/recurly/resources/billing_info_updated_by.rb +18 -0
  101. data/lib/recurly/resources/binary_file.rb +14 -0
  102. data/lib/recurly/resources/coupon.rb +130 -0
  103. data/lib/recurly/resources/coupon_discount.rb +26 -0
  104. data/lib/recurly/resources/coupon_discount_pricing.rb +18 -0
  105. data/lib/recurly/resources/coupon_discount_trial.rb +18 -0
  106. data/lib/recurly/resources/coupon_mini.rb +42 -0
  107. data/lib/recurly/resources/coupon_redemption.rb +50 -0
  108. data/lib/recurly/resources/coupon_redemption_mini.rb +34 -0
  109. data/lib/recurly/resources/credit_payment.rb +66 -0
  110. data/lib/recurly/resources/custom_field.rb +18 -0
  111. data/lib/recurly/resources/custom_field_definition.rb +50 -0
  112. data/lib/recurly/resources/error.rb +22 -0
  113. data/lib/recurly/resources/error_may_have_transaction.rb +26 -0
  114. data/lib/recurly/resources/export_dates.rb +18 -0
  115. data/lib/recurly/resources/export_file.rb +22 -0
  116. data/lib/recurly/resources/export_files.rb +18 -0
  117. data/lib/recurly/resources/fraud_info.rb +22 -0
  118. data/lib/recurly/resources/invoice.rb +146 -0
  119. data/lib/recurly/resources/invoice_address.rb +54 -0
  120. data/lib/recurly/resources/invoice_collection.rb +22 -0
  121. data/lib/recurly/resources/invoice_mini.rb +30 -0
  122. data/lib/recurly/resources/item.rb +82 -0
  123. data/lib/recurly/resources/item_mini.rb +34 -0
  124. data/lib/recurly/resources/line_item.rb +198 -0
  125. data/lib/recurly/resources/line_item_list.rb +26 -0
  126. data/lib/recurly/resources/measured_unit.rb +46 -0
  127. data/lib/recurly/resources/payment_method.rb +66 -0
  128. data/lib/recurly/resources/plan.rb +118 -0
  129. data/lib/recurly/resources/plan_hosted_pages.rb +26 -0
  130. data/lib/recurly/resources/plan_mini.rb +26 -0
  131. data/lib/recurly/resources/plan_pricing.rb +22 -0
  132. data/lib/recurly/resources/pricing.rb +18 -0
  133. data/lib/recurly/resources/settings.rb +22 -0
  134. data/lib/recurly/resources/shipping_address.rb +82 -0
  135. data/lib/recurly/resources/shipping_method.rb +46 -0
  136. data/lib/recurly/resources/shipping_method_mini.rb +26 -0
  137. data/lib/recurly/resources/site.rb +54 -0
  138. data/lib/recurly/resources/subscription.rb +174 -0
  139. data/lib/recurly/resources/subscription_add_on.rb +66 -0
  140. data/lib/recurly/resources/subscription_add_on_tier.rb +18 -0
  141. data/lib/recurly/resources/subscription_change.rb +78 -0
  142. data/lib/recurly/resources/subscription_change_preview.rb +78 -0
  143. data/lib/recurly/resources/subscription_shipping.rb +26 -0
  144. data/lib/recurly/resources/tax_info.rb +22 -0
  145. data/lib/recurly/resources/tier.rb +18 -0
  146. data/lib/recurly/resources/transaction.rb +158 -0
  147. data/lib/recurly/resources/transaction_error.rb +38 -0
  148. data/lib/recurly/resources/transaction_payment_gateway.rb +26 -0
  149. data/lib/recurly/resources/unique_coupon_code.rb +50 -0
  150. data/lib/recurly/resources/usage.rb +70 -0
  151. data/lib/recurly/resources/user.rb +42 -0
  152. data/lib/recurly/resources.rb +18 -0
  153. data/lib/recurly/schema/file_parser.rb +13 -0
  154. data/lib/recurly/schema/json_parser.rb +72 -0
  155. data/lib/recurly/schema/request_caster.rb +60 -0
  156. data/lib/recurly/schema/resource_caster.rb +46 -0
  157. data/lib/recurly/schema/schema_factory.rb +48 -0
  158. data/lib/recurly/schema/schema_validator.rb +144 -0
  159. data/lib/recurly/schema.rb +156 -0
  160. data/lib/recurly/version.rb +1 -15
  161. data/lib/recurly.rb +15 -137
  162. data/openapi/api.yaml +21024 -0
  163. data/recurly.gemspec +39 -0
  164. data/scripts/build +5 -0
  165. data/scripts/bump +11 -0
  166. data/scripts/changelog +14 -0
  167. data/scripts/clean +6 -0
  168. data/scripts/format +12 -0
  169. data/scripts/prepare-release +36 -0
  170. data/scripts/release +32 -0
  171. data/scripts/test +15 -0
  172. metadata +206 -168
  173. data/lib/recurly/account.rb +0 -169
  174. data/lib/recurly/account_balance.rb +0 -21
  175. data/lib/recurly/add_on.rb +0 -30
  176. data/lib/recurly/address.rb +0 -25
  177. data/lib/recurly/adjustment.rb +0 -76
  178. data/lib/recurly/api/errors.rb +0 -206
  179. data/lib/recurly/api/net_http_adapter.rb +0 -111
  180. data/lib/recurly/api.rb +0 -101
  181. data/lib/recurly/billing_info.rb +0 -80
  182. data/lib/recurly/coupon.rb +0 -134
  183. data/lib/recurly/credit_payment.rb +0 -28
  184. data/lib/recurly/custom_field.rb +0 -15
  185. data/lib/recurly/delivery.rb +0 -19
  186. data/lib/recurly/error.rb +0 -13
  187. data/lib/recurly/gift_card.rb +0 -79
  188. data/lib/recurly/helper.rb +0 -51
  189. data/lib/recurly/invoice.rb +0 -268
  190. data/lib/recurly/invoice_collection.rb +0 -14
  191. data/lib/recurly/js.rb +0 -14
  192. data/lib/recurly/juris_detail.rb +0 -14
  193. data/lib/recurly/measured_unit.rb +0 -16
  194. data/lib/recurly/money.rb +0 -120
  195. data/lib/recurly/plan.rb +0 -40
  196. data/lib/recurly/purchase.rb +0 -219
  197. data/lib/recurly/redemption.rb +0 -46
  198. data/lib/recurly/resource/association.rb +0 -16
  199. data/lib/recurly/resource/errors.rb +0 -20
  200. data/lib/recurly/resource/pager.rb +0 -314
  201. data/lib/recurly/shipping_address.rb +0 -22
  202. data/lib/recurly/subscription/add_ons.rb +0 -77
  203. data/lib/recurly/subscription.rb +0 -325
  204. data/lib/recurly/subscription_add_on.rb +0 -50
  205. data/lib/recurly/tax_detail.rb +0 -14
  206. data/lib/recurly/tax_type.rb +0 -12
  207. data/lib/recurly/transaction/errors.rb +0 -107
  208. data/lib/recurly/transaction.rb +0 -116
  209. data/lib/recurly/usage.rb +0 -24
  210. data/lib/recurly/webhook/account_notification.rb +0 -10
  211. data/lib/recurly/webhook/billing_info_updated_notification.rb +0 -6
  212. data/lib/recurly/webhook/canceled_account_notification.rb +0 -6
  213. data/lib/recurly/webhook/canceled_subscription_notification.rb +0 -6
  214. data/lib/recurly/webhook/closed_credit_invoice_notification.rb +0 -6
  215. data/lib/recurly/webhook/closed_invoice_notification.rb +0 -6
  216. data/lib/recurly/webhook/credit_payment_notification.rb +0 -12
  217. data/lib/recurly/webhook/dunning_notification.rb +0 -14
  218. data/lib/recurly/webhook/expired_subscription_notification.rb +0 -6
  219. data/lib/recurly/webhook/failed_charge_invoice_notification.rb +0 -6
  220. data/lib/recurly/webhook/failed_payment_notification.rb +0 -6
  221. data/lib/recurly/webhook/gift_card_notification.rb +0 -8
  222. data/lib/recurly/webhook/invoice_notification.rb +0 -12
  223. data/lib/recurly/webhook/new_account_notification.rb +0 -6
  224. data/lib/recurly/webhook/new_charge_invoice_notification.rb +0 -6
  225. data/lib/recurly/webhook/new_credit_invoice_notification.rb +0 -6
  226. data/lib/recurly/webhook/new_credit_payment_notification.rb +0 -6
  227. data/lib/recurly/webhook/new_dunning_event_notification.rb +0 -6
  228. data/lib/recurly/webhook/new_invoice_notification.rb +0 -6
  229. data/lib/recurly/webhook/new_subscription_notification.rb +0 -6
  230. data/lib/recurly/webhook/new_usage_notification.rb +0 -8
  231. data/lib/recurly/webhook/notification.rb +0 -18
  232. data/lib/recurly/webhook/paid_charge_invoice_notification.rb +0 -6
  233. data/lib/recurly/webhook/past_due_charge_invoice_notification.rb +0 -6
  234. data/lib/recurly/webhook/past_due_invoice_notification.rb +0 -6
  235. data/lib/recurly/webhook/processing_charge_invoice_notification.rb +0 -6
  236. data/lib/recurly/webhook/processing_credit_invoice_notification.rb +0 -6
  237. data/lib/recurly/webhook/processing_invoice_notification.rb +0 -6
  238. data/lib/recurly/webhook/processing_payment_notification.rb +0 -6
  239. data/lib/recurly/webhook/purchased_gift_card_notification.rb +0 -7
  240. data/lib/recurly/webhook/reactivated_account_notification.rb +0 -6
  241. data/lib/recurly/webhook/redeemed_gift_card_notification.rb +0 -7
  242. data/lib/recurly/webhook/renewed_subscription_notification.rb +0 -6
  243. data/lib/recurly/webhook/reopened_charge_invoice_notification.rb +0 -6
  244. data/lib/recurly/webhook/reopened_credit_invoice_notification.rb +0 -6
  245. data/lib/recurly/webhook/scheduled_payment_notification.rb +0 -6
  246. data/lib/recurly/webhook/subscription_notification.rb +0 -12
  247. data/lib/recurly/webhook/successful_payment_notification.rb +0 -6
  248. data/lib/recurly/webhook/successful_refund_notification.rb +0 -6
  249. data/lib/recurly/webhook/transaction_authorized_notification.rb +0 -6
  250. data/lib/recurly/webhook/transaction_notification.rb +0 -12
  251. data/lib/recurly/webhook/updated_account_notification.rb +0 -6
  252. data/lib/recurly/webhook/updated_balance_gift_card_notification.rb +0 -7
  253. data/lib/recurly/webhook/updated_subscription_notification.rb +0 -6
  254. data/lib/recurly/webhook/void_payment_notification.rb +0 -6
  255. data/lib/recurly/webhook/voided_credit_invoice_notification.rb +0 -6
  256. data/lib/recurly/webhook/voided_credit_payment_notification.rb +0 -6
  257. data/lib/recurly/webhook.rb +0 -88
  258. data/lib/recurly/xml/nokogiri.rb +0 -58
  259. data/lib/recurly/xml/rexml.rb +0 -50
  260. data/lib/recurly/xml.rb +0 -120
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,106 @@
1
+ # Contributing Guide
2
+
3
+ 👍🎉 First off, thanks for taking the time to contribute! 🎉👍
4
+
5
+ Filing an Issue or a Pull Request is often the best way to address a problem with this library;
6
+ however, we may not get to these right away. Although we try to be quick, our primary, daily focus is
7
+ writing code. If you want a timely response (especially if you have an emergency), we recommend
8
+ you contact our [official support team](https://support.recurly.com/).
9
+
10
+ ## Code of Conduct
11
+
12
+ Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.
13
+
14
+ #### Table Of Contents
15
+
16
+ * [I don't want to read this whole thing, I just have a question!!!](#i-dont-want-to-read-this-whole-thing-i-just-have-a-question)
17
+ * [I think something is wrong with this library](#i-think-something-is-wrong-with-this-library)
18
+ * [I know what's wrong and I want to submit a code change](#i-know-whats-wrong-and-i-want-to-submit-a-code-change)
19
+ * [Development Dependencies](#development-dependencies)
20
+ * [Building and Testing](#building-and-testing)
21
+ * [Formatting Code](#formatting-code)
22
+ * [Generated Code](#generated-code)
23
+
24
+
25
+ ## I don't want to read this whole thing I just have a question!!!
26
+
27
+ The best way to get a question answered is through our [official support channel](https://support.recurly.com/). If you
28
+ have a specific question related to this library and cannot find an answer, feel free to post an issue with the question.
29
+
30
+ ## I think something is wrong with this library
31
+
32
+ Are you getting an exception or seeing some unexpected behavior from the library? An issue is the way to go.
33
+ Submit an issue and make sure you provide as much detail as possible. Some things you'll want to include:
34
+
35
+ * Your dependency versions (client version, language version, OS, etc)
36
+ * A stack trace if available
37
+ * A [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example)
38
+
39
+ The more information you give us, the quicker and easier the response will be. Keep in mind that issues should be scoped
40
+ to a problem in this library and we may often redirect you to our official support for problems originating from
41
+ upstream systems.
42
+
43
+ ## I know what's wrong and I want to submit a code change
44
+
45
+ So, you are sure you want to submit a change to the code? We appreciate the help!
46
+ Before you do, consider opening a discussion in the form of an issue. This accomplish a few things:
47
+
48
+ 1. We can give you advice to implement the change
49
+ 2. We can give you an idea of our openness to the change
50
+
51
+ **Note**: Sending code without a discussion is *always* fine. Discussion on the PR is often easier anyway. Just understand that we may
52
+ not accept the code if we don't think it's best for everyone using the library.
53
+
54
+ The rest of this section describes what you'll need to know.
55
+
56
+ ### Development Dependencies
57
+
58
+ You're going to first need a supported version of the language toolchain. The best way to find which versions are supported are by checking
59
+ the [Travis File](.travis.yml) which is used to run our tests. We try to test against every supported version of the language. The [README](README.md)
60
+ may also have something to say about supported dependencies.
61
+
62
+ ### Building and Testing
63
+
64
+ All of our client libraries contain a `scripts` folder which houses a set of bash scripts for doing common
65
+ development tasks. These scripts follow the same naming conventions so this can act as a kind of "Bash API"
66
+ for manipulating the libraries.
67
+
68
+ **Note**: If you are on a system without bash (such as some Windows systems), you should find the scripts only consist of a
69
+ few commands which can easily be run in your terminal or editor directly.
70
+
71
+ Start by running the `build` script to setup deps, compile (if applicable), build docs, etc:
72
+
73
+ ```bash
74
+ ./scripts/build
75
+ ```
76
+
77
+ Use the `test` script to run the tests:
78
+
79
+ ```bash
80
+ ./scripts/test
81
+ ```
82
+
83
+ Make sure the tests pass locally before submitting your change.
84
+
85
+ ### Formatting Code
86
+
87
+ The PR (and often the tests) will fail if you have not properly formatted the code. Instead of having a style-guide, we've provided
88
+ an auto-formatter. To use it, run the `format` script:
89
+
90
+ ```bash
91
+ ./scripts/format
92
+ ```
93
+
94
+ ### Generated Code
95
+
96
+ Some files in this codebase are generated by a non-public, proprietary program. Because they are regularly generated and updated as the
97
+ API and docs change, we won't accept any PRs that modify these files. Each of these files has a disclaimer on the top saying that they cannot
98
+ be edited by hand. By convention, they relate to things that are specific to the Recurly API that may change. For example:
99
+
100
+ * Response Schemas (Resources)
101
+ * Request Schemas (Requests)
102
+ * API endpoints (Operations)
103
+ * Errors
104
+
105
+ If you feel like you need one of these to change, please file an issue and we can discuss getting the change upstreamed.
106
+
@@ -0,0 +1,319 @@
1
+ This repository houses the official ruby client for Recurly's V3 API.
2
+
3
+ # Installing
4
+
5
+ In your Gemfile, add `recurly` as a dependency.
6
+
7
+ ```ruby
8
+ gem 'recurly', '~> 3.14'
9
+ ```
10
+
11
+ > *Note*: We try to follow [semantic versioning](https://semver.org/) and will only apply breaking changes to major versions.
12
+
13
+ # Creating a client
14
+
15
+ A client represents a connection to the Recurly servers. Every call
16
+ to the server exists as a method on this class. To initialize, you only need the private API key
17
+ which can be obtained on the [API Credentials Page](https://app.recurly.com/go/integrations/api_keys).
18
+
19
+ ```ruby
20
+ API_KEY = '83749879bbde395b5fe0cc1a5abf8e5'
21
+ client = Recurly::Client.new(api_key: API_KEY)
22
+ sub = client.get_subscription(subscription_id: 'abcd123456')
23
+ ```
24
+
25
+ You can also pass the initializer a block. This will give you a client scoped for just that block:
26
+
27
+ ```ruby
28
+ Recurly::Client.new(api_key: API_KEY) do |client|
29
+ sub = client.get_subscription(subscription_id: 'abcd123456')
30
+ end
31
+ ```
32
+
33
+ If you plan on using the client for more than one site, you should initialize a new client for each site.
34
+
35
+ ```ruby
36
+ client = Recurly::Client.new(api_key: API_KEY1)
37
+ sub = client.get_subscription(subscription_id: 'abcd123456')
38
+
39
+ # you should create a new client to connect to another site
40
+ client = Recurly::Client.new(api_key: API_KEY2)
41
+ sub = client.get_subscription(subscription_id: 'abcd7890')
42
+ ```
43
+
44
+ ## Logging
45
+
46
+ The client constructor optionally accepts a logger provided by the programmer. The logger you pass should be an instance of ruby stdlib's [Logger](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html)
47
+ or follow the same interface. By default, the client creates a logger to `STDOUT` with level `WARN`.
48
+
49
+ ```ruby
50
+ require 'logger'
51
+
52
+ # Create a logger to STDOUT
53
+ logger = Logger.new(STDOUT)
54
+ logger.level = Logger::INFO
55
+
56
+ # You could also use an existing logger
57
+ # If you are using Rails you may want to use your application's logger
58
+ logger = Rails.logger
59
+
60
+ client = Recurly::Client.new(api_key: API_KEY, logger: logger)
61
+ ```
62
+
63
+ > *SECURITY WARNING*: The log level should never be set to DEBUG in production. This could potentially result in sensitive data in your logging system.
64
+
65
+ # Operations
66
+
67
+ The {Recurly::Client} contains every `operation` you can perform on the site as a list of methods. Each method is documented explaining
68
+ the types and descriptions for each input and return type. You can view all available operations by looking at the `Instance Methods Summary` list
69
+ on the {Recurly::Client} documentation page. Clicking a method will give you detailed information about its inputs and returns. Take the `create_account`
70
+ operation as an example: {Recurly::Client#create_account}.
71
+
72
+ # Pagination
73
+
74
+ Pagination is done by the class {Recurly::Pager}. All `list_*` methods on the client return an instance of this class.
75
+ The pager has an `each` method which accepts a block for each object in the entire list. Each page is fetched automatically
76
+ for you presenting the elements as a single enumerable.
77
+
78
+ ```ruby
79
+ plans = client.list_plans()
80
+ plans.each do |plan|
81
+ puts "Plan: #{plan.id}"
82
+ end
83
+ ```
84
+
85
+ You may also paginate in chunks with `each_page`.
86
+
87
+ ```ruby
88
+ plans = client.list_plans()
89
+ plans.each_page do |data|
90
+ data.each do |plan|
91
+ puts "Plan: #{plan.id}"
92
+ end
93
+ end
94
+ ```
95
+
96
+ Both {Pager#each} and {Pager#each_page} return Enumerators if a block is not given. This allows you to use other Enumerator methods
97
+ such as `map` or `each_with_index`.
98
+
99
+ ```ruby
100
+ plans = client.list_plans()
101
+ plans.each_page.each_with_index do |data, page_num|
102
+ puts "Page Number #{page_num}"
103
+ data.each do |plan|
104
+ puts "Plan: #{plan.id}"
105
+ end
106
+ end
107
+ ```
108
+
109
+ Pagination endpoints take a number of options to sort and filter the results. They can be passed in as keyword arguments.
110
+ The names, types, and descriptions of these arguments are listed in the rubydocs for each method:
111
+
112
+ ```ruby
113
+ options = {
114
+ limit: 200, # number of items per page
115
+ state: :active, # only active plans
116
+ sort: :updated_at,
117
+ order: :asc,
118
+ begin_time: DateTime.new(2017,1,1), # January 1st 2017,
119
+ end_time: DateTime.now
120
+ }
121
+
122
+ plans = client.list_plans(**options)
123
+ plans.each do |plan|
124
+ puts "Plan: #{plan.id}"
125
+ end
126
+ ```
127
+
128
+ **A note on `limit`**:
129
+
130
+ `limit` defaults to 20 items per page and can be set from 1 to 200. Choosing a lower limit means more network requests but smaller payloads.
131
+ We recommend keeping the default for most cases but increasing the limit if you are planning on iterating through many pages of items (e.g. all transactions in your site).
132
+
133
+ ## Efficiently Fetch the First or Last Resource
134
+
135
+ The Pager class implements a first method which allows you to fetch just the first or last resource from the server. On top of being a convenient abstraction, this is implemented efficiently by only asking the server for the 1 item you want.
136
+
137
+ ```ruby
138
+ accounts = client.list_accounts(
139
+ subscriber: true,
140
+ order: :desc
141
+ )
142
+
143
+ last_subscriber = accounts.first
144
+ ```
145
+
146
+ If you want to fetch the last account in this scenario, invert the order from descending `desc` to ascending `asc`:
147
+
148
+ ```ruby
149
+ accounts = client.list_accounts(
150
+ subscriber: true,
151
+ order: :asc
152
+ )
153
+
154
+ first_subscriber = accounts.first
155
+ ```
156
+
157
+ ## Counting Resources
158
+
159
+ The Pager class implements a `count` method which allows you to count the resources the pager would return. It does so by calling the endpoint with `HEAD` and parsing and returning the `Recurly-Total-Records` header. This method respects any filtering parameters you apply to the pager, but the sorting parameters will have no effect.
160
+
161
+ ```ruby
162
+ accounts = client.list_accounts(
163
+ subscriber: true,
164
+ begin_time: DateTime.new(2017,1,1)
165
+ )
166
+
167
+ # Calling count here will return an integer indicating
168
+ # the number of subscribers since 2017
169
+ count = accounts.count
170
+ # => 573
171
+ ```
172
+
173
+ # Creating Resources
174
+
175
+ Currently, resources are created by passing in a `body` keyword argument in the form of a `Hash`.
176
+ This Hash must follow the schema of the documented request type. For example, the `create_plan` operation
177
+ takes a request of type {Recurly::Requests::PlanCreate}. Failing to conform to this schema will result in an argument
178
+ error.
179
+
180
+ ```ruby
181
+ require 'securerandom'
182
+
183
+ code = SecureRandom.uuid
184
+ plan_data = {
185
+ code: code,
186
+ interval_length: 1,
187
+ interval_unit: 'months',
188
+ name: code,
189
+ currencies: [
190
+ {
191
+ currency: 'USD',
192
+ setup_fee: 800,
193
+ unit_amount: 10
194
+ }
195
+ ]
196
+ }
197
+
198
+ plan = client.create_plan(body: plan_data)
199
+ ```
200
+
201
+ # Error Handling
202
+
203
+ This library currently throws 2 types of exceptions. {Recurly::Errors::APIError} and {Recurly::Errors::NetworkError}. See these 2 files for the types of exceptions you can catch:
204
+
205
+ 1. [API Errors](./lib/recurly/errors/api_errors.rb)
206
+ 2. [Network Errors](./lib/recurly/errors/network_errors.rb)
207
+
208
+ You will normally be working with {Recurly::Errors::APIError}. You can catch specific or generic versions of these exceptions. Example:
209
+
210
+ ```ruby
211
+ begin
212
+ client = Recurly::Client.new(api_key: API_KEY)
213
+ code = "iexistalready"
214
+ plan_data = {
215
+ code: code,
216
+ interval_length: 1,
217
+ interval_unit: 'months',
218
+ name: code,
219
+ currencies: [
220
+ {
221
+ currency: 'USD',
222
+ setup_fee: 800,
223
+ unit_amount: 10
224
+ }
225
+ ]
226
+ }
227
+
228
+ plan = client.create_plan(body: plan_data)
229
+ rescue Recurly::Errors::ValidationError => ex
230
+ puts ex.inspect
231
+ #=> #<Recurly::ValidationError: Recurly::ValidationError: Code 'iexistalready' already exists>
232
+ puts ex.recurly_error.inspect
233
+ #=> #<Recurly::Error:0x007fbbdf8a32c8 @attributes={:type=>"validation", :message=>"Code 'iexistalready' already exists", :params=>[{"param"=>"code", "message"=>"'iexistalready' already exists"}]}>
234
+ puts ex.status_code
235
+ #=> 422
236
+ rescue Recurly::Errors::APIError => ex
237
+ # catch a generic api error
238
+ rescue Recurly::Errors::TimeoutError => ex
239
+ # catch a specific network error
240
+ rescue Recurly::Errors::NetworkError => ex
241
+ # catch a generic network error
242
+ end
243
+ ```
244
+
245
+ # HTTP Metadata
246
+
247
+ Sometimes you might want to get some additional information about the underlying HTTP request and response. Instead of
248
+ returning this information directly and forcing the programmer to unwrap it, we inject this metadata into the top level
249
+ resource that was returned. You can access the {Recurly::HTTP::Response} by calling `#get_response` on any {Recurly::Resource}.
250
+
251
+ **Warning**: Do not log or render whole requests or responses as they may contain PII or sensitive data.
252
+
253
+ ```ruby
254
+ account = @client.get_account(account_id: "code-benjamin")
255
+ response = account.get_response
256
+ response.rate_limit_remaining #=> 1985
257
+ response.request_id #=> "0av50sm5l2n2gkf88ehg"
258
+ response.request.path #=> "/sites/subdomain-mysite/accounts/code-benjamin"
259
+ response.request.body #=> None
260
+ ```
261
+
262
+ This also works on {Recurly::Resources::Empty} responses:
263
+
264
+ ```ruby
265
+ response = @client.remove_line_item(
266
+ line_item_id: "a959576b2b10b012"
267
+ ).get_response
268
+ ```
269
+ And it can be captured on exceptions through the {Recurly::ApiError} object:
270
+
271
+ ```ruby
272
+ begin
273
+ account = client.get_account(account_id: "code-benjamin")
274
+ rescue Recurly::Errors::NotFoundError => e
275
+ response = e.get_response()
276
+ puts "Give this request id to Recurly Support: #{response.request_id}"
277
+ end
278
+ ```
279
+
280
+ # Webhooks
281
+
282
+ Recurly can send webhooks to any publicly accessible server.
283
+ When an event in Recurly triggers a webhook (e.g., an account is opened),
284
+ Recurly will attempt to send this notification to the endpoint(s) you specify.
285
+ You can specify up to 10 endpoints through the application. All notifications will
286
+ be sent to all configured endpoints for your site.
287
+
288
+ See our [product docs](https://docs.recurly.com/docs/webhooks) to learn more about webhooks
289
+ and see our [dev docs](https://developers.recurly.com/pages/webhooks.html) to learn about what payloads
290
+ are available.
291
+
292
+ Although our API is now JSON, our webhook payloads are still formatted as XML for the time being.
293
+ This library is not yet responsible for handling webhooks. If you do need webhooks, we recommend using a simple
294
+ XML to Hash parser.
295
+
296
+ If you are using Rails, we'd recommend [Hash.from_xml](https://apidock.com/rails/Hash/from_xml/class).
297
+
298
+ ```ruby
299
+ notification = Hash.from_xml <<-XML
300
+ <?xml version="1.0" encoding="UTF-8"?>
301
+ <new_account_notification>
302
+ <account>
303
+ <account_code>1</account_code>
304
+ <username nil="true"></username>
305
+ <email>verena@example.com</email>
306
+ <first_name>Verena</first_name>
307
+ <last_name>Example</last_name>
308
+ <company_name nil="true"></company_name>
309
+ </account>
310
+ </new_account_notification>
311
+ XML
312
+
313
+ code = notification["new_account_notification"]["account"]["account_code"]
314
+ puts "New Account with code #{code} created."
315
+ ```
316
+
317
+ If you are not using Rails, we recommend you use [nokogiri](https://nokogiri.org/); however, heed security warnings
318
+ about parse options. Although the XML should only be coming from Recurly, you should parse it as untrusted to be safe.
319
+ Read more about the security implications of parsing untrusted XML in [this OWASP cheatsheet](https://cheatsheetseries.owasp.org/cheatsheets/XML_Security_Cheat_Sheet.html).
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in recurly.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Recurly Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,161 +1,17 @@
1
- # Recurly [![Build Status](https://secure.travis-ci.org/recurly/recurly-client-ruby.png?branch=master)](http://travis-ci.org/recurly/recurly-client-ruby) [![Gem Version](https://badge.fury.io/rb/recurly.svg)](http://badge.fury.io/rb/recurly)
1
+ # Recurly
2
2
 
3
- <https://github.com/recurly/recurly-client-ruby>
3
+ [![Rubygems](https://img.shields.io/static/v1?label=rubygems&message=recurly&color=purple)](https://rubygems.org/gems/recurly)
4
+ [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)
4
5
 
5
- [Recurly](https://recurly.com/)'s Ruby client library is an interface to its
6
- [REST API](https://dev.recurly.com/docs/getting-started).
6
+ This repository houses the official ruby client for Recurly's V3 API.
7
7
 
8
- You can also look at [rubydocs](http://www.rubydoc.info/github/recurly/recurly-client-ruby/master)
9
- to see documentation on the classes and methods available.
8
+ > *Note*:
9
+ > If you were looking for the V2 client, see the [v2 branch](https://github.com/recurly/recurly-client-ruby/tree/v2).
10
10
 
11
- ## Installation
11
+ ## Reference Documentation
12
12
 
13
- Recurly is packaged as a Ruby gem. We recommend you install it with
14
- [Bundler](http://gembundler.com/) by adding the following line to your Gemfile:
15
-
16
- ``` ruby
17
- gem 'recurly', '~> 2.17'
18
- ```
19
-
20
- Recurly will automatically use [Nokogiri](http://nokogiri.org/) (for a nice
21
- speed boost) if it's available and loaded in your app's environment.
22
-
23
- ## Configuration
24
-
25
- If you're using Rails, you can generate an initializer with the following
26
- command:
27
-
28
- ``` bash
29
- $ rails g recurly:config
30
- ```
31
-
32
- If you're not using Rails, use the following template:
33
-
34
- ``` ruby
35
- Recurly.subdomain = ENV['RECURLY_SUBDOMAIN']
36
- Recurly.api_key = ENV['RECURLY_API_KEY']
37
- ```
38
-
39
- Configure the client library with
40
- [your API credentials](https://app.recurly.com/go/developer/api_access).
41
-
42
- * `RECURLY_SUBDOMAIN` should contain subdomain for your recurly account.
43
- * `RECURLY_API_KEY` is your "Private API Key" which can be found under "API Credentials" on the `api_access` admin page.
44
-
45
- The default currency is USD. To override with a different code:
46
-
47
- ``` ruby
48
- Recurly.default_currency = 'EUR' # Assign nil to disable the default entirely.
49
- ```
50
-
51
- If you are using [Recurly.js](https://js.recurly.com) you can store "Public API Key" (which can be found
52
- under "API Credentials" on the `api_access` admin page):
53
-
54
- ``` ruby
55
- Recurly.js.public_key = ENV['RECURLY_PUBLIC_API_KEY']
56
- ```
57
-
58
- Then, in your Rails project you can create `recurly_service.js.erb` file and
59
- [configure](https://docs.recurly.com/js/#configure) recurly.js with public key this way:
60
-
61
- ``` js
62
- recurly.configure({ publicKey: '<%= Recurly.js.public_key %>'});
63
- ```
64
-
65
- The client library currently uses a Net::HTTP adapter. If you need to
66
- configure the settings passed to Net::HTTP (e.g., an SSL certificates path or timeout lengths),
67
- make sure you assign them when initializing the library:
68
-
69
- ``` ruby
70
- Recurly::API.net_http = {
71
- ca_path: "/etc/ssl/certs",
72
- open_timeout: 5, # 5 seconds (defaults to 60)
73
- read_timeout: 45 # 45 seconds (defaults to 60)
74
- }
75
- ```
76
-
77
- To see which keys are supported for this Hash, see the `Attributes` section
78
- of the [Net::HTTP documentation](http://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html) for your ruby version.
79
-
80
- ## Multi-Threaded Configuration
81
- If you are using the client in a multi-threaded environment and require a different configuration per
82
- thread you can use the following within the thread's context:
83
-
84
- ``` ruby
85
- Recurly.config({
86
- subdomain: ENV['RECURLY_SUBDOMAIN']
87
- api_key: ENV['RECURLY_API_KEY'],
88
- default_currency: "US"
89
- })
90
- ```
91
-
92
- Any configuration items you do not include in the above config call will be defaulted to the standard
93
- configuration items. For example if you do not define default_currency then Recurly.default_currency
94
- will be used.
95
-
96
- ## Supported Ruby Versions
97
-
98
- We are currently supporting ruby language versions `2.3` and above. `1.9`, `2.0`, `2.1`, and `2.3` may still work but are not officially supported.
99
-
100
- If you are still using one of these rubies, you should know that support for them ended in
101
- 2015 (1.9), 2016 (2.0), 2017 (2.1), 2018 (2.2) and continuing to use them is a security risk.
102
-
103
- - https://www.ruby-lang.org/en/news/2015/02/23/support-for-ruby-1-9-3-has-ended/
104
- - https://www.ruby-lang.org/en/news/2016/02/24/support-plan-of-ruby-2-0-0-and-2-1/
105
- - https://www.ruby-lang.org/en/news/2017/04/01/support-of-ruby-2-1-has-ended/
106
- - https://www.ruby-lang.org/en/news/2018/06/20/support-of-ruby-2-2-has-ended/
107
-
108
- ## Nokogiri Support
109
-
110
- For now, we are still running the tests on 2.0 and below but without `nokogiri` and only `rexml`. Nokogiri is
111
- no longer supported on 1.9 or 2.0 and has patched known vulnerabilities since dropping support.
112
- If you must run one of these rubies (this includes jruby1.7), you must use rexml and not nokogiri.
113
-
114
- ## Usage
115
-
116
- Instructions and examples are available on
117
- [Recurly's documentation site](https://dev.recurly.com/docs/getting-started).
118
-
119
- Recurly's gem API is available
120
- [here](http://rubydoc.info/gems/recurly/frames/Recurly).
121
-
122
- ## Support
123
-
124
- - [https://support.recurly.com](https://support.recurly.com)
125
- - [stackoverflow](http://stackoverflow.com/questions/tagged/recurly)
13
+ Getting Started Guide and reference documentation can be found on [Github Pages](https://recurly.github.io/recurly-client-ruby/).
126
14
 
127
15
  ## Contributing
128
16
 
129
- Developing for the Recurly gem is easy with [Bundler](http://gembundler.com/).
130
-
131
- Fork and clone the repository, `cd` into the directory, and, with a Ruby of your choice
132
- (1.9.3 or greater), set up your environment.
133
-
134
- If you don't have Bundler installed, install it with the following command:
135
-
136
- ``` bash
137
- $ [sudo] gem install bundler
138
- ```
139
-
140
- And bundle:
141
-
142
- ``` bash
143
- $ bundle --path=vendor/bundle
144
- ```
145
-
146
- You should now be able to run the test suite with Rake:
147
-
148
- ``` bash
149
- $ bundle exec rake
150
- ```
151
-
152
- To run the suite using Nokogiri:
153
-
154
- ``` bash
155
- $ XML=nokogiri bundle exec rake
156
- ```
157
-
158
- If you plan on submitting a patch, please write tests for it (we use
159
- [MiniTest::Spec](http://bfts.rubyforge.org/minitest/MiniTest/Expectations.html)).
160
-
161
- If everything looks good, submit a pull request on GitHub and we'll bring in your changes.
17
+ Please see our [Contributing Guide](CONTRIBUTING.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/benchmark.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+ require "recurly"
4
+ require "benchmark"
5
+
6
+ N = 1_000
7
+
8
+ account_body = "{\"id\":\"ljvmmbjchtgs\",\"object\":\"account\",\"code\":\"9ebd49f7288@example.com\",\"parent_account_id\":null,\"bill_to\":\"self\",\"state\":\"active\",\"username\":null,\"email\":null,\"cc_emails\":null,\"preferred_locale\":null,\"first_name\":\"Benjamin\",\"last_name\":\"Du Monde\",\"company\":null,\"vat_number\":null,\"tax_exempt\":false,\"exemption_certificate\":null,\"address\":null,\"billing_info\":null,\"shipping_addresses\":[{\"object\":\"shipping_address\",\"first_name\":\"Benjamin\",\"last_name\":\"Du Monde\",\"company\":null,\"phone\":null,\"street1\":\"1 Tchoupitoulas St\",\"street2\":null,\"city\":\"New Orleans\",\"region\":\"LA\",\"postal_code\":\"70115\",\"country\":\"US\",\"nickname\":\"Home\",\"email\":null,\"vat_number\":null,\"id\":\"ljvmmbk9e1as\",\"account_id\":\"ljvmmbjchtgs\",\"created_at\":\"2019-09-19T22:45:59Z\",\"updated_at\":\"2019-09-19T22:45:59Z\"}],\"custom_fields\":[],\"hosted_login_token\":\"PSvcHow5H4HGEGKTfHXadLNoDcRaDVMK\",\"created_at\":\"2019-09-19T22:45:59Z\",\"updated_at\":\"2019-09-19T22:45:59Z\",\"deleted_at\":null}"
9
+
10
+ Benchmark.bm do |benchmark|
11
+ benchmark.report("JSON parsing and casting\n") do
12
+ N.times do
13
+ _account = Recurly::JSONParser.parse(nil, account_body)
14
+ end
15
+ end
16
+ end