Class: BonsaiClient::Client
- Inherits:
-
Object
- Object
- BonsaiClient::Client
- Defined in:
- lib/bonsai_client/client.rb
Overview
Client for a Bonsai server.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
-
#upload(opts = {}) ⇒ Hash
Upload a file.
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
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.
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 |