rail-locator-api 0.0.16 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc672ce3051a65a60ffede6614cdd260866e1b91431961764c4741d014aebc4d
4
- data.tar.gz: 71c29b61bb151fdef8ccc8fc76f458413d21bc7bddc70f055df7cb0dcc64926f
3
+ metadata.gz: 4f775a7f5dbab37a454da5e73f4bd5f04dadaa4d47ae5bfa96c83f7ff0380977
4
+ data.tar.gz: 6c4e23003da7f24a2e816b25ab3148b79e77a77275b8c6a7b5236a71b68c88e8
5
5
  SHA512:
6
- metadata.gz: 3180516cfffdbfc9ccba264333f171e4d9298c0f8c816ba42c00bcc60c3db22b0385a78f72cd65ea714794f444823e0bd2bd1b01afa7ecb62b01a278f49c713c
7
- data.tar.gz: 0ff7688d5e1109da597469c1f902a53d5f599f57c9cef814e61fae47191567ef159bd5e64a01f8925206e3571d262cfeb3a81704db26284331a705759b212008
6
+ metadata.gz: 2aca0f67ea21e47cdf4d6700de4b0c79997126d003e50e29cb238853c18daa782c4944bc667dd6f74e11c429d3ddeab9a4957a7f5920367f25f4b0416e4426b9
7
+ data.tar.gz: 9af82abbdf8c1408a936facf4c798fa0af42af1347cb191d72538b9b92b88cd4241c13a7c72016cbaf2aaa3573d3b5f50c6d557c019527d85b66c9f8c651f02d
@@ -6,6 +6,7 @@ defaults: &defaults
6
6
  KEYCLOAK_TOKEN_URL: "https://iam.ctm.ru/auth/realms/ctm/protocol/openid-connect/token"
7
7
  KEYCLOAK_GRANT_TYPE: "password"
8
8
  KEYCLOAK_CLIENT_ID: "ctm_lk"
9
+ KEYCLOAK_REDIRECT_URI: "http://yousite.ru/callback"
9
10
  production:
10
11
  <<: *defaults
11
12
  development:
@@ -132,10 +132,7 @@ module RailLocatorApi
132
132
  if self.api_auth_method == :base64
133
133
  request.headers['Authorization'] = "Basic " + Base64::encode64("#{self.api_user_email}:#{self.api_user_password}")
134
134
  end
135
- if self.api_auth_method == :api_key
136
- request.headers['X-API-KEY'] = "#{self.api_key}"
137
- end
138
- if self.api_auth_method == :keycloak
135
+ if [:api_key, :keycloak].include?(self.api_auth_method)
139
136
  request.headers['Authorization'] = "Bearer #{RailLocatorApi::Request.access_token}"
140
137
  end
141
138
  request.headers['User-Agent'] = "RailLocatorApi/#{RailLocatorApi::VERSION} Ruby gem"
@@ -60,14 +60,14 @@ module RailLocatorApi
60
60
  @path_parts.join('/')
61
61
  end
62
62
 
63
- def create(params: nil, headers: nil, body: {}, suffix: 'create')
64
- APIRequest.new(builder: self).post(params: params, headers: headers, suffix: suffix, body: body)
63
+ def create(params: nil, headers: nil, body: {})
64
+ APIRequest.new(builder: self).post(params: params, headers: headers, body: body)
65
65
  ensure
66
66
  reset
67
67
  end
68
68
 
69
69
  def update(params: nil, headers: nil, body: {})
70
- APIRequest.new(builder: self).post(params: params, headers: headers, suffix: 'edit', body: body)
70
+ APIRequest.new(builder: self).post(params: params, headers: headers, body: body)
71
71
  ensure
72
72
  reset
73
73
  end
@@ -79,7 +79,7 @@ module RailLocatorApi
79
79
  end
80
80
 
81
81
  def delete(params: nil, headers: nil, body: {})
82
- APIRequest.new(builder: self).post(params: params, headers: headers, body: {}, suffix: 'delete')
82
+ APIRequest.new(builder: self).post(params: params, headers: headers, body: {})
83
83
  ensure
84
84
  reset
85
85
  end
@@ -1,3 +1,3 @@
1
1
  module RailLocatorApi
2
- VERSION = "0.0.16"
2
+ VERSION = "0.0.21"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'faraday'
2
+ require 'multi_json'
2
3
  require 'rail-locator-api/version'
3
4
  require 'rail-locator-api/rail_locator_api_error'
4
5
  require 'rail-locator-api/request'
@@ -8,9 +9,23 @@ require 'rail-locator-api/response'
8
9
  module RailLocatorApi
9
10
  class << self
10
11
  def generate_access_token
11
- response = Faraday.post(
12
- RailLocatorApi.keycloak_token_url,
13
- "grant_type=#{RailLocatorApi.keycloak_grant_type}&client_id=#{RailLocatorApi.keycloak_client_id}&username=#{RailLocatorApi.api_user_email}&password=#{RailLocatorApi.api_user_password}")
12
+ if RailLocatorApi.keycloak_grant_type == "password"
13
+ payload = "grant_type=#{RailLocatorApi.keycloak_grant_type}&client_id=#{RailLocatorApi.keycloak_client_id}&username=#{RailLocatorApi.api_user_email}&password=#{RailLocatorApi.api_user_password}"
14
+ else
15
+ payload = "grant_type=#{RailLocatorApi.keycloak_grant_type}&client_id=#{RailLocatorApi.keycloak_client_id}&code=#{RailLocatorApi::Request.api_key}&redirect_uri=#{RailLocatorApi.keycloak_redirect_uri}"
16
+ end
17
+
18
+ connection = Faraday.new(RailLocatorApi.keycloak_token_url, proxy: nil,
19
+ ssl: { version: "TLSv1_2" }) do |faraday|
20
+ faraday.adapter Faraday.default_adapter
21
+ faraday.response :logger, ::Logger.new(STDOUT), bodies: true
22
+ end
23
+
24
+ response = connection.post RailLocatorApi.keycloak_token_url, payload do |request|
25
+ request.headers['Content-Type'] = 'application/json'
26
+ request.headers['accept'] = 'application/json'
27
+ end
28
+
14
29
  JSON.parse(response.body)
15
30
  end
16
31
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rail-locator-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Osetrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-24 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.11.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: irb
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.3.6
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.6
41
55
  description: ''
42
56
  email: pavel.osetrov@me.com
43
57
  executables: []
@@ -68,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
82
  requirements:
69
83
  - - ">="
70
84
  - !ruby/object:Gem::Version
71
- version: 2.3.8
85
+ version: '2.5'
72
86
  required_rubygems_version: !ruby/object:Gem::Requirement
73
87
  requirements:
74
88
  - - ">="