Class: Fabricio::Client
- Inherits:
-
Object
- Object
- Fabricio::Client
- 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
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#password ⇒ Object
Returns the value of attribute password.
-
#session_storage ⇒ Object
Returns the value of attribute session_storage.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
-
#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
constructor
Initializes a new Client object.
-
#method_missing(*args) ⇒ Object
We use ‘method_missing` approach instead of explicit methods.
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’)
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( = { :client_id => DEFAULT_CLIENT_ID, :client_secret => DEFAULT_CLIENT_SECRET, :username => DEFAULT_USERNAME, :password => DEFAULT_PASSWORD, :session_storage => DEFAULT_SESSION_STORAGE }) .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.
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_id ⇒ Object
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_secret ⇒ Object
Returns the value of attribute client_secret.
22 23 24 |
# File 'lib/fabricio/client/client.rb', line 22 def client_secret @client_secret end |
#password ⇒ Object
Returns the value of attribute password.
22 23 24 |
# File 'lib/fabricio/client/client.rb', line 22 def password @password end |
#session_storage ⇒ Object
Returns the value of attribute session_storage.
22 23 24 |
# File 'lib/fabricio/client/client.rb', line 22 def session_storage @session_storage end |
#username ⇒ Object
Returns the value of attribute username.
22 23 24 |
# File 'lib/fabricio/client/client.rb', line 22 def username @username end |