Sha256: 672edfbba9a06f90cf3da70d3ec464bb823b15564829708aa4e9c76f6c7da553

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

module Ribose
  class Client
    attr_accessor :api_email, :api_token, :access_token, :uid, :client_id

    def initialize(options = {})
      initialize_client_details(options)
    end

    # Initiate a ribose client
    #
    # This interface takes email, password, api_email and api_token
    # Then it will do all the underlying work to find out client id and uid
    # Finally it will return a ribose client.
    #
    # @param :email [String] The email for your Ribose account
    # @param :password [String] The password for your account
    # @param :api_email [String] The email for your API account
    # @param :api_token [String] The authentication token for your API account
    # @return [Ribose::Client] A new client with your details
    #
    def self.from_login(email:, password:)
      session = Ribose::Session.create(
        username: email, password: password,
      )

      new(
        api_email: email,
        uid: session.uid,
        client_id: session.client,
        api_token: session["access-token"],
        access_token: session["access-token"],
      )
    end

    private

    def configuration
      Ribose.configuration
    end

    def initialize_client_details(options)
      @uid = options.fetch(:uid, nil)
      @client_id = options.fetch(:client_id, nil)
      @access_token = options.fetch(:access_token, nil)
      @api_email = options.fetch(:api_email, configuration.api_email)
      @api_token = options.fetch(:api_token, configuration.api_token)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ribose-0.5.0 lib/ribose/client.rb