class BonsaiClient::Client

Client for a Bonsai server.

Public Class Methods

new(opts = {}) click to toggle source

@param [Hash] opts Otions to create the client. @option opts [String] :url Bonsai server URL (such as bonsai-server.com) @option opts [String] :client_id Unique ID for each client. @option opts [String] :client_id Client secret.

# 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

Public Instance Methods

upload(opts = {}) click to toggle source

Upload a file.

@param [Hash] opts Otions to upload a file. @option opts [String] :path File path.

@return [Hash] Response from Bonsai server.

# 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

Private Instance Methods

raise_no_file_path!() click to toggle source
# File lib/bonsai_client/client.rb, line 34
def raise_no_file_path!
  raise 'No file path'
end
upload_url() click to toggle source
# File lib/bonsai_client/client.rb, line 38
def upload_url
  "#{@url}/api/client/#{@client_id}/upload"
end