yapstone-payments 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +79 -0
- data/README.md +203 -0
- data/Rakefile +10 -0
- data/docs/APM.md +29 -0
- data/docs/APMSpecInParameters.md +19 -0
- data/docs/Action.md +16 -0
- data/docs/Address.md +29 -0
- data/docs/Amount.md +21 -0
- data/docs/AuthResponse.md +19 -0
- data/docs/AuthTokenRequest.md +19 -0
- data/docs/AuthTokenResponse.md +17 -0
- data/docs/AuthenticationApi.md +58 -0
- data/docs/BankAccount.md +37 -0
- data/docs/BillingAddress.md +29 -0
- data/docs/BookingInfo.md +31 -0
- data/docs/CapturePaymentRequest.md +21 -0
- data/docs/Card.md +27 -0
- data/docs/CardResponse.md +21 -0
- data/docs/Consent.md +21 -0
- data/docs/CreditCardAuthResponse.md +25 -0
- data/docs/Customer.md +29 -0
- data/docs/CustomerData.md +19 -0
- data/docs/CustomerDetails.md +23 -0
- data/docs/Deposit.md +23 -0
- data/docs/DepositDetails.md +17 -0
- data/docs/DisburseLineItemsReq.md +19 -0
- data/docs/DisburseTransaction.md +19 -0
- data/docs/DisburseTransactionReq.md +17 -0
- data/docs/Disbursement.md +17 -0
- data/docs/DisbursementAllOf.md +17 -0
- data/docs/DisbursementDetails.md +17 -0
- data/docs/DisbursementRequest.md +16 -0
- data/docs/DisbursementRequests.md +17 -0
- data/docs/DisbursementResponse.md +17 -0
- data/docs/DisbursementsApi.md +138 -0
- data/docs/Error.md +25 -0
- data/docs/ErrorResponse.md +19 -0
- data/docs/Fields.md +17 -0
- data/docs/GovIdentification.md +29 -0
- data/docs/Guest.md +29 -0
- data/docs/GuestInfoResponse.md +19 -0
- data/docs/Href.md +17 -0
- data/docs/InlineResponse200.md +25 -0
- data/docs/InstallmentPlan.md +19 -0
- data/docs/Instrument.md +21 -0
- data/docs/InstrumentVerificationResponse.md +31 -0
- data/docs/KYC.md +21 -0
- data/docs/LeaseInfo.md +21 -0
- data/docs/LineItemDetails.md +25 -0
- data/docs/MarketplaceData.md +23 -0
- data/docs/Merketplace.md +17 -0
- data/docs/Money.md +19 -0
- data/docs/Name.md +27 -0
- data/docs/OfferingDetails.md +21 -0
- data/docs/OrderTransactions.md +25 -0
- data/docs/Payment.md +21 -0
- data/docs/PaymentCancelResponse.md +23 -0
- data/docs/PaymentCancelTransactionResponse.md +21 -0
- data/docs/PaymentDetails.md +29 -0
- data/docs/PaymentInstrument.md +27 -0
- data/docs/PaymentInstrumentCard.md +19 -0
- data/docs/PaymentInstrumentResponse.md +19 -0
- data/docs/PaymentPayment.md +27 -0
- data/docs/PaymentPaymentAllOf.md +27 -0
- data/docs/PaymentResponse.md +33 -0
- data/docs/PaymentsApi.md +447 -0
- data/docs/Phone.md +21 -0
- data/docs/ProcessPayment.md +29 -0
- data/docs/PropertyInfo.md +21 -0
- data/docs/PropertyInfoResponse.md +19 -0
- data/docs/RefundAction.md +16 -0
- data/docs/RefundCancelResponse.md +21 -0
- data/docs/RefundCancelTransactionResponse.md +19 -0
- data/docs/RefundRequest.md +25 -0
- data/docs/RefundResponse.md +29 -0
- data/docs/RefundStatus.md +16 -0
- data/docs/RefundTransactions.md +27 -0
- data/docs/RefundsApi.md +378 -0
- data/docs/RentalInfo.md +21 -0
- data/docs/Renter.md +29 -0
- data/docs/Resolution.md +17 -0
- data/docs/Result.md +21 -0
- data/docs/RiskStatus.md +17 -0
- data/docs/SanctionedEntities.md +19 -0
- data/docs/SearchApi.md +132 -0
- data/docs/SearchPaymentResponse.md +17 -0
- data/docs/StackTraceElement.md +25 -0
- data/docs/Status.md +16 -0
- data/docs/Throwable.md +21 -0
- data/docs/ToEntityRef.md +19 -0
- data/docs/Token.md +19 -0
- data/docs/TokenApi.md +134 -0
- data/docs/TokenReq.md +19 -0
- data/docs/TokenRequest.md +17 -0
- data/docs/TokenResponse.md +17 -0
- data/docs/Transaction.md +21 -0
- data/docs/TransactionResponse.md +27 -0
- data/docs/Triggers.md +21 -0
- data/docs/VacationRentalInfo.md +19 -0
- data/docs/VacationRentalInfoRequest.md +21 -0
- data/docs/VerifyInstrumentRequest.md +21 -0
- data/git_push.sh +55 -0
- data/lib/yapstone-payments.rb +137 -0
- data/lib/yapstone-payments/api/authentication_api.rb +92 -0
- data/lib/yapstone-payments/api/disbursements_api.rb +202 -0
- data/lib/yapstone-payments/api/payments_api.rb +598 -0
- data/lib/yapstone-payments/api/refunds_api.rb +507 -0
- data/lib/yapstone-payments/api/search_api.rb +187 -0
- data/lib/yapstone-payments/api/token_api.rb +182 -0
- data/lib/yapstone-payments/api_client.rb +386 -0
- data/lib/yapstone-payments/api_error.rb +57 -0
- data/lib/yapstone-payments/configuration.rb +249 -0
- data/lib/yapstone-payments/models/action.rb +39 -0
- data/lib/yapstone-payments/models/address.rb +258 -0
- data/lib/yapstone-payments/models/amount.rb +218 -0
- data/lib/yapstone-payments/models/apm.rb +292 -0
- data/lib/yapstone-payments/models/apm_spec_in_parameters.rb +208 -0
- data/lib/yapstone-payments/models/auth_response.rb +217 -0
- data/lib/yapstone-payments/models/auth_token_request.rb +205 -0
- data/lib/yapstone-payments/models/auth_token_response.rb +196 -0
- data/lib/yapstone-payments/models/bank_account.rb +347 -0
- data/lib/yapstone-payments/models/billing_address.rb +258 -0
- data/lib/yapstone-payments/models/booking_info.rb +266 -0
- data/lib/yapstone-payments/models/capture_payment_request.rb +252 -0
- data/lib/yapstone-payments/models/card.rb +247 -0
- data/lib/yapstone-payments/models/card_response.rb +217 -0
- data/lib/yapstone-payments/models/consent.rb +248 -0
- data/lib/yapstone-payments/models/credit_card_auth_response.rb +267 -0
- data/lib/yapstone-payments/models/customer.rb +256 -0
- data/lib/yapstone-payments/models/customer_data.rb +208 -0
- data/lib/yapstone-payments/models/customer_details.rb +226 -0
- data/lib/yapstone-payments/models/deposit.rb +228 -0
- data/lib/yapstone-payments/models/deposit_details.rb +199 -0
- data/lib/yapstone-payments/models/disburse_line_items_req.rb +208 -0
- data/lib/yapstone-payments/models/disburse_transaction.rb +208 -0
- data/lib/yapstone-payments/models/disburse_transaction_req.rb +199 -0
- data/lib/yapstone-payments/models/disbursement.rb +203 -0
- data/lib/yapstone-payments/models/disbursement_all_of.rb +197 -0
- data/lib/yapstone-payments/models/disbursement_details.rb +200 -0
- data/lib/yapstone-payments/models/disbursement_request.rb +187 -0
- data/lib/yapstone-payments/models/disbursement_requests.rb +198 -0
- data/lib/yapstone-payments/models/disbursement_response.rb +198 -0
- data/lib/yapstone-payments/models/error.rb +241 -0
- data/lib/yapstone-payments/models/error_response.rb +218 -0
- data/lib/yapstone-payments/models/fields.rb +196 -0
- data/lib/yapstone-payments/models/gov_identification.rb +292 -0
- data/lib/yapstone-payments/models/guest.rb +257 -0
- data/lib/yapstone-payments/models/guest_info_response.rb +208 -0
- data/lib/yapstone-payments/models/href.rb +196 -0
- data/lib/yapstone-payments/models/inline_response200.rb +232 -0
- data/lib/yapstone-payments/models/installment_plan.rb +208 -0
- data/lib/yapstone-payments/models/instrument.rb +250 -0
- data/lib/yapstone-payments/models/instrument_verification_response.rb +260 -0
- data/lib/yapstone-payments/models/kyc.rb +215 -0
- data/lib/yapstone-payments/models/lease_info.rb +218 -0
- data/lib/yapstone-payments/models/line_item_details.rb +236 -0
- data/lib/yapstone-payments/models/marketplace_data.rb +260 -0
- data/lib/yapstone-payments/models/merketplace.rb +197 -0
- data/lib/yapstone-payments/models/money.rb +207 -0
- data/lib/yapstone-payments/models/name.rb +248 -0
- data/lib/yapstone-payments/models/offering_details.rb +216 -0
- data/lib/yapstone-payments/models/order_transactions.rb +235 -0
- data/lib/yapstone-payments/models/payment.rb +216 -0
- data/lib/yapstone-payments/models/payment_cancel_response.rb +227 -0
- data/lib/yapstone-payments/models/payment_cancel_transaction_response.rb +218 -0
- data/lib/yapstone-payments/models/payment_details.rb +319 -0
- data/lib/yapstone-payments/models/payment_instrument.rb +277 -0
- data/lib/yapstone-payments/models/payment_instrument_card.rb +241 -0
- data/lib/yapstone-payments/models/payment_instrument_response.rb +205 -0
- data/lib/yapstone-payments/models/payment_payment.rb +257 -0
- data/lib/yapstone-payments/models/payment_payment_all_of.rb +250 -0
- data/lib/yapstone-payments/models/payment_response.rb +275 -0
- data/lib/yapstone-payments/models/phone.rb +218 -0
- data/lib/yapstone-payments/models/process_payment.rb +304 -0
- data/lib/yapstone-payments/models/property_info.rb +216 -0
- data/lib/yapstone-payments/models/property_info_response.rb +207 -0
- data/lib/yapstone-payments/models/refund_action.rb +35 -0
- data/lib/yapstone-payments/models/refund_cancel_response.rb +217 -0
- data/lib/yapstone-payments/models/refund_cancel_transaction_response.rb +207 -0
- data/lib/yapstone-payments/models/refund_request.rb +285 -0
- data/lib/yapstone-payments/models/refund_response.rb +253 -0
- data/lib/yapstone-payments/models/refund_status.rb +90 -0
- data/lib/yapstone-payments/models/refund_transactions.rb +245 -0
- data/lib/yapstone-payments/models/rental_info.rb +215 -0
- data/lib/yapstone-payments/models/renter.rb +254 -0
- data/lib/yapstone-payments/models/resolution.rb +196 -0
- data/lib/yapstone-payments/models/result.rb +218 -0
- data/lib/yapstone-payments/models/risk_status.rb +196 -0
- data/lib/yapstone-payments/models/sanctioned_entities.rb +207 -0
- data/lib/yapstone-payments/models/search_payment_response.rb +196 -0
- data/lib/yapstone-payments/models/stack_trace_element.rb +238 -0
- data/lib/yapstone-payments/models/status.rb +91 -0
- data/lib/yapstone-payments/models/throwable.rb +220 -0
- data/lib/yapstone-payments/models/to_entity_ref.rb +207 -0
- data/lib/yapstone-payments/models/token.rb +207 -0
- data/lib/yapstone-payments/models/token_req.rb +206 -0
- data/lib/yapstone-payments/models/token_request.rb +196 -0
- data/lib/yapstone-payments/models/token_response.rb +196 -0
- data/lib/yapstone-payments/models/transaction.rb +218 -0
- data/lib/yapstone-payments/models/transaction_response.rb +248 -0
- data/lib/yapstone-payments/models/triggers.rb +216 -0
- data/lib/yapstone-payments/models/vacation_rental_info.rb +205 -0
- data/lib/yapstone-payments/models/vacation_rental_info_request.rb +215 -0
- data/lib/yapstone-payments/models/verify_instrument_request.rb +215 -0
- data/lib/yapstone-payments/version.rb +15 -0
- data/spec/api/authentication_api_spec.rb +48 -0
- data/spec/api/disbursements_api_spec.rb +69 -0
- data/spec/api/payments_api_spec.rb +146 -0
- data/spec/api/refunds_api_spec.rb +127 -0
- data/spec/api/search_api_spec.rb +66 -0
- data/spec/api/token_api_spec.rb +67 -0
- data/spec/api_client_spec.rb +226 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/action_spec.rb +35 -0
- data/spec/models/address_spec.rb +77 -0
- data/spec/models/amount_spec.rb +53 -0
- data/spec/models/apm_spec.rb +81 -0
- data/spec/models/apm_spec_in_parameters_spec.rb +47 -0
- data/spec/models/auth_response_spec.rb +47 -0
- data/spec/models/auth_token_request_spec.rb +47 -0
- data/spec/models/auth_token_response_spec.rb +41 -0
- data/spec/models/bank_account_spec.rb +105 -0
- data/spec/models/billing_address_spec.rb +77 -0
- data/spec/models/booking_info_spec.rb +83 -0
- data/spec/models/capture_payment_request_spec.rb +57 -0
- data/spec/models/card_response_spec.rb +53 -0
- data/spec/models/card_spec.rb +71 -0
- data/spec/models/consent_spec.rb +57 -0
- data/spec/models/credit_card_auth_response_spec.rb +69 -0
- data/spec/models/customer_data_spec.rb +47 -0
- data/spec/models/customer_details_spec.rb +59 -0
- data/spec/models/customer_spec.rb +77 -0
- data/spec/models/deposit_details_spec.rb +41 -0
- data/spec/models/deposit_spec.rb +59 -0
- data/spec/models/disburse_line_items_req_spec.rb +47 -0
- data/spec/models/disburse_transaction_req_spec.rb +41 -0
- data/spec/models/disburse_transaction_spec.rb +47 -0
- data/spec/models/disbursement_all_of_spec.rb +41 -0
- data/spec/models/disbursement_details_spec.rb +41 -0
- data/spec/models/disbursement_request_spec.rb +35 -0
- data/spec/models/disbursement_requests_spec.rb +41 -0
- data/spec/models/disbursement_response_spec.rb +41 -0
- data/spec/models/disbursement_spec.rb +41 -0
- data/spec/models/error_response_spec.rb +47 -0
- data/spec/models/error_spec.rb +65 -0
- data/spec/models/fields_spec.rb +41 -0
- data/spec/models/gov_identification_spec.rb +81 -0
- data/spec/models/guest_info_response_spec.rb +47 -0
- data/spec/models/guest_spec.rb +77 -0
- data/spec/models/href_spec.rb +41 -0
- data/spec/models/inline_response200_spec.rb +65 -0
- data/spec/models/installment_plan_spec.rb +47 -0
- data/spec/models/instrument_spec.rb +57 -0
- data/spec/models/instrument_verification_response_spec.rb +83 -0
- data/spec/models/kyc_spec.rb +53 -0
- data/spec/models/lease_info_spec.rb +53 -0
- data/spec/models/line_item_details_spec.rb +65 -0
- data/spec/models/marketplace_data_spec.rb +63 -0
- data/spec/models/merketplace_spec.rb +41 -0
- data/spec/models/money_spec.rb +47 -0
- data/spec/models/name_spec.rb +71 -0
- data/spec/models/offering_details_spec.rb +53 -0
- data/spec/models/order_transactions_spec.rb +65 -0
- data/spec/models/payment_cancel_response_spec.rb +59 -0
- data/spec/models/payment_cancel_transaction_response_spec.rb +53 -0
- data/spec/models/payment_details_spec.rb +81 -0
- data/spec/models/payment_instrument_card_spec.rb +51 -0
- data/spec/models/payment_instrument_response_spec.rb +47 -0
- data/spec/models/payment_instrument_spec.rb +75 -0
- data/spec/models/payment_payment_all_of_spec.rb +71 -0
- data/spec/models/payment_payment_spec.rb +71 -0
- data/spec/models/payment_response_spec.rb +89 -0
- data/spec/models/payment_spec.rb +53 -0
- data/spec/models/phone_spec.rb +53 -0
- data/spec/models/process_payment_spec.rb +77 -0
- data/spec/models/property_info_response_spec.rb +47 -0
- data/spec/models/property_info_spec.rb +53 -0
- data/spec/models/refund_action_spec.rb +35 -0
- data/spec/models/refund_cancel_response_spec.rb +53 -0
- data/spec/models/refund_cancel_transaction_response_spec.rb +47 -0
- data/spec/models/refund_request_spec.rb +65 -0
- data/spec/models/refund_response_spec.rb +77 -0
- data/spec/models/refund_status_spec.rb +35 -0
- data/spec/models/refund_transactions_spec.rb +71 -0
- data/spec/models/rental_info_spec.rb +53 -0
- data/spec/models/renter_spec.rb +77 -0
- data/spec/models/resolution_spec.rb +41 -0
- data/spec/models/result_spec.rb +53 -0
- data/spec/models/risk_status_spec.rb +41 -0
- data/spec/models/sanctioned_entities_spec.rb +47 -0
- data/spec/models/search_payment_response_spec.rb +41 -0
- data/spec/models/stack_trace_element_spec.rb +65 -0
- data/spec/models/status_spec.rb +35 -0
- data/spec/models/throwable_spec.rb +53 -0
- data/spec/models/to_entity_ref_spec.rb +47 -0
- data/spec/models/token_req_spec.rb +47 -0
- data/spec/models/token_request_spec.rb +41 -0
- data/spec/models/token_response_spec.rb +41 -0
- data/spec/models/token_spec.rb +47 -0
- data/spec/models/transaction_response_spec.rb +71 -0
- data/spec/models/transaction_spec.rb +53 -0
- data/spec/models/triggers_spec.rb +53 -0
- data/spec/models/vacation_rental_info_request_spec.rb +53 -0
- data/spec/models/vacation_rental_info_spec.rb +47 -0
- data/spec/models/verify_instrument_request_spec.rb +53 -0
- data/spec/spec_helper.rb +111 -0
- data/yapstone-payments.gemspec +45 -0
- metadata +633 -0
@@ -0,0 +1,187 @@
|
|
1
|
+
=begin
|
2
|
+
#Payments Orchestrator
|
3
|
+
|
4
|
+
#\"REST API for Payments Orchestrator\"
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.6.4-SNAPSHOT
|
7
|
+
Contact: test@yapstone.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 4.1.0-SNAPSHOT
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'cgi'
|
14
|
+
|
15
|
+
module Yapstone
|
16
|
+
class SearchApi
|
17
|
+
attr_accessor :api_client
|
18
|
+
|
19
|
+
def initialize(api_client = ApiClient.default)
|
20
|
+
@api_client = api_client
|
21
|
+
end
|
22
|
+
# Search with Payment Id
|
23
|
+
# Use this endpoint to search for a payment by payment ID.
|
24
|
+
# @param authorization [String] Authorization
|
25
|
+
# @param x_yapstone_ip_address [String] IP Address of the client
|
26
|
+
# @param payment_id [String]
|
27
|
+
# @param [Hash] opts the optional parameters
|
28
|
+
# @option opts [String] :x_yapstone_trace_id Optionally provide a unique identifier for this request, for use later if you need to debug this request with Yapstone support. Can be any arbitrary string.
|
29
|
+
# @return [SearchPaymentResponse]
|
30
|
+
def search_by_payment_id(authorization, x_yapstone_ip_address, payment_id, opts = {})
|
31
|
+
data, _status_code, _headers = search_by_payment_id_with_http_info(authorization, x_yapstone_ip_address, payment_id, opts)
|
32
|
+
data
|
33
|
+
end
|
34
|
+
|
35
|
+
# Search with Payment Id
|
36
|
+
# Use this endpoint to search for a payment by payment ID.
|
37
|
+
# @param authorization [String] Authorization
|
38
|
+
# @param x_yapstone_ip_address [String] IP Address of the client
|
39
|
+
# @param payment_id [String]
|
40
|
+
# @param [Hash] opts the optional parameters
|
41
|
+
# @option opts [String] :x_yapstone_trace_id Optionally provide a unique identifier for this request, for use later if you need to debug this request with Yapstone support. Can be any arbitrary string.
|
42
|
+
# @return [Array<(SearchPaymentResponse, Integer, Hash)>] SearchPaymentResponse data, response status code and response headers
|
43
|
+
def search_by_payment_id_with_http_info(authorization, x_yapstone_ip_address, payment_id, opts = {})
|
44
|
+
if @api_client.config.debugging
|
45
|
+
@api_client.config.logger.debug 'Calling API: SearchApi.search_by_payment_id ...'
|
46
|
+
end
|
47
|
+
# verify the required parameter 'authorization' is set
|
48
|
+
if @api_client.config.client_side_validation && authorization.nil?
|
49
|
+
fail ArgumentError, "Missing the required parameter 'authorization' when calling SearchApi.search_by_payment_id"
|
50
|
+
end
|
51
|
+
# verify the required parameter 'x_yapstone_ip_address' is set
|
52
|
+
if @api_client.config.client_side_validation && x_yapstone_ip_address.nil?
|
53
|
+
fail ArgumentError, "Missing the required parameter 'x_yapstone_ip_address' when calling SearchApi.search_by_payment_id"
|
54
|
+
end
|
55
|
+
# verify the required parameter 'payment_id' is set
|
56
|
+
if @api_client.config.client_side_validation && payment_id.nil?
|
57
|
+
fail ArgumentError, "Missing the required parameter 'payment_id' when calling SearchApi.search_by_payment_id"
|
58
|
+
end
|
59
|
+
# resource path
|
60
|
+
local_var_path = '/v2/search/payment/{paymentId}'.sub('{' + 'paymentId' + '}', CGI.escape(payment_id.to_s).gsub('%2F', '/'))
|
61
|
+
|
62
|
+
# query parameters
|
63
|
+
query_params = opts[:query_params] || {}
|
64
|
+
|
65
|
+
# header parameters
|
66
|
+
header_params = opts[:header_params] || {}
|
67
|
+
# HTTP header 'Accept' (if needed)
|
68
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
69
|
+
header_params[:'Authorization'] = authorization
|
70
|
+
header_params[:'X-Yapstone-IPAddress'] = x_yapstone_ip_address
|
71
|
+
header_params[:'X-Yapstone-Trace-Id'] = opts[:'x_yapstone_trace_id'] if !opts[:'x_yapstone_trace_id'].nil?
|
72
|
+
|
73
|
+
# form parameters
|
74
|
+
form_params = opts[:form_params] || {}
|
75
|
+
|
76
|
+
# http body (model)
|
77
|
+
post_body = opts[:body]
|
78
|
+
|
79
|
+
# return_type
|
80
|
+
return_type = opts[:return_type] || 'SearchPaymentResponse'
|
81
|
+
|
82
|
+
# auth_names
|
83
|
+
auth_names = opts[:auth_names] || ['Bearer']
|
84
|
+
|
85
|
+
new_options = opts.merge(
|
86
|
+
:header_params => header_params,
|
87
|
+
:query_params => query_params,
|
88
|
+
:form_params => form_params,
|
89
|
+
:body => post_body,
|
90
|
+
:auth_names => auth_names,
|
91
|
+
:return_type => return_type
|
92
|
+
)
|
93
|
+
|
94
|
+
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
|
95
|
+
if @api_client.config.debugging
|
96
|
+
@api_client.config.logger.debug "API called: SearchApi#search_by_payment_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
97
|
+
end
|
98
|
+
return data, status_code, headers
|
99
|
+
end
|
100
|
+
|
101
|
+
# Search with transaction id
|
102
|
+
# Use this endpoint to search for particular transactions using their transaction ID.
|
103
|
+
# @param authorization [String] Authorization
|
104
|
+
# @param x_yapstone_fpsid [String] Device Finger Print Id
|
105
|
+
# @param x_yapstone_ip_address [String] IP Address of the client
|
106
|
+
# @param transaction_id [String]
|
107
|
+
# @param [Hash] opts the optional parameters
|
108
|
+
# @option opts [String] :x_yapstone_trace_id Optionally provide a unique identifier for this request, for use later if you need to debug this request with Yapstone support. Can be any arbitrary string.
|
109
|
+
# @return [SearchPaymentResponse]
|
110
|
+
def search_by_transaction_id(authorization, x_yapstone_fpsid, x_yapstone_ip_address, transaction_id, opts = {})
|
111
|
+
data, _status_code, _headers = search_by_transaction_id_with_http_info(authorization, x_yapstone_fpsid, x_yapstone_ip_address, transaction_id, opts)
|
112
|
+
data
|
113
|
+
end
|
114
|
+
|
115
|
+
# Search with transaction id
|
116
|
+
# Use this endpoint to search for particular transactions using their transaction ID.
|
117
|
+
# @param authorization [String] Authorization
|
118
|
+
# @param x_yapstone_fpsid [String] Device Finger Print Id
|
119
|
+
# @param x_yapstone_ip_address [String] IP Address of the client
|
120
|
+
# @param transaction_id [String]
|
121
|
+
# @param [Hash] opts the optional parameters
|
122
|
+
# @option opts [String] :x_yapstone_trace_id Optionally provide a unique identifier for this request, for use later if you need to debug this request with Yapstone support. Can be any arbitrary string.
|
123
|
+
# @return [Array<(SearchPaymentResponse, Integer, Hash)>] SearchPaymentResponse data, response status code and response headers
|
124
|
+
def search_by_transaction_id_with_http_info(authorization, x_yapstone_fpsid, x_yapstone_ip_address, transaction_id, opts = {})
|
125
|
+
if @api_client.config.debugging
|
126
|
+
@api_client.config.logger.debug 'Calling API: SearchApi.search_by_transaction_id ...'
|
127
|
+
end
|
128
|
+
# verify the required parameter 'authorization' is set
|
129
|
+
if @api_client.config.client_side_validation && authorization.nil?
|
130
|
+
fail ArgumentError, "Missing the required parameter 'authorization' when calling SearchApi.search_by_transaction_id"
|
131
|
+
end
|
132
|
+
# verify the required parameter 'x_yapstone_fpsid' is set
|
133
|
+
if @api_client.config.client_side_validation && x_yapstone_fpsid.nil?
|
134
|
+
fail ArgumentError, "Missing the required parameter 'x_yapstone_fpsid' when calling SearchApi.search_by_transaction_id"
|
135
|
+
end
|
136
|
+
# verify the required parameter 'x_yapstone_ip_address' is set
|
137
|
+
if @api_client.config.client_side_validation && x_yapstone_ip_address.nil?
|
138
|
+
fail ArgumentError, "Missing the required parameter 'x_yapstone_ip_address' when calling SearchApi.search_by_transaction_id"
|
139
|
+
end
|
140
|
+
# verify the required parameter 'transaction_id' is set
|
141
|
+
if @api_client.config.client_side_validation && transaction_id.nil?
|
142
|
+
fail ArgumentError, "Missing the required parameter 'transaction_id' when calling SearchApi.search_by_transaction_id"
|
143
|
+
end
|
144
|
+
# resource path
|
145
|
+
local_var_path = '/v2/search/transaction/{transactionId}'.sub('{' + 'transactionId' + '}', CGI.escape(transaction_id.to_s).gsub('%2F', '/'))
|
146
|
+
|
147
|
+
# query parameters
|
148
|
+
query_params = opts[:query_params] || {}
|
149
|
+
|
150
|
+
# header parameters
|
151
|
+
header_params = opts[:header_params] || {}
|
152
|
+
# HTTP header 'Accept' (if needed)
|
153
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
154
|
+
header_params[:'Authorization'] = authorization
|
155
|
+
header_params[:'X-Yapstone-fpsid'] = x_yapstone_fpsid
|
156
|
+
header_params[:'X-Yapstone-IPAddress'] = x_yapstone_ip_address
|
157
|
+
header_params[:'X-Yapstone-Trace-Id'] = opts[:'x_yapstone_trace_id'] if !opts[:'x_yapstone_trace_id'].nil?
|
158
|
+
|
159
|
+
# form parameters
|
160
|
+
form_params = opts[:form_params] || {}
|
161
|
+
|
162
|
+
# http body (model)
|
163
|
+
post_body = opts[:body]
|
164
|
+
|
165
|
+
# return_type
|
166
|
+
return_type = opts[:return_type] || 'SearchPaymentResponse'
|
167
|
+
|
168
|
+
# auth_names
|
169
|
+
auth_names = opts[:auth_names] || ['Bearer']
|
170
|
+
|
171
|
+
new_options = opts.merge(
|
172
|
+
:header_params => header_params,
|
173
|
+
:query_params => query_params,
|
174
|
+
:form_params => form_params,
|
175
|
+
:body => post_body,
|
176
|
+
:auth_names => auth_names,
|
177
|
+
:return_type => return_type
|
178
|
+
)
|
179
|
+
|
180
|
+
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
|
181
|
+
if @api_client.config.debugging
|
182
|
+
@api_client.config.logger.debug "API called: SearchApi#search_by_transaction_id\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
183
|
+
end
|
184
|
+
return data, status_code, headers
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
=begin
|
2
|
+
#Payments Orchestrator
|
3
|
+
|
4
|
+
#\"REST API for Payments Orchestrator\"
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.6.4-SNAPSHOT
|
7
|
+
Contact: test@yapstone.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 4.1.0-SNAPSHOT
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'cgi'
|
14
|
+
|
15
|
+
module Yapstone
|
16
|
+
class TokenApi
|
17
|
+
attr_accessor :api_client
|
18
|
+
|
19
|
+
def initialize(api_client = ApiClient.default)
|
20
|
+
@api_client = api_client
|
21
|
+
end
|
22
|
+
# Create a Token
|
23
|
+
# Create a token to make a payment. In your request you specify the type of instrument and you are returned a token for that instrument in the response.
|
24
|
+
# @param authorization [String] Authorization
|
25
|
+
# @param x_yapstone_ip_address [String] IP Address of the client
|
26
|
+
# @param [Hash] opts the optional parameters
|
27
|
+
# @option opts [String] :x_yapstone_trace_id Optionally provide a unique identifier for this request, for use later if you need to debug this request with Yapstone support. Can be any arbitrary string.
|
28
|
+
# @option opts [String] :x_yapstone_fpsid Device Finger Print Id
|
29
|
+
# @option opts [TokenRequest] :token_request
|
30
|
+
# @return [Token]
|
31
|
+
def create_token(authorization, x_yapstone_ip_address, opts = {})
|
32
|
+
data, _status_code, _headers = create_token_with_http_info(authorization, x_yapstone_ip_address, opts)
|
33
|
+
data
|
34
|
+
end
|
35
|
+
|
36
|
+
# Create a Token
|
37
|
+
# Create a token to make a payment. In your request you specify the type of instrument and you are returned a token for that instrument in the response.
|
38
|
+
# @param authorization [String] Authorization
|
39
|
+
# @param x_yapstone_ip_address [String] IP Address of the client
|
40
|
+
# @param [Hash] opts the optional parameters
|
41
|
+
# @option opts [String] :x_yapstone_trace_id Optionally provide a unique identifier for this request, for use later if you need to debug this request with Yapstone support. Can be any arbitrary string.
|
42
|
+
# @option opts [String] :x_yapstone_fpsid Device Finger Print Id
|
43
|
+
# @option opts [TokenRequest] :token_request
|
44
|
+
# @return [Array<(Token, Integer, Hash)>] Token data, response status code and response headers
|
45
|
+
def create_token_with_http_info(authorization, x_yapstone_ip_address, opts = {})
|
46
|
+
if @api_client.config.debugging
|
47
|
+
@api_client.config.logger.debug 'Calling API: TokenApi.create_token ...'
|
48
|
+
end
|
49
|
+
# verify the required parameter 'authorization' is set
|
50
|
+
if @api_client.config.client_side_validation && authorization.nil?
|
51
|
+
fail ArgumentError, "Missing the required parameter 'authorization' when calling TokenApi.create_token"
|
52
|
+
end
|
53
|
+
# verify the required parameter 'x_yapstone_ip_address' is set
|
54
|
+
if @api_client.config.client_side_validation && x_yapstone_ip_address.nil?
|
55
|
+
fail ArgumentError, "Missing the required parameter 'x_yapstone_ip_address' when calling TokenApi.create_token"
|
56
|
+
end
|
57
|
+
# resource path
|
58
|
+
local_var_path = '/v2/token'
|
59
|
+
|
60
|
+
# query parameters
|
61
|
+
query_params = opts[:query_params] || {}
|
62
|
+
|
63
|
+
# header parameters
|
64
|
+
header_params = opts[:header_params] || {}
|
65
|
+
# HTTP header 'Accept' (if needed)
|
66
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
67
|
+
# HTTP header 'Content-Type'
|
68
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
69
|
+
header_params[:'Authorization'] = authorization
|
70
|
+
header_params[:'X-Yapstone-IPAddress'] = x_yapstone_ip_address
|
71
|
+
header_params[:'X-Yapstone-Trace-Id'] = opts[:'x_yapstone_trace_id'] if !opts[:'x_yapstone_trace_id'].nil?
|
72
|
+
header_params[:'X-Yapstone-fpsid'] = opts[:'x_yapstone_fpsid'] if !opts[:'x_yapstone_fpsid'].nil?
|
73
|
+
|
74
|
+
# form parameters
|
75
|
+
form_params = opts[:form_params] || {}
|
76
|
+
|
77
|
+
# http body (model)
|
78
|
+
post_body = opts[:body] || @api_client.object_to_http_body(opts[:'token_request'])
|
79
|
+
|
80
|
+
# return_type
|
81
|
+
return_type = opts[:return_type] || 'Token'
|
82
|
+
|
83
|
+
# auth_names
|
84
|
+
auth_names = opts[:auth_names] || ['Bearer']
|
85
|
+
|
86
|
+
new_options = opts.merge(
|
87
|
+
:header_params => header_params,
|
88
|
+
:query_params => query_params,
|
89
|
+
:form_params => form_params,
|
90
|
+
:body => post_body,
|
91
|
+
:auth_names => auth_names,
|
92
|
+
:return_type => return_type
|
93
|
+
)
|
94
|
+
|
95
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
96
|
+
if @api_client.config.debugging
|
97
|
+
@api_client.config.logger.debug "API called: TokenApi#create_token\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
98
|
+
end
|
99
|
+
return data, status_code, headers
|
100
|
+
end
|
101
|
+
|
102
|
+
# Lookup a Token
|
103
|
+
# Lookup a token to make a payment. Submit the token ID to retrieve details about the token.
|
104
|
+
# @param authorization [String] Authorization
|
105
|
+
# @param x_yapstone_ip_address [String] IP Address of the client
|
106
|
+
# @param [Hash] opts the optional parameters
|
107
|
+
# @option opts [String] :x_yapstone_trace_id Optionally provide a unique identifier for this request, for use later if you need to debug this request with Yapstone support. Can be any arbitrary string.
|
108
|
+
# @option opts [String] :x_yapstone_fpsid Device Finger Print Id
|
109
|
+
# @option opts [Token] :token
|
110
|
+
# @return [TokenResponse]
|
111
|
+
def lookup_token(authorization, x_yapstone_ip_address, opts = {})
|
112
|
+
data, _status_code, _headers = lookup_token_with_http_info(authorization, x_yapstone_ip_address, opts)
|
113
|
+
data
|
114
|
+
end
|
115
|
+
|
116
|
+
# Lookup a Token
|
117
|
+
# Lookup a token to make a payment. Submit the token ID to retrieve details about the token.
|
118
|
+
# @param authorization [String] Authorization
|
119
|
+
# @param x_yapstone_ip_address [String] IP Address of the client
|
120
|
+
# @param [Hash] opts the optional parameters
|
121
|
+
# @option opts [String] :x_yapstone_trace_id Optionally provide a unique identifier for this request, for use later if you need to debug this request with Yapstone support. Can be any arbitrary string.
|
122
|
+
# @option opts [String] :x_yapstone_fpsid Device Finger Print Id
|
123
|
+
# @option opts [Token] :token
|
124
|
+
# @return [Array<(TokenResponse, Integer, Hash)>] TokenResponse data, response status code and response headers
|
125
|
+
def lookup_token_with_http_info(authorization, x_yapstone_ip_address, opts = {})
|
126
|
+
if @api_client.config.debugging
|
127
|
+
@api_client.config.logger.debug 'Calling API: TokenApi.lookup_token ...'
|
128
|
+
end
|
129
|
+
# verify the required parameter 'authorization' is set
|
130
|
+
if @api_client.config.client_side_validation && authorization.nil?
|
131
|
+
fail ArgumentError, "Missing the required parameter 'authorization' when calling TokenApi.lookup_token"
|
132
|
+
end
|
133
|
+
# verify the required parameter 'x_yapstone_ip_address' is set
|
134
|
+
if @api_client.config.client_side_validation && x_yapstone_ip_address.nil?
|
135
|
+
fail ArgumentError, "Missing the required parameter 'x_yapstone_ip_address' when calling TokenApi.lookup_token"
|
136
|
+
end
|
137
|
+
# resource path
|
138
|
+
local_var_path = '/v2/token/lookup'
|
139
|
+
|
140
|
+
# query parameters
|
141
|
+
query_params = opts[:query_params] || {}
|
142
|
+
|
143
|
+
# header parameters
|
144
|
+
header_params = opts[:header_params] || {}
|
145
|
+
# HTTP header 'Accept' (if needed)
|
146
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
147
|
+
# HTTP header 'Content-Type'
|
148
|
+
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
|
149
|
+
header_params[:'Authorization'] = authorization
|
150
|
+
header_params[:'X-Yapstone-IPAddress'] = x_yapstone_ip_address
|
151
|
+
header_params[:'X-Yapstone-Trace-Id'] = opts[:'x_yapstone_trace_id'] if !opts[:'x_yapstone_trace_id'].nil?
|
152
|
+
header_params[:'X-Yapstone-fpsid'] = opts[:'x_yapstone_fpsid'] if !opts[:'x_yapstone_fpsid'].nil?
|
153
|
+
|
154
|
+
# form parameters
|
155
|
+
form_params = opts[:form_params] || {}
|
156
|
+
|
157
|
+
# http body (model)
|
158
|
+
post_body = opts[:body] || @api_client.object_to_http_body(opts[:'token'])
|
159
|
+
|
160
|
+
# return_type
|
161
|
+
return_type = opts[:return_type] || 'TokenResponse'
|
162
|
+
|
163
|
+
# auth_names
|
164
|
+
auth_names = opts[:auth_names] || ['Bearer']
|
165
|
+
|
166
|
+
new_options = opts.merge(
|
167
|
+
:header_params => header_params,
|
168
|
+
:query_params => query_params,
|
169
|
+
:form_params => form_params,
|
170
|
+
:body => post_body,
|
171
|
+
:auth_names => auth_names,
|
172
|
+
:return_type => return_type
|
173
|
+
)
|
174
|
+
|
175
|
+
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
|
176
|
+
if @api_client.config.debugging
|
177
|
+
@api_client.config.logger.debug "API called: TokenApi#lookup_token\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
178
|
+
end
|
179
|
+
return data, status_code, headers
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,386 @@
|
|
1
|
+
=begin
|
2
|
+
#Payments Orchestrator
|
3
|
+
|
4
|
+
#\"REST API for Payments Orchestrator\"
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.6.4-SNAPSHOT
|
7
|
+
Contact: test@yapstone.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 4.1.0-SNAPSHOT
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'json'
|
15
|
+
require 'logger'
|
16
|
+
require 'tempfile'
|
17
|
+
require 'typhoeus'
|
18
|
+
|
19
|
+
module Yapstone
|
20
|
+
class ApiClient
|
21
|
+
# The Configuration object holding settings to be used in the API client.
|
22
|
+
attr_accessor :config
|
23
|
+
|
24
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
25
|
+
#
|
26
|
+
# @return [Hash]
|
27
|
+
attr_accessor :default_headers
|
28
|
+
|
29
|
+
# Initializes the ApiClient
|
30
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
31
|
+
def initialize(config = Configuration.default)
|
32
|
+
@config = config
|
33
|
+
@user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
|
34
|
+
@default_headers = {
|
35
|
+
'Content-Type' => 'application/json',
|
36
|
+
'User-Agent' => @user_agent
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.default
|
41
|
+
@@default ||= ApiClient.new
|
42
|
+
end
|
43
|
+
|
44
|
+
# Call an API with given options.
|
45
|
+
#
|
46
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
47
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
48
|
+
def call_api(http_method, path, opts = {})
|
49
|
+
request = build_request(http_method, path, opts)
|
50
|
+
response = request.run
|
51
|
+
|
52
|
+
if @config.debugging
|
53
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
unless response.success?
|
57
|
+
if response.timed_out?
|
58
|
+
fail ApiError.new('Connection timed out')
|
59
|
+
elsif response.code == 0
|
60
|
+
# Errors from libcurl will be made visible here
|
61
|
+
fail ApiError.new(:code => 0,
|
62
|
+
:message => response.return_message)
|
63
|
+
else
|
64
|
+
fail ApiError.new(:code => response.code,
|
65
|
+
:response_headers => response.headers,
|
66
|
+
:response_body => response.body),
|
67
|
+
response.status_message
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if opts[:return_type]
|
72
|
+
data = deserialize(response, opts[:return_type])
|
73
|
+
else
|
74
|
+
data = nil
|
75
|
+
end
|
76
|
+
return data, response.code, response.headers
|
77
|
+
end
|
78
|
+
|
79
|
+
# Builds the HTTP request
|
80
|
+
#
|
81
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
82
|
+
# @param [String] path URL path (e.g. /account/new)
|
83
|
+
# @option opts [Hash] :header_params Header parameters
|
84
|
+
# @option opts [Hash] :query_params Query parameters
|
85
|
+
# @option opts [Hash] :form_params Query parameters
|
86
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
87
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
88
|
+
def build_request(http_method, path, opts = {})
|
89
|
+
url = build_request_url(path)
|
90
|
+
http_method = http_method.to_sym.downcase
|
91
|
+
|
92
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
93
|
+
query_params = opts[:query_params] || {}
|
94
|
+
form_params = opts[:form_params] || {}
|
95
|
+
|
96
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
97
|
+
|
98
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
99
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
100
|
+
|
101
|
+
req_opts = {
|
102
|
+
:method => http_method,
|
103
|
+
:headers => header_params,
|
104
|
+
:params => query_params,
|
105
|
+
:params_encoding => @config.params_encoding,
|
106
|
+
:timeout => @config.timeout,
|
107
|
+
:ssl_verifypeer => @config.verify_ssl,
|
108
|
+
:ssl_verifyhost => _verify_ssl_host,
|
109
|
+
:sslcert => @config.cert_file,
|
110
|
+
:sslkey => @config.key_file,
|
111
|
+
:verbose => @config.debugging
|
112
|
+
}
|
113
|
+
|
114
|
+
# set custom cert, if provided
|
115
|
+
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
116
|
+
|
117
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
118
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
119
|
+
req_opts.update :body => req_body
|
120
|
+
if @config.debugging
|
121
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
request = Typhoeus::Request.new(url, req_opts)
|
126
|
+
download_file(request) if opts[:return_type] == 'File'
|
127
|
+
request
|
128
|
+
end
|
129
|
+
|
130
|
+
# Check if the given MIME is a JSON MIME.
|
131
|
+
# JSON MIME examples:
|
132
|
+
# application/json
|
133
|
+
# application/json; charset=UTF8
|
134
|
+
# APPLICATION/JSON
|
135
|
+
# */*
|
136
|
+
# @param [String] mime MIME
|
137
|
+
# @return [Boolean] True if the MIME is application/json
|
138
|
+
def json_mime?(mime)
|
139
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
140
|
+
end
|
141
|
+
|
142
|
+
# Deserialize the response to the given return type.
|
143
|
+
#
|
144
|
+
# @param [Response] response HTTP response
|
145
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
146
|
+
def deserialize(response, return_type)
|
147
|
+
body = response.body
|
148
|
+
|
149
|
+
# handle file downloading - return the File instance processed in request callbacks
|
150
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
151
|
+
return @tempfile if return_type == 'File'
|
152
|
+
|
153
|
+
return nil if body.nil? || body.empty?
|
154
|
+
|
155
|
+
# return response body directly for String return type
|
156
|
+
return body if return_type == 'String'
|
157
|
+
|
158
|
+
# ensuring a default content type
|
159
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
160
|
+
|
161
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
162
|
+
|
163
|
+
begin
|
164
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
165
|
+
rescue JSON::ParserError => e
|
166
|
+
if %w(String Date DateTime).include?(return_type)
|
167
|
+
data = body
|
168
|
+
else
|
169
|
+
raise e
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
convert_to_type data, return_type
|
174
|
+
end
|
175
|
+
|
176
|
+
# Convert data to the given return type.
|
177
|
+
# @param [Object] data Data to be converted
|
178
|
+
# @param [String] return_type Return type
|
179
|
+
# @return [Mixed] Data in a particular type
|
180
|
+
def convert_to_type(data, return_type)
|
181
|
+
return nil if data.nil?
|
182
|
+
case return_type
|
183
|
+
when 'String'
|
184
|
+
data.to_s
|
185
|
+
when 'Integer'
|
186
|
+
data.to_i
|
187
|
+
when 'Float'
|
188
|
+
data.to_f
|
189
|
+
when 'Boolean'
|
190
|
+
data == true
|
191
|
+
when 'DateTime'
|
192
|
+
# parse date time (expecting ISO 8601 format)
|
193
|
+
DateTime.parse data
|
194
|
+
when 'Date'
|
195
|
+
# parse date time (expecting ISO 8601 format)
|
196
|
+
Date.parse data
|
197
|
+
when 'Object'
|
198
|
+
# generic object (usually a Hash), return directly
|
199
|
+
data
|
200
|
+
when /\AArray<(.+)>\z/
|
201
|
+
# e.g. Array<Pet>
|
202
|
+
sub_type = $1
|
203
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
204
|
+
when /\AHash\<String, (.+)\>\z/
|
205
|
+
# e.g. Hash<String, Integer>
|
206
|
+
sub_type = $1
|
207
|
+
{}.tap do |hash|
|
208
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
209
|
+
end
|
210
|
+
else
|
211
|
+
# models, e.g. Pet
|
212
|
+
Yapstone.const_get(return_type).build_from_hash(data)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
217
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
218
|
+
# The response body is written to the file in chunks in order to handle files which
|
219
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
220
|
+
# process can use.
|
221
|
+
#
|
222
|
+
# @see Configuration#temp_folder_path
|
223
|
+
def download_file(request)
|
224
|
+
tempfile = nil
|
225
|
+
encoding = nil
|
226
|
+
request.on_headers do |response|
|
227
|
+
content_disposition = response.headers['Content-Disposition']
|
228
|
+
if content_disposition && content_disposition =~ /filename=/i
|
229
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
230
|
+
prefix = sanitize_filename(filename)
|
231
|
+
else
|
232
|
+
prefix = 'download-'
|
233
|
+
end
|
234
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
235
|
+
encoding = response.body.encoding
|
236
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
237
|
+
@tempfile = tempfile
|
238
|
+
end
|
239
|
+
request.on_body do |chunk|
|
240
|
+
chunk.force_encoding(encoding)
|
241
|
+
tempfile.write(chunk)
|
242
|
+
end
|
243
|
+
request.on_complete do |response|
|
244
|
+
tempfile.close if tempfile
|
245
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
246
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
247
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
248
|
+
"explicitly with `tempfile.delete`"
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
# Sanitize filename by removing path.
|
253
|
+
# e.g. ../../sun.gif becomes sun.gif
|
254
|
+
#
|
255
|
+
# @param [String] filename the filename to be sanitized
|
256
|
+
# @return [String] the sanitized filename
|
257
|
+
def sanitize_filename(filename)
|
258
|
+
filename.gsub(/.*[\/\\]/, '')
|
259
|
+
end
|
260
|
+
|
261
|
+
def build_request_url(path)
|
262
|
+
# Add leading and trailing slashes to path
|
263
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
264
|
+
@config.base_url + path
|
265
|
+
end
|
266
|
+
|
267
|
+
# Builds the HTTP request body
|
268
|
+
#
|
269
|
+
# @param [Hash] header_params Header parameters
|
270
|
+
# @param [Hash] form_params Query parameters
|
271
|
+
# @param [Object] body HTTP body (JSON/XML)
|
272
|
+
# @return [String] HTTP body data in the form of string
|
273
|
+
def build_request_body(header_params, form_params, body)
|
274
|
+
# http form
|
275
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
276
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
277
|
+
data = {}
|
278
|
+
form_params.each do |key, value|
|
279
|
+
case value
|
280
|
+
when ::File, ::Array, nil
|
281
|
+
# let typhoeus handle File, Array and nil parameters
|
282
|
+
data[key] = value
|
283
|
+
else
|
284
|
+
data[key] = value.to_s
|
285
|
+
end
|
286
|
+
end
|
287
|
+
elsif body
|
288
|
+
data = body.is_a?(String) ? body : body.to_json
|
289
|
+
else
|
290
|
+
data = nil
|
291
|
+
end
|
292
|
+
data
|
293
|
+
end
|
294
|
+
|
295
|
+
# Update hearder and query params based on authentication settings.
|
296
|
+
#
|
297
|
+
# @param [Hash] header_params Header parameters
|
298
|
+
# @param [Hash] query_params Query parameters
|
299
|
+
# @param [String] auth_names Authentication scheme name
|
300
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
301
|
+
Array(auth_names).each do |auth_name|
|
302
|
+
auth_setting = @config.auth_settings[auth_name]
|
303
|
+
next unless auth_setting
|
304
|
+
case auth_setting[:in]
|
305
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
306
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
307
|
+
else fail ArgumentError, 'Authentication token must be in `query` of `header`'
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
# Sets user agent in HTTP header
|
313
|
+
#
|
314
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
315
|
+
def user_agent=(user_agent)
|
316
|
+
@user_agent = user_agent
|
317
|
+
@default_headers['User-Agent'] = @user_agent
|
318
|
+
end
|
319
|
+
|
320
|
+
# Return Accept header based on an array of accepts provided.
|
321
|
+
# @param [Array] accepts array for Accept
|
322
|
+
# @return [String] the Accept header (e.g. application/json)
|
323
|
+
def select_header_accept(accepts)
|
324
|
+
return nil if accepts.nil? || accepts.empty?
|
325
|
+
# use JSON when present, otherwise use all of the provided
|
326
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
327
|
+
json_accept || accepts.join(',')
|
328
|
+
end
|
329
|
+
|
330
|
+
# Return Content-Type header based on an array of content types provided.
|
331
|
+
# @param [Array] content_types array for Content-Type
|
332
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
333
|
+
def select_header_content_type(content_types)
|
334
|
+
# use application/json by default
|
335
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
336
|
+
# use JSON when present, otherwise use the first one
|
337
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
338
|
+
json_content_type || content_types.first
|
339
|
+
end
|
340
|
+
|
341
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
342
|
+
# @param [Object] model object to be converted into JSON string
|
343
|
+
# @return [String] JSON string representation of the object
|
344
|
+
def object_to_http_body(model)
|
345
|
+
return model if model.nil? || model.is_a?(String)
|
346
|
+
local_body = nil
|
347
|
+
if model.is_a?(Array)
|
348
|
+
local_body = model.map { |m| object_to_hash(m) }
|
349
|
+
else
|
350
|
+
local_body = object_to_hash(model)
|
351
|
+
end
|
352
|
+
local_body.to_json
|
353
|
+
end
|
354
|
+
|
355
|
+
# Convert object(non-array) to hash.
|
356
|
+
# @param [Object] obj object to be converted into JSON string
|
357
|
+
# @return [String] JSON string representation of the object
|
358
|
+
def object_to_hash(obj)
|
359
|
+
if obj.respond_to?(:to_hash)
|
360
|
+
obj.to_hash
|
361
|
+
else
|
362
|
+
obj
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
# Build parameter value according to the given collection format.
|
367
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
368
|
+
def build_collection_param(param, collection_format)
|
369
|
+
case collection_format
|
370
|
+
when :csv
|
371
|
+
param.join(',')
|
372
|
+
when :ssv
|
373
|
+
param.join(' ')
|
374
|
+
when :tsv
|
375
|
+
param.join("\t")
|
376
|
+
when :pipes
|
377
|
+
param.join('|')
|
378
|
+
when :multi
|
379
|
+
# return the array directly as typhoeus will handle it as expected
|
380
|
+
param
|
381
|
+
else
|
382
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|