recurly 3.18.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.bumpversion.cfg +1 -1
  3. data/.github_changelog_generator +1 -1
  4. data/.travis.yml +0 -1
  5. data/CHANGELOG.md +82 -80
  6. data/CONTRIBUTING.md +0 -4
  7. data/GETTING_STARTED.md +20 -17
  8. data/README.md +0 -3
  9. data/lib/recurly/client.rb +41 -23
  10. data/lib/recurly/client/operations.rb +768 -546
  11. data/lib/recurly/errors.rb +5 -23
  12. data/lib/recurly/errors/api_errors.rb +3 -0
  13. data/lib/recurly/pager.rb +4 -14
  14. data/lib/recurly/requests/{account_acquisition_updatable.rb → account_acquisition_update.rb} +1 -1
  15. data/lib/recurly/requests/account_create.rb +2 -2
  16. data/lib/recurly/requests/account_purchase.rb +2 -2
  17. data/lib/recurly/requests/add_on_create.rb +2 -2
  18. data/lib/recurly/requests/add_on_pricing.rb +5 -1
  19. data/lib/recurly/requests/add_on_update.rb +2 -2
  20. data/lib/recurly/requests/address.rb +0 -8
  21. data/lib/recurly/requests/billing_info_create.rb +1 -25
  22. data/lib/recurly/requests/coupon_create.rb +1 -1
  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/subscription_add_on_create.rb +6 -2
  27. data/lib/recurly/requests/subscription_add_on_tier.rb +5 -1
  28. data/lib/recurly/requests/subscription_add_on_update.rb +6 -2
  29. data/lib/recurly/requests/subscription_change_create.rb +1 -1
  30. data/lib/recurly/requests/subscription_create.rb +3 -3
  31. data/lib/recurly/requests/tier.rb +2 -2
  32. data/lib/recurly/requests/tier_pricing.rb +22 -0
  33. data/lib/recurly/resources/add_on.rb +1 -1
  34. data/lib/recurly/resources/add_on_pricing.rb +5 -1
  35. data/lib/recurly/resources/address.rb +0 -8
  36. data/lib/recurly/resources/address_with_name.rb +46 -0
  37. data/lib/recurly/resources/coupon.rb +5 -17
  38. data/lib/recurly/resources/invoice.rb +6 -2
  39. data/lib/recurly/resources/line_item.rb +4 -0
  40. data/lib/recurly/resources/plan.rb +1 -1
  41. data/lib/recurly/resources/subscription_add_on.rb +6 -2
  42. data/lib/recurly/resources/subscription_add_on_tier.rb +5 -1
  43. data/lib/recurly/resources/subscription_change.rb +0 -4
  44. data/lib/recurly/resources/tier.rb +2 -2
  45. data/lib/recurly/resources/tier_pricing.rb +22 -0
  46. data/lib/recurly/resources/transaction.rb +2 -2
  47. data/lib/recurly/resources/unique_coupon_code_params.rb +26 -0
  48. data/lib/recurly/resources/usage.rb +5 -1
  49. data/lib/recurly/version.rb +1 -1
  50. data/openapi/api.yaml +1835 -1785
  51. data/scripts/changelog +1 -1
  52. metadata +9 -9
  53. data/CODE_OF_CONDUCT.md +0 -130
  54. data/lib/recurly/errors/network_errors.rb +0 -10
  55. data/lib/recurly/resources/line_item_list.rb +0 -26
  56. 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: 116deeff1797454126fb1dcdf1aa3b4c597706b801108db0fe733e03f29e2d96
4
- data.tar.gz: 1393beaf04029829abef57a7daf685891bdf1181f32452af2d772d1bce8eb1ec
3
+ metadata.gz: b79c9d91182cfc400ba447bf0bf05f29973d58a53838304c43138bcd09d35893
4
+ data.tar.gz: 5a0a31f1b0f1cfc16a8be6e854bedc71d6e49bf0ac51d4d806888accac7ad154
5
5
  SHA512:
