rail-locator-api 0.0.24 → 0.0.25
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 +6 -2
 - data/lib/rail-locator-api/request.rb +9 -7
 - data/lib/rail-locator-api/version.rb +1 -1
 - data/lib/rail-locator-api.rb +15 -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: 3b25b34e0bbca2dc11a3a0e5c1582763bab4d1d010d7a35e5aeb6cc09122b07b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 5bd43dabc4467fe756210544a910290b4d65b59dbddbd15b33d36f2e9277d4b7
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: b45549523425ac1dd977927991534507273156f0ab8d14d82e75f7e73a46156b408aec2864d0bbf4bc2a9de0ab6436cd8cfa766d52d7f1f8237439106e5216ce
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 00aa0506a19cc0b1bd4dff0b5b9a11152cf068360cc469fd7829f69673959ba662b670435e92758633a899fff1a55624cad00b70d2da8de2add99935b04dae62
         
     | 
| 
         @@ -5,7 +5,7 @@ module RailLocatorApi 
     | 
|
| 
       5 
5 
     | 
    
         
             
                  @request_builder = builder
         
     | 
| 
       6 
6 
     | 
    
         
             
                end
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
                def post(params: nil, headers: nil, suffix: nil, body: {} 
     | 
| 
      
 8 
     | 
    
         
            +
                def post(params: nil, headers: nil, suffix: nil, body: {})
         
     | 
| 
       9 
9 
     | 
    
         
             
                  validate_api_key
         
     | 
| 
       10 
10 
     | 
    
         
             
                  begin
         
     | 
| 
       11 
11 
     | 
    
         
             
                    response = self.rest_client(suffix).post do |request|
         
     | 
| 
         @@ -17,7 +17,7 @@ module RailLocatorApi 
     | 
|
| 
       17 
17 
     | 
    
         
             
                  end
         
     | 
| 
       18 
18 
     | 
    
         
             
                end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
                def get(params: nil, headers: nil, body: {} 
     | 
| 
      
 20 
     | 
    
         
            +
                def get(params: nil, headers: nil, body: {})
         
     | 
| 
       21 
21 
     | 
    
         
             
                  validate_api_key
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
                  begin
         
     | 
| 
         @@ -38,6 +38,10 @@ module RailLocatorApi 
     | 
|
| 
       38 
38 
     | 
    
         
             
                  @request_builder.access_token
         
     | 
| 
       39 
39 
     | 
    
         
             
                end
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
      
 41 
     | 
    
         
            +
                def refresh_token
         
     | 
| 
      
 42 
     | 
    
         
            +
                  @request_builder.refresh_token
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
       41 
45 
     | 
    
         
             
                def api_key
         
     | 
| 
       42 
46 
     | 
    
         
             
                  @request_builder.api_key
         
     | 
| 
       43 
47 
     | 
    
         
             
                end
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module RailLocatorApi
         
     | 
| 
       2 
2 
     | 
    
         
             
              class Request
         
     | 
| 
       3 
     | 
    
         
            -
                attr_accessor :access_token, :api_key, :api_user_email, :api_user_password, :api_auth_method, :api_endpoint,
         
     | 
| 
      
 3 
     | 
    
         
            +
                attr_accessor :access_token, :refresh_token, :api_key, :api_user_email, :api_user_password, :api_auth_method, :api_endpoint,
         
     | 
| 
       4 
4 
     | 
    
         
             
                              :timeout, :open_timeout, :proxy, :ssl_options, :faraday_adapter, :symbolize_keys, :debug, :logger, :test
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
                AUTH_METHODS = [:keycloak, :api_key, :base64]
         
     | 
| 
         @@ -8,7 +8,7 @@ module RailLocatorApi 
     | 
|
| 
       8 
8 
     | 
    
         
             
                DEFAULT_TIMEOUT = 60
         
     | 
| 
       9 
9 
     | 
    
         
             
                DEFAULT_OPEN_TIMEOUT = 60
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                def initialize(access_token: nil, api_key: nil, api_user_email: nil, api_user_password: nil,
         
     | 
| 
      
 11 
     | 
    
         
            +
                def initialize(access_token: nil, refresh_token: nil, api_key: nil, api_user_email: nil, api_user_password: nil,
         
     | 
| 
       12 
12 
     | 
    
         
             
                               api_endpoint: nil, api_auth_method: nil, timeout: nil, open_timeout: nil, proxy: nil, ssl_options: nil,
         
     | 
| 
       13 
13 
     | 
    
         
             
                               faraday_adapter: nil, symbolize_keys: false, debug: false, logger: nil, test: false)
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
         @@ -19,10 +19,12 @@ module RailLocatorApi 
     | 
|
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                  @access_token = access_token || self.class.access_token || RailLocatorApi.generate_access_token.try(:dig, "access_token")
         
     | 
| 
       21 
21 
     | 
    
         
             
                  @access_token = @access_token.strip if @access_token
         
     | 
| 
       22 
     | 
    
         
            -
                  @access_token = RailLocatorApi::generate_access_token if @access_token.nil?
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @access_token = RailLocatorApi::generate_access_token.try(:dig, "access_token") if @access_token.nil?
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @refresh_token = refresh_token  || self.class.refresh_token
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @refresh_token = @refresh_token.strip if @refresh_token
         
     | 
| 
       23 
25 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                  @api_user_email = api_user_email || RailLocatorApi::api_user_email || ENV['API_USER_EMAIL']
         
     | 
| 
       25 
     | 
    
         
            -
                  @api_user_password = api_user_password || RailLocatorApi::api_user_password || ENV['API_USER_PASSWORD']
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @api_user_email = api_user_email || RailLocatorApi::api_user_email || ENV['API_USER_EMAIL'] || ""
         
     | 
| 
      
 27 
     | 
    
         
            +
                  @api_user_password = api_user_password || RailLocatorApi::api_user_password || ENV['API_USER_PASSWORD'] || ""
         
     | 
| 
       26 
28 
     | 
    
         
             
                  @api_endpoint = api_endpoint || self.class.api_endpoint
         
     | 
| 
       27 
29 
     | 
    
         
             
                  @api_endpoint = RailLocatorApi::api_endpoint if @api_endpoint.nil?
         
     | 
| 
       28 
30 
     | 
    
         
             
                  @api_auth_method = api_auth_method || DEFAULT_AUTH_METHOD
         
     | 
| 
         @@ -95,8 +97,8 @@ module RailLocatorApi 
     | 
|
| 
       95 
97 
     | 
    
         
             
                                :api_endpoint, :proxy, :ssl_options, :faraday_adapter, :symbolize_keys, :debug, :logger, :test
         
     | 
| 
       96 
98 
     | 
    
         | 
| 
       97 
99 
     | 
    
         
             
                  def method_missing(sym, *args, &block)
         
     | 
| 
       98 
     | 
    
         
            -
                    new(access_token: self.access_token,  
     | 
| 
       99 
     | 
    
         
            -
                        api_user_password: self.api_user_email,
         
     | 
| 
      
 100 
     | 
    
         
            +
                    new(access_token: self.access_token, refresh_token: self.refresh_token, api_key: self.api_key,
         
     | 
| 
      
 101 
     | 
    
         
            +
                        api_user_email: self.api_user_email, api_user_password: self.api_user_email,
         
     | 
| 
       100 
102 
     | 
    
         
             
                        api_auth_method: self.api_auth_method, api_endpoint: self.api_endpoint,
         
     | 
| 
       101 
103 
     | 
    
         
             
                        timeout: self.timeout, open_timeout: self.open_timeout, faraday_adapter: self.faraday_adapter,
         
     | 
| 
       102 
104 
     | 
    
         
             
                        symbolize_keys: self.symbolize_keys, debug: self.debug, proxy: self.proxy, ssl_options: self.ssl_options, logger: self.logger,
         
     | 
    
        data/lib/rail-locator-api.rb
    CHANGED
    
    | 
         @@ -14,7 +14,21 @@ module RailLocatorApi 
     | 
|
| 
       14 
14 
     | 
    
         
             
                  else
         
     | 
| 
       15 
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 
16 
     | 
    
         
             
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
                  connection = Faraday.new(RailLocatorApi.keycloak_token_url, proxy: nil,
         
     | 
| 
      
 18 
     | 
    
         
            +
                                           ssl: { version: "TLSv1_2" }) do |faraday|
         
     | 
| 
      
 19 
     | 
    
         
            +
                    faraday.adapter Faraday.default_adapter
         
     | 
| 
      
 20 
     | 
    
         
            +
                    faraday.response :logger, ::Logger.new(STDOUT), bodies: true
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  response = connection.post RailLocatorApi.keycloak_token_url, payload do |request|
         
     | 
| 
      
 24 
     | 
    
         
            +
                    request.headers['accept'] = 'application/json'
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  JSON.parse(response.body)
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
       17 
29 
     | 
    
         | 
| 
      
 30 
     | 
    
         
            +
                def refresh_access_token
         
     | 
| 
      
 31 
     | 
    
         
            +
                  payload = "grant_type=refresh_token&client_id=#{RailLocatorApi.keycloak_client_id}&refresh_token=#{RailLocatorApi::Request.access_token}&redirect_uri=#{RailLocatorApi.keycloak_redirect_uri}"
         
     | 
| 
       18 
32 
     | 
    
         
             
                  connection = Faraday.new(RailLocatorApi.keycloak_token_url, proxy: nil,
         
     | 
| 
       19 
33 
     | 
    
         
             
                                           ssl: { version: "TLSv1_2" }) do |faraday|
         
     | 
| 
       20 
34 
     | 
    
         
             
                    faraday.adapter Faraday.default_adapter
         
     | 
| 
         @@ -25,7 +39,7 @@ module RailLocatorApi 
     | 
|
| 
       25 
39 
     | 
    
         
             
                    request.headers['accept'] = 'application/json'
         
     | 
| 
       26 
40 
     | 
    
         
             
                  end
         
     | 
| 
       27 
41 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
                  JSON.parse(response.body) 
     | 
| 
      
 42 
     | 
    
         
            +
                  JSON.parse(response.body)
         
     | 
| 
       29 
43 
     | 
    
         
             
                end
         
     | 
| 
       30 
44 
     | 
    
         | 
| 
       31 
45 
     | 
    
         
             
                def setup
         
     |