recurly 3.15.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.bumpversion.cfg +1 -1
  3. data/.github_changelog_generator +1 -1
  4. data/CHANGELOG.md +103 -44
  5. data/CONTRIBUTING.md +0 -4
  6. data/GETTING_STARTED.md +20 -17
  7. data/README.md +0 -3
  8. data/lib/recurly/client.rb +39 -21
  9. data/lib/recurly/client/operations.rb +769 -534
  10. data/lib/recurly/errors.rb +5 -23
  11. data/lib/recurly/errors/api_errors.rb +3 -0
  12. data/lib/recurly/pager.rb +3 -13
  13. data/lib/recurly/requests/{account_acquisition_updatable.rb → account_acquisition_update.rb} +1 -1
  14. data/lib/recurly/requests/account_create.rb +2 -2
  15. data/lib/recurly/requests/account_purchase.rb +2 -2
  16. data/lib/recurly/requests/add_on_create.rb +2 -2
  17. data/lib/recurly/requests/add_on_pricing.rb +5 -1
  18. data/lib/recurly/requests/add_on_update.rb +2 -2
  19. data/lib/recurly/requests/address.rb +0 -8
  20. data/lib/recurly/requests/billing_info_create.rb +7 -23
  21. data/lib/recurly/requests/coupon_create.rb +1 -1
  22. data/lib/recurly/requests/coupon_redemption_create.rb +4 -0
  23. data/lib/recurly/requests/external_transaction.rb +1 -1
  24. data/lib/recurly/requests/{invoice_updatable.rb → invoice_update.rb} +1 -1
  25. data/lib/recurly/requests/line_item_create.rb +1 -1
  26. data/lib/recurly/requests/plan_update.rb +0 -4
  27. data/lib/recurly/requests/purchase_create.rb +4 -0
  28. data/lib/recurly/requests/subscription_add_on_create.rb +6 -2
  29. data/lib/recurly/requests/subscription_add_on_tier.rb +5 -1
  30. data/lib/recurly/requests/subscription_add_on_update.rb +6 -2
  31. data/lib/recurly/requests/subscription_change_create.rb +1 -1
  32. data/lib/recurly/requests/subscription_create.rb +7 -3
  33. data/lib/recurly/requests/tier.rb +2 -2
  34. data/lib/recurly/requests/tier_pricing.rb +22 -0
  35. data/lib/recurly/resources/add_on.rb +1 -1
  36. data/lib/recurly/resources/add_on_pricing.rb +5 -1
  37. data/lib/recurly/resources/address.rb +0 -8
  38. data/lib/recurly/resources/address_with_name.rb +46 -0
  39. data/lib/recurly/resources/coupon.rb +5 -17
  40. data/lib/recurly/resources/coupon_redemption.rb +4 -0
  41. data/lib/recurly/resources/invoice.rb +6 -2
  42. data/lib/recurly/resources/line_item.rb +4 -0
  43. data/lib/recurly/resources/plan.rb +1 -1
  44. data/lib/recurly/resources/subscription.rb +1 -1
  45. data/lib/recurly/resources/subscription_add_on.rb +6 -2
  46. data/lib/recurly/resources/subscription_add_on_tier.rb +5 -1
  47. data/lib/recurly/resources/subscription_change.rb +0 -4
  48. data/lib/recurly/resources/tier.rb +2 -2
  49. data/lib/recurly/resources/tier_pricing.rb +22 -0
  50. data/lib/recurly/resources/transaction.rb +2 -2
  51. data/lib/recurly/resources/unique_coupon_code_params.rb +26 -0
  52. data/lib/recurly/resources/usage.rb +5 -1
  53. data/lib/recurly/version.rb +1 -1
  54. data/openapi/api.yaml +1871 -1690
  55. data/scripts/changelog +1 -1
  56. metadata +9 -9
  57. data/CODE_OF_CONDUCT.md +0 -130
  58. data/lib/recurly/errors/network_errors.rb +0 -10
  59. data/lib/recurly/resources/line_item_list.rb +0 -26
  60. data/lib/recurly/resources/subscription_change_preview.rb +0 -78
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecaa5f1cc2110480aac4355c469c84d7a423badce1a4860cd494ab9e4966a118
4
- data.tar.gz: b5c805224d670c22eed575410d51af2e801279f7f5dae0d274d84ecc60731363
3
+ metadata.gz: b79c9d91182cfc400ba447bf0bf05f29973d58a53838304c43138bcd09d35893
4
+ data.tar.gz: 5a0a31f1b0f1cfc16a8be6e854bedc71d6e49bf0ac51d4d806888accac7ad154
5
5
  SHA512:
