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.
Files changed (154) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +303 -0
  4. data/Rakefile +10 -0
  5. data/docs/CarsApi.md +151 -0
  6. data/docs/CheckinsApi.md +71 -0
  7. data/docs/CheckoutsApi.md +71 -0
  8. data/docs/GetaroundCar.md +28 -0
  9. data/docs/GetaroundCarsIndexInner.md +18 -0
  10. data/docs/GetaroundCheckin.md +24 -0
  11. data/docs/GetaroundCheckinsIndexInner.md +18 -0
  12. data/docs/GetaroundCheckout.md +26 -0
  13. data/docs/GetaroundCreateMessagesRequest.md +18 -0
  14. data/docs/GetaroundCreateUnavailabilitiesRequest.md +22 -0
  15. data/docs/GetaroundDestroyUnavailabilityRequest.md +20 -0
  16. data/docs/GetaroundInvoice.md +34 -0
  17. data/docs/GetaroundInvoiceChargesInner.md +20 -0
  18. data/docs/GetaroundInvoicesIndexInner.md +18 -0
  19. data/docs/GetaroundMessage.md +26 -0
  20. data/docs/GetaroundMessagesSent.md +22 -0
  21. data/docs/GetaroundMessagesSentAllOfData.md +20 -0
  22. data/docs/GetaroundPayout.md +28 -0
  23. data/docs/GetaroundPayoutInvoicesInner.md +18 -0
  24. data/docs/GetaroundPayoutsIndexInner.md +18 -0
  25. data/docs/GetaroundReason.md +15 -0
  26. data/docs/GetaroundRental.md +32 -0
  27. data/docs/GetaroundRentalInvoicesIndexInner.md +18 -0
  28. data/docs/GetaroundRentalMessagesIndexInner.md +18 -0
  29. data/docs/GetaroundRentalsBooked.md +22 -0
  30. data/docs/GetaroundRentalsBookedAllOfData.md +18 -0
  31. data/docs/GetaroundRentalsCanceled.md +22 -0
  32. data/docs/GetaroundRentalsCarCheckedIn.md +22 -0
  33. data/docs/GetaroundRentalsCarCheckedOut.md +22 -0
  34. data/docs/GetaroundRentalsCarSwitched.md +22 -0
  35. data/docs/GetaroundRentalsIndexInner.md +18 -0
  36. data/docs/GetaroundRentalsTimesChanged.md +22 -0
  37. data/docs/GetaroundUnavailabilitiesCreated.md +22 -0
  38. data/docs/GetaroundUnavailabilitiesCreatedAllOfData.md +24 -0
  39. data/docs/GetaroundUnavailabilitiesDeleted.md +22 -0
  40. data/docs/GetaroundUnavailabilitiesDeletedAllOfData.md +22 -0
  41. data/docs/GetaroundUnavailability.md +24 -0
  42. data/docs/GetaroundUser.md +42 -0
  43. data/docs/GetaroundUsersUpdated.md +22 -0
  44. data/docs/GetaroundUsersUpdatedAllOfData.md +18 -0
  45. data/docs/GetaroundWebhook.md +22 -0
  46. data/docs/InvoicesApi.md +231 -0
  47. data/docs/MessagesApi.md +71 -0
  48. data/docs/PayoutsApi.md +155 -0
  49. data/docs/RentalsApi.md +263 -0
  50. data/docs/UnavailabilitiesApi.md +135 -0
  51. data/docs/UsersApi.md +71 -0
  52. data/get_around_owner.gemspec +26 -0
  53. data/git_push.sh +57 -0
  54. data/lib/get_around_owner/api/cars_api.rb +148 -0
  55. data/lib/get_around_owner/api/checkins_api.rb +82 -0
  56. data/lib/get_around_owner/api/checkouts_api.rb +82 -0
  57. data/lib/get_around_owner/api/invoices_api.rb +223 -0
  58. data/lib/get_around_owner/api/messages_api.rb +82 -0
  59. data/lib/get_around_owner/api/payouts_api.rb +162 -0
  60. data/lib/get_around_owner/api/rentals_api.rb +262 -0
  61. data/lib/get_around_owner/api/unavailabilities_api.rb +142 -0
  62. data/lib/get_around_owner/api/users_api.rb +82 -0
  63. data/lib/get_around_owner/api_client.rb +394 -0
  64. data/lib/get_around_owner/api_error.rb +58 -0
  65. data/lib/get_around_owner/configuration.rb +298 -0
  66. data/lib/get_around_owner/models/getaround_car.rb +308 -0
  67. data/lib/get_around_owner/models/getaround_cars_index_inner.rb +223 -0
  68. data/lib/get_around_owner/models/getaround_checkin.rb +279 -0
  69. data/lib/get_around_owner/models/getaround_checkins_index_inner.rb +222 -0
  70. data/lib/get_around_owner/models/getaround_checkout.rb +298 -0
  71. data/lib/get_around_owner/models/getaround_create_messages_request.rb +222 -0
  72. data/lib/get_around_owner/models/getaround_create_unavailabilities_request.rb +283 -0
  73. data/lib/get_around_owner/models/getaround_destroy_unavailability_request.rb +239 -0
  74. data/lib/get_around_owner/models/getaround_invoice.rb +396 -0
  75. data/lib/get_around_owner/models/getaround_invoice_charges_inner.rb +225 -0
  76. data/lib/get_around_owner/models/getaround_invoices_index_inner.rb +223 -0
  77. data/lib/get_around_owner/models/getaround_message.rb +291 -0
  78. data/lib/get_around_owner/models/getaround_messages_sent.rb +257 -0
  79. data/lib/get_around_owner/models/getaround_messages_sent_all_of_data.rb +225 -0
  80. data/lib/get_around_owner/models/getaround_payout.rb +347 -0
  81. data/lib/get_around_owner/models/getaround_payout_invoices_inner.rb +223 -0
  82. data/lib/get_around_owner/models/getaround_payouts_index_inner.rb +223 -0
  83. data/lib/get_around_owner/models/getaround_reason.rb +45 -0
  84. data/lib/get_around_owner/models/getaround_rental.rb +380 -0
  85. data/lib/get_around_owner/models/getaround_rental_invoices_index_inner.rb +223 -0
  86. data/lib/get_around_owner/models/getaround_rental_messages_index_inner.rb +223 -0
  87. data/lib/get_around_owner/models/getaround_rentals_booked.rb +257 -0
  88. data/lib/get_around_owner/models/getaround_rentals_booked_all_of_data.rb +215 -0
  89. data/lib/get_around_owner/models/getaround_rentals_canceled.rb +257 -0
  90. data/lib/get_around_owner/models/getaround_rentals_car_checked_in.rb +257 -0
  91. data/lib/get_around_owner/models/getaround_rentals_car_checked_out.rb +257 -0
  92. data/lib/get_around_owner/models/getaround_rentals_car_switched.rb +257 -0
  93. data/lib/get_around_owner/models/getaround_rentals_index_inner.rb +223 -0
  94. data/lib/get_around_owner/models/getaround_rentals_times_changed.rb +257 -0
  95. data/lib/get_around_owner/models/getaround_unavailabilities_created.rb +257 -0
  96. data/lib/get_around_owner/models/getaround_unavailabilities_created_all_of_data.rb +267 -0
  97. data/lib/get_around_owner/models/getaround_unavailabilities_deleted.rb +257 -0
  98. data/lib/get_around_owner/models/getaround_unavailabilities_deleted_all_of_data.rb +235 -0
  99. data/lib/get_around_owner/models/getaround_unavailability.rb +302 -0
  100. data/lib/get_around_owner/models/getaround_user.rb +420 -0
  101. data/lib/get_around_owner/models/getaround_users_updated.rb +257 -0
  102. data/lib/get_around_owner/models/getaround_users_updated_all_of_data.rb +215 -0
  103. data/lib/get_around_owner/models/getaround_webhook.rb +252 -0
  104. data/lib/get_around_owner/version.rb +15 -0
  105. data/lib/get_around_owner.rb +86 -0
  106. data/spec/api/cars_api_spec.rb +60 -0
  107. data/spec/api/checkins_api_spec.rb +62 -0
  108. data/spec/api/checkouts_api_spec.rb +62 -0
  109. data/spec/api/invoices_api_spec.rb +76 -0
  110. data/spec/api/messages_api_spec.rb +73 -0
  111. data/spec/api/payouts_api_spec.rb +62 -0
  112. data/spec/api/rentals_api_spec.rb +62 -0
  113. data/spec/api/unavailabilities_api_spec.rb +77 -0
  114. data/spec/api/users_api_spec.rb +47 -0
  115. data/spec/models/getaround_car_spec.rb +66 -0
  116. data/spec/models/getaround_cars_index_inner_spec.rb +36 -0
  117. data/spec/models/getaround_checkin_spec.rb +54 -0
  118. data/spec/models/getaround_checkins_index_inner_spec.rb +36 -0
  119. data/spec/models/getaround_checkout_spec.rb +60 -0
  120. data/spec/models/getaround_create_messages_request_spec.rb +36 -0
  121. data/spec/models/getaround_create_unavailabilities_request_spec.rb +52 -0
  122. data/spec/models/getaround_destroy_unavailability_request_spec.rb +42 -0
  123. data/spec/models/getaround_invoice_charges_inner_spec.rb +42 -0
  124. data/spec/models/getaround_invoice_spec.rb +92 -0
  125. data/spec/models/getaround_invoices_index_inner_spec.rb +36 -0
  126. data/spec/models/getaround_message_spec.rb +60 -0
  127. data/spec/models/getaround_messages_sent_all_of_data_spec.rb +42 -0
  128. data/spec/models/getaround_messages_sent_spec.rb +48 -0
  129. data/spec/models/getaround_payout_invoices_inner_spec.rb +36 -0
  130. data/spec/models/getaround_payout_spec.rb +70 -0
  131. data/spec/models/getaround_payouts_index_inner_spec.rb +36 -0
  132. data/spec/models/getaround_reason_spec.rb +30 -0
  133. data/spec/models/getaround_rental_invoices_index_inner_spec.rb +36 -0
  134. data/spec/models/getaround_rental_messages_index_inner_spec.rb +36 -0
  135. data/spec/models/getaround_rental_spec.rb +78 -0
  136. data/spec/models/getaround_rentals_booked_all_of_data_spec.rb +36 -0
  137. data/spec/models/getaround_rentals_booked_spec.rb +48 -0
  138. data/spec/models/getaround_rentals_canceled_spec.rb +48 -0
  139. data/spec/models/getaround_rentals_car_checked_in_spec.rb +48 -0
  140. data/spec/models/getaround_rentals_car_checked_out_spec.rb +48 -0
  141. data/spec/models/getaround_rentals_car_switched_spec.rb +48 -0
  142. data/spec/models/getaround_rentals_index_inner_spec.rb +36 -0
  143. data/spec/models/getaround_rentals_times_changed_spec.rb +48 -0
  144. data/spec/models/getaround_unavailabilities_created_all_of_data_spec.rb +54 -0
  145. data/spec/models/getaround_unavailabilities_created_spec.rb +48 -0
  146. data/spec/models/getaround_unavailabilities_deleted_all_of_data_spec.rb +48 -0
  147. data/spec/models/getaround_unavailabilities_deleted_spec.rb +48 -0
  148. data/spec/models/getaround_unavailability_spec.rb +58 -0
  149. data/spec/models/getaround_user_spec.rb +108 -0
  150. data/spec/models/getaround_users_updated_all_of_data_spec.rb +36 -0
  151. data/spec/models/getaround_users_updated_spec.rb +48 -0
  152. data/spec/models/getaround_webhook_spec.rb +48 -0
  153. data/spec/spec_helper.rb +111 -0
  154. metadata +283 -0
