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
37 38 39 |
# File 'lib/filebound_client.rb', line 37 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
88 89 90 |
# File 'lib/filebound_client.rb', line 88 def connection @connection end |
Class Method Details
.connect(config) ⇒ FileboundClient::Client
Creates, initialize and logs into the Filebound API
28 29 30 31 32 |
# File 'lib/filebound_client.rb', line 28 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
81 82 83 84 |
# File 'lib/filebound_client.rb', line 81 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
45 46 47 |
# File 'lib/filebound_client.rb', line 45 def get(url, query_params = nil) JSON.parse(perform('get', url, query: query_params), symbolize_names: 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
53 54 55 |
# File 'lib/filebound_client.rb', line 53 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
72 73 74 75 |
# File 'lib/filebound_client.rb', line 72 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) 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
62 63 64 65 |
# File 'lib/filebound_client.rb', line 62 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) end |