6
- metadata.gz: 322cf51b9d06fb661860d02603896a370b92b0292eae793a1ec911bd5528f8452180e76a80199f0f938b9ff4f7c8458001941a18f899c3bdfdd6b49aaf6e0963
7
- data.tar.gz: 2cace6d2929076220ae9f029865a9bc6ca73e66edd0bafb66bce496e5e70985bb1da9a72fa0265c659c725a187a1fdc42730b696524bc1a66bdd84495ccc6958
6
+ metadata.gz: d0b79a687fc8b447b8e52f22532ecc7c14f9636bbd0bbad03de2fee269656b9261ce4a4aae2b983507d6cf3b541168108ffd1bfd69bf7da57c2a69544c0a533d
7
+ data.tar.gz: 9f1bba74512aa006ddbec0e81b39fc847975ec648ccd0fad2d86be49215da3ddb665d23ac62361f8f2018c404480b38412f5fca5b3704f7982d6a61f0baf1e3c
data/.bumpversion.cfg CHANGED
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 3.15.0
2
+ current_version = 4.0.0
3
3
  parse = (?P<major>\d+)
4
4
  \.(?P<minor>\d+)
5
5
  \.(?P<patch>\d+)
@@ -2,7 +2,7 @@ user=recurly
2
2
  project=recurly-client-ruby
3
3
  unreleased=false
4
4
  exclude-labels=question,bug?,duplicate,V2
5
- exclude-tags-regex=^[^3]+\..*
5
+ exclude-tags-regex=^[^34]+\..*
6
6
  issues-wo-labels=false
7
7
  verbose=false
8
8
  since-tag=3.0.0.beta.1
data/CHANGELOG.md CHANGED
@@ -1,80 +1,131 @@
1
1
  # Changelog
2
2
 
