Sha256: 2211f58593f7a7bde73146a3b41b6ef02ecaa6b1c084ca72e6573542ce380eb5

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

module GettyConnect
  class Client
    module Session

      def request_token(options={})
        options = { 
          :RequestHeader => { 
            :Token => ''
          },
          :CreateSessionRequestBody => {
            :SystemId => GettyConnect.system_id,
            :SystemPassword => GettyConnect.system_password,
            :UserName => GettyConnect.api_username,
            :UserPassword => GettyConnect.api_password
          }
        }.merge options

        response = post(@create_session_endpoint, options, use_ssl=true)
        if response.ResponseHeader.Status == "success"
          self.token = response.CreateSessionResult.Token
          self.secure_token = response.CreateSessionResult.SecureToken
          self.token_issued_at = Time.now()
          self.token_duration = response.CreateSessionResult.TokenDurationMinutes
        end
        response
      end

      def renew_token(options={})
        if self.secure_token
          options = {
            :RequestHeader => { 
              :Token => self.secure_token 
            },
            :RenewSessionRequestBody => {
              :SystemId => GettyConnect.system_id,
              :SystemPassword => GettyConnect.system_password
            }
          }.merge options
        else 
          "Token must be first requested."
        end

        response = post(@renew_session_endpoint, options, use_ssl=true)
        if response.ResponseHeader.Status == "success"
          self.token_renewed_at = Time.now()
        end
        response
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
getty_connect-0.0.4 lib/getty_connect/client/session.rb
getty_connect-0.0.3 lib/getty_connect/client/session.rb