Class: Fabricio::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/fabricio/client/client.rb

Overview

The main object of the gem. It’s used to initiate all data requests.

Constant Summary collapse

DEFAULT_CLIENT_ID =

Default values for initialization parameters clientId and clientSecret are taken from Android application.

'2c18f8a77609ee6bbac9e53f3768fedc45fb96be0dbcb41defa706dc57d9c931'
DEFAULT_CLIENT_SECRET =
'092ed1cdde336647b13d44178932cba10911577faf0eda894896188a7d900cc9'
DEFAULT_USERNAME =
nil
DEFAULT_PASSWORD =
nil
DEFAULT_SESSION_STORAGE =

In-memory session storage is used by default

Fabricio::Authorization::MemorySessionStorage.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { :client_id => DEFAULT_CLIENT_ID, :client_secret => DEFAULT_CLIENT_SECRET, :username => DEFAULT_USERNAME, :password => DEFAULT_PASSWORD, :session_storage => DEFAULT_SESSION_STORAGE }) {|_self| ... } ⇒ Fabricio::Client

Initializes a new Client object. You can use a block to fill all the options: client = Fabricio::Client.new do |config|

config.username = '[email protected]'
config.password = 'pa$$word'

end

After initializing you can query this client to get data: client.app.all client.app.active_now(‘app_id’)

Parameters:

  • options (Hash) (defaults to: { :client_id => DEFAULT_CLIENT_ID, :client_secret => DEFAULT_CLIENT_SECRET, :username => DEFAULT_USERNAME, :password => DEFAULT_PASSWORD, :session_storage => DEFAULT_SESSION_STORAGE })

    Hash containing customizable options

Options Hash (options):

  • :client_id (String)

    Client identifier. You can take it from the ‘Organization’ section in Fabric.io settings.

  • :client_secret (String)

    Client secret key. You can take it from the ‘Organization’ section in Fabric.io settings.

  • :username (String)

    Your Fabric.io username

  • :password (String)

    Your Fabric.io password

  • :session_storage (Fabricio::Authorization::AbstractSessionStorage)

    Your custom AbstractSessionStorage subclass that provides its own logic of storing session data.

Yields:

  • (_self)

Yield Parameters:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fabricio/client/client.rb', line 41

def initialize(options =
                   {
                       :client_id => DEFAULT_CLIENT_ID,
                       :client_secret => DEFAULT_CLIENT_SECRET,
                       :username => DEFAULT_USERNAME,
                       :password => DEFAULT_PASSWORD,
                       :session_storage => DEFAULT_SESSION_STORAGE
                   })
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
  yield(self) if block_given?

  @auth_client = Fabricio::Authorization::AuthorizationClient.new
  session = obtain_session
  network_client = Fabricio::Networking::NetworkClient.new(@auth_client, @session_storage)

  @organization_service ||= Fabricio::Service::OrganizationService.new(session, network_client)
  @app_service ||= Fabricio::Service::AppService.new(session, network_client)
  @build_service ||= Fabricio::Service::BuildService.new(session, network_client)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object

We use ‘method_missing` approach instead of explicit methods. Generally, look at the initialized services and use the first part of their names as a method. app_service -> client.app

# @raise [NoMethodError] Error raised when unsupported method is called.

Raises:

  • (NoMethodError)


68
69
70
71
72
# File 'lib/fabricio/client/client.rb', line 68

def method_missing(*args)
  service = instance_variable_get("@#{args.first}_service")
  return service if service
  raise NoMethodError.new("There's no method called #{args.first} here -- please try again.", args.first)
end

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



22
23
24
# File 'lib/fabricio/client/client.rb', line 22

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



22
23
24
# File 'lib/fabricio/client/client.rb', line 22

def client_secret
  @client_secret
end

#passwordObject

Returns the value of attribute password.



22
23
24
# File 'lib/fabricio/client/client.rb', line 22

def password
  @password
end

#session_storageObject

Returns the value of attribute session_storage.



22
23
24
# File 'lib/fabricio/client/client.rb', line 22

def session_storage
  @session_storage
end

#usernameObject

Returns the value of attribute username.



22
23
24
# File 'lib/fabricio/client/client.rb', line 22

def username
  @username
end