deliveree_sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ =begin
2
+ #Deliveree SDK
3
+ #With Deliveree API, developers can integrate our on-demand local delivery platform into their applications. The API is designed for developers to check prices, book an immediate or scheduled delivery and follow updates until delivery completion.
4
+ Contact: duke@deliveree.com
5
+ =end
6
+
7
+ module Deliveree
8
+ class ApiError < StandardError
9
+ attr_reader :code, :response_headers, :response_body
10
+
11
+ # Usage examples:
12
+ # ApiError.new
13
+ # ApiError.new("message")
14
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
15
+ # ApiError.new(:code => 404, :message => "Not Found")
16
+ def initialize(arg = nil)
17
+ if arg.is_a? Hash
18
+ if arg.key?(:message) || arg.key?('message')
19
+ super(arg[:message] || arg['message'])
20
+ else
21
+ super arg
22
+ end
23
+
24
+ arg.each do |k, v|
25
+ instance_variable_set "@#{k}", v
26
+ end
27
+ else
28
+ super arg
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,202 @@
1
+ =begin
2
+ #Deliveree SDK
3
+ #With Deliveree SDK, developers can integrate our on-demand local delivery platform into their applications. The SDK is designed for developers to check prices, book an immediate or scheduled delivery and follow updates until delivery completion.
4
+ Contact: duke@deliveree.com
5
+ =end
6
+
7
+ require 'uri'
8
+
9
+ module Deliveree
10
+ class Configuration
11
+ # Defines url scheme
12
+ attr_accessor :scheme
13
+
14
+ # Defines url host
15
+ attr_accessor :host
16
+
17
+ # Defines url base path
18
+ attr_accessor :base_path
19
+
20
+ # Defines API keys used with API Key authentications.
21
+ #
22
+ # @return [Hash] key: parameter name, value: parameter value (API key)
23
+ #
24
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
25
+ # config.api_key['api_key'] = 'xxx'
26
+ attr_accessor :api_key
27
+
28
+ # Defines API key prefixes used with API Key authentications.
29
+ #
30
+ # @return [Hash] key: parameter name, value: API key prefix
31
+ #
32
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
33
+ # config.api_key_prefix['api_key'] = 'Token'
34
+ attr_accessor :api_key_prefix
35
+
36
+ # Defines the username used with HTTP basic authentication.
37
+ #
38
+ # @return [String]
39
+ attr_accessor :username
40
+
41
+ # Defines the password used with HTTP basic authentication.
42
+ #
43
+ # @return [String]
44
+ attr_accessor :password
45
+
46
+ # Defines the access token (Bearer) used with OAuth2.
47
+ attr_accessor :access_token
48
+
49
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
50
+ # details will be logged with `logger.debug` (see the `logger` attribute).
51
+ # Default to false.
52
+ #
53
+ # @return [true, false]
54
+ attr_accessor :debugging
55
+
56
+ # Defines the logger used for debugging.
57
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
58
+ #
59
+ # @return [#debug]
60
+ attr_accessor :logger
61
+
62
+ # Defines the temporary folder to store downloaded files
63
+ # (for API endpoints that have file response).
64
+ # Default to use `Tempfile`.
65
+ #
66
+ # @return [String]
67
+ attr_accessor :temp_folder_path
68
+
69
+ # The time limit for HTTP request in seconds.
70
+ # Default to 0 (never times out).
71
+ attr_accessor :timeout
72
+
73
+ # Set this to false to skip client side validation in the operation.
74
+ # Default to true.
75
+ # @return [true, false]
76
+ attr_accessor :client_side_validation
77
+
78
+ ### TLS/SSL setting
79
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
80
+ # Default to true.
81
+ #
82
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
83
+ #
84
+ # @return [true, false]
85
+ attr_accessor :verify_ssl
86
+
87
+ ### TLS/SSL setting
88
+ # Set this to false to skip verifying SSL host name
89
+ # Default to true.
90
+ #
91
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
92
+ #
93
+ # @return [true, false]
94
+ attr_accessor :verify_ssl_host
95
+
96
+ ### TLS/SSL setting
97
+ # Set this to customize the certificate file to verify the peer.
98
+ #
99
+ # @return [String] the path to the certificate file
100
+ #
101
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
102
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
103
+ attr_accessor :ssl_ca_cert
104
+
105
+ ### TLS/SSL setting
106
+ # Client certificate file (for client certificate)
107
+ attr_accessor :cert_file
108
+
109
+ ### TLS/SSL setting
110
+ # Client private key file (for client certificate)
111
+ attr_accessor :key_file
112
+
113
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
114
+ # Default to nil.
115
+ #
116
+ # @see The params_encoding option of Ethon. Related source code:
117
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
118
+ attr_accessor :params_encoding
119
+
120
+ attr_accessor :inject_format
121
+
122
+ attr_accessor :force_ending_format
123
+ def initialize
124
+ @scheme = 'https'
125
+ @host = 'api.sandbox.deliveree.com'
126
+ @base_path = '/public_api/v1'
127
+ @api_key = {}
128
+ @api_key_prefix = {}
129
+ @timeout = 0
130
+ @client_side_validation = true
131
+ @verify_ssl = true
132
+ @verify_ssl_host = true
133
+ @params_encoding = nil
134
+ @cert_file = nil
135
+ @key_file = nil
136
+ @debugging = false
137
+ @inject_format = false
138
+ @force_ending_format = false
139
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
140
+
141
+ yield(self) if block_given?
142
+ end
143
+
144
+ # The default Configuration object.
145
+ def self.default
146
+ @@default ||= Configuration.new
147
+ end
148
+
149
+ def configure
150
+ yield(self) if block_given?
151
+ end
152
+
153
+ def scheme=(scheme)
154
+ # remove :// from scheme
155
+ @scheme = scheme.sub(/:\/\//, '')
156
+ end
157
+
158
+ def host=(host)
159
+ # remove http(s):// and anything after a slash
160
+ @host = host.sub(/https?:\/\//, '').split('/').first
161
+ end
162
+
163
+ def base_path=(base_path)
164
+ # Add leading and trailing slashes to base_path
165
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
166
+ @base_path = '' if @base_path == '/'
167
+ end
168
+
169
+ def base_url
170
+ url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
171
+ URI.encode(url)
172
+ end
173
+
174
+ # Gets API key (with prefix if set).
175
+ # @param [String] param_name the parameter name of API key auth
176
+ def api_key_with_prefix(param_name)
177
+ if @api_key_prefix[param_name]
178
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
179
+ else
180
+ @api_key[param_name]
181
+ end
182
+ end
183
+
184
+ # Gets Basic Auth token string
185
+ def basic_auth_token
186
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
187
+ end
188
+
189
+ # Returns Auth Settings hash for api client.
190
+ def auth_settings
191
+ {
192
+ 'ApiKeyAuth' =>
193
+ {
194
+ type: 'api_key',
195
+ in: 'header',
196
+ key: 'Authorization',
197
+ value: api_key_with_prefix('Authorization')
198
+ },
199
+ }
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,265 @@
1
+ =begin
2
+ #Deliveree SDK
3
+
4
+ #With Deliveree SDK, developers can integrate our on-demand local delivery platform into their applications. The SDK is designed for developers to check prices, book an immediate or scheduled delivery and follow updates until delivery completion.
5
+ Contact: duke@deliveree.com
6
+ =end
7
+
8
+ require 'date'
9
+
10
+ module Deliveree
11
+ class Delivery
12
+ attr_accessor :vehicle_type_id
13
+
14
+ attr_accessor :note
15
+
16
+ attr_accessor :time_type
17
+
18
+ attr_accessor :pickup_time
19
+
20
+ attr_accessor :job_order_number
21
+
22
+ attr_accessor :allow_parking_fees
23
+
24
+ attr_accessor :allow_tolls_fees
25
+
26
+ attr_accessor :allow_waiting_time_fees
27
+
28
+ attr_accessor :fleet_partner_id
29
+
30
+ attr_accessor :container_size
31
+
32
+ attr_accessor :locations
33
+
34
+ # Attribute mapping from ruby-style variable name to JSON key.
35
+ def self.attribute_map
36
+ {
37
+ :'vehicle_type_id' => :'vehicle_type_id',
38
+ :'note' => :'note',
39
+ :'time_type' => :'time_type',
40
+ :'pickup_time' => :'pickup_time',
41
+ :'job_order_number' => :'job_order_number',
42
+ :'allow_parking_fees' => :'allow_parking_fees',
43
+ :'allow_tolls_fees' => :'allow_tolls_fees',
44
+ :'allow_waiting_time_fees' => :'allow_waiting_time_fees',
45
+ :'fleet_partner_id' => :'fleet_partner_id',
46
+ :'container_size' => :'container_size',
47
+ :'locations' => :'locations'
48
+ }
49
+ end
50
+
51
+ # Attribute type mapping.
52
+ def self.delivery_types
53
+ {
54
+ :'vehicle_type_id' => :'Integer',
55
+ :'note' => :'String',
56
+ :'time_type' => :'String',
57
+ :'pickup_time' => :'DateTime',
58
+ :'job_order_number' => :'String',
59
+ :'allow_parking_fees' => :'BOOLEAN',
60
+ :'allow_tolls_fees' => :'BOOLEAN',
61
+ :'allow_waiting_time_fees' => :'BOOLEAN',
62
+ :'fleet_partner_id' => :'Integer',
63
+ :'container_size' => :'String',
64
+ :'locations' => :'Array<Location>'
65
+ }
66
+ end
67
+
68
+ # Initializes the object
69
+ # @param [Hash] attributes Model attributes in the form of hash
70
+ def initialize(attributes = {})
71
+ return unless attributes.is_a?(Hash)
72
+
73
+ # convert string to symbol for hash key
74
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
75
+ # To make sure attribute mandatory
76
+ self.vehicle_type_id = attributes[:'vehicle_type_id']
77
+ self.time_type = attributes[:'time_type']
78
+
79
+ if attributes.has_key?(:'note')
80
+ self.note = attributes[:'note']
81
+ end
82
+
83
+ if attributes.has_key?(:'pickup_time')
84
+ self.pickup_time = attributes[:'pickup_time']
85
+ end
86
+
87
+ if attributes.has_key?(:'job_order_number')
88
+ self.job_order_number = attributes[:'job_order_number']
89
+ end
90
+
91
+ if attributes.has_key?(:'allow_parking_fees')
92
+ self.allow_parking_fees = attributes[:'allow_parking_fees']
93
+ end
94
+
95
+ if attributes.has_key?(:'allow_tolls_fees')
96
+ self.allow_tolls_fees = attributes[:'allow_tolls_fees']
97
+ end
98
+
99
+ if attributes.has_key?(:'allow_waiting_time_fees')
100
+ self.allow_waiting_time_fees = attributes[:'allow_waiting_time_fees']
101
+ end
102
+
103
+ if attributes.has_key?(:'fleet_partner_id')
104
+ self.fleet_partner_id = attributes[:'fleet_partner_id']
105
+ end
106
+
107
+ if attributes.has_key?(:'container_size')
108
+ self.container_size = attributes[:'container_size']
109
+ end
110
+
111
+ if attributes.has_key?(:'locations')
112
+ if (value = attributes[:'locations']).is_a?(Array)
113
+ self.locations = value
114
+ end
115
+ end
116
+ end
117
+
118
+ # Show invalid properties with the reasons. Usually used together with valid?
119
+ # @return Array for valid properties with the reasons
120
+ def list_invalid_properties
121
+ invalid_properties = []
122
+ invalid_properties
123
+ end
124
+
125
+ # Check to see if the all the properties in the model are valid
126
+ # @return true if the model is valid
127
+ def valid?
128
+ true
129
+ end
130
+
131
+ # Checks equality by comparing each attribute.
132
+ # @param [Object] Object to be compared
133
+ def ==(o)
134
+ return true if self.equal?(o)
135
+ self.class == o.class &&
136
+ vehicle_type_id == o.vehicle_type_id &&
137
+ note == o.note &&
138
+ time_type == o.time_type &&
139
+ pickup_time == o.pickup_time &&
140
+ job_order_number == o.job_order_number &&
141
+ allow_parking_fees == o.allow_parking_fees &&
142
+ allow_tolls_fees == o.allow_tolls_fees &&
143
+ allow_waiting_time_fees == o.allow_waiting_time_fees &&
144
+ fleet_partner_id == o.fleet_partner_id &&
145
+ container_size == o.container_size &&
146
+ locations == o.locations
147
+ end
148
+
149
+ # @see the `==` method
150
+ # @param [Object] Object to be compared
151
+ def eql?(o)
152
+ self == o
153
+ end
154
+
155
+ # Calculates hash code according to all attributes.
156
+ # @return [Fixnum] Hash code
157
+ def hash
158
+ [vehicle_type_id, note, time_type, pickup_time, job_order_number, allow_parking_fees, allow_tolls_fees, allow_waiting_time_fees, fleet_partner_id, container_size, locations].hash
159
+ end
160
+
161
+ # Builds the object from hash
162
+ # @param [Hash] attributes Model attributes in the form of hash
163
+ # @return [Object] Returns the model itself
164
+ def build_from_hash(attributes)
165
+ return nil unless attributes.is_a?(Hash)
166
+ self.class.delivery_types.each_pair do |key, type|
167
+ if type =~ /\AArray<(.*)>/i
168
+ # check to ensure the input is an array given that the the attribute
169
+ # is documented as an array but the input is not
170
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
171
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
172
+ end
173
+ elsif !attributes[self.class.attribute_map[key]].nil?
174
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
175
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
176
+ end
177
+
178
+ self
179
+ end
180
+
181
+ # Deserializes the data based on type
182
+ # @param string type Data type
183
+ # @param string value Value to be deserialized
184
+ # @return [Object] Deserialized data
185
+ def _deserialize(type, value)
186
+ case type.to_sym
187
+ when :DateTime
188
+ DateTime.parse(value)
189
+ when :Date
190
+ Date.parse(value)
191
+ when :String
192
+ value.to_s
193
+ when :Integer
194
+ value.to_i
195
+ when :Float
196
+ value.to_f
197
+ when :BOOLEAN
198
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
199
+ true
200
+ else
201
+ false
202
+ end
203
+ when :Object
204
+ # generic object (usually a Hash), return directly
205
+ value
206
+ when /\AArray<(?<inner_type>.+)>\z/
207
+ inner_type = Regexp.last_match[:inner_type]
208
+ value.map { |v| _deserialize(inner_type, v) }
209
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
210
+ k_type = Regexp.last_match[:k_type]
211
+ v_type = Regexp.last_match[:v_type]
212
+ {}.tap do |hash|
213
+ value.each do |k, v|
214
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
215
+ end
216
+ end
217
+ else # model
218
+ temp_model = Deliveree.const_get(type).new
219
+ temp_model.build_from_hash(value)
220
+ end
221
+ end
222
+
223
+ # Returns the string representation of the object
224
+ # @return [String] String presentation of the object
225
+ def to_s
226
+ to_hash.to_s
227
+ end
228
+
229
+ # to_body is an alias to to_hash (backward compatibility)
230
+ # @return [Hash] Returns the object in the form of hash
231
+ def to_body
232
+ to_hash
233
+ end
234
+
235
+ # Returns the object in the form of hash
236
+ # @return [Hash] Returns the object in the form of hash
237
+ def to_hash
238
+ hash = {}
239
+ self.class.attribute_map.each_pair do |attr, param|
240
+ value = self.send(attr)
241
+ next if value.nil?
242
+ hash[param] = _to_hash(value)
243
+ end
244
+ hash
245
+ end
246
+
247
+ # Outputs non-array value in the form of hash
248
+ # For object, use to_hash. Otherwise, just return the value
249
+ # @param [Object] value Any valid value
250
+ # @return [Hash] Returns the value in the form of hash
251
+ def _to_hash(value)
252
+ if value.is_a?(Array)
253
+ value.compact.map { |v| _to_hash(v) }
254
+ elsif value.is_a?(Hash)
255
+ {}.tap do |hash|
256
+ value.each { |k, v| hash[k] = _to_hash(v) }
257
+ end
258
+ elsif value.respond_to? :to_hash
259
+ value.to_hash
260
+ else
261
+ value
262
+ end
263
+ end
264
+ end
265
+ end