Class: FileboundClient::Client

Inherits:
Object
  • Object
show all
Includes:
Endpoints
Defined in:
lib/filebound_client.rb

Overview

This encapsulates all client/server communications

Defined Under Namespace

Classes: FileboundClientException

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Endpoints

included

Constructor Details

#initialize(connection) ⇒ FileboundClient::Client

Initializes the client with the supplied Connection

Parameters:

  • connection (Connection)

    the logged in Connection



36
37
38
# File 'lib/filebound_client.rb', line 36

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionFileboundClient::Connection (readonly)

The connection representing the currently logged on session with the Filebound API

Returns:



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

Parameters:

  • config (Hash)

    a hash of configuration values

Returns:

Raises:



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.
  new(connection)
end

Instance Method Details

#delete(url, query_params = nil) ⇒ true, false

Executes a DELETE request on the current Filebound client session

Parameters:

  • url (String)

    the resource url to request

  • query_params (Hash) (defaults to: nil)

    the optional query parameters to pass to the DELETE request

Returns:

  • (true, false)

    true if resource was deleted successfully



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

Parameters:

  • url (String)

    the resource url to request

  • query_params (Hash) (defaults to: nil)

    the optional query parameters to pass to the GET request

Returns:

  • (Hash)

    the JSON parsed hash of the response body



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

Parameters:

  • url (String)

    the resource url to request

  • query_params (Hash) (defaults to: nil)

    the optional query parameters to pass to the GET request

Returns:

  • (String)

    Base64 encoded binary string



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

Parameters:

  • url (String)

    the resource url to request

  • query_params (Hash) (defaults to: nil)

    the optional query parameters to pass to the POST request

  • body (Hash) (defaults to: nil)

    the hash that will be converted to JSON when inserted in the body of the request

Returns:

  • (Hash)

    the JSON parsed hash of the response body



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

Parameters:

  • url (String)

    the resource url to request

  • query_params (Hash) (defaults to: nil)

    the optional query parameters to pass to the PUT request

  • body (Hash) (defaults to: nil)

    the hash that will be converted to JSON when inserted in the body of the request

Returns:

  • (Hash)

    the JSON parsed hash of the response body



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