6
- metadata.gz: af7712df32a93b5091d892b77b5dacba27c2f6bb3fe48fffedce730b652c466c2e02e772243c5c5c43a83434490c15b172295e1df93d4287b975b36f42aeebdc
7
- data.tar.gz: 53b2ded880393c1c81909b6d2ec7e5fc7da73827ede6b6fdd7030defa15a9f707821d28de4d8aee9951f1c99e7a80ef8d0685feaced8c330fce9dfe1ea4ef927
6
+ metadata.gz: d0b79a687fc8b447b8e52f22532ecc7c14f9636bbd0bbad03de2fee269656b9261ce4a4aae2b983507d6cf3b541168108ffd1bfd69bf7da57c2a69544c0a533d
7
+ data.tar.gz: 9f1bba74512aa006ddbec0e81b39fc847975ec648ccd0fad2d86be49215da3ddb665d23ac62361f8f2018c404480b38412f5fca5b3704f7982d6a61f0baf1e3c
data/.bumpversion.cfg CHANGED
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 3.18.1
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/.travis.yml CHANGED
@@ -5,7 +5,6 @@ rvm:
5
5
  - 2.5
6
6
  - 2.6
7
7
  - 2.7
8
- - 3.0
9
8
  bundler_args: --binstubs
10
9
  before_install:
11
10
  - gem update --system
data/CHANGELOG.md CHANGED
@@ -1,129 +1,131 @@
1
1
  # Changelog
2
2
 