3
- ## [3.15.0](https://github.com/recurly/recurly-client-ruby/tree/HEAD)
4
-
5
- [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.14.0...HEAD)
3
+ ## [4.0.0](https://github.com/recurly/recurly-client-ruby/tree/4.0.0) (2021-03-01)
4
+
5
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.18.1...4.0.0)
6
+
7
+ # Major Version Release
8
+
9
+ The 4.x major version of the client pairs with the `v2021-02-25` API version. This version of the client and the API contain breaking changes that should be considered before upgrading your integration.
10
+
11
+ ## Breaking Changes in the API
12
+ All changes to the core API are documented in the [Developer Portal changelog](https://developers.recurly.com/api/changelog.html#v2021-02-25---current-ga-version)
13
+
14
+ ## Breaking Changes in Client
15
+
16
+ - Remove `site_id` and `subdomain` from client initializer. [#624]
17
+ - Remove `set_site_id` method from client. [#627]
18
+ - Classify unexpected error responses from Recurly API via an HTTP status code mapping provided in `Recurly::Errors::ERROR_MAP`. [#616]
19
+ - Remove `NetworkError` class. All error classes now extend the `APIError`. This means that the order of multiple rescue blocks will need to be re-considered. [#616]
20
+
21
+ ### 3.x
22
+
23
+ ```ruby
24
+ rescue Recurly::Errors::ValidationError => ex
25
+ # catch a validation error
26
+ rescue Recurly::Errors::APIError => ex
27
+ # catch a generic api error
28
+ rescue Recurly::Errors::TimeoutError => ex
29
+ # catch a specific network error
30
+ ```
31
+
32
+ ### 4.x
33
+
34
+ ```ruby
35
+ rescue Recurly::Errors::ValidationError => ex
36
+ # catch a validation error
37
+ rescue Recurly::Errors::TimeoutError => ex
38
+ # catch a specific network error
39
+ rescue Recurly::Errors::APIError => ex
40
+ # catch a generic api error
41
+ ```
42
+
43
+ - Rename `InvalidResponseError` to `InvalidContentTypeError`. [#616]
44
+ - Rename `UnavailableError` to `ServiceUnavailableError`. [#616]
45
+ - Reorganize top-level keys of the optional parameters hash to improve clarity and create space for additional options. [#619]
46
+
47
+ ### 3.x
48
+
49
+ ```ruby
50
+ options = {
51
+ limit: 200,
52
+ headers: {
53
+ 'Accept-Language' => 'fr'
54
+ }
55
+ }
56
+ accounts = @client.list_accounts(options)
57
+ ```
58
+
59
+ ### 4.x
60
+
61
+ ```ruby
62
+ options = {
63
+ params: {
64
+ limit: 200
65
+ }
66
+ headers: {
67
+ 'Accept-Language' => 'fr'
68
+ }
69
+ }
70
+ accounts = @client.list_accounts(options)
71
+ ```
6
72
 
7
73
  **Implemented enhancements:**
8
74
 
9
- - Latest Changes for 2019-10-10 \(Wallet, Item Coupons\) [\#645](https://github.com/recurly/recurly-client-ruby/pull/645) ([douglasmiller](https://github.com/douglasmiller))
75
+ - Remove site\_id and subdomain from client initializer [\#624](https://github.com/recurly/recurly-client-ruby/pull/624) ([joannasese](https://github.com/joannasese))
10
76
 
11
- **Merged pull requests:**
77
+ **Fixed bugs:**
12
78
 
13
- - Release 3.15.0 [\#647](https://github.com/recurly/recurly-client-ruby/pull/647) ([douglasmiller](https://github.com/douglasmiller))
79
+ - Every method is returning wrong number of arguments [\#664](https://github.com/recurly/recurly-client-ruby/issues/664)
14
80
 
15
- ## [3.14.0](https://github.com/recurly/recurly-client-ruby/tree/3.14.0) (2020-10-20)
81
+ **Merged pull requests:**
16
82
 
17
- [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.13.0...3.14.0)
83
+ - Release 4.0.0 [\#669](https://github.com/recurly/recurly-client-ruby/pull/669) ([douglasmiller](https://github.com/douglasmiller))
84
+ - Updating changelog script and changelog generator config for 4.x release [\#663](https://github.com/recurly/recurly-client-ruby/pull/663) ([douglasmiller](https://github.com/douglasmiller))
85
+ - Removing unused method 'set\_site\_id' [\#627](https://github.com/recurly/recurly-client-ruby/pull/627) ([douglasmiller](https://github.com/douglasmiller))
86
+ - Updating 4.x client to expect query string params as \['params'\] [\#619](https://github.com/recurly/recurly-client-ruby/pull/619) ([douglasmiller](https://github.com/douglasmiller))
87
+ - Updating error mapping based on status code [\#616](https://github.com/recurly/recurly-client-ruby/pull/616) ([douglasmiller](https://github.com/douglasmiller))
18
88
 
19
- **Implemented enhancements:**
89
+ ## [3.18.1](https://github.com/recurly/recurly-client-ruby/tree/3.18.1) (2021-02-22)
20
90
 
21
- - Mon Oct 19 20:38:03 UTC 2020 Upgrade API version v2019-10-10 [\#642](https://github.com/recurly/recurly-client-ruby/pull/642) ([douglasmiller](https://github.com/douglasmiller))
91
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.18.0...3.18.1)
22
92
 
23
- **Merged pull requests:**
93
+ ## [3.18.0](https://github.com/recurly/recurly-client-ruby/tree/3.18.0) (2021-01-22)
24
94
 
25
- - Release 3.14.0 [\#643](https://github.com/recurly/recurly-client-ruby/pull/643) ([douglasmiller](https://github.com/douglasmiller))
26
- - Fixes uninitialized constant `Recurly::Errors::ServiceNotAvailableError` [\#641](https://github.com/recurly/recurly-client-ruby/pull/641) ([ruyrocha](https://github.com/ruyrocha))
95
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.17.0...3.18.0)
27
96
 
28
- ## [3.13.0](https://github.com/recurly/recurly-client-ruby/tree/3.13.0) (2020-09-22)
97
+ ## [3.17.0](https://github.com/recurly/recurly-client-ruby/tree/3.17.0) (2020-12-08)
29
98
 
30
- [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.12.0...3.13.0)
99
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.16.0...3.17.0)
31
100
 
32
- **Implemented enhancements:**
101
+ ## [3.16.0](https://github.com/recurly/recurly-client-ruby/tree/3.16.0) (2020-11-24)
33
102
 
34
- - Latest Changes for 2019-10-10 \(Automated Exports, additional resource data attributes\) [\#638](https://github.com/recurly/recurly-client-ruby/pull/638) ([douglasmiller](https://github.com/douglasmiller))
103
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.15.0...3.16.0)
35
104
 
36
- **Merged pull requests:**
105
+ ## [3.15.0](https://github.com/recurly/recurly-client-ruby/tree/3.15.0) (2020-11-06)
37
106
 
38
- - Release 3.13.0 [\#639](https://github.com/recurly/recurly-client-ruby/pull/639) ([douglasmiller](https://github.com/douglasmiller))
107
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.14.0...3.15.0)
39
108
 
40
- ## [3.12.0](https://github.com/recurly/recurly-client-ruby/tree/3.12.0) (2020-08-31)
109
+ ## [3.14.0](https://github.com/recurly/recurly-client-ruby/tree/3.14.0) (2020-10-20)
41
110
 
42
- [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.11.0...3.12.0)
111
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.13.0...3.14.0)
43
112
 
44
- **Implemented enhancements:**
113
+ ## [3.13.0](https://github.com/recurly/recurly-client-ruby/tree/3.13.0) (2020-09-22)
45
114
 
46
- - Mon Aug 31 19:44:58 UTC 2020 Upgrade API version v2019-10-10 [\#632](https://github.com/recurly/recurly-client-ruby/pull/632) ([douglasmiller](https://github.com/douglasmiller))
115
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.12.0...3.13.0)
47
116
 
48
- **Merged pull requests:**
117
+ ## [3.12.0](https://github.com/recurly/recurly-client-ruby/tree/3.12.0) (2020-08-31)
49
118
 
50
- - Release 3.12.0 [\#633](https://github.com/recurly/recurly-client-ruby/pull/633) ([douglasmiller](https://github.com/douglasmiller))
51
- - Code of Conduct [\#631](https://github.com/recurly/recurly-client-ruby/pull/631) ([bhelx](https://github.com/bhelx))
119
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.11.0...3.12.0)
52
120
 
53
121
  ## [3.11.0](https://github.com/recurly/recurly-client-ruby/tree/3.11.0) (2020-08-21)
54
122
 
55
123
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.10.0...3.11.0)
56
124
 
57
- **Implemented enhancements:**
58
-
59
- - Fri Aug 21 16:17:28 UTC 2020 Upgrade API version v2019-10-10 [\#629](https://github.com/recurly/recurly-client-ruby/pull/629) ([douglasmiller](https://github.com/douglasmiller))
60
-
61
- **Merged pull requests:**
62
-
63
- - Release 3.11.0 [\#630](https://github.com/recurly/recurly-client-ruby/pull/630) ([douglasmiller](https://github.com/douglasmiller))
64
-
65
125
  ## [3.10.0](https://github.com/recurly/recurly-client-ruby/tree/3.10.0) (2020-07-31)
66
126
 
67
127
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.9.0...3.10.0)
68
128
 
69
- **Implemented enhancements:**
70
-
71
- - Latest Changes for 2019-10-10 \(usage, measured units, etc\) [\#621](https://github.com/recurly/recurly-client-ruby/pull/621) ([bhelx](https://github.com/bhelx))
72
- - Adding hierarchical errors [\#610](https://github.com/recurly/recurly-client-ruby/pull/610) ([douglasmiller](https://github.com/douglasmiller))
73
-
74
- **Merged pull requests:**
75
-
76
- - Release 3.10.0 [\#623](https://github.com/recurly/recurly-client-ruby/pull/623) ([douglasmiller](https://github.com/douglasmiller))
77
-
78
129
  ## [3.9.0](https://github.com/recurly/recurly-client-ruby/tree/3.9.0) (2020-07-06)
79
130
 
80
131
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.8.0...3.9.0)
@@ -307,7 +358,7 @@
307
358
 
308
359
  ## [3.0.0.beta.4](https://github.com/recurly/recurly-client-ruby/tree/3.0.0.beta.4) (2019-04-04)
309
360
 
310
- [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.0.0.beta.1...3.0.0.beta.4)
361
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.0.0.beta.3...3.0.0.beta.4)
311
362
 
312
363
  **Merged pull requests:**
313
364
 
@@ -320,6 +371,14 @@
320
371
  - \[V3\] Test more versions of ruby [\#397](https://github.com/recurly/recurly-client-ruby/pull/397) ([drewish](https://github.com/drewish))
321
372
  - Allow faraday 0.12 for compatibility with oauth2 gem [\#396](https://github.com/recurly/recurly-client-ruby/pull/396) ([drewish](https://github.com/drewish))
322
373
 
374
+ ## [3.0.0.beta.3](https://github.com/recurly/recurly-client-ruby/tree/3.0.0.beta.3) (2018-08-27)
375
+
376
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.0.0.beta.2...3.0.0.beta.3)
377
+
378
+ ## [3.0.0.beta.2](https://github.com/recurly/recurly-client-ruby/tree/3.0.0.beta.2) (2018-07-17)
379
+
380
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.0.0.beta.1...3.0.0.beta.2)
381
+
323
382
 
324
383
 
325
384
  \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/CONTRIBUTING.md CHANGED
@@ -7,10 +7,6 @@ however, we may not get to these right away. Although we try to be quick, our pr
7
7
  writing code. If you want a timely response (especially if you have an emergency), we recommend
8
8
  you contact our [official support team](https://support.recurly.com/).
9
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
10
  #### Table Of Contents
15
11
 
16
12
  * [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)
data/GETTING_STARTED.md CHANGED
@@ -5,7 +5,7 @@ This repository houses the official ruby client for Recurly's V3 API.
5
5
  In your Gemfile, add `recurly` as a dependency.
6
6
 
7
7
  ```ruby
8
- gem 'recurly', '~> 3.15'
8
+ gem 'recurly', '~> 4.0'
9
9
  ```
10
10
 
11
11
  > *Note*: We try to follow [semantic versioning](https://semver.org/) and will only apply breaking changes to major versions.
@@ -106,17 +106,19 @@ plans.each_page.each_with_index do |data, page_num|
106
106
  end
107
107
  ```
108
108
 
109
- Pagination endpoints take a number of options to sort and filter the results. They can be passed in as keyword arguments.
109
+ Pagination endpoints take a number of options to sort and filter the results. They can be passed in as a hash provided by the `:params` keyword argument.
110
110
  The names, types, and descriptions of these arguments are listed in the rubydocs for each method:
111
111
 
112
112
  ```ruby
113
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
114
+ params: {
115
+ limit: 200, # number of items per page
116
+ state: :active, # only active plans
117
+ sort: :updated_at,
118
+ order: :asc,
119
+ begin_time: DateTime.new(2017,1,1), # January 1st 2017,
120
+ end_time: DateTime.now
121
+ }
120
122
  }
121
123
 
122
124
  plans = client.list_plans(**options)
@@ -200,12 +202,11 @@ plan = client.create_plan(body: plan_data)
200
202
 
201
203
  # Error Handling
202
204
 
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:
205
+ All errors thrown by this library are based off of the `Recurly::Errors::APIError`. There
204
206
 
205
- 1. [API Errors](./lib/recurly/errors/api_errors.rb)
206
- 2. [Network Errors](./lib/recurly/errors/network_errors.rb)
207
+ This library throws one main type of exception, `Recurly::Errors::APIError`. There exists an additional hierarchy of errors to facilitate the process of rescuing various classes of errors. More detail can be found in the [Api Errors Module](./lib/recurly/errors/api_errors.rb).
207
208
 
208
- You will normally be working with {Recurly::Errors::APIError}. You can catch specific or generic versions of these exceptions. Example:
209
+ You can catch specific or generic versions of these exceptions. Example:
209
210
 
210
211
  ```ruby
211
212
  begin
@@ -233,15 +234,17 @@ rescue Recurly::Errors::ValidationError => ex
233
234
  #=> #<Recurly::Error:0x007fbbdf8a32c8 @attributes={:type=>"validation", :message=>"Code 'iexistalready' already exists", :params=>[{"param"=>"code", "message"=>"'iexistalready' already exists"}]}>
234
235
  puts ex.status_code
235
236
  #=> 422
237
+ rescue Recurly::Errors::TimeoutError => ex
238
+ # catch a specific server error
239
+ rescue Recurly::Errors::ServerError => ex
240
+ # catch a generic server error
236
241
  rescue Recurly::Errors::APIError => ex
237
242
  # 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
243
  end
243
244
  ```
244
245
 
246
+ `Recurly::Errors::APIError` instances provide access to the response via the `#get_response` method.
247
+
245
248
  # HTTP Metadata
246
249
 
247
250
  Sometimes you might want to get some additional information about the underlying HTTP request and response. Instead of
@@ -266,7 +269,7 @@ response = @client.remove_line_item(
266
269
  line_item_id: "a959576b2b10b012"
267
270
  ).get_response
268
271
  ```
269
- And it can be captured on exceptions through the {Recurly::ApiError} object:
272
+ And it can be captured on exceptions through the {Recurly::APIError} object:
270
273
 
271
274
  ```ruby
272
275
  begin
data/README.md CHANGED
@@ -1,8 +1,5 @@
1
1
  # Recurly
2
2
 
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)
5
-
6
3
  This repository houses the official ruby client for Recurly's V3 API.
7
4
 
8
5
  > *Note*:
@@ -20,7 +20,14 @@ module Recurly
20
20
  MAX_RETRIES = 3
21
21
  LOG_LEVELS = %i(debug info warn error fatal).freeze
22
22
  BASE36_ALPHABET = (("0".."9").to_a + ("a".."z").to_a).freeze
23
- REQUEST_OPTIONS = [:headers].freeze
23
+ ALLOWED_OPTIONS = [
24
+ :site_id,
25
+ :open_timeout,
26
+ :read_timeout,
27
+ :body,
28
+ :params,
29
+ :headers,
30
+ ].freeze
24
31
 
25
32
  # Initialize a client. It requires an API key.
26
33
  #
@@ -47,8 +54,7 @@ module Recurly
47
54
  #
48
55
  # @param api_key [String] The private API key
49
56
  # @param logger [Logger] A logger to use. Defaults to creating a new STDOUT logger with level WARN.
50
- def initialize(api_key:, site_id: nil, subdomain: nil, logger: nil)
51
- set_site_id(site_id, subdomain)
57
+ def initialize(api_key:, logger: nil)
52
58
  set_api_key(api_key)
53
59
 
54
60
  if logger.nil?
@@ -90,6 +96,7 @@ module Recurly
90
96
  end
91
97
 
92
98
  def head(path, **options)
99
+ validate_options!(options)
93
100
  request = Net::HTTP::Head.new build_url(path, options)
94
101
  set_headers(request, options[:headers])
95
102
  http_response = run_request(request, options)
@@ -97,6 +104,7 @@ module Recurly
97
104
  end
98
105
 
99
106
  def get(path, **options)
107
+ validate_options!(options)
100
108
  request = Net::HTTP::Get.new build_url(path, options)
101
109
  set_headers(request, options[:headers])
102
110
  http_response = run_request(request, options)
@@ -104,6 +112,7 @@ module Recurly
104
112
  end
105
113
 
106
114
  def post(path, request_data, request_class, **options)
115
+ validate_options!(options)
107
116
  request_class.new(request_data).validate!
108
117
  request = Net::HTTP::Post.new build_url(path, options)
109
118
  request.set_content_type(JSON_CONTENT_TYPE)
@@ -114,6 +123,7 @@ module Recurly
114
123
  end
115
124
 
116
125
  def put(path, request_data = nil, request_class = nil, **options)
126
+ validate_options!(options)
117
127
  request = Net::HTTP::Put.new build_url(path, options)
118
128
  request.set_content_type(JSON_CONTENT_TYPE)
119
129
  set_headers(request, options[:headers])
@@ -127,6 +137,7 @@ module Recurly
127
137
  end
128
138
 
129
139
  def delete(path, **options)
140
+ validate_options!(options)
130
141
  request = Net::HTTP::Delete.new build_url(path, options)
131
142
  set_headers(request, options[:headers])
132
143
  http_response = run_request(request, options)
@@ -240,7 +251,7 @@ module Recurly
240
251
  elsif BINARY_TYPES.include?(http_response.content_type)
241
252
  FileParser.parse(response.body)
242
253
  else
243
- raise Recurly::Errors::InvalidResponseError, "Unexpected content type: #{http_response.content_type}"
254
+ raise Recurly::Errors::InvalidContentTypeError, "Unexpected content type: #{http_response.content_type}"
244
255
  end
245
256
  else
246
257
  Resources::Empty.new
@@ -253,20 +264,15 @@ module Recurly
253
264
  def raise_api_error!(http_response, response)
254
265
  if response.content_type.include?(JSON_CONTENT_TYPE)
255
266
  error = JSONParser.parse(self, response.body)
256
- begin
257
- error_class = Errors::APIError.error_class(error.type)
258
- raise error_class.new(response, error)
259
- rescue NameError
260
- error_class = Errors::APIError.from_response(http_response)
261
- raise error_class.new(response, error)
262
- end
267
+ error_class = Errors::APIError.error_class(error.type)
268
+ raise error_class.new(error.message, response, error)
263
269
  end
264
270
 
265
271
  error_class = Errors::APIError.from_response(http_response)
266
272
 
267
273
  if error_class <= Recurly::Errors::APIError
268
274
  error = Recurly::Resources::Error.new(message: "#{http_response.code}: #{http_response.message}")
269
- raise error_class.new(response, error)
275
+ raise error_class.new(error.message, response, error)
270
276
  else
271
277
  raise error_class, "#{http_response.code}: #{http_response.message}"
272
278
  end
@@ -279,6 +285,17 @@ module Recurly
279
285
  response
280
286
  end
281
287
 
288
+ def validate_options!(**options)
289
+ invalid_options = options.keys.reject do |k|
290
+ ALLOWED_OPTIONS.include?(k)
291
+ end
292
+ if invalid_options.any?
293
+ joinedKeys = invalid_options.join(", ")
294
+ joinedOptions = ALLOWED_OPTIONS.join(", ")
295
+ raise ArgumentError, "Invalid options: '#{joinedKeys}'. Allowed options: '#{joinedOptions}'"
296
+ end
297
+ end
298
+
282
299
  def validate_path_parameters!(**options)
283
300
  # Check to see that we are passing the correct data types
284
301
  # This prevents a confusing error if the user passes in a non-primitive by mistake
@@ -308,21 +325,13 @@ module Recurly
308
325
  path % options
309
326
  end
310
327
 
311
- def set_site_id(site_id, subdomain)
312
- if site_id
313
- @site_id = site_id
314
- elsif subdomain
315
- @site_id = "subdomain-#{subdomain}"
316
- end
317
- end
318
-
319
328
  def set_api_key(api_key)
320
329
  @api_key = api_key
321
330
  end
322
331
 
323
332
  def build_url(path, options)
324
333
  path = scope_by_site(path, options)
325
- query_params = options.reject { |k, _| REQUEST_OPTIONS.include?(k.to_sym) }
334
+ query_params = map_array_params(options.fetch(:params, {}))
326
335
  if query_params.any?
327
336
  "#{path}?#{URI.encode_www_form(query_params)}"
328
337
  else
@@ -330,6 +339,15 @@ module Recurly
330
339
  end
331
340
  end
332
341
 
342
+ # Converts array parameters to CSV strings to maintain consistency with
343
+ # how the server expects the request to be formatted while providing the
344
+ # developer with an array type to maintain developer happiness!
345
+ def map_array_params(params)
346
+ params.map do |key, param|
347
+ [key, param.is_a?(Array) ? param.join(",") : param]
348
+ end.to_h
349
+ end
350
+
333
351
  def scope_by_site(path, **options)
334
352
  if site = site_id || options[:site_id]
335
353
  # Ensure that we are only including the site_id once because the Pager operations