rail-locator-api 0.1.15 → 0.1.16
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 +4 -4
- data/lib/rail-locator-api/api_request.rb +8 -0
- data/lib/rail-locator-api/request.rb +2 -32
- data/lib/rail-locator-api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 954fca62238bc7b33b0b86999e017649c5338f01b0fd4d684651abcf75b062a4
|
4
|
+
data.tar.gz: e1e0fb3102e08e62195644fd8a479c6172eea3220c7b62bfd049f8e85dc026cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be314fe74d7ec16776b2c528de676d44d067d38792f4eb671942e2e8c91c3e3fe66292492abdb7fa9bd11dd44db2065fe6fb712912148bd633bf363fc78c4396
|
7
|
+
data.tar.gz: 855004fb2e73a23d5086ba1bad484fd7509364fa9325820fd3792d4bc30e02fad838a9b28ba918bfa9fbbc7d0e1705088bf854da18cedf444043f78be3bd3611
|
@@ -121,6 +121,14 @@ module RailLocatorApi
|
|
121
121
|
if request
|
122
122
|
request.params.merge!(params) if params
|
123
123
|
request.headers['Content-Type'] = 'application/json'
|
124
|
+
unless RailLocatorApi::Request.token_alive?(RailLocatorApi::Request.access_token)
|
125
|
+
if RailLocatorApi::Request.token_alive?(RailLocatorApi::Request.refresh_token)
|
126
|
+
response = RailLocatorApi.refresh_access_token
|
127
|
+
RailLocatorApi::Request.access_token = response.try(:dig, "access_token")
|
128
|
+
RailLocatorApi::Request.refresh_token = response.try(:dig, "refresh_token")
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
124
132
|
if self.api_auth_method == :base64
|
125
133
|
request.headers['Authorization'] = "Basic " + Base64::encode64("#{self.api_user_email}:#{self.api_user_password}")
|
126
134
|
end
|
@@ -22,15 +22,6 @@ module RailLocatorApi
|
|
22
22
|
@access_token = @access_token.strip if @access_token
|
23
23
|
@refresh_token = refresh_token || self.class.refresh_token
|
24
24
|
@refresh_token = @refresh_token.strip if @refresh_token
|
25
|
-
unless token_alive?(@access_token)
|
26
|
-
if token_alive?(@refresh_token)
|
27
|
-
RailLocatorApi::Request.refresh_token = @refresh_token
|
28
|
-
response = RailLocatorApi.refresh_access_token
|
29
|
-
@access_token = response.try(:dig, "access_token")
|
30
|
-
@refresh_token = response.try(:dig, "refresh_token")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
25
|
@api_user_email = api_user_email || ENV['API_USER_EMAIL'] || ""
|
35
26
|
@api_user_password = api_user_password || ENV['API_USER_PASSWORD'] || ""
|
36
27
|
@api_endpoint = api_endpoint || self.class.api_endpoint
|
@@ -95,29 +86,6 @@ module RailLocatorApi
|
|
95
86
|
reset
|
96
87
|
end
|
97
88
|
|
98
|
-
protected
|
99
|
-
|
100
|
-
def need_login?
|
101
|
-
RailLocatorApi::Request.api_key = state
|
102
|
-
RailLocatorApi::Request.access_token = token
|
103
|
-
if token_alive?(token)
|
104
|
-
return false
|
105
|
-
else
|
106
|
-
if token_alive?(refresh_token)
|
107
|
-
RailLocatorApi::Request.refresh_token = refresh_token
|
108
|
-
response = RailLocatorApi.refresh_access_token
|
109
|
-
self.token = response.try(:dig, "access_token")
|
110
|
-
self.refresh_token = response.try(:dig, "refresh_token")
|
111
|
-
RailLocatorApi::Request.api_key = state
|
112
|
-
RailLocatorApi::Request.access_token = token
|
113
|
-
return !save
|
114
|
-
else
|
115
|
-
true
|
116
|
-
end
|
117
|
-
end
|
118
|
-
true
|
119
|
-
end
|
120
|
-
|
121
89
|
def token_alive?(token)
|
122
90
|
begin
|
123
91
|
return false if token.nil?
|
@@ -130,6 +98,8 @@ module RailLocatorApi
|
|
130
98
|
end
|
131
99
|
end
|
132
100
|
|
101
|
+
protected
|
102
|
+
|
133
103
|
def reset
|
134
104
|
@path_parts = []
|
135
105
|
end
|