get_around_owner 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +9 -0
- data/README.md +303 -0
- data/Rakefile +10 -0
- data/docs/CarsApi.md +151 -0
- data/docs/CheckinsApi.md +71 -0
- data/docs/CheckoutsApi.md +71 -0
- data/docs/GetaroundCar.md +28 -0
- data/docs/GetaroundCarsIndexInner.md +18 -0
- data/docs/GetaroundCheckin.md +24 -0
- data/docs/GetaroundCheckinsIndexInner.md +18 -0
- data/docs/GetaroundCheckout.md +26 -0
- data/docs/GetaroundCreateMessagesRequest.md +18 -0
- data/docs/GetaroundCreateUnavailabilitiesRequest.md +22 -0
- data/docs/GetaroundDestroyUnavailabilityRequest.md +20 -0
- data/docs/GetaroundInvoice.md +34 -0
- data/docs/GetaroundInvoiceChargesInner.md +20 -0
- data/docs/GetaroundInvoicesIndexInner.md +18 -0
- data/docs/GetaroundMessage.md +26 -0
- data/docs/GetaroundMessagesSent.md +22 -0
- data/docs/GetaroundMessagesSentAllOfData.md +20 -0
- data/docs/GetaroundPayout.md +28 -0
- data/docs/GetaroundPayoutInvoicesInner.md +18 -0
- data/docs/GetaroundPayoutsIndexInner.md +18 -0
- data/docs/GetaroundReason.md +15 -0
- data/docs/GetaroundRental.md +32 -0
- data/docs/GetaroundRentalInvoicesIndexInner.md +18 -0
- data/docs/GetaroundRentalMessagesIndexInner.md +18 -0
- data/docs/GetaroundRentalsBooked.md +22 -0
- data/docs/GetaroundRentalsBookedAllOfData.md +18 -0
- data/docs/GetaroundRentalsCanceled.md +22 -0
- data/docs/GetaroundRentalsCarCheckedIn.md +22 -0
- data/docs/GetaroundRentalsCarCheckedOut.md +22 -0
- data/docs/GetaroundRentalsCarSwitched.md +22 -0
- data/docs/GetaroundRentalsIndexInner.md +18 -0
- data/docs/GetaroundRentalsTimesChanged.md +22 -0
- data/docs/GetaroundUnavailabilitiesCreated.md +22 -0
- data/docs/GetaroundUnavailabilitiesCreatedAllOfData.md +24 -0
- data/docs/GetaroundUnavailabilitiesDeleted.md +22 -0
- data/docs/GetaroundUnavailabilitiesDeletedAllOfData.md +22 -0
- data/docs/GetaroundUnavailability.md +24 -0
- data/docs/GetaroundUser.md +42 -0
- data/docs/GetaroundUsersUpdated.md +22 -0
- data/docs/GetaroundUsersUpdatedAllOfData.md +18 -0
- data/docs/GetaroundWebhook.md +22 -0
- data/docs/InvoicesApi.md +231 -0
- data/docs/MessagesApi.md +71 -0
- data/docs/PayoutsApi.md +155 -0
- data/docs/RentalsApi.md +263 -0
- data/docs/UnavailabilitiesApi.md +135 -0
- data/docs/UsersApi.md +71 -0
- data/get_around_owner.gemspec +26 -0
- data/git_push.sh +57 -0
- data/lib/get_around_owner/api/cars_api.rb +148 -0
- data/lib/get_around_owner/api/checkins_api.rb +82 -0
- data/lib/get_around_owner/api/checkouts_api.rb +82 -0
- data/lib/get_around_owner/api/invoices_api.rb +223 -0
- data/lib/get_around_owner/api/messages_api.rb +82 -0
- data/lib/get_around_owner/api/payouts_api.rb +162 -0
- data/lib/get_around_owner/api/rentals_api.rb +262 -0
- data/lib/get_around_owner/api/unavailabilities_api.rb +142 -0
- data/lib/get_around_owner/api/users_api.rb +82 -0
- data/lib/get_around_owner/api_client.rb +394 -0
- data/lib/get_around_owner/api_error.rb +58 -0
- data/lib/get_around_owner/configuration.rb +298 -0
- data/lib/get_around_owner/models/getaround_car.rb +308 -0
- data/lib/get_around_owner/models/getaround_cars_index_inner.rb +223 -0
- data/lib/get_around_owner/models/getaround_checkin.rb +279 -0
- data/lib/get_around_owner/models/getaround_checkins_index_inner.rb +222 -0
- data/lib/get_around_owner/models/getaround_checkout.rb +298 -0
- data/lib/get_around_owner/models/getaround_create_messages_request.rb +222 -0
- data/lib/get_around_owner/models/getaround_create_unavailabilities_request.rb +283 -0
- data/lib/get_around_owner/models/getaround_destroy_unavailability_request.rb +239 -0
- data/lib/get_around_owner/models/getaround_invoice.rb +396 -0
- data/lib/get_around_owner/models/getaround_invoice_charges_inner.rb +225 -0
- data/lib/get_around_owner/models/getaround_invoices_index_inner.rb +223 -0
- data/lib/get_around_owner/models/getaround_message.rb +291 -0
- data/lib/get_around_owner/models/getaround_messages_sent.rb +257 -0
- data/lib/get_around_owner/models/getaround_messages_sent_all_of_data.rb +225 -0
- data/lib/get_around_owner/models/getaround_payout.rb +347 -0
- data/lib/get_around_owner/models/getaround_payout_invoices_inner.rb +223 -0
- data/lib/get_around_owner/models/getaround_payouts_index_inner.rb +223 -0
- data/lib/get_around_owner/models/getaround_reason.rb +45 -0
- data/lib/get_around_owner/models/getaround_rental.rb +380 -0
- data/lib/get_around_owner/models/getaround_rental_invoices_index_inner.rb +223 -0
- data/lib/get_around_owner/models/getaround_rental_messages_index_inner.rb +223 -0
- data/lib/get_around_owner/models/getaround_rentals_booked.rb +257 -0
- data/lib/get_around_owner/models/getaround_rentals_booked_all_of_data.rb +215 -0
- data/lib/get_around_owner/models/getaround_rentals_canceled.rb +257 -0
- data/lib/get_around_owner/models/getaround_rentals_car_checked_in.rb +257 -0
- data/lib/get_around_owner/models/getaround_rentals_car_checked_out.rb +257 -0
- data/lib/get_around_owner/models/getaround_rentals_car_switched.rb +257 -0
- data/lib/get_around_owner/models/getaround_rentals_index_inner.rb +223 -0
- data/lib/get_around_owner/models/getaround_rentals_times_changed.rb +257 -0
- data/lib/get_around_owner/models/getaround_unavailabilities_created.rb +257 -0
- data/lib/get_around_owner/models/getaround_unavailabilities_created_all_of_data.rb +267 -0
- data/lib/get_around_owner/models/getaround_unavailabilities_deleted.rb +257 -0
- data/lib/get_around_owner/models/getaround_unavailabilities_deleted_all_of_data.rb +235 -0
- data/lib/get_around_owner/models/getaround_unavailability.rb +302 -0
- data/lib/get_around_owner/models/getaround_user.rb +420 -0
- data/lib/get_around_owner/models/getaround_users_updated.rb +257 -0
- data/lib/get_around_owner/models/getaround_users_updated_all_of_data.rb +215 -0
- data/lib/get_around_owner/models/getaround_webhook.rb +252 -0
- data/lib/get_around_owner/version.rb +15 -0
- data/lib/get_around_owner.rb +86 -0
- data/spec/api/cars_api_spec.rb +60 -0
- data/spec/api/checkins_api_spec.rb +62 -0
- data/spec/api/checkouts_api_spec.rb +62 -0
- data/spec/api/invoices_api_spec.rb +76 -0
- data/spec/api/messages_api_spec.rb +73 -0
- data/spec/api/payouts_api_spec.rb +62 -0
- data/spec/api/rentals_api_spec.rb +62 -0
- data/spec/api/unavailabilities_api_spec.rb +77 -0
- data/spec/api/users_api_spec.rb +47 -0
- data/spec/models/getaround_car_spec.rb +66 -0
- data/spec/models/getaround_cars_index_inner_spec.rb +36 -0
- data/spec/models/getaround_checkin_spec.rb +54 -0
- data/spec/models/getaround_checkins_index_inner_spec.rb +36 -0
- data/spec/models/getaround_checkout_spec.rb +60 -0
- data/spec/models/getaround_create_messages_request_spec.rb +36 -0
- data/spec/models/getaround_create_unavailabilities_request_spec.rb +52 -0
- data/spec/models/getaround_destroy_unavailability_request_spec.rb +42 -0
- data/spec/models/getaround_invoice_charges_inner_spec.rb +42 -0
- data/spec/models/getaround_invoice_spec.rb +92 -0
- data/spec/models/getaround_invoices_index_inner_spec.rb +36 -0
- data/spec/models/getaround_message_spec.rb +60 -0
- data/spec/models/getaround_messages_sent_all_of_data_spec.rb +42 -0
- data/spec/models/getaround_messages_sent_spec.rb +48 -0
- data/spec/models/getaround_payout_invoices_inner_spec.rb +36 -0
- data/spec/models/getaround_payout_spec.rb +70 -0
- data/spec/models/getaround_payouts_index_inner_spec.rb +36 -0
- data/spec/models/getaround_reason_spec.rb +30 -0
- data/spec/models/getaround_rental_invoices_index_inner_spec.rb +36 -0
- data/spec/models/getaround_rental_messages_index_inner_spec.rb +36 -0
- data/spec/models/getaround_rental_spec.rb +78 -0
- data/spec/models/getaround_rentals_booked_all_of_data_spec.rb +36 -0
- data/spec/models/getaround_rentals_booked_spec.rb +48 -0
- data/spec/models/getaround_rentals_canceled_spec.rb +48 -0
- data/spec/models/getaround_rentals_car_checked_in_spec.rb +48 -0
- data/spec/models/getaround_rentals_car_checked_out_spec.rb +48 -0
- data/spec/models/getaround_rentals_car_switched_spec.rb +48 -0
- data/spec/models/getaround_rentals_index_inner_spec.rb +36 -0
- data/spec/models/getaround_rentals_times_changed_spec.rb +48 -0
- data/spec/models/getaround_unavailabilities_created_all_of_data_spec.rb +54 -0
- data/spec/models/getaround_unavailabilities_created_spec.rb +48 -0
- data/spec/models/getaround_unavailabilities_deleted_all_of_data_spec.rb +48 -0
- data/spec/models/getaround_unavailabilities_deleted_spec.rb +48 -0
- data/spec/models/getaround_unavailability_spec.rb +58 -0
- data/spec/models/getaround_user_spec.rb +108 -0
- data/spec/models/getaround_users_updated_all_of_data_spec.rb +36 -0
- data/spec/models/getaround_users_updated_spec.rb +48 -0
- data/spec/models/getaround_webhook_spec.rb +48 -0
- data/spec/spec_helper.rb +111 -0
- metadata +283 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
=begin
|
2
|
+
#Getaround Owner API
|
3
|
+
|
4
|
+
## Quick Start The Owner API uses the JSON format, and must be accessed over a [secure connection](https://en.wikipedia.org/wiki/HTTPS). Let’s assume that the access token provided by your account manager is “TOKEN”. Here’s how to get the list of ids of all your invoices from the first week of August with a shell script: ```bash query=\"end_date=2018-08-08T00%3A00%3A00%2B00%3A00&start_date=2018-08-01T00%3A00%3A00%2B00%3A00\" curl -i \"https://api-eu.getaround.com/owner/v1/invoices?${query}\" \\ -H \"Authorization: Bearer TOKEN\" \\ -H \"Accept:application/json\" \\ -H \"Content-Type:application/json\" ``` And here’s how to get the invoice with the id 12345: ```bash curl -i \"https://api-eu.getaround.com/owner/v1/invoices/12345\" \\ -H \"Authorization: Bearer TOKEN\" \\ -H \"Accept: application/json\" \\ -H \"Content-Type: application/json\"\" ``` See the [endpoints section](#tag/Invoices) of this guide for details about the response format. Dates in request params should follow the ISO 8601 standard. # Authentication All requests must be authenticated with a [bearer token header](https://tools.ietf.org/html/rfc6750#section-2.1). You token will be sent to you by your account manager. Unauthenticated requests will return a 401 status. # Pagination The page number and the number of items per page can be set with the “page” and “per_page” params. For example, this request will return the second page of invoices, and 50 invoices per page: `https://api-eu.getaround.com/owner/v1/invoices?page=2&per_page=50` Both of these params are optional. The default page size is 30 items. The Getaround Owner API follows the [RFC 8288 convention](https://datatracker.ietf.org/doc/html/rfc8288) of using the `Link` header to provide the `next` page URL. Please don't build the pagination URLs yourself. The `next` page will be missing when you are requesting the last available page. Here's an example response header from requesting the second page of invoices `https://api-eu.getaround.com/owner/v1/invoices?page=2&per_page=50` ``` Link: <https://api-eu.getaround.com/owner/v1/invoices?page=3&per_page=50>; rel=\"next\" ``` # Throttling policy and Date range limitation We have throttling policy that prevents you to perform more than 100 requests per min from the same IP. Also, there is a limitation on the size of the range of dates given in params in some requests. All requests that need start_date and end_date, do not accept a range bigger than 30 days. # Webhooks Getaround can send webhook events that notify your application when certain events happen on your account. This is especially useful to follow the lifecycle of rentals, tracking for example bookings or cancellations. ### Setup To set up an endpoint, you need to define a route on your server for receiving events, and then <a href=\"mailto:owner-api@getaround.com\">ask Getaround</a> to add this URL to your account. To acknowledge receipt of a event, your endpoint must: - Return a `2xx` HTTP status code. - Be a secure `https` endpoint with a valid SSL certificate. ### Testing Once Getaround has set up the endpoint, and it is properly configured as described above, a test `ping` event can be sent by clicking the button below: <form action=\"/docs/api/owner/fire_ping_webhook\" method=\"post\"><input type=\"submit\" value=\"Send Ping Event\"></form> You should receive the following JSON payload: ```json { \"data\": { \"ping\": \"pong\" }, \"type\": \"ping\", \"occurred_at\": \"2019-04-18T08:30:05Z\" } ``` ### Retries Webhook deliveries will be attempted for up to three days with an exponential back off. After that point the delivery will be abandoned. ### Verifying Signatures Getaround will also provide you with a secret token, which is used to create a hash signature with each payload. This hash signature is passed along with each request in the headers as `X-Drivy-Signature`. Suppose you have a basic server listening to webhooks that looks like this: ```ruby require 'sinatra' require 'json' post '/payload' do push = JSON.parse(params[:payload]) \"I got some JSON: \#{push.inspect}\" end ``` The goal is to compute a hash using your secret token, and ensure that the hash from Getaround matches. Getaround uses an HMAC hexdigest to compute the hash, so you could change your server to look a little like this: ```ruby post '/payload' do request.body.rewind payload_body = request.body.read verify_signature(payload_body) push = JSON.parse(params[:payload]) \"I got some JSON: \#{push.inspect}\" end def verify_signature(payload_body) signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), ENV['SECRET_TOKEN'], payload_body) return halt 500, \"Signatures didn't match!\" unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_DRIVY_SIGNATURE']) end ``` Obviously, your language and server implementations may differ from this code. There are a couple of important things to point out, however: No matter which implementation you use, the hash signature starts with `sha1=`, using the key of your secret token and your payload body. Using a plain `==` operator is not advised. A method like secure_compare performs a \"constant time\" string comparison, which renders it safe from certain timing attacks against regular equality operators. ### Best Practices - **Acknowledge events immediately**. If your webhook script performs complex logic, or makes network calls, it’s possible that the script would time out before Getaround sees its complete execution. Ideally, your webhook handler code (acknowledging receipt of an event by returning a `2xx` status code) is separate of any other logic you do for that event. - **Handle duplicate events**. Webhook endpoints might occasionally receive the same event more than once. We advise you to guard against duplicated event receipts by making your event processing idempotent. One way of doing this is logging the events you’ve processed, and then not processing already-logged events. - **Do not expect events in order**. Getaround does not guarantee delivery of events in the order in which they are generated. Your endpoint should therefore handle this accordingly. We do provide an `occurred_at` timestamp for each event, though, to help reconcile ordering.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
7
|
+
Contact: owner-api@getaround.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
Generator version: 7.6.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
module GetAroundOwner
|
14
|
+
class ApiError < StandardError
|
15
|
+
attr_reader :code, :response_headers, :response_body
|
16
|
+
|
17
|
+
# Usage examples:
|
18
|
+
# ApiError.new
|
19
|
+
# ApiError.new("message")
|
20
|
+
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
21
|
+
# ApiError.new(:code => 404, :message => "Not Found")
|
22
|
+
def initialize(arg = nil)
|
23
|
+
if arg.is_a? Hash
|
24
|
+
if arg.key?(:message) || arg.key?('message')
|
25
|
+
super(arg[:message] || arg['message'])
|
26
|
+
else
|
27
|
+
super arg
|
28
|
+
end
|
29
|
+
|
30
|
+
arg.each do |k, v|
|
31
|
+
instance_variable_set "@#{k}", v
|
32
|
+
end
|
33
|
+
else
|
34
|
+
super arg
|
35
|
+
@message = arg
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Override to_s to display a friendly error message
|
40
|
+
def to_s
|
41
|
+
message
|
42
|
+
end
|
43
|
+
|
44
|
+
def message
|
45
|
+
if @message.nil?
|
46
|
+
msg = "Error message: the server returns an error"
|
47
|
+
else
|
48
|
+
msg = @message
|
49
|
+
end
|
50
|
+
|
51
|
+
msg += "\nHTTP status code: #{code}" if code
|
52
|
+
msg += "\nResponse headers: #{response_headers}" if response_headers
|
53
|
+
msg += "\nResponse body: #{response_body}" if response_body
|
54
|
+
|
55
|
+
msg
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,298 @@
|
|
1
|
+
=begin
|
2
|
+
#Getaround Owner API
|
3
|
+
|
4
|
+
## Quick Start The Owner API uses the JSON format, and must be accessed over a [secure connection](https://en.wikipedia.org/wiki/HTTPS). Let’s assume that the access token provided by your account manager is “TOKEN”. Here’s how to get the list of ids of all your invoices from the first week of August with a shell script: ```bash query=\"end_date=2018-08-08T00%3A00%3A00%2B00%3A00&start_date=2018-08-01T00%3A00%3A00%2B00%3A00\" curl -i \"https://api-eu.getaround.com/owner/v1/invoices?${query}\" \\ -H \"Authorization: Bearer TOKEN\" \\ -H \"Accept:application/json\" \\ -H \"Content-Type:application/json\" ``` And here’s how to get the invoice with the id 12345: ```bash curl -i \"https://api-eu.getaround.com/owner/v1/invoices/12345\" \\ -H \"Authorization: Bearer TOKEN\" \\ -H \"Accept: application/json\" \\ -H \"Content-Type: application/json\"\" ``` See the [endpoints section](#tag/Invoices) of this guide for details about the response format. Dates in request params should follow the ISO 8601 standard. # Authentication All requests must be authenticated with a [bearer token header](https://tools.ietf.org/html/rfc6750#section-2.1). You token will be sent to you by your account manager. Unauthenticated requests will return a 401 status. # Pagination The page number and the number of items per page can be set with the “page” and “per_page” params. For example, this request will return the second page of invoices, and 50 invoices per page: `https://api-eu.getaround.com/owner/v1/invoices?page=2&per_page=50` Both of these params are optional. The default page size is 30 items. The Getaround Owner API follows the [RFC 8288 convention](https://datatracker.ietf.org/doc/html/rfc8288) of using the `Link` header to provide the `next` page URL. Please don't build the pagination URLs yourself. The `next` page will be missing when you are requesting the last available page. Here's an example response header from requesting the second page of invoices `https://api-eu.getaround.com/owner/v1/invoices?page=2&per_page=50` ``` Link: <https://api-eu.getaround.com/owner/v1/invoices?page=3&per_page=50>; rel=\"next\" ``` # Throttling policy and Date range limitation We have throttling policy that prevents you to perform more than 100 requests per min from the same IP. Also, there is a limitation on the size of the range of dates given in params in some requests. All requests that need start_date and end_date, do not accept a range bigger than 30 days. # Webhooks Getaround can send webhook events that notify your application when certain events happen on your account. This is especially useful to follow the lifecycle of rentals, tracking for example bookings or cancellations. ### Setup To set up an endpoint, you need to define a route on your server for receiving events, and then <a href=\"mailto:owner-api@getaround.com\">ask Getaround</a> to add this URL to your account. To acknowledge receipt of a event, your endpoint must: - Return a `2xx` HTTP status code. - Be a secure `https` endpoint with a valid SSL certificate. ### Testing Once Getaround has set up the endpoint, and it is properly configured as described above, a test `ping` event can be sent by clicking the button below: <form action=\"/docs/api/owner/fire_ping_webhook\" method=\"post\"><input type=\"submit\" value=\"Send Ping Event\"></form> You should receive the following JSON payload: ```json { \"data\": { \"ping\": \"pong\" }, \"type\": \"ping\", \"occurred_at\": \"2019-04-18T08:30:05Z\" } ``` ### Retries Webhook deliveries will be attempted for up to three days with an exponential back off. After that point the delivery will be abandoned. ### Verifying Signatures Getaround will also provide you with a secret token, which is used to create a hash signature with each payload. This hash signature is passed along with each request in the headers as `X-Drivy-Signature`. Suppose you have a basic server listening to webhooks that looks like this: ```ruby require 'sinatra' require 'json' post '/payload' do push = JSON.parse(params[:payload]) \"I got some JSON: \#{push.inspect}\" end ``` The goal is to compute a hash using your secret token, and ensure that the hash from Getaround matches. Getaround uses an HMAC hexdigest to compute the hash, so you could change your server to look a little like this: ```ruby post '/payload' do request.body.rewind payload_body = request.body.read verify_signature(payload_body) push = JSON.parse(params[:payload]) \"I got some JSON: \#{push.inspect}\" end def verify_signature(payload_body) signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), ENV['SECRET_TOKEN'], payload_body) return halt 500, \"Signatures didn't match!\" unless Rack::Utils.secure_compare(signature, request.env['HTTP_X_DRIVY_SIGNATURE']) end ``` Obviously, your language and server implementations may differ from this code. There are a couple of important things to point out, however: No matter which implementation you use, the hash signature starts with `sha1=`, using the key of your secret token and your payload body. Using a plain `==` operator is not advised. A method like secure_compare performs a \"constant time\" string comparison, which renders it safe from certain timing attacks against regular equality operators. ### Best Practices - **Acknowledge events immediately**. If your webhook script performs complex logic, or makes network calls, it’s possible that the script would time out before Getaround sees its complete execution. Ideally, your webhook handler code (acknowledging receipt of an event by returning a `2xx` status code) is separate of any other logic you do for that event. - **Handle duplicate events**. Webhook endpoints might occasionally receive the same event more than once. We advise you to guard against duplicated event receipts by making your event processing idempotent. One way of doing this is logging the events you’ve processed, and then not processing already-logged events. - **Do not expect events in order**. Getaround does not guarantee delivery of events in the order in which they are generated. Your endpoint should therefore handle this accordingly. We do provide an `occurred_at` timestamp for each event, though, to help reconcile ordering.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
7
|
+
Contact: owner-api@getaround.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
Generator version: 7.6.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
module GetAroundOwner
|
14
|
+
class Configuration
|
15
|
+
# Defines url scheme
|
16
|
+
attr_accessor :scheme
|
17
|
+
|
18
|
+
# Defines url host
|
19
|
+
attr_accessor :host
|
20
|
+
|
21
|
+
# Defines url base path
|
22
|
+
attr_accessor :base_path
|
23
|
+
|
24
|
+
# Define server configuration index
|
25
|
+
attr_accessor :server_index
|
26
|
+
|
27
|
+
# Define server operation configuration index
|
28
|
+
attr_accessor :server_operation_index
|
29
|
+
|
30
|
+
# Default server variables
|
31
|
+
attr_accessor :server_variables
|
32
|
+
|
33
|
+
# Default server operation variables
|
34
|
+
attr_accessor :server_operation_variables
|
35
|
+
|
36
|
+
# Defines API keys used with API Key authentications.
|
37
|
+
#
|
38
|
+
# @return [Hash] key: parameter name, value: parameter value (API key)
|
39
|
+
#
|
40
|
+
# @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
|
41
|
+
# config.api_key['api_key'] = 'xxx'
|
42
|
+
attr_accessor :api_key
|
43
|
+
|
44
|
+
# Defines API key prefixes used with API Key authentications.
|
45
|
+
#
|
46
|
+
# @return [Hash] key: parameter name, value: API key prefix
|
47
|
+
#
|
48
|
+
# @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
|
49
|
+
# config.api_key_prefix['api_key'] = 'Token'
|
50
|
+
attr_accessor :api_key_prefix
|
51
|
+
|
52
|
+
# Defines the username used with HTTP basic authentication.
|
53
|
+
#
|
54
|
+
# @return [String]
|
55
|
+
attr_accessor :username
|
56
|
+
|
57
|
+
# Defines the password used with HTTP basic authentication.
|
58
|
+
#
|
59
|
+
# @return [String]
|
60
|
+
attr_accessor :password
|
61
|
+
|
62
|
+
# Defines the access token (Bearer) used with OAuth2.
|
63
|
+
attr_accessor :access_token
|
64
|
+
|
65
|
+
# Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
|
66
|
+
# Overrides the access_token if set
|
67
|
+
# @return [Proc]
|
68
|
+
attr_accessor :access_token_getter
|
69
|
+
|
70
|
+
# Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
|
71
|
+
# HTTP responses with return type `File` will be returned as a stream of binary data.
|
72
|
+
# Default to false.
|
73
|
+
attr_accessor :return_binary_data
|
74
|
+
|
75
|
+
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
76
|
+
# details will be logged with `logger.debug` (see the `logger` attribute).
|
77
|
+
# Default to false.
|
78
|
+
#
|
79
|
+
# @return [true, false]
|
80
|
+
attr_accessor :debugging
|
81
|
+
|
82
|
+
# Defines the logger used for debugging.
|
83
|
+
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
|
84
|
+
#
|
85
|
+
# @return [#debug]
|
86
|
+
attr_accessor :logger
|
87
|
+
|
88
|
+
# Defines the temporary folder to store downloaded files
|
89
|
+
# (for API endpoints that have file response).
|
90
|
+
# Default to use `Tempfile`.
|
91
|
+
#
|
92
|
+
# @return [String]
|
93
|
+
attr_accessor :temp_folder_path
|
94
|
+
|
95
|
+
# The time limit for HTTP request in seconds.
|
96
|
+
# Default to 0 (never times out).
|
97
|
+
attr_accessor :timeout
|
98
|
+
|
99
|
+
# Set this to false to skip client side validation in the operation.
|
100
|
+
# Default to true.
|
101
|
+
# @return [true, false]
|
102
|
+
attr_accessor :client_side_validation
|
103
|
+
|
104
|
+
### TLS/SSL setting
|
105
|
+
# Set this to false to skip verifying SSL certificate when calling API from https server.
|
106
|
+
# Default to true.
|
107
|
+
#
|
108
|
+
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
109
|
+
#
|
110
|
+
# @return [true, false]
|
111
|
+
attr_accessor :verify_ssl
|
112
|
+
|
113
|
+
### TLS/SSL setting
|
114
|
+
# Set this to false to skip verifying SSL host name
|
115
|
+
# Default to true.
|
116
|
+
#
|
117
|
+
# @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
|
118
|
+
#
|
119
|
+
# @return [true, false]
|
120
|
+
attr_accessor :verify_ssl_host
|
121
|
+
|
122
|
+
### TLS/SSL setting
|
123
|
+
# Set this to customize the certificate file to verify the peer.
|
124
|
+
#
|
125
|
+
# @return [String] the path to the certificate file
|
126
|
+
#
|
127
|
+
# @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
|
128
|
+
# https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
|
129
|
+
attr_accessor :ssl_ca_cert
|
130
|
+
|
131
|
+
### TLS/SSL setting
|
132
|
+
# Client certificate file (for client certificate)
|
133
|
+
attr_accessor :cert_file
|
134
|
+
|
135
|
+
### TLS/SSL setting
|
136
|
+
# Client private key file (for client certificate)
|
137
|
+
attr_accessor :key_file
|
138
|
+
|
139
|
+
# Set this to customize parameters encoding of array parameter with multi collectionFormat.
|
140
|
+
# Default to nil.
|
141
|
+
#
|
142
|
+
# @see The params_encoding option of Ethon. Related source code:
|
143
|
+
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
|
144
|
+
attr_accessor :params_encoding
|
145
|
+
|
146
|
+
|
147
|
+
attr_accessor :inject_format
|
148
|
+
|
149
|
+
attr_accessor :force_ending_format
|
150
|
+
|
151
|
+
def initialize
|
152
|
+
@scheme = 'https'
|
153
|
+
@host = 'api-eu.getaround.com'
|
154
|
+
@base_path = '/owner/v1'
|
155
|
+
@server_index = nil
|
156
|
+
@server_operation_index = {}
|
157
|
+
@server_variables = {}
|
158
|
+
@server_operation_variables = {}
|
159
|
+
@api_key = {}
|
160
|
+
@api_key_prefix = {}
|
161
|
+
@client_side_validation = true
|
162
|
+
@verify_ssl = true
|
163
|
+
@verify_ssl_host = true
|
164
|
+
@cert_file = nil
|
165
|
+
@key_file = nil
|
166
|
+
@timeout = 0
|
167
|
+
@params_encoding = nil
|
168
|
+
@debugging = false
|
169
|
+
@inject_format = false
|
170
|
+
@force_ending_format = false
|
171
|
+
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
172
|
+
|
173
|
+
yield(self) if block_given?
|
174
|
+
end
|
175
|
+
|
176
|
+
# The default Configuration object.
|
177
|
+
def self.default
|
178
|
+
@@default ||= Configuration.new
|
179
|
+
end
|
180
|
+
|
181
|
+
def configure
|
182
|
+
yield(self) if block_given?
|
183
|
+
end
|
184
|
+
|
185
|
+
def scheme=(scheme)
|
186
|
+
# remove :// from scheme
|
187
|
+
@scheme = scheme.sub(/:\/\//, '')
|
188
|
+
end
|
189
|
+
|
190
|
+
def host=(host)
|
191
|
+
# remove http(s):// and anything after a slash
|
192
|
+
@host = host.sub(/https?:\/\//, '').split('/').first
|
193
|
+
end
|
194
|
+
|
195
|
+
def base_path=(base_path)
|
196
|
+
# Add leading and trailing slashes to base_path
|
197
|
+
@base_path = "/#{base_path}".gsub(/\/+/, '/')
|
198
|
+
@base_path = '' if @base_path == '/'
|
199
|
+
end
|
200
|
+
|
201
|
+
# Returns base URL for specified operation based on server settings
|
202
|
+
def base_url(operation = nil)
|
203
|
+
if operation_server_settings.key?(operation) then
|
204
|
+
index = server_operation_index.fetch(operation, server_index)
|
205
|
+
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
|
206
|
+
else
|
207
|
+
server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# Gets API key (with prefix if set).
|
212
|
+
# @param [String] param_name the parameter name of API key auth
|
213
|
+
def api_key_with_prefix(param_name, param_alias = nil)
|
214
|
+
key = @api_key[param_name]
|
215
|
+
key = @api_key.fetch(param_alias, key) unless param_alias.nil?
|
216
|
+
if @api_key_prefix[param_name]
|
217
|
+
"#{@api_key_prefix[param_name]} #{key}"
|
218
|
+
else
|
219
|
+
key
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
# Gets access_token using access_token_getter or uses the static access_token
|
224
|
+
def access_token_with_refresh
|
225
|
+
return access_token if access_token_getter.nil?
|
226
|
+
access_token_getter.call
|
227
|
+
end
|
228
|
+
|
229
|
+
# Gets Basic Auth token string
|
230
|
+
def basic_auth_token
|
231
|
+
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
232
|
+
end
|
233
|
+
|
234
|
+
# Returns Auth Settings hash for api client.
|
235
|
+
def auth_settings
|
236
|
+
{
|
237
|
+
'bearerAuth' =>
|
238
|
+
{
|
239
|
+
type: 'bearer',
|
240
|
+
in: 'header',
|
241
|
+
key: 'Authorization',
|
242
|
+
value: "Bearer #{access_token_with_refresh}"
|
243
|
+
},
|
244
|
+
}
|
245
|
+
end
|
246
|
+
|
247
|
+
# Returns an array of Server setting
|
248
|
+
def server_settings
|
249
|
+
[
|
250
|
+
{
|
251
|
+
url: "https://api-eu.getaround.com/owner/v1",
|
252
|
+
description: "Production server",
|
253
|
+
}
|
254
|
+
]
|
255
|
+
end
|
256
|
+
|
257
|
+
def operation_server_settings
|
258
|
+
{
|
259
|
+
}
|
260
|
+
end
|
261
|
+
|
262
|
+
# Returns URL based on server settings
|
263
|
+
#
|
264
|
+
# @param index array index of the server settings
|
265
|
+
# @param variables hash of variable and the corresponding value
|
266
|
+
def server_url(index, variables = {}, servers = nil)
|
267
|
+
servers = server_settings if servers == nil
|
268
|
+
|
269
|
+
# check array index out of bound
|
270
|
+
if (index.nil? || index < 0 || index >= servers.size)
|
271
|
+
fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
|
272
|
+
end
|
273
|
+
|
274
|
+
server = servers[index]
|
275
|
+
url = server[:url]
|
276
|
+
|
277
|
+
return url unless server.key? :variables
|
278
|
+
|
279
|
+
# go through variable and assign a value
|
280
|
+
server[:variables].each do |name, variable|
|
281
|
+
if variables.key?(name)
|
282
|
+
if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
|
283
|
+
url.gsub! "{" + name.to_s + "}", variables[name]
|
284
|
+
else
|
285
|
+
fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
|
286
|
+
end
|
287
|
+
else
|
288
|
+
# use default value
|
289
|
+
url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
url
|
294
|
+
end
|
295
|
+
|
296
|
+
|
297
|
+
end
|
298
|
+
end
|