Class: TogglAPI::BaseClient
- Inherits:
-
Object
- Object
- TogglAPI::BaseClient
- Defined in:
- lib/toggl_api/base_client.rb
Overview
Superclass for API clients.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_USER_AGENT =
"TogglAPI"
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #credentials ⇒ Object
- #default_api_token ⇒ Object
- #default_headers ⇒ Object
- #default_user_agent ⇒ Object
- #default_workspace_id ⇒ Object
-
#initialize(api_token: default_api_token, user_agent: default_user_agent, logger: nil) ⇒ BaseClient
constructor
Returns a new instance of the client, configured with the specified parameters.
Constructor Details
#initialize(api_token: default_api_token, user_agent: default_user_agent, logger: nil) ⇒ BaseClient
Returns a new instance of the client, configured with the specified parameters.
20 21 22 23 24 25 |
# File 'lib/toggl_api/base_client.rb', line 20 def initialize(api_token: default_api_token, user_agent: default_user_agent, logger: nil) raise "Missing api_token" if api_token.nil? || api_token.empty? @api_token = api_token @user_agent = user_agent @logger = logger end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
10 11 12 |
# File 'lib/toggl_api/base_client.rb', line 10 def api_token @api_token end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/toggl_api/base_client.rb', line 10 def logger @logger end |
Instance Method Details
#credentials ⇒ Object
35 36 37 38 39 40 |
# File 'lib/toggl_api/base_client.rb', line 35 def credentials { username: @api_token, password: "api_token" } end |
#default_api_token ⇒ Object
27 28 29 |
# File 'lib/toggl_api/base_client.rb', line 27 def default_api_token ENV["TOGGL_API_TOKEN"] end |
#default_headers ⇒ Object
42 43 44 45 46 |
# File 'lib/toggl_api/base_client.rb', line 42 def default_headers { "Content-Type" => "application/json" } end |
#default_user_agent ⇒ Object
31 32 33 |
# File 'lib/toggl_api/base_client.rb', line 31 def default_user_agent DEFAULT_USER_AGENT end |
#default_workspace_id ⇒ Object
48 49 50 |
# File 'lib/toggl_api/base_client.rb', line 48 def default_workspace_id DEFAULT_WORKSPACE_ID end |