Class: BonsaiClient::Client

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

Overview

Client for a Bonsai server.

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

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

    Otions to create the client.

Options Hash (opts):

  • :url (String)

    Bonsai server URL (such as bonsai-server.com)

  • :client_id (String)

    Unique ID for each client.

  • :client_id (String)

    Client secret.



9
10
11
12
13
# File 'lib/bonsai_client/client.rb', line 9

def initialize(opts = {})
  @url = opts[:url] || ''
  @client_id = opts[:client_id] || ''
  @client_secret = opts[:client_secret] || ''
end

Instance Method Details

#upload(opts = {}) ⇒ Hash

Upload a file.

Parameters:

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

    Otions to upload a file.

Options Hash (opts):

  • :path (String)

    File path.

Returns:

  • (Hash)

    Response from Bonsai server.



21
22
23
24
25
26
27
28
29
30
# File 'lib/bonsai_client/client.rb', line 21

def upload(opts = {})
  path = opts[:path] || ''
  raise_no_file_path! if path.empty?
  response = RestClient.post(
    upload_url,
    client_secret: @client_secret,
    file: File.new(path, 'rb')
  )
  JSON.parse(response.to_str, symbolize_names: true)
end