Sha256: 242c6a2c5fb54e193c80bc116cfce97204b81abeed08e4cc14a35a7033f3d020

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

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

    def initialize(options = {})
      @api_token    = options.fetch(:api_token, configuration.api_token).to_s
      @api_email    = options.fetch(:api_email, configuration.api_email).to_s
      @client_id    = options[:client_id]
      @uid          = options[:uid]
      @access_token = options[:access_token]
    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:, api_email:, api_token:)
      session = Session.create(
        username: email,
        password: password,
        api_email: api_email,
        api_token: api_token
      )

      new(
        api_email:    api_email,
        api_token:    api_token,
        client_id:    session.nil? ? nil : session['client'],
        uid:          session.nil? ? nil : session['uid'],
        access_token: session.nil? ? nil : session['access-token'],
      )
    end

    private

    def configuration
      Ribose.configuration
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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