Class: FileboundClient::Connection
- Includes:
- Config
- Defined in:
- lib/filebound_client/connection.rb
Overview
Encapsulates low level logic to talk to Filebound server
Instance Attribute Summary collapse
-
#token ⇒ Guid
readonly
The token returned from the Filebound server on successfully logging in.
Class Method Summary collapse
-
.build_connection(config) ⇒ Connection
Creates a new connection using the supplied configuration.
Instance Method Summary collapse
-
#api_base_uri ⇒ String
The base path to the API on the Filebound server.
-
#auth_params ⇒ Hash
The authentication query parameters required by all requests to the API.
-
#delete(url, params) ⇒ Net::HTTPResponse
Sends a DELETE request to the supplied resource using the supplied params hash.
-
#get(url, params) ⇒ Net::HTTPResponse
Sends a GET request to the supplied resource using the supplied params hash.
-
#host ⇒ String
The Filebound server hostname and protocol.
-
#initialize(config) ⇒ Connection
constructor
Initialize a new connection with the supplied configuration.
-
#login ⇒ true, false
Sends a POST request to the Filebound API’s login endpoint to request a new security token.
-
#ntlm_domain ⇒ String
The NTLM domain to use for NTLM Authentication.
-
#ntlm_password ⇒ String
The NTLM password to use for NTLM Authentication.
-
#ntlm_user ⇒ String
The NTLM username to use for NTLM Authentication.
-
#password ⇒ String
The password to log on to the Filebound server with.
-
#post(url, params) ⇒ Net::HTTPResponse
Sends a POST request to the supplied resource using the supplied params hash.
-
#put(url, params) ⇒ Net::HTTPResponse
Sends a PUT request to the supplied resource using the supplied params hash.
-
#username ⇒ String
The username to log on to the Filebound server with.
Methods included from Config
Constructor Details
#initialize(config) ⇒ Connection
Initialize a new connection with the supplied configuration
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/filebound_client/connection.rb', line 24 def initialize(config) configure do |c| c.host = config[:host] c.api_base_uri = config[:api_base_uri] c.username = config[:username] c.password = config[:password] # rubocop:disable Metrics/LineLength c.ntlm_auth = { user: config[:ntlm_user], password: config[:ntlm_password], domain: config[:ntlm_domain] } if config[:use_ntlm] # rubocop:enable Metrics/LineLength HTTPI.adapter = :net_http end end |
Instance Attribute Details
#token ⇒ Guid (readonly)
The token returned from the Filebound server on successfully logging in
12 13 14 |
# File 'lib/filebound_client/connection.rb', line 12 def token @token end |
Class Method Details
.build_connection(config) ⇒ Connection
Creates a new connection using the supplied configuration
17 18 19 |
# File 'lib/filebound_client/connection.rb', line 17 def self.build_connection(config) new(config) end |
Instance Method Details
#api_base_uri ⇒ String
The base path to the API on the Filebound server
51 52 53 |
# File 'lib/filebound_client/connection.rb', line 51 def api_base_uri configuration.api_base_uri end |
#auth_params ⇒ Hash
The authentication query parameters required by all requests to the API
97 98 99 |
# File 'lib/filebound_client/connection.rb', line 97 def auth_params { query: { guid: token } } end |
#delete(url, params) ⇒ Net::HTTPResponse
Sends a DELETE request to the supplied resource using the supplied params hash
134 135 136 137 |
# File 'lib/filebound_client/connection.rb', line 134 def delete(url, params) request = HTTPI::Request.new(resource_url(url, query_params(params[:query]))) execute_request(:delete, request, params) end |
#get(url, params) ⇒ Net::HTTPResponse
Sends a GET request to the supplied resource using the supplied params hash
105 106 107 108 |
# File 'lib/filebound_client/connection.rb', line 105 def get(url, params) request = HTTPI::Request.new(resource_url(url, query_params(params[:query]))) execute_request(:get, request, params) end |
#host ⇒ String
The Filebound server hostname and protocol
43 44 45 |
# File 'lib/filebound_client/connection.rb', line 43 def host configuration.host end |
#login ⇒ true, false
Sends a POST request to the Filebound API’s login endpoint to request a new security token
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/filebound_client/connection.rb', line 141 def login response = post('/login', body: { username: configuration.username, password: configuration.password }, headers: { 'Content-Type' => 'application/json' }) if response.code == 200 @token = JSON.parse(response.body, symbolize_names: true, quirks_mode: true) true else false end end |
#ntlm_domain ⇒ String
The NTLM domain to use for NTLM Authentication
91 92 93 |
# File 'lib/filebound_client/connection.rb', line 91 def ntlm_domain configuration.ntlm_auth[:domain] if configuration.ntlm_auth end |
#ntlm_password ⇒ String
The NTLM password to use for NTLM Authentication
83 84 85 |
# File 'lib/filebound_client/connection.rb', line 83 def ntlm_password configuration.ntlm_auth[:password] if configuration.ntlm_auth end |
#ntlm_user ⇒ String
The NTLM username to use for NTLM Authentication
75 76 77 |
# File 'lib/filebound_client/connection.rb', line 75 def ntlm_user configuration.ntlm_auth[:user] if configuration.ntlm_auth end |
#password ⇒ String
The password to log on to the Filebound server with
67 68 69 |
# File 'lib/filebound_client/connection.rb', line 67 def password configuration.password end |
#post(url, params) ⇒ Net::HTTPResponse
Sends a POST request to the supplied resource using the supplied params hash
124 125 126 127 128 |
# File 'lib/filebound_client/connection.rb', line 124 def post(url, params) request = HTTPI::Request.new(resource_url(url, query_params(params[:query]))) request.body = params[:body].to_json execute_request(:post, request, params) end |
#put(url, params) ⇒ Net::HTTPResponse
Sends a PUT request to the supplied resource using the supplied params hash
114 115 116 117 118 |
# File 'lib/filebound_client/connection.rb', line 114 def put(url, params) request = HTTPI::Request.new(resource_url(url, query_params(params[:query]))) request.body = params[:body].to_json execute_request(:put, request, params) end |
#username ⇒ String
The username to log on to the Filebound server with
59 60 61 |
# File 'lib/filebound_client/connection.rb', line 59 def username configuration.username end |