Class: Fizzy::Client

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

Overview

Main client for the Fizzy API.

Client holds shared resources and provides service accessors for all 15 Fizzy services. Unlike Basecamp’s Client -> AccountClient pattern, Fizzy does not require an account ID – all services are available directly on the Client.

Examples:

Basic usage

config = Fizzy::Config.from_env
token_provider = Fizzy::StaticTokenProvider.new(ENV["FIZZY_ACCESS_TOKEN"])
client = Fizzy::Client.new(config: config, token_provider: token_provider)

boards = client.boards.list.to_a
card = client.cards.get(board_id: 1, card_id: 42)

With custom hooks

require "logger"
logger = Logger.new($stdout)
hooks = Fizzy::LoggerHooks.new(logger)

client = Fizzy::Client.new(
  config: config,
  token_provider: token_provider,
  hooks: hooks
)

Instance Attribute Summary collapse

Services collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, token_provider: nil, auth_strategy: nil, hooks: nil) ⇒ Client

Creates a new Fizzy API client.

Parameters:

  • config (Config)

    configuration settings

  • token_provider (TokenProvider, nil) (defaults to: nil)

    token provider (deprecated, use auth_strategy)

  • auth_strategy (AuthStrategy, nil) (defaults to: nil)

    authentication strategy

  • hooks (Hooks, nil) (defaults to: nil)

    observability hooks

Raises:

  • (ArgumentError)


39
40
41
42
43
44
45
46
47
48
# File 'lib/fizzy/client.rb', line 39

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)
  @services = {}
  @mutex = Mutex.new
end

Instance Attribute Details

#configConfig (readonly)

Returns client configuration.

Returns:

  • (Config)

    client configuration



31
32
33
# File 'lib/fizzy/client.rb', line 31

def config
  @config
end

#hooksHooks (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.

Returns:



58
59
60
# File 'lib/fizzy/client.rb', line 58

def hooks
  @hooks
end

#httpHttp (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.

Returns:



53
54
55
# File 'lib/fizzy/client.rb', line 53

def http
  @http
end

Instance Method Details

#boardsServices::BoardsService



128
129
130
# File 'lib/fizzy/client.rb', line 128

def boards
  service(:boards) { Services::BoardsService.new(self) }
end

#cardsServices::CardsService



138
139
140
# File 'lib/fizzy/client.rb', line 138

def cards
  service(:cards) { Services::CardsService.new(self) }
end

#columnsServices::ColumnsService



133
134
135
# File 'lib/fizzy/client.rb', line 133

def columns
  service(:columns) { Services::ColumnsService.new(self) }
end

#commentsServices::CommentsService



143
144
145
# File 'lib/fizzy/client.rb', line 143

def comments
  service(:comments) { Services::CommentsService.new(self) }
end

#delete(path, retryable: nil) ⇒ Response

Performs a DELETE request.

Parameters:

  • path (String)

    URL path

  • retryable (Boolean, nil) (defaults to: nil)

    override retry behavior

Returns:



97
98
99
# File 'lib/fizzy/client.rb', line 97

def delete(path, retryable: nil)
  @http.delete(path, retryable: retryable)
end

#devicesServices::DevicesService



193
194
195
# File 'lib/fizzy/client.rb', line 193

def devices
  service(:devices) { Services::DevicesService.new(self) }
end

#get(path, params: {}) ⇒ Response

Performs a GET request.

Parameters:

  • path (String)

    URL path

  • params (Hash) (defaults to: {})

    query parameters

Returns:



64
65
66
# File 'lib/fizzy/client.rb', line 64

def get(path, params: {})
  @http.get(path, params: params)
end

#identityServices::IdentityService



123
124
125
# File 'lib/fizzy/client.rb', line 123

def identity
  service(:identity) { Services::IdentityService.new(self) }
end

#miscellaneousServices::MiscellaneousService



198
199
200
# File 'lib/fizzy/client.rb', line 198

def miscellaneous
  service(:miscellaneous) { Services::MiscellaneousService.new(self) }
end

#notificationsServices::NotificationsService



158
159
160
# File 'lib/fizzy/client.rb', line 158

def notifications
  service(:notifications) { Services::NotificationsService.new(self) }
end

#paginate(path, params: {}) {|Hash| ... } ⇒ Enumerator

Fetches all pages of a paginated resource.

Parameters:

  • path (String)

    URL path

  • params (Hash) (defaults to: {})

    query parameters

Yields:

  • (Hash)

    each item from the response

Returns:

  • (Enumerator)

    if no block given



116
117
118
# File 'lib/fizzy/client.rb', line 116

def paginate(path, params: {}, &)
  @http.paginate(path, params: params, &)
end

#patch(path, body: nil) ⇒ Response

Performs a PATCH request.

Parameters:

  • path (String)

    URL path

  • body (Hash, nil) (defaults to: nil)

    request body

Returns:



89
90
91
# File 'lib/fizzy/client.rb', line 89

def patch(path, body: nil)
  @http.patch(path, body: body)
end

#pinsServices::PinsService



173
174
175
# File 'lib/fizzy/client.rb', line 173

def pins
  service(:pins) { Services::PinsService.new(self) }
end

#post(path, body: nil, retryable: nil) ⇒ Response

Performs a POST request.

Parameters:

  • path (String)

    URL path

  • body (Hash, nil) (defaults to: nil)

    request body

  • retryable (Boolean, nil) (defaults to: nil)

    override retry behavior (true for idempotent POSTs)

Returns:



73
74
75
# File 'lib/fizzy/client.rb', line 73

def post(path, body: nil, retryable: nil)
  @http.post(path, body: body, retryable: retryable)
end

#post_raw(path, body:, content_type:) ⇒ Response

Performs a POST request with raw binary data. Used for file uploads.

Parameters:

  • path (String)

    URL path

  • body (String, IO)

    raw binary data

  • content_type (String)

    MIME content type

Returns:



107
108
109
# File 'lib/fizzy/client.rb', line 107

def post_raw(path, body:, content_type:)
  @http.post_raw(path, body: body, content_type: content_type)
end

#put(path, body: nil) ⇒ Response

Performs a PUT request.

Parameters:

  • path (String)

    URL path

  • body (Hash, nil) (defaults to: nil)

    request body

Returns:



81
82
83
# File 'lib/fizzy/client.rb', line 81

def put(path, body: nil)
  @http.put(path, body: body)
end

#reactionsServices::ReactionsService



153
154
155
# File 'lib/fizzy/client.rb', line 153

def reactions
  service(:reactions) { Services::ReactionsService.new(self) }
end

#sessionsServices::SessionsService



188
189
190
# File 'lib/fizzy/client.rb', line 188

def sessions
  service(:sessions) { Services::SessionsService.new(self) }
end

#stepsServices::StepsService



148
149
150
# File 'lib/fizzy/client.rb', line 148

def steps
  service(:steps) { Services::StepsService.new(self) }
end

#tagsServices::TagsService



163
164
165
# File 'lib/fizzy/client.rb', line 163

def tags
  service(:tags) { Services::TagsService.new(self) }
end

#uploadsServices::UploadsService



178
179
180
# File 'lib/fizzy/client.rb', line 178

def uploads
  service(:uploads) { Services::UploadsService.new(self) }
end

#usersServices::UsersService



168
169
170
# File 'lib/fizzy/client.rb', line 168

def users
  service(:users) { Services::UsersService.new(self) }
end

#webhooksServices::WebhooksService



183
184
185
# File 'lib/fizzy/client.rb', line 183

def webhooks
  service(:webhooks) { Services::WebhooksService.new(self) }
end