rail-locator-api 1.0.21 → 1.0.24
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bd00871ef27b6d49f125af92cd42cc3a9962f36f0df2a40cba25edebfea0ba9
|
4
|
+
data.tar.gz: 0e4cdf61f4bbd87eed4ea3e5f75404b86dc3625a7319658ad23a1145f26b3737
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91dbeb069e8f2a59d21df3efcef7d3ba0de201d6cb24928ea869aa5705d6e932a9aad8039ecdcadf52f817bbe0f64883c5921b44a6e60fade91376e9316edcd0
|
7
|
+
data.tar.gz: 1c10769ea83bdd40651bfcc8728a521f00a14dfe8f3b83fc179dd9efbef93999b82bed9a5574824427d03a50f5611a2fc8e34757734494d3602a983a5983fd32
|
@@ -1,7 +1,8 @@
|
|
1
1
|
defaults: &defaults
|
2
2
|
API_ENDPOINT: "https://rail-scan.com"
|
3
3
|
UNION_ENDPOINT: "http://192.168.88.38:8000"
|
4
|
-
|
4
|
+
NOTIFY_ENDPOINT: "http://192.168.1.153:3003"
|
5
|
+
|
5
6
|
API_AUTH_METHOD: "api_key"
|
6
7
|
API_KEY: "***"
|
7
8
|
|
@@ -16,6 +17,7 @@ defaults: &defaults
|
|
16
17
|
production:
|
17
18
|
<<: *defaults
|
18
19
|
UNION_ENDPOINT: "http://192.168.1.88:3500"
|
20
|
+
NOTIFY_ENDPOINT: "http://192.168.1.153:3003"
|
19
21
|
development:
|
20
22
|
<<: *defaults
|
21
23
|
test:
|
@@ -8,13 +8,21 @@ module RailLocatorApi
|
|
8
8
|
def post(params: nil, headers: nil, format: nil, body: {})
|
9
9
|
validate_api_key
|
10
10
|
begin
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
if is_multipart?(body)
|
12
|
+
url = URI("#{self.api_url}#{format.present? ? ".#{format}": ""}")
|
13
|
+
http = Net::HTTP.new(url.host, url.port);
|
14
|
+
request = Net::HTTP::Post.new(url)
|
15
|
+
request.set_form body.to_params, 'multipart/form-data'
|
16
|
+
http.request(request)
|
16
17
|
else
|
17
|
-
response
|
18
|
+
response = self.rest_client(format).post do |request|
|
19
|
+
configure_request(request: request, params: params, headers: headers, body: body)
|
20
|
+
end
|
21
|
+
if [nil, 'json'].include?(format)
|
22
|
+
parse_response(response)
|
23
|
+
else
|
24
|
+
response
|
25
|
+
end
|
18
26
|
end
|
19
27
|
rescue => e
|
20
28
|
handle_error(e)
|
@@ -126,6 +134,10 @@ module RailLocatorApi
|
|
126
134
|
@request_builder.union_endpoint
|
127
135
|
end
|
128
136
|
|
137
|
+
def notify_endpoint
|
138
|
+
@request_builder.notify_endpoint
|
139
|
+
end
|
140
|
+
|
129
141
|
def timeout
|
130
142
|
@request_builder.timeout
|
131
143
|
end
|
@@ -217,12 +229,31 @@ module RailLocatorApi
|
|
217
229
|
request.headers['X-Is-Allow-Access-To-Coordinates'] = "true"
|
218
230
|
end
|
219
231
|
request.headers.merge!(headers) if headers
|
220
|
-
|
232
|
+
|
233
|
+
request.body = MultiJson.dump(body) if body && request.headers['Content-Type'] == 'application/json'
|
234
|
+
|
221
235
|
request.options.timeout = self.timeout
|
222
236
|
request.options.open_timeout = self.open_timeout
|
223
237
|
end
|
224
238
|
end
|
225
239
|
|
240
|
+
def is_multipart?(body, result=false)
|
241
|
+
if body.is_a?(Hash)
|
242
|
+
body.inject({}) do |acc, kv|
|
243
|
+
result = is_multipart?(kv.last, result)
|
244
|
+
end
|
245
|
+
elsif body.is_a?(Array)
|
246
|
+
body.map do |item|
|
247
|
+
result = is_multipart?(item, result)
|
248
|
+
end
|
249
|
+
result
|
250
|
+
elsif body.is_a?(ActionDispatch::Http::UploadedFile)
|
251
|
+
return true
|
252
|
+
else
|
253
|
+
result || false
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
226
257
|
def rest_client(format=nil)
|
227
258
|
client = Faraday.new("#{self.api_url}#{format.present? ? ".#{format}": ""}", proxy: self.proxy,
|
228
259
|
ssl: self.ssl_options) do |faraday|
|
@@ -308,7 +339,45 @@ module RailLocatorApi
|
|
308
339
|
end
|
309
340
|
|
310
341
|
def notify_api_url
|
311
|
-
"
|
342
|
+
"#{RailLocatorApi.notify_endpoint}/"
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
class Hash
|
348
|
+
def to_params(namespace = nil)
|
349
|
+
query = []
|
350
|
+
each do |key, value|
|
351
|
+
if value.present?
|
352
|
+
if value.is_a?(Hash) || value.is_a?(Array)
|
353
|
+
query += value.to_params(namespace ? "#{namespace}[#{key}]" : key)
|
354
|
+
else
|
355
|
+
query << value.to_params(namespace ? "#{namespace}[#{key}]" : key)
|
356
|
+
end
|
357
|
+
end
|
312
358
|
end
|
359
|
+
query
|
313
360
|
end
|
314
361
|
end
|
362
|
+
|
363
|
+
class Object
|
364
|
+
def to_params(key)
|
365
|
+
if self.is_a? ActionDispatch::Http::UploadedFile
|
366
|
+
[key.to_param, File.open(self.path)]
|
367
|
+
else
|
368
|
+
[key.to_param, to_param.to_s]
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
class Array
|
374
|
+
def to_params(key)
|
375
|
+
prefix = "#{key}[]"
|
376
|
+
|
377
|
+
if empty?
|
378
|
+
nil.to_params(prefix)
|
379
|
+
else
|
380
|
+
collect { |value| value.to_params(prefix) }
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module RailLocatorApi
|
2
2
|
class Request
|
3
3
|
attr_accessor :access_token, :refresh_token, :api_user_id, :api_key, :api_user_email, :api_user_password,
|
4
|
-
:api_auth_method, :api_endpoint, :union_endpoint,
|
4
|
+
:api_auth_method, :api_endpoint, :union_endpoint, :notify_endpoint,
|
5
5
|
:timeout, :open_timeout, :proxy, :ssl_options, :faraday_adapter, :symbolize_keys, :debug, :debug_options,
|
6
6
|
:without_ratelimit, :is_allow_access_to_coordinates, :logger, :test, :language
|
7
7
|
|
@@ -135,7 +135,8 @@ module RailLocatorApi
|
|
135
135
|
|
136
136
|
class << self
|
137
137
|
attr_accessor :access_token, :refresh_token, :api_user_id, :api_key, :api_user_email, :api_user_password, :api_auth_method,
|
138
|
-
:timeout, :open_timeout, :api_endpoint, :union_endpoint, :
|
138
|
+
:timeout, :open_timeout, :api_endpoint, :union_endpoint, :notify_endpoint,
|
139
|
+
:proxy, :ssl_options, :faraday_adapter, :symbolize_keys,
|
139
140
|
:debug, :debug_options, :without_ratelimit, :is_allow_access_to_coordinates, :logger, :test, :language
|
140
141
|
|
141
142
|
def method_missing(sym, *args, &block)
|
data/lib/rail-locator-api.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rail-locator-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Osetrov
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: multipart-post
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: ''
|
84
98
|
email: pavel.osetrov@me.com
|
85
99
|
executables: []
|