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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46f3ba77786e00789be21fba3ae3fa14c81742b13b66f4a915adf43a37b6f6bf
4
- data.tar.gz: dd003015b650dcaee169b8d6581de9dba0753efc7d1b3e96a8d98663fadbba30
3
+ metadata.gz: 4560816624b25f0c01b6403a22f7b6425c9b7dde31ef860544d4eb3b7bc36fc5
4
+ data.tar.gz: 154f6697035218babd3b843c820e17fd7650cc275ce1f931eb0800204b67b9ea
5
5
  SHA512:
6
- metadata.gz: e9a97329f3eeec72986edd65d03881640fa08115d9f060081bf27d2736f084663e6e4b7b79f1753a8e85f2dc4d848617717af650378bd1597395a7a4dae00ab9
7
- data.tar.gz: a213bebf6ddeaa9a58952d52e4d2bb1ff0ffea35d75b201f61d55d92ffc8cdc9aafd4df4adada6fbe1c08d27febba7b972c1fe7df2f971a1e5d1426c580f6aaa
6
+ metadata.gz: e1c15b8a70794c06a3d064c4d4b830975d6f5c4aeddfa14a7d5387294d2ecb1ea42f8e96070cf6adb4742a606ed36b2e8fd3e97c96b39688da2099ab72a5159d
7
+ data.tar.gz: bc16dd1d21814913aa3cb3e23d85bf745a14f47a4fe22ec1931171eef20adae9333f1ad990deacc27857f53a6941b361452123e97a32c697a05c19530e2d920b
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ *.gem
14
+ coverage
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format progress
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.6
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,150 +1,198 @@
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
+ This gem is the ruby client for Recurly's V3 API (or "partner api"). It's currently Beta software
4
+ and is not yet an official release. Documentation for the API can be [found here](https://partner-docs.recurly.com).
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
+ ## Getting Started
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
+ ### Documentation
10
9
 
11
- ## Installation
10
+ Documentation can be found at this link: [https://www.rubydoc.info/github/recurly/recurly-client-ruby/3_0_0_beta](https://www.rubydoc.info/github/recurly/recurly-client-ruby/3_0_0_beta).
11
+ This contains everything in the README as well as code-level documentation. We suggest starting there.
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:
13
+ ### Installing
15
14
 
16
- ``` ruby
17
- gem 'recurly', '~> 2.19.7'
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
15
+ This gem is a pre-release. In your Gemfile, add `recurly` as a dependency.
24
16
 
25
- Use the following template to configure Recurly:
26
-
27
- ``` ruby
28
- Recurly.subdomain = ENV['RECURLY_SUBDOMAIN']
29
- Recurly.api_key = ENV['RECURLY_API_KEY']
17
+ ```ruby
18
+ gem 'recurly', '3.0.0.beta.1'
30
19
  ```
31
20
 
32
- > Note: In Rails, these would be added in an initializer `config/initializers/recurly.rb`.
33
-
34
- Configure the client library with
35
- [your API credentials](https://app.recurly.com/go/developer/api_access).
21
+ It's important that you lock on a specific version as there may be breaking changes between releases.
22
+ All beta releases will have the format `3.0.0.beta.x` until we go live.
36
23
 
37
- * `RECURLY_SUBDOMAIN` should contain subdomain for your recurly account.
38
- * `RECURLY_API_KEY` is your "Private API Key" which can be found under "API Credentials" on the `api_access` admin page.
24
+ ### Creating a client
39
25
 
40
- The default currency is USD. To override with a different code:
26
+ Client instances are now explicitly created and referenced as opposed to V2's use of global, statically
27
+ initialized clients.
41
28
 
42
- ``` ruby
43
- Recurly.default_currency = 'EUR' # Assign nil to disable the default entirely.
44
- ```
29
+ This makes multithreaded environments simpler and provides one location where every
30
+ operation can be found (rather than having them spread out among classes).
45
31
 
46
- If you are using [Recurly.js](https://js.recurly.com) you can store "Public API Key" (which can be found
47
- under "API Credentials" on the `api_access` admin page):
32
+ `Recurly::Client#new` initializes a new client. It requires an API key and a site id:
48
33
 
49
- ``` ruby
50
- Recurly.js.public_key = ENV['RECURLY_PUBLIC_API_KEY']
34
+ ```ruby
35
+ API_KEY = '83749879bbde395b5fe0cc1a5abf8e5'
36
+ SITE_ID = 'dqzlv9shi7wa'
37
+ client = Recurly::Client.new(site_id: SITE_ID, api_key: API_KEY)
38
+ # You may use the subdomain instead of the site_id if you do not know the site_id
39
+ client = Recurly::Client.new(subdomain: 'mysite-prod', api_key: API_KEY)
40
+ sub = client.get_subscription(subscription_id: 'abcd123456')
51
41
  ```
52
42
 
53
- Then, in your Rails project you can create `recurly_service.js.erb` file and
54
- [configure](https://docs.recurly.com/js/#configure) recurly.js with public key this way:
43
+ You can also pass the initializer a block. This will give you a client scoped for just that block:
55
44
 
56
- ``` js
57
- recurly.configure({ publicKey: '<%= Recurly.js.public_key %>'});
45
+ ```ruby
46
+ Recurly::Client.new(subdomain: 'mysite-prod', api_key: API_KEY) do |client|
47
+ sub = client.get_subscription(subscription_id: 'abcd123456')
48
+ end
58
49
  ```
59
50
 
60
- The client library currently uses a Net::HTTP adapter. If you need to
61
- configure the settings passed to Net::HTTP (e.g., an SSL certificates path or timeout lengths),
62
- make sure you assign them when initializing the library:
51
+ If you only plan on using the client for more than one site, you should initialize a new client for each site.
63
52
 
64
- ``` ruby
65
- Recurly::API.net_http = {
66
- ca_path: "/etc/ssl/certs",
67
- open_timeout: 5, # 5 seconds (defaults to 60)
68
- read_timeout: 45 # 45 seconds (defaults to 60)
69
- }
70
- ```
71
-
72
- To see which keys are supported for this Hash, see the `Attributes` section
73
- of the [Net::HTTP documentation](http://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTP.html) for your ruby version.
53
+ ```ruby
54
+ # Give a `site_id`
55
+ client = Recurly::Client.new(api_key: API_KEY, site_id: SITE_ID)
56
+ # Or use the subdomain
57
+ client = Recurly::Client.new(api_key: API_KEY, subdomain: 'mysite-dev')
74
58
 
75
- ## Multi-Threaded Configuration
76
- If you are using the client in a multi-threaded environment and require a different configuration per
77
- thread you can use the following within the thread's context:
59
+ sub = client.get_subscription(subscription_id: 'abcd123456')
78
60
 
79
- ``` ruby
80
- Recurly.config({
81
- subdomain: ENV['RECURLY_SUBDOMAIN']
82
- api_key: ENV['RECURLY_API_KEY'],
83
- default_currency: "US"
84
- })
61
+ # you should create a new client to connect to another site
62
+ client = Recurly::Client.new(api_key: API_KEY, subdomain: 'mysite-prod')
63
+ sub = client.get_subscription(subscription_id: 'abcd7890')
85
64
  ```
86
65
 
87
- Any configuration items you do not include in the above config call will be defaulted to the standard
88
- configuration items. For example if you do not define default_currency then Recurly.default_currency
89
- will be used.
90
-
91
- ## Supported Ruby Versions
92
-
93
- Recurly will support whichever versions the [Ruby maintainers are supporting](https://www.ruby-lang.org/en/downloads/branches/).
94
- We support all versions with status `* maintenance`. We do not support `eol` versions or `preview` versions. This library
95
- may work on EOL versions of ruby, but we may not be able to support you if you use one.
96
-
97
- ## Nokogiri Support
66
+ ### Operations
98
67
 
99
- For now, we are still running the tests on 2.0 and below but without `nokogiri` and only `rexml`. Nokogiri is
100
- no longer supported on 1.9 or 2.0 and has patched known vulnerabilities since dropping support.
101
- If you must run one of these rubies (this includes jruby1.7), you must use rexml and not nokogiri.
68
+ The {Recurly::Client} contains every `operation` you can perform on the site as a list of methods. Each method is documented explaining
69
+ the types and descriptions for each input and return type. You can view all available operations by looking at the `Instance Methods Summary` list
70
+ on the {Recurly::Client} documentation page. Clicking a method will give you detailed information about its inputs and returns. Take the `create_account`
71
+ operation as an example: {Recurly::Client#create_account}.
102
72
 
103
- ## Usage
73
+ ### Pagination
104
74
 
105
- Instructions and examples are available on
106
- [Recurly's documentation site](https://dev.recurly.com/docs/getting-started).
75
+ Pagination is done by the class `Recurly::Pager`. All `list_*` methods on the client return an instance of this class.
76
+ The pager has an `each` method which accepts a block for each object in the entire list. Each page is fetched automatically
77
+ for you presenting the elements as a single enumerable.
107
78
 
108
- Recurly's gem API is available
109
- [here](http://rubydoc.info/gems/recurly/frames/Recurly).
110
-
111
- ## Support
112
-
113
- - [https://support.recurly.com](https://support.recurly.com)
114
- - [stackoverflow](http://stackoverflow.com/questions/tagged/recurly)
115
-
116
- ## Contributing
117
-
118
- Developing for the Recurly gem is easy with [Bundler](http://gembundler.com/).
119
-
120
- Fork and clone the repository, `cd` into the directory, and, with a Ruby of your choice
121
- (1.9.3 or greater), set up your environment.
79
+ ```ruby
80
+ plans = client.list_plans()
81
+ plans.each do |plan|
82
+ puts "Plan: #{plan.id}"
83
+ end
84
+ ```
122
85
 
123
- If you don't have Bundler installed, install it with the following command:
86
+ You may also paginate in chunks with `each_page`.
124
87
 
125
- ``` bash
126
- $ [sudo] gem install bundler
88
+ ```ruby
89
+ plans = client.list_plans()
90
+ plans.each_page do |data|
91
+ data.each do |plan|
92
+ puts "Plan: #{plan.id}"
93
+ end
94
+ end
127
95
  ```
128
96
 
129
- And bundle:
130
-
131
- ``` bash
132
- $ bundle --path=vendor/bundle
97
+ Both `Pager#each` and `Pager#each_page` return Enumerators if a block is not given. This allows you to use other Enumerator methods
98
+ such as `map` or `each_with_index`.
99
+
100
+ ```ruby
101
+ plans = client.list_plans()
102
+ plans.each_page.each_with_index do |data, page_num|
103
+ puts "Page Number #{page_num}"
104
+ data.each do |plan|
105
+ puts "Plan: #{plan.id}"
106
+ end
107
+ end
133
108
  ```
134
109
 
135
- You should now be able to run the test suite with Rake:
110
+ Pagination endpoints take a number of options to sort and filter the results. They can be passed in as keyword arguments.
111
+ The names, types, and descriptions of these arguments are listed in the rubydocs for each method:
112
+
113
+ ```ruby
114
+ options = {
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
+ }
136
121
 
137
- ``` bash
138
- $ bundle exec rake
122
+ plans = client.list_plans(**options)
123
+ plans.each do |plan|
124
+ puts "Plan: #{plan.id}"
125
+ end
139
126
  ```
140
127
 
141
- To run the suite using Nokogiri:
128
+ ### Creating Resources
129
+
130
+ Currently, resources are created by passing in a `body` keyword argument in the form of a `Hash`.
131
+ This Hash must follow the schema of the documented request type. For example, the `create_plan` operation
132
+ takes a request of type {Recurly::Requests::PlanCreate}. Failing to conform to this schema will result in an argument
133
+ error.
134
+
135
+ ```ruby
136
+ require 'securerandom'
137
+
138
+ code = SecureRandom.uuid
139
+ plan_data = {
140
+ code: code,
141
+ interval_length: 1,
142
+ interval_unit: 'months',
143
+ name: code,
144
+ currencies: [
145
+ {
146
+ currency: 'USD',
147
+ setup_fee: 800,
148
+ unit_amount: 10
149
+ }
150
+ ]
151
+ }
142
152
 
143
- ``` bash
144
- $ XML=nokogiri bundle exec rake
153
+ plan = client.create_plan(body: plan_data)
145
154
  ```
146
155
 
147
- If you plan on submitting a patch, please write tests for it (we use
148
- [MiniTest::Spec](http://bfts.rubyforge.org/minitest/MiniTest/Expectations.html)).
149
-
150
- If everything looks good, submit a pull request on GitHub and we'll bring in your changes.
156
+ ### Error Handling
157
+
158
+ 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:
159
+
160
+ 1. [API Errors](./lib/recurly/errors/api_errors.rb)
161
+ 2. [Network Errors](./lib/recurly/errors/network_errors.rb)
162
+
163
+ You will normally be working with {Recurly::Errors::APIError}. You can catch specific or generic versions of these exceptions. Example:
164
+
165
+ ```ruby
166
+ begin
167
+ client = Recurly::Client.new(site_id: SITE_ID, api_key: API_KEY)
168
+ code = "iexistalready"
169
+ plan_data = {
170
+ code: code,
171
+ interval_length: 1,
172
+ interval_unit: 'months',
173
+ name: code,
174
+ currencies: [
175
+ {
176
+ currency: 'USD',
177
+ setup_fee: 800,
178
+ unit_amount: 10
179
+ }
180
+ ]
181
+ }
182
+
183
+ plan = client.create_plan(body: plan_data)
184
+ rescue Recurly::Errors::ValidationError => ex
185
+ puts ex.inspect
186
+ #=> #<Recurly::ValidationError: Recurly::ValidationError: Code 'iexistalready' already exists>
187
+ puts ex.recurly_error.inspect
188
+ #=> #<Recurly::Error:0x007fbbdf8a32c8 @attributes={:type=>"validation", :message=>"Code 'iexistalready' already exists", :params=>[{"param"=>"code", "message"=>"'iexistalready' already exists"}]}>
189
+ puts ex.status_code
190
+ #=> 422
191
+ rescue Recurly::Errors::APIError => ex
192
+ # catch a generic api error
193
+ rescue Recurly::Errors::TimeoutError => ex
194
+ # catch a specific network error
195
+ rescue Recurly::Errors::NetworkError => ex
196
+ # catch a generic network error
197
+ end
198
+ ```
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/bin/bundle ADDED
@@ -0,0 +1,105 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1 || ">= 0.a"
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../../Gemfile", __FILE__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_version
64
+ @bundler_version ||= begin
65
+ env_var_version || cli_arg_version ||
66
+ lockfile_version || "#{Gem::Requirement.default}.a"
67
+ end
68
+ end
69
+
70
+ def load_bundler!
71
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
72
+
73
+ # must dup string for RG < 1.8 compatibility
74
+ activate_bundler(bundler_version.dup)
75
+ end
76
+
77
+ def activate_bundler(bundler_version)
78
+ if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
79
+ bundler_version = "< 2"
80
+ end
81
+ gem_error = activation_error_handling do
82
+ gem "bundler", bundler_version
83
+ end
84
+ return if gem_error.nil?
85
+ require_error = activation_error_handling do
86
+ require "bundler/version"
87
+ end
88
+ return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
89
+ warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
90
+ exit 42
91
+ end
92
+
93
+ def activation_error_handling
94
+ yield
95
+ nil
96
+ rescue StandardError, LoadError => e
97
+ e
98
+ end
99
+ end
100
+
101
+ m.load_bundler!
102
+
103
+ if m.invoked_as_script?
104
+ load Gem.bin_path("bundler", "bundle")
105
+ end
data/bin/coderay ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'coderay' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("coderay", "coderay")
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "recurly"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/htmldiff ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'htmldiff' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("diff-lcs", "htmldiff")
data/bin/ldiff ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'ldiff' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("diff-lcs", "ldiff")
data/bin/pry ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'pry' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("pry", "pry")
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("rake", "rake")