recurly 3.16.0 → 4.0.1
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.
- checksums.yaml +4 -4
- data/.bumpversion.cfg +1 -1
- data/.github_changelog_generator +2 -2
- data/.travis.yml +1 -0
- data/CHANGELOG.md +144 -6
- data/GETTING_STARTED.md +20 -17
- data/lib/recurly/client.rb +41 -18
- data/lib/recurly/client/operations.rb +770 -549
- data/lib/recurly/errors.rb +5 -23
- data/lib/recurly/errors/api_errors.rb +3 -0
- data/lib/recurly/pager.rb +5 -15
- data/lib/recurly/requests/{account_acquisition_updatable.rb → account_acquisition_update.rb} +1 -1
- data/lib/recurly/requests/account_create.rb +2 -2
- data/lib/recurly/requests/account_purchase.rb +2 -2
- data/lib/recurly/requests/add_on_create.rb +2 -2
- data/lib/recurly/requests/add_on_pricing.rb +5 -1
- data/lib/recurly/requests/add_on_update.rb +2 -2
- data/lib/recurly/requests/address.rb +0 -8
- data/lib/recurly/requests/billing_info_create.rb +1 -25
- data/lib/recurly/requests/coupon_create.rb +1 -1
- data/lib/recurly/requests/coupon_redemption_create.rb +4 -0
- data/lib/recurly/requests/external_transaction.rb +1 -1
- data/lib/recurly/requests/{invoice_updatable.rb → invoice_update.rb} +1 -1
- data/lib/recurly/requests/line_item_create.rb +1 -1
- data/lib/recurly/requests/purchase_create.rb +4 -0
- data/lib/recurly/requests/subscription_add_on_create.rb +6 -2
- data/lib/recurly/requests/subscription_add_on_tier.rb +5 -1
- data/lib/recurly/requests/subscription_add_on_update.rb +6 -2
- data/lib/recurly/requests/subscription_change_create.rb +1 -1
- data/lib/recurly/requests/subscription_create.rb +7 -3
- data/lib/recurly/requests/tier.rb +2 -2
- data/lib/recurly/requests/tier_pricing.rb +22 -0
- data/lib/recurly/resources/add_on.rb +1 -1
- data/lib/recurly/resources/add_on_pricing.rb +5 -1
- data/lib/recurly/resources/address.rb +0 -8
- data/lib/recurly/resources/address_with_name.rb +46 -0
- data/lib/recurly/resources/coupon.rb +5 -17
- data/lib/recurly/resources/coupon_redemption.rb +4 -0
- data/lib/recurly/resources/invoice.rb +6 -2
- data/lib/recurly/resources/line_item.rb +4 -0
- data/lib/recurly/resources/plan.rb +1 -1
- data/lib/recurly/resources/subscription_add_on.rb +6 -2
- data/lib/recurly/resources/subscription_add_on_tier.rb +5 -1
- data/lib/recurly/resources/subscription_change.rb +0 -4
- data/lib/recurly/resources/tier.rb +2 -2
- data/lib/recurly/resources/tier_pricing.rb +22 -0
- data/lib/recurly/resources/transaction.rb +2 -2
- data/lib/recurly/resources/unique_coupon_code_params.rb +26 -0
- data/lib/recurly/resources/usage.rb +5 -1
- data/lib/recurly/version.rb +1 -1
- data/openapi/api.yaml +1896 -1846
- data/scripts/build +2 -2
- data/scripts/changelog +1 -1
- data/scripts/format +2 -2
- metadata +9 -8
- data/lib/recurly/errors/network_errors.rb +0 -10
- data/lib/recurly/resources/line_item_list.rb +0 -26
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 363aee14af2df360e4440e215556f60535e2a5293c413b37204371e46dba7f30
|
4
|
+
data.tar.gz: 83bae016d349769eebe8206f4ba8e02d2cd072c6d1fccee519054fc433bbde62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99d4ee6a951df8b4714c56c31c35b0c6ae27f29c7dc77e22a6ddd57dd743174980a280d65013350fa89c18b14523a885c56e3214ea05bdf6388c5876b3d28ec1
|
7
|
+
data.tar.gz: 96584a101083b1d7b3678bed505fd1e91bf9c1747bc9a7834467c9e7d6fb2c4f1f18ce17af4f4ff366fe5f0c32f39996f87566f7ea6c15f7c62172fe2b6d3047
|
data/.bumpversion.cfg
CHANGED
data/.github_changelog_generator
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
user=recurly
|
2
2
|
project=recurly-client-ruby
|
3
3
|
unreleased=false
|
4
|
-
exclude-labels=question,bug?,duplicate,V2
|
5
|
-
exclude-tags-regex=^[^
|
4
|
+
exclude-labels=internal,question,bug?,duplicate,V2
|
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
data/CHANGELOG.md
CHANGED
@@ -1,17 +1,147 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## [
|
3
|
+
## [4.0.1](https://github.com/recurly/recurly-client-ruby/tree/4.0.1) (2021-03-19)
|
4
4
|
|
5
|
-
[Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/
|
5
|
+
[Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/4.0.0...4.0.1)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- Release 4.0.1 [\#682](https://github.com/recurly/recurly-client-ruby/pull/682) ([douglasmiller](https://github.com/douglasmiller))
|
10
|
+
- More ruby 3.0 [\#680](https://github.com/recurly/recurly-client-ruby/pull/680) ([douglasmiller](https://github.com/douglasmiller))
|
11
|
+
- Additional fix for ruby 3.x [\#679](https://github.com/recurly/recurly-client-ruby/pull/679) ([douglasmiller](https://github.com/douglasmiller))
|
12
|
+
- Generated Latest Changes for v2021-02-25 [\#678](https://github.com/recurly/recurly-client-ruby/pull/678) ([recurly-integrations](https://github.com/recurly-integrations))
|
13
|
+
- Sync updates not ported from 3.x client [\#671](https://github.com/recurly/recurly-client-ruby/pull/671) ([douglasmiller](https://github.com/douglasmiller))
|
14
|
+
|
15
|
+
## [4.0.0](https://github.com/recurly/recurly-client-ruby/tree/4.0.0) (2021-03-01)
|
16
|
+
|
17
|
+
[Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.18.1...4.0.0)
|
18
|
+
|
19
|
+
# Major Version Release
|
20
|
+
|
21
|
+
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.
|
22
|
+
|
23
|
+
## Breaking Changes in the API
|
24
|
+
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)
|
25
|
+
|
26
|
+
## Breaking Changes in Client
|
27
|
+
|
28
|
+
- Remove `site_id` and `subdomain` from client initializer. [#624]
|
29
|
+
- Remove `set_site_id` method from client. [#627]
|
30
|
+
- Classify unexpected error responses from Recurly API via an HTTP status code mapping provided in `Recurly::Errors::ERROR_MAP`. [#616]
|
31
|
+
- 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]
|
32
|
+
|
33
|
+
### 3.x
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
rescue Recurly::Errors::ValidationError => ex
|
37
|
+
# catch a validation error
|
38
|
+
rescue Recurly::Errors::APIError => ex
|
39
|
+
# catch a generic api error
|
40
|
+
rescue Recurly::Errors::TimeoutError => ex
|
41
|
+
# catch a specific network error
|
42
|
+
```
|
43
|
+
|
44
|
+
### 4.x
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
rescue Recurly::Errors::ValidationError => ex
|
48
|
+
# catch a validation error
|
49
|
+
rescue Recurly::Errors::TimeoutError => ex
|
50
|
+
# catch a specific network error
|
51
|
+
rescue Recurly::Errors::APIError => ex
|
52
|
+
# catch a generic api error
|
53
|
+
```
|
54
|
+
|
55
|
+
- Rename `InvalidResponseError` to `InvalidContentTypeError`. [#616]
|
56
|
+
- Rename `UnavailableError` to `ServiceUnavailableError`. [#616]
|
57
|
+
- Reorganize top-level keys of the optional parameters hash to improve clarity and create space for additional options. [#619]
|
58
|
+
|
59
|
+
### 3.x
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
options = {
|
63
|
+
limit: 200,
|
64
|
+
headers: {
|
65
|
+
'Accept-Language' => 'fr'
|
66
|
+
}
|
67
|
+
}
|
68
|
+
accounts = @client.list_accounts(options)
|
69
|
+
```
|
70
|
+
|
71
|
+
### 4.x
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
options = {
|
75
|
+
params: {
|
76
|
+
limit: 200
|
77
|
+
}
|
78
|
+
headers: {
|
79
|
+
'Accept-Language' => 'fr'
|
80
|
+
}
|
81
|
+
}
|
82
|
+
accounts = @client.list_accounts(options)
|
83
|
+
```
|
6
84
|
|
7
85
|
**Implemented enhancements:**
|
8
86
|
|
9
|
-
-
|
10
|
-
|
87
|
+
- Remove site\_id and subdomain from client initializer [\#624](https://github.com/recurly/recurly-client-ruby/pull/624) ([joannasese](https://github.com/joannasese))
|
88
|
+
|
89
|
+
**Fixed bugs:**
|
90
|
+
|
91
|
+
- Every method is returning wrong number of arguments [\#664](https://github.com/recurly/recurly-client-ruby/issues/664)
|
92
|
+
|
93
|
+
**Merged pull requests:**
|
94
|
+
|
95
|
+
- Release 4.0.0 [\#669](https://github.com/recurly/recurly-client-ruby/pull/669) ([douglasmiller](https://github.com/douglasmiller))
|
96
|
+
- 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))
|
97
|
+
- Removing unused method 'set\_site\_id' [\#627](https://github.com/recurly/recurly-client-ruby/pull/627) ([douglasmiller](https://github.com/douglasmiller))
|
98
|
+
- 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))
|
99
|
+
- Updating error mapping based on status code [\#616](https://github.com/recurly/recurly-client-ruby/pull/616) ([douglasmiller](https://github.com/douglasmiller))
|
100
|
+
|
101
|
+
## [3.18.1](https://github.com/recurly/recurly-client-ruby/tree/3.18.1) (2021-02-22)
|
102
|
+
|
103
|
+
[Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.18.0...3.18.1)
|
11
104
|
|
12
105
|
**Fixed bugs:**
|
13
106
|
|
14
|
-
-
|
107
|
+
- Fixing issues with ruby 3.0 [\#665](https://github.com/recurly/recurly-client-ruby/pull/665) ([douglasmiller](https://github.com/douglasmiller))
|
108
|
+
|
109
|
+
**Merged pull requests:**
|
110
|
+
|
111
|
+
- Release 3.18.1 [\#666](https://github.com/recurly/recurly-client-ruby/pull/666) ([douglasmiller](https://github.com/douglasmiller))
|
112
|
+
|
113
|
+
## [3.18.0](https://github.com/recurly/recurly-client-ruby/tree/3.18.0) (2021-01-22)
|
114
|
+
|
115
|
+
[Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.17.0...3.18.0)
|
116
|
+
|
117
|
+
**Implemented enhancements:**
|
118
|
+
|
119
|
+
- Latest Changes for 2019-10-10 [\#660](https://github.com/recurly/recurly-client-ruby/pull/660) ([douglasmiller](https://github.com/douglasmiller))
|
120
|
+
|
121
|
+
**Merged pull requests:**
|
122
|
+
|
123
|
+
- Release 3.18.0 [\#661](https://github.com/recurly/recurly-client-ruby/pull/661) ([douglasmiller](https://github.com/douglasmiller))
|
124
|
+
|
125
|
+
## [3.17.0](https://github.com/recurly/recurly-client-ruby/tree/3.17.0) (2020-12-08)
|
126
|
+
|
127
|
+
[Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.16.0...3.17.0)
|
128
|
+
|
129
|
+
**Implemented enhancements:**
|
130
|
+
|
131
|
+
- Latest Changes for 2019-10-10 [\#657](https://github.com/recurly/recurly-client-ruby/pull/657) ([douglasmiller](https://github.com/douglasmiller))
|
132
|
+
|
133
|
+
**Merged pull requests:**
|
134
|
+
|
135
|
+
- Release 3.17.0 [\#658](https://github.com/recurly/recurly-client-ruby/pull/658) ([douglasmiller](https://github.com/douglasmiller))
|
136
|
+
|
137
|
+
## [3.16.0](https://github.com/recurly/recurly-client-ruby/tree/3.16.0) (2020-11-24)
|
138
|
+
|
139
|
+
[Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.15.0...3.16.0)
|
140
|
+
|
141
|
+
**Implemented enhancements:**
|
142
|
+
|
143
|
+
- 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))
|
144
|
+
- Latest Changes for 2019-10-10 [\#651](https://github.com/recurly/recurly-client-ruby/pull/651) ([douglasmiller](https://github.com/douglasmiller))
|
15
145
|
|
16
146
|
**Merged pull requests:**
|
17
147
|
|
@@ -324,7 +454,7 @@
|
|
324
454
|
|
325
455
|
## [3.0.0.beta.4](https://github.com/recurly/recurly-client-ruby/tree/3.0.0.beta.4) (2019-04-04)
|
326
456
|
|
327
|
-
[Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.0.0.beta.
|
457
|
+
[Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.0.0.beta.3...3.0.0.beta.4)
|
328
458
|
|
329
459
|
**Merged pull requests:**
|
330
460
|
|
@@ -337,6 +467,14 @@
|
|
337
467
|
- \[V3\] Test more versions of ruby [\#397](https://github.com/recurly/recurly-client-ruby/pull/397) ([drewish](https://github.com/drewish))
|
338
468
|
- Allow faraday 0.12 for compatibility with oauth2 gem [\#396](https://github.com/recurly/recurly-client-ruby/pull/396) ([drewish](https://github.com/drewish))
|
339
469
|
|
470
|
+
## [3.0.0.beta.3](https://github.com/recurly/recurly-client-ruby/tree/3.0.0.beta.3) (2018-08-27)
|
471
|
+
|
472
|
+
[Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.0.0.beta.2...3.0.0.beta.3)
|
473
|
+
|
474
|
+
## [3.0.0.beta.2](https://github.com/recurly/recurly-client-ruby/tree/3.0.0.beta.2) (2018-07-17)
|
475
|
+
|
476
|
+
[Full Changelog](https://github.com/recurly/recurly-client-ruby/compare/3.0.0.beta.1...3.0.0.beta.2)
|
477
|
+
|
340
478
|
|
341
479
|
|
342
480
|
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
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', '~>
|
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
|
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
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
205
|
+
All errors thrown by this library are based off of the `Recurly::Errors::APIError`. There
|
204
206
|
|
205
|
-
|
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
|
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::
|
272
|
+
And it can be captured on exceptions through the {Recurly::APIError} object:
|
270
273
|
|
271
274
|
```ruby
|
272
275
|
begin
|
data/lib/recurly/client.rb
CHANGED
@@ -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
|
-
|
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:,
|
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::
|
254
|
+
raise Recurly::Errors::InvalidContentTypeError, "Unexpected content type: #{http_response.content_type}"
|
244
255
|
end
|
245
256
|
else
|
246
257
|
Resources::Empty.new
|
@@ -255,10 +266,10 @@ module Recurly
|
|
255
266
|
error = JSONParser.parse(self, response.body)
|
256
267
|
begin
|
257
268
|
error_class = Errors::APIError.error_class(error.type)
|
258
|
-
raise error_class.new(response, error)
|
269
|
+
raise error_class.new(error.message, response, error)
|
259
270
|
rescue NameError
|
260
271
|
error_class = Errors::APIError.from_response(http_response)
|
261
|
-
raise error_class.new(response, error)
|
272
|
+
raise error_class.new("Unknown Error", response, error)
|
262
273
|
end
|
263
274
|
end
|
264
275
|
|
@@ -266,7 +277,7 @@ module Recurly
|
|
266
277
|
|
267
278
|
if error_class <= Recurly::Errors::APIError
|
268
279
|
error = Recurly::Resources::Error.new(message: "#{http_response.code}: #{http_response.message}")
|
269
|
-
raise error_class.new(response, error)
|
280
|
+
raise error_class.new(error.message, response, error)
|
270
281
|
else
|
271
282
|
raise error_class, "#{http_response.code}: #{http_response.message}"
|
272
283
|
end
|
@@ -279,6 +290,17 @@ module Recurly
|
|
279
290
|
response
|
280
291
|
end
|
281
292
|
|
293
|
+
def validate_options!(**options)
|
294
|
+
invalid_options = options.keys.reject do |k|
|
295
|
+
ALLOWED_OPTIONS.include?(k)
|
296
|
+
end
|
297
|
+
if invalid_options.any?
|
298
|
+
joinedKeys = invalid_options.join(", ")
|
299
|
+
joinedOptions = ALLOWED_OPTIONS.join(", ")
|
300
|
+
raise ArgumentError, "Invalid options: '#{joinedKeys}'. Allowed options: '#{joinedOptions}'"
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
282
304
|
def validate_path_parameters!(**options)
|
283
305
|
# Check to see that we are passing the correct data types
|
284
306
|
# This prevents a confusing error if the user passes in a non-primitive by mistake
|
@@ -299,7 +321,7 @@ module Recurly
|
|
299
321
|
end
|
300
322
|
|
301
323
|
def interpolate_path(path, **options)
|
302
|
-
validate_path_parameters!(options)
|
324
|
+
validate_path_parameters!(**options)
|
303
325
|
options.each do |k, v|
|
304
326
|
# We need to encode the values for the url
|
305
327
|
options[k] = ERB::Util.url_encode(v.to_s)
|
@@ -308,21 +330,13 @@ module Recurly
|
|
308
330
|
path % options
|
309
331
|
end
|
310
332
|
|
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
333
|
def set_api_key(api_key)
|
320
334
|
@api_key = api_key
|
321
335
|
end
|
322
336
|
|
323
337
|
def build_url(path, options)
|
324
338
|
path = scope_by_site(path, options)
|
325
|
-
query_params = options.
|
339
|
+
query_params = map_array_params(options.fetch(:params, {}))
|
326
340
|
if query_params.any?
|
327
341
|
"#{path}?#{URI.encode_www_form(query_params)}"
|
328
342
|
else
|
@@ -330,7 +344,16 @@ module Recurly
|
|
330
344
|
end
|
331
345
|
end
|
332
346
|
|
333
|
-
|
347
|
+
# Converts array parameters to CSV strings to maintain consistency with
|
348
|
+
# how the server expects the request to be formatted while providing the
|
349
|
+
# developer with an array type to maintain developer happiness!
|
350
|
+
def map_array_params(params)
|
351
|
+
params.map do |key, param|
|
352
|
+
[key, param.is_a?(Array) ? param.join(",") : param]
|
353
|
+
end.to_h
|
354
|
+
end
|
355
|
+
|
356
|
+
def scope_by_site(path, options)
|
334
357
|
if site = site_id || options[:site_id]
|
335
358
|
# Ensure that we are only including the site_id once because the Pager operations
|
336
359
|
# will use the cursor returned from the API which may already have these components
|