Sha256: d7118c7b3e2b93b2e120957750ce3824b10ba164a9257bc7a98d790971826f66

Contents?: true

Size: 1.3 KB

Versions: 41

Compression:

Stored size: 1.3 KB

Contents

module DeployGate
  module API
    module V1
      class Session
        ENDPOINT = '/sessions'

        class << self

          # @param [String] token
          # @return [Hash]
          def show(token)
            res = Base.new(token).get(ENDPOINT + '/user', {})
            return nil if res['error']

            res['results']
          end

          # @param [String] name
          # @param [String] token
          # @return [Boolean]
          def check(name, token)
            results = show(token)
            return false if results.nil?

            name == results['name']
          end

          # @param [String] email
          # @param [String] password
          # @return [Hash]
          def login(email, password)
            res = Base.new().post(ENDPOINT, {:email => email, :password => password})

            login_results = {
                :error => res['error'],
                :message => res['because']
            }

            results = res['results']
            unless results.nil?
              login_results.merge!({
                                       :name => results['name'],
                                       :token => results['api_token']
                                   })
            end

            login_results
          end
        end
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
deploygate-0.9.1 lib/deploygate/api/v1/session.rb
deploygate-0.9.0 lib/deploygate/api/v1/session.rb
deploygate-0.8.6 lib/deploygate/api/v1/session.rb
deploygate-0.8.5 lib/deploygate/api/v1/session.rb
deploygate-0.8.4 lib/deploygate/api/v1/session.rb
deploygate-0.8.3 lib/deploygate/api/v1/session.rb
deploygate-0.8.2 lib/deploygate/api/v1/session.rb
deploygate-0.8.1 lib/deploygate/api/v1/session.rb
deploygate-0.8.0 lib/deploygate/api/v1/session.rb
deploygate-0.7.0 lib/deploygate/api/v1/session.rb
deploygate-0.6.8 lib/deploygate/api/v1/session.rb
deploygate-0.6.7 lib/deploygate/api/v1/session.rb
deploygate-0.6.6 lib/deploygate/api/v1/session.rb
deploygate-0.6.5 lib/deploygate/api/v1/session.rb
deploygate-0.6.4 lib/deploygate/api/v1/session.rb
deploygate-0.6.3 lib/deploygate/api/v1/session.rb
deploygate-0.6.2 lib/deploygate/api/v1/session.rb
deploygate-0.6.1 lib/deploygate/api/v1/session.rb
deploygate-0.6.0 lib/deploygate/api/v1/session.rb
deploygate-0.5.6 lib/deploygate/api/v1/session.rb