3
- ## [3.18.1](https://github.com/recurly/recurly-client-ruby/tree/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
+ ```
4
72
 
5
- [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.18.0...HEAD)
73
+ **Implemented enhancements:**
74
+
75
+ - Remove site\_id and subdomain from client initializer [\#624](https://github.com/recurly/recurly-client-ruby/pull/624) ([joannasese](https://github.com/joannasese))
6
76
 
7
77
  **Fixed bugs:**
8
78
 
9
- - Fixing issues with ruby 3.0 [\#665](https://github.com/recurly/recurly-client-ruby/pull/665) ([douglasmiller](https://github.com/douglasmiller))
79
+ - Every method is returning wrong number of arguments [\#664](https://github.com/recurly/recurly-client-ruby/issues/664)
10
80
 
11
81
  **Merged pull requests:**
12
82
 
13
- - Release 3.18.1 [\#666](https://github.com/recurly/recurly-client-ruby/pull/666) ([douglasmiller](https://github.com/douglasmiller))
14
-
15
- ## [3.18.0](https://github.com/recurly/recurly-client-ruby/tree/3.18.0) (2021-01-22)
16
-
17
- [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.17.0...3.18.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
- - Latest Changes for 2019-10-10 [\#660](https://github.com/recurly/recurly-client-ruby/pull/660) ([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.18.0 [\#661](https://github.com/recurly/recurly-client-ruby/pull/661) ([douglasmiller](https://github.com/douglasmiller))
95
+ [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.17.0...3.18.0)
26
96
 
27
97
  ## [3.17.0](https://github.com/recurly/recurly-client-ruby/tree/3.17.0) (2020-12-08)
28
98
 
29
99
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.16.0...3.17.0)
30
100
 
31
- **Implemented enhancements:**
32
-
33
- - Latest Changes for 2019-10-10 [\#657](https://github.com/recurly/recurly-client-ruby/pull/657) ([douglasmiller](https://github.com/douglasmiller))
34
-
35
- **Merged pull requests:**
36
-
37
- - Release 3.17.0 [\#658](https://github.com/recurly/recurly-client-ruby/pull/658) ([douglasmiller](https://github.com/douglasmiller))
38
-
39
101
  ## [3.16.0](https://github.com/recurly/recurly-client-ruby/tree/3.16.0) (2020-11-24)
40
102
 
41
103
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.15.0...3.16.0)
42
104
 
43
- **Implemented enhancements:**
44
-
45
- - Latest Changes for 2019-10-10 \(tax\_identifier / tax\_identifier\_type\) [\#654](https://github.com/recurly/recurly-client-ruby/pull/654) ([douglasmiller](https://github.com/douglasmiller))
46
- - Latest Changes for 2019-10-10 [\#651](https://github.com/recurly/recurly-client-ruby/pull/651) ([douglasmiller](https://github.com/douglasmiller))
47
-
48
- **Merged pull requests:**
49
-
50
- - Release 3.16.0 [\#656](https://github.com/recurly/recurly-client-ruby/pull/656) ([douglasmiller](https://github.com/douglasmiller))
51
-
52
105
  ## [3.15.0](https://github.com/recurly/recurly-client-ruby/tree/3.15.0) (2020-11-06)
53
106
 
54
107
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.14.0...3.15.0)
55
108
 
56
- **Implemented enhancements:**
57
-
58
- - Latest Changes for 2019-10-10 \(Wallet, Item Coupons\) [\#645](https://github.com/recurly/recurly-client-ruby/pull/645) ([douglasmiller](https://github.com/douglasmiller))
59
-
60
- **Merged pull requests:**
61
-
62
- - Release 3.15.0 [\#647](https://github.com/recurly/recurly-client-ruby/pull/647) ([douglasmiller](https://github.com/douglasmiller))
63
-
64
109
  ## [3.14.0](https://github.com/recurly/recurly-client-ruby/tree/3.14.0) (2020-10-20)
65
110
 
66
111
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.13.0...3.14.0)
67
112
 
68
- **Implemented enhancements:**
69
-
70
- - 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))
71
-
72
- **Merged pull requests:**
73
-
74
- - Release 3.14.0 [\#643](https://github.com/recurly/recurly-client-ruby/pull/643) ([douglasmiller](https://github.com/douglasmiller))
75
- - Fixes uninitialized constant `Recurly::Errors::ServiceNotAvailableError` [\#641](https://github.com/recurly/recurly-client-ruby/pull/641) ([ruyrocha](https://github.com/ruyrocha))
76
-
77
113
  ## [3.13.0](https://github.com/recurly/recurly-client-ruby/tree/3.13.0) (2020-09-22)
78
114
 
79
115
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.12.0...3.13.0)
80
116
 
81
- **Implemented enhancements:**
82
-
83
- - 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))
84
-
85
- **Merged pull requests:**
86
-
87
- - Release 3.13.0 [\#639](https://github.com/recurly/recurly-client-ruby/pull/639) ([douglasmiller](https://github.com/douglasmiller))
88
-
89
117
  ## [3.12.0](https://github.com/recurly/recurly-client-ruby/tree/3.12.0) (2020-08-31)
90
118
 
91
119
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.11.0...3.12.0)
92
120
 
93
- **Implemented enhancements:**
94
-
95
- - 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))
96
-
97
- **Merged pull requests:**
98
-
99
- - Release 3.12.0 [\#633](https://github.com/recurly/recurly-client-ruby/pull/633) ([douglasmiller](https://github.com/douglasmiller))
100
- - Code of Conduct [\#631](https://github.com/recurly/recurly-client-ruby/pull/631) ([bhelx](https://github.com/bhelx))
101
-
102
121
  ## [3.11.0](https://github.com/recurly/recurly-client-ruby/tree/3.11.0) (2020-08-21)
103
122
 
104
123
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.10.0...3.11.0)
105
124
 
106
- **Implemented enhancements:**
107
-
108
- - 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))
109
-
110
- **Merged pull requests:**
111
-
112
- - Release 3.11.0 [\#630](https://github.com/recurly/recurly-client-ruby/pull/630) ([douglasmiller](https://github.com/douglasmiller))
113
-
114
125
  ## [3.10.0](https://github.com/recurly/recurly-client-ruby/tree/3.10.0) (2020-07-31)
115
126
 
116
127
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.9.0...3.10.0)
117
128
 
118
- **Implemented enhancements:**
119
-
120
- - 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))
121
- - Adding hierarchical errors [\#610](https://github.com/recurly/recurly-client-ruby/pull/610) ([douglasmiller](https://github.com/douglasmiller))
122
-
123
- **Merged pull requests:**
124
-
125
- - Release 3.10.0 [\#623](https://github.com/recurly/recurly-client-ruby/pull/623) ([douglasmiller](https://github.com/douglasmiller))
126
-
127
129
  ## [3.9.0](https://github.com/recurly/recurly-client-ruby/tree/3.9.0) (2020-07-06)
128
130
 
129
131
  [Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.8.0...3.9.0)
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.18'
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
@@ -299,7 +316,7 @@ module Recurly
299
316
  end
300
317
 
301
318
  def interpolate_path(path, **options)
302
- validate_path_parameters!(**options)
319
+ validate_path_parameters!(options)
303
320
  options.each do |k, v|
304
321
  # We need to encode the values for the url
305
322
  options[k] = ERB::Util.url_encode(v.to_s)
@@ -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,7 +339,16 @@ module Recurly
330
339
  end
331
340
  end
332
341
 
333
- def scope_by_site(path, options)
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
+
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
336
354
  # will use the cursor returned from the API which may already have these components