Class: Bloomy::Client

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

Overview

The Client class is the main entry point for interacting with the Bloomy API. It provides methods for managing Bloom Growth features.

Constant Summary collapse

DEFAULT_RETRY_OPTIONS =

Default retry options for transient failures

{
  max: 3,
  interval: 0.5,
  interval_randomness: 0.5,
  backoff_factor: 2,
  retry_statuses: [429, 502, 503, 504],
  exceptions: [Faraday::TimeoutError, Faraday::ConnectionFailed]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, open_timeout: 10, read_timeout: 30, retry_options: {}) ⇒ Client

Initializes a new Client instance

Examples:

Basic usage

client = Bloomy::Client.new
client.meeting.list

With custom timeouts

client = Bloomy::Client.new(open_timeout: 5, read_timeout: 60)

With custom retry options

client = Bloomy::Client.new(retry_options: { max: 5 })

Parameters:

  • api_key (String, nil) (defaults to: nil)

    API key for authentication (optional if configured elsewhere)

  • open_timeout (Integer) (defaults to: 10)

    connection timeout in seconds (default: 10)

  • read_timeout (Integer) (defaults to: 30)

    read timeout in seconds (default: 30)

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

    custom retry options to merge with defaults

Raises:

  • (ArgumentError)

    if no API key is provided or configured



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/bloomy/client.rb', line 56

def initialize(api_key = nil, open_timeout: 10, read_timeout: 30, retry_options: {})
  @configuration = Configuration.new unless api_key
  @api_key = api_key || @configuration.api_key

  raise ArgumentError, "No API key provided. Set it in configuration or pass it directly." unless @api_key

  @base_url = "https://app.bloomgrowth.com/api/v1/"
  merged_retry_options = DEFAULT_RETRY_OPTIONS.merge(retry_options)

  @conn = Faraday.new(url: @base_url) do |faraday|
    faraday.request :retry, merged_retry_options
    faraday.response :json
    faraday.adapter Faraday.default_adapter
    faraday.headers["Accept"] = "*/*"
    faraday.headers["Content-Type"] = "application/json"
    faraday.headers["Authorization"] = "Bearer #{@api_key}"
    faraday.options.open_timeout = open_timeout
    faraday.options.timeout = read_timeout
  end

  @user = User.new(@conn)
  @todo = Todo.new(@conn)
  @goal = Goal.new(@conn)
  @meeting = Meeting.new(@conn)
  @scorecard = Scorecard.new(@conn)
  @issue = Issue.new(@conn)
  @headline = Headline.new(@conn)
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



28
29
30
# File 'lib/bloomy/client.rb', line 28

def configuration
  @configuration
end

#goalObject (readonly)

Returns the value of attribute goal.



28
29
30
# File 'lib/bloomy/client.rb', line 28

def goal
  @goal
end

#headlineObject (readonly)

Returns the value of attribute headline.



28
29
30
# File 'lib/bloomy/client.rb', line 28

def headline
  @headline
end

#issueObject (readonly)

Returns the value of attribute issue.



28
29
30
# File 'lib/bloomy/client.rb', line 28

def issue
  @issue
end

#meetingObject (readonly)

Returns the value of attribute meeting.



28
29
30
# File 'lib/bloomy/client.rb', line 28

def meeting
  @meeting
end

#scorecardObject (readonly)

Returns the value of attribute scorecard.



28
29
30
# File 'lib/bloomy/client.rb', line 28

def scorecard
  @scorecard
end

#todoObject (readonly)

Returns the value of attribute todo.



28
29
30
# File 'lib/bloomy/client.rb', line 28

def todo
  @todo
end

#userObject (readonly)

Returns the value of attribute user.



28
29
30
# File 'lib/bloomy/client.rb', line 28

def user
  @user
end

Instance Method Details

#user_idInteger

Returns the current user’s ID

Examples:

client.user_id
#=> 12345

Returns:

  • (Integer)

    the current user’s ID



36
37
38
# File 'lib/bloomy/client.rb', line 36

def user_id
  @user_id ||= @user.user_id
end