Class: Bizowie::API

Inherits:
Object
  • Object
show all
Defined in:
lib/bizowie/api.rb,
lib/bizowie/api/version.rb,
lib/bizowie/api/response.rb

Overview

Ruby client for the Bizowie ERP API.

Examples:

require 'bizowie/api'

bz = Bizowie::API.new(
  api_key:    '02cc7058-cd22-4c8e-ad7c-a8f3f2a64bd0',
  secret_key: '58c57abc-1e16-3571-bb35-73876bcef746',
  site:       'mysite.bizowie.com',
  v2:         true,
)

res = bz.call('databases/add_note/3/10/123', comment: 'hello from Ruby')
puts res.success
puts res.data

Defined Under Namespace

Classes: Response

Constant Summary collapse

USER_AGENT =
'Bizowie::API'.freeze
VERSION =
'0.5.0'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, secret_key:, site:, v2: false, api_version: nil, debug: false) ⇒ API

Returns a new instance of API.

Parameters:

  • api_key (String)

    Your Bizowie API key.

  • secret_key (String)

    Your Bizowie secret key.

  • site (String)

    Hostname of your Bizowie instance (e.g. mysite.bizowie.com).

  • v2 (Boolean) (defaults to: false)

    Route calls through the v2 endpoint. Recommended for new integrations.

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

    API version sent with each v2 request. Defaults to ‘1.00’.

  • debug (Boolean) (defaults to: false)

    When true, log the raw HTTP body to stderr if the response can’t be parsed as JSON.

Raises:

  • (ArgumentError)

    if site, api_key, or secret_key is missing.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bizowie/api.rb', line 35

def initialize(api_key:, secret_key:, site:, v2: false, api_version: nil, debug: false)
  raise ArgumentError, 'site not specified'       if site.nil?       || site.to_s.empty?
  raise ArgumentError, 'api_key not specified'    if api_key.nil?    || api_key.to_s.empty?
  raise ArgumentError, 'secret_key not specified' if secret_key.nil? || secret_key.to_s.empty?

  @api_key     = api_key
  @secret_key  = secret_key
  @site        = site
  @v2          = v2
  @api_version = api_version
  @debug       = debug
end

Instance Method Details

#call(method, params = nil) ⇒ Bizowie::API::Response

Make an API call. Dispatches to the v1 or v2 endpoint based on the v2 option passed to the constructor.

Does not raise on HTTP errors — application-level failures are surfaced via success: 0 on the returned response. Network-level failures (DNS, connection refused, TLS errors) bubble up from Net::HTTP.

Parameters:

  • method (String)

    Path to the API method (everything after /bz/api/ for v1 or /bz/apiv2/call/ for v2).

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

    Parameters to send. JSON-encoded for you. In v2 mode, api_key/secret_key/api_version are injected automatically — don’t include them here.

Returns:

Raises:

  • (RuntimeError)

    if method is empty.



62
63
64
# File 'lib/bizowie/api.rb', line 62

def call(method, params = nil)
  @v2 ? call_v2(method, params) : call_v1(method, params)
end