@@ -0,0 +1,142 @@
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
+ require 'cgi'
14
+
15
+ module GetAroundOwner
16
+ class UnavailabilitiesApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+ # Unavailability created on one of your cars
23
+ # @param [Hash] opts the optional parameters
24
+ # @option opts [GetaroundUnavailabilitiesCreated] :getaround_unavailabilities_created This event is triggered whenever an unavailability is created (through the API or directly in the app/website). It shows the unavailability that has just been created, with the same timestamps as those entered by the user. It does not show the changes of other potential overlapping unavailabilities. For example: if an unavailability was already set between June 10 and June 20, and if the user creates a new one between June 18 and June 22, this webhook will only send information about the newly created June 18 - June 22 unavailability. It will not show that, under the hood, the unavailability from June 10 to June 20 has be deleted, and that a new unavailability from June 10 to June 22 has been created.
25
+ # @return [nil]
26
+ def created_unavailability_post(opts = {})
27
+ created_unavailability_post_with_http_info(opts)
28
+ nil
29
+ end
30
+
31
+ # Unavailability created on one of your cars
32
+ # @param [Hash] opts the optional parameters
33
+ # @option opts [GetaroundUnavailabilitiesCreated] :getaround_unavailabilities_created This event is triggered whenever an unavailability is created (through the API or directly in the app/website). It shows the unavailability that has just been created, with the same timestamps as those entered by the user. It does not show the changes of other potential overlapping unavailabilities. For example: if an unavailability was already set between June 10 and June 20, and if the user creates a new one between June 18 and June 22, this webhook will only send information about the newly created June 18 - June 22 unavailability. It will not show that, under the hood, the unavailability from June 10 to June 20 has be deleted, and that a new unavailability from June 10 to June 22 has been created.
34
+ # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
35
+ def created_unavailability_post_with_http_info(opts = {})
36
+ if @api_client.config.debugging
37
+ @api_client.config.logger.debug 'Calling API: UnavailabilitiesApi.created_unavailability_post ...'
38
+ end
39
+ # resource path
40
+ local_var_path = '/createdUnavailability'
41
+
42
+ # query parameters
43
+ query_params = opts[:query_params] || {}
44
+
45
+ # header parameters
46
+ header_params = opts[:header_params] || {}
47
+ # HTTP header 'Content-Type'
48
+ content_type = @api_client.select_header_content_type(['application/json'])
49
+ if !content_type.nil?
50
+ header_params['Content-Type'] = content_type
51
+ end
52
+
53
+ # form parameters
54
+ form_params = opts[:form_params] || {}
55
+
56
+ # http body (model)
57
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'getaround_unavailabilities_created'])
58
+
59
+ # return_type
60
+ return_type = opts[:debug_return_type]
61
+
62
+ # auth_names
63
+ auth_names = opts[:debug_auth_names] || []
64
+
65
+ new_options = opts.merge(
66
+ :operation => :"UnavailabilitiesApi.created_unavailability_post",
67
+ :header_params => header_params,
68
+ :query_params => query_params,
69
+ :form_params => form_params,
70
+ :body => post_body,
71
+ :auth_names => auth_names,
72
+ :return_type => return_type
73
+ )
74
+
75
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
76
+ if @api_client.config.debugging
77
+ @api_client.config.logger.debug "API called: UnavailabilitiesApi#created_unavailability_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
78
+ end
79
+ return data, status_code, headers
80
+ end
81
+
82
+ # Unavailabilities deleted on one of your cars
83
+ # @param [Hash] opts the optional parameters
84
+ # @option opts [GetaroundUnavailabilitiesDeleted] :getaround_unavailabilities_deleted This event is triggered whenever an unavailability is deleted (through the API or directly in the app/website). It shows the unavailability that has just been deleted, with the same timestamps as those entered by the user. It does not show the changes of other potential overlapping unavailabilities. For example: if an unavailability was already set between June 10 and June 20, and if the user deletes an unavailability between June 18 and June 22 (to set their car as available between this dates), this webhook will only send information about the newly deleted June 18 - June 22 unavailability. It will not show that, under the hood, the unavailability from June 10 to June 20 has be deleted, and that a new unavailability from June 10 to June 18 has been created.
85
+ # @return [nil]
86
+ def deleted_unavailability_post(opts = {})
87
+ deleted_unavailability_post_with_http_info(opts)
88
+ nil
89
+ end
90
+
91
+ # Unavailabilities deleted on one of your cars
92
+ # @param [Hash] opts the optional parameters
93
+ # @option opts [GetaroundUnavailabilitiesDeleted] :getaround_unavailabilities_deleted This event is triggered whenever an unavailability is deleted (through the API or directly in the app/website). It shows the unavailability that has just been deleted, with the same timestamps as those entered by the user. It does not show the changes of other potential overlapping unavailabilities. For example: if an unavailability was already set between June 10 and June 20, and if the user deletes an unavailability between June 18 and June 22 (to set their car as available between this dates), this webhook will only send information about the newly deleted June 18 - June 22 unavailability. It will not show that, under the hood, the unavailability from June 10 to June 20 has be deleted, and that a new unavailability from June 10 to June 18 has been created.
94
+ # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
95
+ def deleted_unavailability_post_with_http_info(opts = {})
96
+ if @api_client.config.debugging
97
+ @api_client.config.logger.debug 'Calling API: UnavailabilitiesApi.deleted_unavailability_post ...'
98
+ end
99
+ # resource path
100
+ local_var_path = '/deletedUnavailability'
101
+
102
+ # query parameters
103
+ query_params = opts[:query_params] || {}
104
+
105
+ # header parameters
106
+ header_params = opts[:header_params] || {}
107
+ # HTTP header 'Content-Type'
108
+ content_type = @api_client.select_header_content_type(['application/json'])
109
+ if !content_type.nil?
110
+ header_params['Content-Type'] = content_type
111
+ end
112
+
113
+ # form parameters
114
+ form_params = opts[:form_params] || {}
115
+
116
+ # http body (model)
117
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'getaround_unavailabilities_deleted'])
118
+
119
+ # return_type
120
+ return_type = opts[:debug_return_type]
121
+
122
+ # auth_names
123
+ auth_names = opts[:debug_auth_names] || []
124
+
125
+ new_options = opts.merge(
126
+ :operation => :"UnavailabilitiesApi.deleted_unavailability_post",
127
+ :header_params => header_params,
128
+ :query_params => query_params,
129
+ :form_params => form_params,
130
+ :body => post_body,
131
+ :auth_names => auth_names,
132
+ :return_type => return_type
133
+ )
134
+
135
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
136
+ if @api_client.config.debugging
137
+ @api_client.config.logger.debug "API called: UnavailabilitiesApi#deleted_unavailability_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
138
+ end
139
+ return data, status_code, headers
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,82 @@
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
+ require 'cgi'
14
+
15
+ module GetAroundOwner
16
+ class UsersApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+ # User updated his profile information
23
+ # @param [Hash] opts the optional parameters
24
+ # @option opts [GetaroundUsersUpdated] :getaround_users_updated This event is triggered when a user updates his profile information (You will only receive this event on users with a booked rental or a started rental).
25
+ # @return [nil]
26
+ def updated_user_post(opts = {})
27
+ updated_user_post_with_http_info(opts)
28
+ nil
29
+ end
30
+
31
+ # User updated his profile information
32
+ # @param [Hash] opts the optional parameters
33
+ # @option opts [GetaroundUsersUpdated] :getaround_users_updated This event is triggered when a user updates his profile information (You will only receive this event on users with a booked rental or a started rental).
34
+ # @return [Array<(nil, Integer, Hash)>] nil, response status code and response headers
35
+ def updated_user_post_with_http_info(opts = {})
36
+ if @api_client.config.debugging
37
+ @api_client.config.logger.debug 'Calling API: UsersApi.updated_user_post ...'
38
+ end
39
+ # resource path
40
+ local_var_path = '/updatedUser'
41
+
42
+ # query parameters
43
+ query_params = opts[:query_params] || {}
44
+
45
+ # header parameters
46
+ header_params = opts[:header_params] || {}
47
+ # HTTP header 'Content-Type'
48
+ content_type = @api_client.select_header_content_type(['application/json'])
49
+ if !content_type.nil?
50
+ header_params['Content-Type'] = content_type
51
+ end
52
+
53
+ # form parameters
54
+ form_params = opts[:form_params] || {}
55
+
56
+ # http body (model)
57
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(opts[:'getaround_users_updated'])
58
+
59
+ # return_type
60
+ return_type = opts[:debug_return_type]
61
+
62
+ # auth_names
63
+ auth_names = opts[:debug_auth_names] || []
64
+
65
+ new_options = opts.merge(
66
+ :operation => :"UsersApi.updated_user_post",
67
+ :header_params => header_params,
68
+ :query_params => query_params,
69
+ :form_params => form_params,
70
+ :body => post_body,
71
+ :auth_names => auth_names,
72
+ :return_type => return_type
73
+ )
74
+
75
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
76
+ if @api_client.config.debugging
77
+ @api_client.config.logger.debug "API called: UsersApi#updated_user_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
78
+ end
79
+ return data, status_code, headers
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,394 @@
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
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'time'
18
+ require 'typhoeus'
19
+
20
+
21
+ module GetAroundOwner
22
+ class ApiClient
23
+ # The Configuration object holding settings to be used in the API client.
24
+ attr_accessor :config
25
+
26
+ # Defines the headers to be used in HTTP requests of all API calls by default.
27
+ #
28
+ # @return [Hash]
29
+ attr_accessor :default_headers
30
+
31
+ # Initializes the ApiClient
32
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
33
+ def initialize(config = Configuration.default)
34
+ @config = config
35
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
36
+ @default_headers = {
37
+ 'Content-Type' => 'application/json',
38
+ 'User-Agent' => @user_agent
39
+ }
40
+ end
41
+
42
+ def self.default
43
+ @@default ||= ApiClient.new
44
+ end
45
+
46
+ # Call an API with given options.
47
+ #
48
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
49
+ # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
50
+ def call_api(http_method, path, opts = {})
51
+ request = build_request(http_method, path, opts)
52
+ tempfile = download_file(request) if opts[:return_type] == 'File'
53
+ response = request.run
54
+
55
+ if @config.debugging
56
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
57
+ end
58
+
59
+ unless response.success?
60
+ if response.timed_out?
61
+ fail ApiError.new('Connection timed out')
62
+ elsif response.code == 0
63
+ # Errors from libcurl will be made visible here
64
+ fail ApiError.new(:code => 0,
65
+ :message => response.return_message)
66
+ else
67
+ fail ApiError.new(:code => response.code,
68
+ :response_headers => response.headers,
69
+ :response_body => response.body),
70
+ response.status_message
71
+ end
72
+ end
73
+
74
+ if opts[:return_type] == 'File'
75
+ data = tempfile
76
+ elsif opts[:return_type]
77
+ data = deserialize(response, opts[:return_type])
78
+ else
79
+ data = nil
80
+ end
81
+ return data, response.code, response.headers
82
+ end
83
+
84
+ # Builds the HTTP request
85
+ #
86
+ # @param [String] http_method HTTP method/verb (e.g. POST)
87
+ # @param [String] path URL path (e.g. /account/new)
88
+ # @option opts [Hash] :header_params Header parameters
89
+ # @option opts [Hash] :query_params Query parameters
90
+ # @option opts [Hash] :form_params Query parameters
91
+ # @option opts [Object] :body HTTP body (JSON/XML)
92
+ # @return [Typhoeus::Request] A Typhoeus Request
93
+ def build_request(http_method, path, opts = {})
94
+ url = build_request_url(path, opts)
95
+ http_method = http_method.to_sym.downcase
96
+
97
+ header_params = @default_headers.merge(opts[:header_params] || {})
98
+ query_params = opts[:query_params] || {}
99
+ form_params = opts[:form_params] || {}
100
+ follow_location = opts[:follow_location] || true
101
+
102
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
103
+
104
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
105
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
106
+
107
+ req_opts = {
108
+ :method => http_method,
109
+ :headers => header_params,
110
+ :params => query_params,
111
+ :params_encoding => @config.params_encoding,
112
+ :timeout => @config.timeout,
113
+ :ssl_verifypeer => @config.verify_ssl,
114
+ :ssl_verifyhost => _verify_ssl_host,
115
+ :sslcert => @config.cert_file,
116
+ :sslkey => @config.key_file,
117
+ :verbose => @config.debugging,
118
+ :followlocation => follow_location
119
+ }
120
+
121
+ # set custom cert, if provided
122
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
123
+
124
+ if [:post, :patch, :put, :delete].include?(http_method)
125
+ req_body = build_request_body(header_params, form_params, opts[:body])
126
+ req_opts.update :body => req_body
127
+ if @config.debugging
128
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
129
+ end
130
+ end
131
+
132
+ Typhoeus::Request.new(url, req_opts)
133
+ end
134
+
135
+ # Builds the HTTP request body
136
+ #
137
+ # @param [Hash] header_params Header parameters
138
+ # @param [Hash] form_params Query parameters
139
+ # @param [Object] body HTTP body (JSON/XML)
140
+ # @return [String] HTTP body data in the form of string
141
+ def build_request_body(header_params, form_params, body)
142
+ # http form
143
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
144
+ header_params['Content-Type'] == 'multipart/form-data'
145
+ data = {}
146
+ form_params.each do |key, value|
147
+ case value
148
+ when ::File, ::Array, nil
149
+ # let typhoeus handle File, Array and nil parameters
150
+ data[key] = value
151
+ else
152
+ data[key] = value.to_s
153
+ end
154
+ end
155
+ elsif body
156
+ data = body.is_a?(String) ? body : body.to_json
157
+ else
158
+ data = nil
159
+ end
160
+ data
161
+ end
162
+
163
+ # Save response body into a file in (the defined) temporary folder, using the filename
164
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
165
+ # The response body is written to the file in chunks in order to handle files which
166
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
167
+ # process can use.
168
+ #
169
+ # @see Configuration#temp_folder_path
170
+ #
171
+ # @return [Tempfile] the tempfile generated
172
+ def download_file(request)
173
+ tempfile = nil
174
+ encoding = nil
175
+ request.on_headers do |response|
176
+ content_disposition = response.headers['Content-Disposition']
177
+ if content_disposition && content_disposition =~ /filename=/i
178
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
179
+ prefix = sanitize_filename(filename)
180
+ else
181
+ prefix = 'download-'
182
+ end
183
+ prefix = prefix + '-' unless prefix.end_with?('-')
184
+ encoding = response.body.encoding
185
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
186
+ end
187
+ request.on_body do |chunk|
188
+ chunk.force_encoding(encoding)
189
+ tempfile.write(chunk)
190
+ end
191
+ # run the request to ensure the tempfile is created successfully before returning it
192
+ request.run
193
+ if tempfile
194
+ tempfile.close
195
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
196
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
197
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
198
+ "explicitly with `tempfile.delete`"
199
+ else
200
+ fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
201
+ end
202
+
203
+ tempfile
204
+ end
205
+
206
+ # Check if the given MIME is a JSON MIME.
207
+ # JSON MIME examples:
208
+ # application/json
209
+ # application/json; charset=UTF8
210
+ # APPLICATION/JSON
211
+ # */*
212
+ # @param [String] mime MIME
213
+ # @return [Boolean] True if the MIME is application/json
214
+ def json_mime?(mime)
215
+ (mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
216
+ end
217
+
218
+ # Deserialize the response to the given return type.
219
+ #
220
+ # @param [Response] response HTTP response
221
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
222
+ def deserialize(response, return_type)
223
+ body = response.body
224
+ return nil if body.nil? || body.empty?
225
+
226
+ # return response body directly for String return type
227
+ return body.to_s if return_type == 'String'
228
+
229
+ # ensuring a default content type
230
+ content_type = response.headers['Content-Type'] || 'application/json'
231
+
232
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
233
+
234
+ begin
235
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
236
+ rescue JSON::ParserError => e
237
+ if %w(String Date Time).include?(return_type)
238
+ data = body
239
+ else
240
+ raise e
241
+ end
242
+ end
243
+
244
+ convert_to_type data, return_type
245
+ end
246
+
247
+ # Convert data to the given return type.
248
+ # @param [Object] data Data to be converted
249
+ # @param [String] return_type Return type
250
+ # @return [Mixed] Data in a particular type
251
+ def convert_to_type(data, return_type)
252
+ return nil if data.nil?
253
+ case return_type
254
+ when 'String'
255
+ data.to_s
256
+ when 'Integer'
257
+ data.to_i
258
+ when 'Float'
259
+ data.to_f
260
+ when 'Boolean'
261
+ data == true
262
+ when 'Time'
263
+ # parse date time (expecting ISO 8601 format)
264
+ Time.parse data
265
+ when 'Date'
266
+ # parse date time (expecting ISO 8601 format)
267
+ Date.parse data
268
+ when 'Object'
269
+ # generic object (usually a Hash), return directly
270
+ data
271
+ when /\AArray<(.+)>\z/
272
+ # e.g. Array<Pet>
273
+ sub_type = $1
274
+ data.map { |item| convert_to_type(item, sub_type) }
275
+ when /\AHash\<String, (.+)\>\z/
276
+ # e.g. Hash<String, Integer>
277
+ sub_type = $1
278
+ {}.tap do |hash|
279
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
280
+ end
281
+ else
282
+ # models (e.g. Pet) or oneOf
283
+ klass = GetAroundOwner.const_get(return_type)
284
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
285
+ end
286
+ end
287
+
288
+ # Sanitize filename by removing path.
289
+ # e.g. ../../sun.gif becomes sun.gif
290
+ #
291
+ # @param [String] filename the filename to be sanitized
292
+ # @return [String] the sanitized filename
293
+ def sanitize_filename(filename)
294
+ filename.split(/[\/\\]/).last
295
+ end
296
+
297
+ def build_request_url(path, opts = {})
298
+ # Add leading and trailing slashes to path
299
+ path = "/#{path}".gsub(/\/+/, '/')
300
+ @config.base_url(opts[:operation]) + path
301
+ end
302
+
303
+ # Update header and query params based on authentication settings.
304
+ #
305
+ # @param [Hash] header_params Header parameters
306
+ # @param [Hash] query_params Query parameters
307
+ # @param [String] auth_names Authentication scheme name
308
+ def update_params_for_auth!(header_params, query_params, auth_names)
309
+ Array(auth_names).each do |auth_name|
310
+ auth_setting = @config.auth_settings[auth_name]
311
+ next unless auth_setting
312
+ case auth_setting[:in]
313
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
314
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
315
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
316
+ end
317
+ end
318
+ end
319
+
320
+ # Sets user agent in HTTP header
321
+ #
322
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
323
+ def user_agent=(user_agent)
324
+ @user_agent = user_agent
325
+ @default_headers['User-Agent'] = @user_agent
326
+ end
327
+
328
+ # Return Accept header based on an array of accepts provided.
329
+ # @param [Array] accepts array for Accept
330
+ # @return [String] the Accept header (e.g. application/json)
331
+ def select_header_accept(accepts)
332
+ return nil if accepts.nil? || accepts.empty?
333
+ # use JSON when present, otherwise use all of the provided
334
+ json_accept = accepts.find { |s| json_mime?(s) }
335
+ json_accept || accepts.join(',')
336
+ end
337
+
338
+ # Return Content-Type header based on an array of content types provided.
339
+ # @param [Array] content_types array for Content-Type
340
+ # @return [String] the Content-Type header (e.g. application/json)
341
+ def select_header_content_type(content_types)
342
+ # return nil by default
343
+ return if content_types.nil? || content_types.empty?
344
+ # use JSON when present, otherwise use the first one
345
+ json_content_type = content_types.find { |s| json_mime?(s) }
346
+ json_content_type || content_types.first
347
+ end
348
+
349
+ # Convert object (array, hash, object, etc) to JSON string.
350
+ # @param [Object] model object to be converted into JSON string
351
+ # @return [String] JSON string representation of the object
352
+ def object_to_http_body(model)
353
+ return model if model.nil? || model.is_a?(String)
354
+ local_body = nil
355
+ if model.is_a?(Array)
356
+ local_body = model.map { |m| object_to_hash(m) }
357
+ else
358
+ local_body = object_to_hash(model)
359
+ end
360
+ local_body.to_json
361
+ end
362
+
363
+ # Convert object(non-array) to hash.
364
+ # @param [Object] obj object to be converted into JSON string
365
+ # @return [String] JSON string representation of the object
366
+ def object_to_hash(obj)
367
+ if obj.respond_to?(:to_hash)
368
+ obj.to_hash
369
+ else
370
+ obj
371
+ end
372
+ end
373
+
374
+ # Build parameter value according to the given collection format.
375
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
376
+ def build_collection_param(param, collection_format)
377
+ case collection_format
378
+ when :csv
379
+ param.join(',')
380
+ when :ssv
381
+ param.join(' ')
382
+ when :tsv
383
+ param.join("\t")
384
+ when :pipes
385
+ param.join('|')
386
+ when :multi
387
+ # return the array directly as typhoeus will handle it as expected
388
+ param
389
+ else
390
+ fail "unknown collection format: #{collection_format.inspect}"
391
+ end
392
+ end
393
+ end
394
+ end