Sha256: b9f31bf2f618da5eb1d0f9c9d4f9e183ae32af4d87f32d3cf7169cfdbfc9127b

Contents?: true

Size: 1001 Bytes

Versions: 6

Compression:

Stored size: 1001 Bytes

Contents

# frozen_string_literal: true

module Qismo
  module Resources
    module UserResource
      #
      # Login to Qismo
      #
      # @param email [String]
      # @param password [String]
      # @param role [String]
      #
      # @return [User]
      #
      def login(email, password, role: "admin")
        path = if role == "admin"
          "/api/v1/auth"
        else
          "/api/v1/#{Qismo.client.app_id}/agent_auth"
        end

        resp = Qismo.client.post(path, email: email, password: password)

        body = resp.http_body

        data = body.fetch("data", {})
        user = data.fetch("user", {})
        user[:long_lived_token] = data["long_lived_token"]

        User.new(user)
      end

      #
      # Logout from Qismo
      #
      # @param access_token [String]
      #
      # @return [Response]
      #
      def logout(access_token)
        Qismo.client.request(:post, "/api/v2/auth/logout", headers: { authorization: access_token })
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
qismo-0.1.8 lib/qismo/resources/user_resource.rb
qismo-0.1.5 lib/qismo/resources/user_resource.rb
qismo-0.1.4 lib/qismo/resources/user_resource.rb
qismo-0.1.2 lib/qismo/resources/user_resource.rb
qismo-0.1.1 lib/qismo/resources/user_resource.rb
qismo-0.1.0 lib/qismo/resources/user_resource.rb