Class: FileboundClient::Client
- Includes:
- Endpoints
- Defined in:
- lib/filebound_client.rb
Overview
This encapsulates all client/server communications
Defined Under Namespace
Classes: FileboundClientException
Instance Attribute Summary collapse
-
#connection ⇒ FileboundClient::Connection
readonly
The connection representing the currently logged on session with the Filebound API.
Class Method Summary collapse
-
.connect(config) ⇒ FileboundClient::Client
Creates, initialize and logs into the Filebound API.
Instance Method Summary collapse
-
#delete(url, query_params = nil) ⇒ true, false
Executes a DELETE request on the current Filebound client session.
-
#get(url, query_params = nil) ⇒ Hash
Executes a GET request on the current Filebound client session expecting JSON in the body of the response.
-
#get_binary(url, query_params = nil) ⇒ String
Executes a GET request on the current Filebound client session expecting binary in the body of the response.
-
#initialize(connection) ⇒ FileboundClient::Client
constructor
Initializes the client with the supplied Connection.
-
#post(url, query_params = nil, body = nil) ⇒ Hash
Executes a POST request on the current Filebound client session expecting JSON in the body of the request/response.
-
#put(url, query_params = nil, body = nil) ⇒ Hash
Executes a PUT request on the current Filebound client session expecting JSON in the body of the request/response.
Methods included from Endpoints
Constructor Details
#initialize(connection) ⇒ FileboundClient::Client
Initializes the client with the supplied Connection
36 37 38 |
# File 'lib/filebound_client.rb', line 36 def initialize(connection) @connection = connection end |
Instance Attribute Details
#connection ⇒ FileboundClient::Connection (readonly)
The connection representing the currently logged on session with the Filebound API
87 88 89 |
# File 'lib/filebound_client.rb', line 87 def connection @connection end |
Class Method Details
.connect(config) ⇒ FileboundClient::Client
Creates, initialize and logs into the Filebound API
27 28 29 30 31 |
# File 'lib/filebound_client.rb', line 27 def self.connect(config) connection = FileboundClient::Connection.build_connection(config) raise FileboundClientException.new('Failed to login', 401) unless connection.login new(connection) end |
Instance Method Details
#delete(url, query_params = nil) ⇒ true, false
Executes a DELETE request on the current Filebound client session
80 81 82 83 |
# File 'lib/filebound_client.rb', line 80 def delete(url, query_params = nil) perform('delete', url, query: query_params) true end |
#get(url, query_params = nil) ⇒ Hash
Executes a GET request on the current Filebound client session expecting JSON in the body of the response
44 45 46 |
# File 'lib/filebound_client.rb', line 44 def get(url, query_params = nil) JSON.parse(perform('get', url, query: query_params), symbolize_names: true, quirks_mode: true) end |
#get_binary(url, query_params = nil) ⇒ String
Executes a GET request on the current Filebound client session expecting binary in the body of the response
52 53 54 |
# File 'lib/filebound_client.rb', line 52 def get_binary(url, query_params = nil) perform('get', url, query: query_params) end |
#post(url, query_params = nil, body = nil) ⇒ Hash
Executes a POST request on the current Filebound client session expecting JSON in the body of the request/response
71 72 73 74 |
# File 'lib/filebound_client.rb', line 71 def post(url, query_params = nil, body = nil) params = { headers: { 'Content-Type' => 'application/json' }, query: query_params, body: body } JSON.parse(perform('post', url, params), symbolize_names: true, quirks_mode: true) end |
#put(url, query_params = nil, body = nil) ⇒ Hash
Executes a PUT request on the current Filebound client session expecting JSON in the body of the request/response
61 62 63 64 |
# File 'lib/filebound_client.rb', line 61 def put(url, query_params = nil, body = nil) params = { headers: { 'Content-Type' => 'application/json' }, query: query_params, body: body } JSON.parse(perform('put', url, params), symbolize_names: true, quirks_mode: true) end |