transferzero-sdk 1.19.2 → 1.19.5
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/README.md +4 -4
- data/docs/CurrencyExchangeAllOf.md +17 -0
- data/docs/CurrencyOppositeAllOf.md +21 -0
- data/docs/DocumentWebhookAllOf.md +17 -0
- data/docs/PayinMethod.md +1 -1
- data/docs/PayinMethodsApi.md +1 -1
- data/docs/PayoutMethodWebhookAllOf.md +17 -0
- data/docs/PayoutMethodsApi.md +1 -1
- data/docs/RecipientWebhookAllOf.md +17 -0
- data/docs/SenderWebhookAllOf.md +17 -0
- data/docs/SendersApi.md +1 -1
- data/docs/TransactionWebhookAllOf.md +17 -0
- data/lib/transferzero-sdk/api/payin_methods_api.rb +2 -2
- data/lib/transferzero-sdk/api/payout_methods_api.rb +2 -2
- data/lib/transferzero-sdk/api/senders_api.rb +2 -2
- data/lib/transferzero-sdk/api_client.rb +124 -89
- data/lib/transferzero-sdk/configuration.rb +95 -19
- data/lib/transferzero-sdk/models/currency_exchange_all_of.rb +205 -0
- data/lib/transferzero-sdk/models/currency_opposite_all_of.rb +223 -0
- data/lib/transferzero-sdk/models/document_webhook_all_of.rb +202 -0
- data/lib/transferzero-sdk/models/payin_method.rb +1 -1
- data/lib/transferzero-sdk/models/payin_method_ux_flow.rb +1 -0
- data/lib/transferzero-sdk/models/payout_method_country_enum.rb +1 -1
- data/lib/transferzero-sdk/models/payout_method_webhook_all_of.rb +202 -0
- data/lib/transferzero-sdk/models/recipient_webhook_all_of.rb +202 -0
- data/lib/transferzero-sdk/models/sender_webhook_all_of.rb +202 -0
- data/lib/transferzero-sdk/models/transaction_webhook_all_of.rb +202 -0
- data/lib/transferzero-sdk/version.rb +1 -1
- data/spec/models/currency_exchange_all_of_spec.rb +41 -0
- data/spec/models/currency_opposite_all_of_spec.rb +53 -0
- data/spec/models/document_webhook_all_of_spec.rb +41 -0
- data/spec/models/payout_method_webhook_all_of_spec.rb +41 -0
- data/spec/models/recipient_webhook_all_of_spec.rb +41 -0
- data/spec/models/sender_webhook_all_of_spec.rb +41 -0
- data/spec/models/transaction_webhook_all_of_spec.rb +41 -0
- data/transferzero-sdk-1.19.2.gem +0 -0
- data/transferzero-sdk-1.19.3.gem +0 -0
- data/transferzero-sdk-1.19.4.gem +0 -0
- data/transferzero-sdk.gemspec +2 -8
- metadata +40 -123
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 711cab66de6f674b4c8a26cb49d592b823b1157823780e44d17dd86cb3c4f1e2
|
4
|
+
data.tar.gz: c8cbfdc26f64b1d8e76974cfce5f6b136ea027b2cd01bbff5d52294b8b8878cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7195f09b3c82779a5c741bf583c5d007d270c065b3175469a7f5e1e07be4972c55bef885efafc99a6382bbada07a8677bcd22fc542ed27cf9cf2e6ba6828ad58
|
7
|
+
data.tar.gz: 86661a8a92640e8b76f6aa4a2291d145632cf8d76d8b322cc9bc0fc1b4a47000fec36acc0a0b49e616bf64cad80aa74075363928711fe05b6e3c948b054c8810
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@ Reference documentation for the TransferZero API V1
|
|
7
7
|
This SDK is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
8
8
|
|
9
9
|
- API version: 1.0
|
10
|
-
- Package version: 1.19.
|
10
|
+
- Package version: 1.19.5
|
11
11
|
- Build package: org.openapitools.codegen.languages.RubyClientCodegen
|
12
12
|
|
13
13
|
For more information, please visit:
|
@@ -31,15 +31,15 @@ gem build transferzero-sdk.gemspec
|
|
31
31
|
Then either install the gem locally:
|
32
32
|
|
33
33
|
```shell
|
34
|
-
gem install ./transferzero-sdk-1.19.
|
34
|
+
gem install ./transferzero-sdk-1.19.5.gem
|
35
35
|
```
|
36
|
-
(for development, run `gem install --dev ./transferzero-sdk-1.19.
|
36
|
+
(for development, run `gem install --dev ./transferzero-sdk-1.19.5.gem` to install the development dependencies)
|
37
37
|
|
38
38
|
or publish the gem to a gem hosting service, e.g. [RubyGems](https://rubygems.org/).
|
39
39
|
|
40
40
|
Finally add this to the Gemfile:
|
41
41
|
|
42
|
-
gem 'transferzero-sdk', '~> 1.19.
|
42
|
+
gem 'transferzero-sdk', '~> 1.19.5'
|
43
43
|
|
44
44
|
### Install from Git
|
45
45
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# TransferZero::CurrencyExchangeAllOf
|
2
|
+
|
3
|
+
## Properties
|
4
|
+
|
5
|
+
Name | Type | Description | Notes
|
6
|
+
------------ | ------------- | ------------- | -------------
|
7
|
+
**opposites** | [**Array<CurrencyOpposite>**](CurrencyOpposite.md) | Lists the currencies where you can exchange from this one | [optional]
|
8
|
+
|
9
|
+
## Code Sample
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'TransferZero'
|
13
|
+
|
14
|
+
instance = TransferZero::CurrencyExchangeAllOf.new(opposites: null)
|
15
|
+
```
|
16
|
+
|
17
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# TransferZero::CurrencyOppositeAllOf
|
2
|
+
|
3
|
+
## Properties
|
4
|
+
|
5
|
+
Name | Type | Description | Notes
|
6
|
+
------------ | ------------- | ------------- | -------------
|
7
|
+
**rate** | **Float** | The rate of this particular currency with the base one | [optional]
|
8
|
+
**mtm_rate** | **Float** | Mark to market rate of this particular currency against the base one with the margin factored in | [optional]
|
9
|
+
**margin** | **String** | The margin set for transactions of this particular currency with the base one | [optional]
|
10
|
+
|
11
|
+
## Code Sample
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'TransferZero'
|
15
|
+
|
16
|
+
instance = TransferZero::CurrencyOppositeAllOf.new(rate: null,
|
17
|
+
mtm_rate: null,
|
18
|
+
margin: null)
|
19
|
+
```
|
20
|
+
|
21
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# TransferZero::DocumentWebhookAllOf
|
2
|
+
|
3
|
+
## Properties
|
4
|
+
|
5
|
+
Name | Type | Description | Notes
|
6
|
+
------------ | ------------- | ------------- | -------------
|
7
|
+
**object** | [**Document**](Document.md) | | [optional]
|
8
|
+
|
9
|
+
## Code Sample
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'TransferZero'
|
13
|
+
|
14
|
+
instance = TransferZero::DocumentWebhookAllOf.new(object: null)
|
15
|
+
```
|
16
|
+
|
17
|
+
|
data/docs/PayinMethod.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Name | Type | Description | Notes
|
6
6
|
------------ | ------------- | ------------- | -------------
|
7
|
-
**type** | **String** | Describes how the payment should be requested from the sender. Possible values: - `GHS::Mobile`: GHS mobile collections - `UGX::Mobile`: UGX mobile collections - `EUR::Bank`: EUR IBAN collections - `GBP::Bank`: GBP IBAN collections | [optional]
|
7
|
+
**type** | **String** | Describes how the payment should be requested from the sender. Possible values: - `GHS::Mobile`: GHS mobile collections - `UGX::Mobile`: UGX mobile collections - `XOF::Mobile`: XOF mobile collections - `EUR::Bank`: EUR IBAN collections - `GBP::Bank`: GBP IBAN collections | [optional]
|
8
8
|
**ux_flow** | [**PayinMethodUxFlow**](PayinMethodUxFlow.md) | | [optional]
|
9
9
|
**in_details** | [**PayinMethodDetails**](PayinMethodDetails.md) | | [optional]
|
10
10
|
**id** | **String** | | [optional]
|
data/docs/PayinMethodsApi.md
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# TransferZero::PayoutMethodWebhookAllOf
|
2
|
+
|
3
|
+
## Properties
|
4
|
+
|
5
|
+
Name | Type | Description | Notes
|
6
|
+
------------ | ------------- | ------------- | -------------
|
7
|
+
**object** | [**PayoutMethod**](PayoutMethod.md) | | [optional]
|
8
|
+
|
9
|
+
## Code Sample
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'TransferZero'
|
13
|
+
|
14
|
+
instance = TransferZero::PayoutMethodWebhookAllOf.new(object: null)
|
15
|
+
```
|
16
|
+
|
17
|
+
|
data/docs/PayoutMethodsApi.md
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# TransferZero::RecipientWebhookAllOf
|
2
|
+
|
3
|
+
## Properties
|
4
|
+
|
5
|
+
Name | Type | Description | Notes
|
6
|
+
------------ | ------------- | ------------- | -------------
|
7
|
+
**object** | [**Recipient**](Recipient.md) | | [optional]
|
8
|
+
|
9
|
+
## Code Sample
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'TransferZero'
|
13
|
+
|
14
|
+
instance = TransferZero::RecipientWebhookAllOf.new(object: null)
|
15
|
+
```
|
16
|
+
|
17
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# TransferZero::SenderWebhookAllOf
|
2
|
+
|
3
|
+
## Properties
|
4
|
+
|
5
|
+
Name | Type | Description | Notes
|
6
|
+
------------ | ------------- | ------------- | -------------
|
7
|
+
**object** | [**Sender**](Sender.md) | | [optional]
|
8
|
+
|
9
|
+
## Code Sample
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'TransferZero'
|
13
|
+
|
14
|
+
instance = TransferZero::SenderWebhookAllOf.new(object: null)
|
15
|
+
```
|
16
|
+
|
17
|
+
|
data/docs/SendersApi.md
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# TransferZero::TransactionWebhookAllOf
|
2
|
+
|
3
|
+
## Properties
|
4
|
+
|
5
|
+
Name | Type | Description | Notes
|
6
|
+
------------ | ------------- | ------------- | -------------
|
7
|
+
**object** | [**Transaction**](Transaction.md) | | [optional]
|
8
|
+
|
9
|
+
## Code Sample
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require 'TransferZero'
|
13
|
+
|
14
|
+
instance = TransferZero::TransactionWebhookAllOf.new(object: null)
|
15
|
+
```
|
16
|
+
|
17
|
+
|
@@ -130,7 +130,7 @@ module TransferZero
|
|
130
130
|
|
131
131
|
|
132
132
|
# Updating a payin method
|
133
|
-
# Updates
|
133
|
+
# Updates a single payin method by the Payin Method ID
|
134
134
|
# @param payin_method_id ID of the payin method to get. Example: `/v1/payin_methods/bf9ff782-e182-45ac-abea-5bce83ad6670`
|
135
135
|
# @param payin_method
|
136
136
|
# @param [Hash] opts the optional parameters
|
@@ -141,7 +141,7 @@ module TransferZero
|
|
141
141
|
end
|
142
142
|
|
143
143
|
# Updating a payin method
|
144
|
-
# Updates
|
144
|
+
# Updates a single payin method by the Payin Method ID
|
145
145
|
# @param payin_method_id ID of the payin method to get. Example: `/v1/payin_methods/bf9ff782-e182-45ac-abea-5bce83ad6670`
|
146
146
|
# @param payin_method
|
147
147
|
# @param [Hash] opts the optional parameters
|
@@ -202,7 +202,7 @@ module TransferZero
|
|
202
202
|
|
203
203
|
|
204
204
|
# Updating a payout method
|
205
|
-
# Updates
|
205
|
+
# Updates a single payout method by the Payout Method ID
|
206
206
|
# @param payout_method_id ID of the payout method to get. Example: `/v1/payout_methods/bf9ff782-e182-45ac-abea-5bce83ad6670`
|
207
207
|
# @param payout_method
|
208
208
|
# @param [Hash] opts the optional parameters
|
@@ -213,7 +213,7 @@ module TransferZero
|
|
213
213
|
end
|
214
214
|
|
215
215
|
# Updating a payout method
|
216
|
-
# Updates
|
216
|
+
# Updates a single payout method by the Payout Method ID
|
217
217
|
# @param payout_method_id ID of the payout method to get. Example: `/v1/payout_methods/bf9ff782-e182-45ac-abea-5bce83ad6670`
|
218
218
|
# @param payout_method
|
219
219
|
# @param [Hash] opts the optional parameters
|
@@ -203,7 +203,7 @@ module TransferZero
|
|
203
203
|
|
204
204
|
|
205
205
|
# Updating a sender
|
206
|
-
# Updates
|
206
|
+
# Updates a single sender by the Sender ID
|
207
207
|
# @param sender_id ID of the sender to get. Example: `/v1/senders/bf9ff782-e182-45ac-abea-5bce83ad6670`
|
208
208
|
# @param sender_request
|
209
209
|
# @param [Hash] opts the optional parameters
|
@@ -214,7 +214,7 @@ module TransferZero
|
|
214
214
|
end
|
215
215
|
|
216
216
|
# Updating a sender
|
217
|
-
# Updates
|
217
|
+
# Updates a single sender by the Sender ID
|
218
218
|
# @param sender_id ID of the sender to get. Example: `/v1/senders/bf9ff782-e182-45ac-abea-5bce83ad6670`
|
219
219
|
# @param sender_request
|
220
220
|
# @param [Hash] opts the optional parameters
|
@@ -14,7 +14,8 @@ require 'date'
|
|
14
14
|
require 'json'
|
15
15
|
require 'logger'
|
16
16
|
require 'tempfile'
|
17
|
-
require '
|
17
|
+
require 'time'
|
18
|
+
require 'faraday'
|
18
19
|
require 'uri'
|
19
20
|
require 'openssl'
|
20
21
|
require 'securerandom'
|
@@ -35,7 +36,7 @@ module TransferZero
|
|
35
36
|
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
36
37
|
def initialize(config = Configuration.default)
|
37
38
|
@config = config
|
38
|
-
@user_agent = "TransferZero-SDK/Ruby/1.19.
|
39
|
+
@user_agent = "TransferZero-SDK/Ruby/1.19.5"
|
39
40
|
@default_headers = {
|
40
41
|
'Content-Type' => 'application/json',
|
41
42
|
'User-Agent' => @user_agent
|
@@ -51,33 +52,51 @@ module TransferZero
|
|
51
52
|
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
52
53
|
# the data deserialized from response body (could be nil), response status code and response headers.
|
53
54
|
def call_api(http_method, path, opts = {})
|
54
|
-
|
55
|
-
|
55
|
+
ssl_options = {
|
56
|
+
:ca_file => @config.ssl_ca_file,
|
57
|
+
:verify => @config.ssl_verify,
|
58
|
+
:verify_mode => @config.ssl_verify_mode,
|
59
|
+
:client_cert => @config.ssl_client_cert,
|
60
|
+
:client_key => @config.ssl_client_key
|
61
|
+
}
|
56
62
|
|
57
|
-
|
58
|
-
|
63
|
+
connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn|
|
64
|
+
if opts[:header_params]["Content-Type"] == "multipart/form-data"
|
65
|
+
conn.request :multipart
|
66
|
+
conn.request :url_encoded
|
67
|
+
end
|
68
|
+
conn.adapter(Faraday.default_adapter)
|
59
69
|
end
|
60
70
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
71
|
+
begin
|
72
|
+
response = connection.public_send(http_method.to_sym.downcase) do |req|
|
73
|
+
build_request(http_method, path, req, opts)
|
74
|
+
end
|
75
|
+
|
76
|
+
if @config.debugging
|
77
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
78
|
+
end
|
79
|
+
|
80
|
+
unless response.success?
|
81
|
+
if response.status == 0 || response.status.nil?
|
82
|
+
# Errors from libcurl will be made visible here
|
83
|
+
fail ApiError.new(:code => 0,
|
84
|
+
:message => response.return_message)
|
85
|
+
elsif response.status == 422
|
86
|
+
fail ApiError.new(:code => response.status,
|
87
|
+
:response_headers => response.headers,
|
88
|
+
:response_body => response.body,
|
89
|
+
:validation_error => true
|
90
|
+
)
|
91
|
+
else
|
92
|
+
fail ApiError.new(:code => response.status,
|
93
|
+
:response_headers => response.headers,
|
94
|
+
:response_body => response.body),
|
95
|
+
response.reason_phrase
|
96
|
+
end
|
80
97
|
end
|
98
|
+
rescue Faraday::TimeoutError
|
99
|
+
fail ApiError.new('Connection timed out')
|
81
100
|
end
|
82
101
|
|
83
102
|
if opts[:return_type]
|
@@ -85,7 +104,7 @@ module TransferZero
|
|
85
104
|
else
|
86
105
|
data = nil
|
87
106
|
end
|
88
|
-
return data, response.
|
107
|
+
return data, response.status, response.headers
|
89
108
|
end
|
90
109
|
|
91
110
|
# Builds the HTTP request
|
@@ -97,57 +116,49 @@ module TransferZero
|
|
97
116
|
# @option opts [Hash] :form_params Query parameters
|
98
117
|
# @option opts [Object] :body HTTP body (JSON/XML)
|
99
118
|
# @return [Typhoeus::Request] A Typhoeus Request
|
100
|
-
def build_request(http_method, path, opts = {})
|
101
|
-
url = build_request_url(path)
|
119
|
+
def build_request(http_method, path, request, opts = {})
|
120
|
+
url = build_request_url(path, opts)
|
102
121
|
http_method = http_method.to_sym.downcase
|
103
122
|
|
104
123
|
header_params = @default_headers.merge(opts[:header_params] || {})
|
105
124
|
query_params = opts[:query_params] || {}
|
106
|
-
url_with_params = add_query(url, query_params)
|
107
125
|
form_params = opts[:form_params] || {}
|
108
|
-
|
109
|
-
request_body = opts[:body].to_s.gsub(/[[:space:]]+/, ' ').strip
|
110
|
-
|
111
|
-
request_nonce = SecureRandom.uuid
|
112
|
-
request_signature = sign_request([
|
113
|
-
request_nonce,
|
114
|
-
http_method.to_s.upcase,
|
115
|
-
url_with_params,
|
116
|
-
DIGEST.hexdigest(request_body)
|
117
|
-
])
|
118
|
-
|
119
|
-
header_params['Authorization-Nonce'] = request_nonce
|
120
|
-
header_params['Authorization-Signature'] = request_signature
|
121
|
-
header_params['Authorization-Key'] = @config.api_key
|
122
|
-
|
123
|
-
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
124
|
-
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
126
|
+
url_with_params = add_query(url, query_params)
|
125
127
|
|
126
128
|
req_opts = {
|
127
129
|
:method => http_method,
|
128
130
|
:headers => header_params,
|
129
|
-
:params =>
|
131
|
+
:params => query_params,
|
130
132
|
:params_encoding => @config.params_encoding,
|
131
133
|
:timeout => @config.timeout,
|
132
|
-
:ssl_verifypeer => @config.verify_ssl,
|
133
|
-
:ssl_verifyhost => _verify_ssl_host,
|
134
|
-
:sslcert => @config.cert_file,
|
135
|
-
:sslkey => @config.key_file,
|
136
134
|
:verbose => @config.debugging
|
137
135
|
}
|
138
136
|
|
139
|
-
|
140
|
-
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
141
|
-
|
137
|
+
req_body = ''
|
142
138
|
if [:post, :patch, :put, :delete].include?(http_method)
|
143
|
-
req_body = build_request_body(header_params, form_params,
|
139
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
144
140
|
req_opts.update :body => req_body
|
145
141
|
if @config.debugging
|
146
142
|
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
147
143
|
end
|
148
144
|
end
|
149
145
|
|
150
|
-
|
146
|
+
request_nonce = SecureRandom.uuid
|
147
|
+
request_signature = sign_request([
|
148
|
+
request_nonce,
|
149
|
+
http_method.to_s.upcase,
|
150
|
+
url_with_params,
|
151
|
+
DIGEST.hexdigest(req_body)
|
152
|
+
])
|
153
|
+
|
154
|
+
header_params['Authorization-Nonce'] = request_nonce
|
155
|
+
header_params['Authorization-Signature'] = request_signature
|
156
|
+
header_params['Authorization-Key'] = @config.api_key
|
157
|
+
|
158
|
+
request.headers = header_params
|
159
|
+
request.body = req_body
|
160
|
+
request.url url
|
161
|
+
request.params = query_params
|
151
162
|
download_file(request) if opts[:return_type] == 'File'
|
152
163
|
request
|
153
164
|
end
|
@@ -214,7 +225,25 @@ module TransferZero
|
|
214
225
|
|
215
226
|
# handle file downloading - return the File instance processed in request callbacks
|
216
227
|
# note that response body is empty when the file is written in chunks in request on_body callback
|
217
|
-
|
228
|
+
if return_type == 'File'
|
229
|
+
content_disposition = response.headers['Content-Disposition']
|
230
|
+
if content_disposition && content_disposition =~ /filename=/i
|
231
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
232
|
+
prefix = sanitize_filename(filename)
|
233
|
+
else
|
234
|
+
prefix = 'download-'
|
235
|
+
end
|
236
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
237
|
+
encoding = body.encoding
|
238
|
+
@tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
239
|
+
@tempfile.write(@stream.join.force_encoding(encoding))
|
240
|
+
@tempfile.close
|
241
|
+
@config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
|
242
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
243
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
244
|
+
"explicitly with `tempfile.delete`"
|
245
|
+
return @tempfile
|
246
|
+
end
|
218
247
|
|
219
248
|
return nil if body.nil? || body.empty?
|
220
249
|
|
@@ -281,39 +310,45 @@ module TransferZero
|
|
281
310
|
end
|
282
311
|
end
|
283
312
|
|
284
|
-
|
285
|
-
#
|
286
|
-
# The response body is written to the file in chunks in order to handle files which
|
287
|
-
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
288
|
-
# process can use.
|
313
|
+
|
314
|
+
# Builds the HTTP request body
|
289
315
|
#
|
290
|
-
# @
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
316
|
+
# @param [Hash] header_params Header parameters
|
317
|
+
# @param [Hash] form_params Query parameters
|
318
|
+
# @param [Object] body HTTP body (JSON/XML)
|
319
|
+
# @return [String] HTTP body data in the form of string
|
320
|
+
def build_request_body(header_params, form_params, body)
|
321
|
+
# http form
|
322
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
|
323
|
+
data = URI.encode_www_form(form_params)
|
324
|
+
elsif header_params['Content-Type'] == 'multipart/form-data'
|
325
|
+
data = {}
|
326
|
+
form_params.each do |key, value|
|
327
|
+
case value
|
328
|
+
when ::File, ::Tempfile
|
329
|
+
# TODO hardcode to application/octet-stream, need better way to detect content type
|
330
|
+
data[key] = Faraday::UploadIO.new(value.path, 'application/octet-stream', value.path)
|
331
|
+
when ::Array, nil
|
332
|
+
# let Faraday handle Array and nil parameters
|
333
|
+
data[key] = value
|
334
|
+
else
|
335
|
+
data[key] = value.to_s
|
336
|
+
end
|
301
337
|
end
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
end
|
307
|
-
request.on_body do |chunk|
|
308
|
-
chunk.force_encoding(encoding)
|
309
|
-
tempfile.write(chunk)
|
338
|
+
elsif body
|
339
|
+
data = body.is_a?(String) ? body : body.to_json
|
340
|
+
else
|
341
|
+
data = nil
|
310
342
|
end
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
343
|
+
data
|
344
|
+
end
|
345
|
+
|
346
|
+
def download_file(request)
|
347
|
+
@stream = []
|
348
|
+
|
349
|
+
# handle streaming Responses
|
350
|
+
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
|
351
|
+
@stream << chunk
|
317
352
|
end
|
318
353
|
end
|
319
354
|
|
@@ -326,10 +361,10 @@ module TransferZero
|
|
326
361
|
filename.gsub(/.*[\/\\]/, '')
|
327
362
|
end
|
328
363
|
|
329
|
-
def build_request_url(path)
|
364
|
+
def build_request_url(path, opts = {})
|
330
365
|
# Add leading and trailing slashes to path
|
331
366
|
path = "/#{path}".gsub(/\/+/, '/')
|
332
|
-
|
367
|
+
@config.base_url(opts[:operation]) + path
|
333
368
|
end
|
334
369
|
|
335
370
|
# Builds the HTTP request body
|