Class: Basecamp::Client
- Inherits:
-
Object
- Object
- Basecamp::Client
- Defined in:
- lib/basecamp/client.rb
Overview
Main client for the Basecamp API.
Client holds shared resources and is used to create AccountClient instances for specific Basecamp accounts via the #for_account method.
Instance Attribute Summary collapse
-
#config ⇒ Config
readonly
Client configuration.
-
#hooks ⇒ Hooks
readonly
private
Returns the observability hooks.
-
#http ⇒ Http
readonly
private
Returns the HTTP client for making requests.
Instance Method Summary collapse
-
#account_id ⇒ nil
private
Returns nil since Client is not bound to an account.
-
#authorization ⇒ Services::AuthorizationService
Returns the AuthorizationService for authorization operations.
-
#for_account(account_id) ⇒ AccountClient
Returns an AccountClient bound to the specified Basecamp account.
-
#initialize(config:, token_provider: nil, auth_strategy: nil, hooks: nil) ⇒ Client
constructor
Creates a new Basecamp API client.
Constructor Details
#initialize(config:, token_provider: nil, auth_strategy: nil, hooks: nil) ⇒ Client
Creates a new Basecamp API client.
42 43 44 45 46 47 48 49 50 |
# File 'lib/basecamp/client.rb', line 42 def initialize(config:, token_provider: nil, auth_strategy: nil, hooks: nil) raise ArgumentError, "provide either token_provider or auth_strategy, not both" if token_provider && auth_strategy raise ArgumentError, "provide token_provider or auth_strategy" if !token_provider && !auth_strategy @config = config @hooks = hooks || NoopHooks.new @http = Http.new(config: config, token_provider: token_provider, auth_strategy: auth_strategy, hooks: @hooks) @mutex = Mutex.new end |
Instance Attribute Details
#config ⇒ Config (readonly)
Returns client configuration.
34 35 36 |
# File 'lib/basecamp/client.rb', line 34 def config @config end |
#hooks ⇒ Hooks (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the observability hooks.
91 92 93 |
# File 'lib/basecamp/client.rb', line 91 def hooks @hooks end |
#http ⇒ Http (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the HTTP client for making requests.
86 87 88 |
# File 'lib/basecamp/client.rb', line 86 def http @http end |
Instance Method Details
#account_id ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns nil since Client is not bound to an account.
96 97 98 |
# File 'lib/basecamp/client.rb', line 96 def account_id nil end |
#authorization ⇒ Services::AuthorizationService
Returns the AuthorizationService for authorization operations. This is the only service available directly on Client, as it doesn't require an account context. All other services require an AccountClient via #for_account.
77 78 79 80 81 |
# File 'lib/basecamp/client.rb', line 77 def @mutex.synchronize do @authorization ||= Services::AuthorizationService.new(self) end end |
#for_account(account_id) ⇒ AccountClient
Returns an AccountClient bound to the specified Basecamp account.
The Basecamp API requires an account ID in the URL path (e.g., https://3.basecampapi.com/12345/projects.json).
64 65 66 67 68 69 70 |
# File 'lib/basecamp/client.rb', line 64 def for_account(account_id) account_id = account_id.to_s raise ArgumentError, "account_id cannot be empty" if account_id.empty? raise ArgumentError, "account_id must be numeric, got: #{account_id}" unless account_id.match?(/\A\d+\z/) AccountClient.new(parent: self, account_id: account_id) end |