Sha256: 76ead26f9c3baa29237b6b5cc4470fbfcd8cfd8c1e07993336c0e4f70fcf3d31

Contents?: true

Size: 1005 Bytes

Versions: 4

Compression:

Stored size: 1005 Bytes

Contents

module EspSdk
  class Configure
    attr_accessor :token, :email, :version, :token_expires_at

    def initialize(options)
      @email   = options[:email]
      @version = options[:version] || 'v1'
      token_setup(options)
    end

    def uri
      return @uri if @uri.present?

      if EspSdk.production?
        @uri = 'https://api.evident.io/api'
      elsif EspSdk.release?
        @uri = 'https://api-rel.evident.io/api'
      else
        @uri = 'http://0.0.0.0:3001/api'
      end
    end

    private

    def token_setup(options)
      self.token = options[:password] || options[:token]
      end_point  = options[:password].present? ? 'new' : 'valid'
      client     = Client.new(self)
      response   = client.connect("#{uri}/#{version}/token/#{end_point}")
      user       = JSON.load(response.body)
      self.token = user['authentication_token']
      self.token_expires_at = user['token_expires_at'].to_s.to_datetime.utc ||
        1.hour.from_now.to_datetime.utc
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
esp_sdk-1.0.3 lib/esp_sdk/configure.rb
esp_sdk-1.0.2 lib/esp_sdk/configure.rb
esp_sdk-1.0.1 lib/esp_sdk/configure.rb
esp_sdk-1.0.0 lib/esp_sdk/configure.rb