class Couchy::Server
Constants
- DEFAULT_HOST
- DEFAULT_PORT
- DEFAULT_PROTOCOL
- ERRORS
Public Instance Methods
database(name)
click to toggle source
# File lib/couchy/server.rb, line 29 def database(name) Database.new(name, self) end
exec(method, path, data = {})
click to toggle source
# File lib/couchy/server.rb, line 22 def exec(method, path, data = {}) body = request(method, path, data).body_str response = Oj.load(body, symbol_keys: true) raise_response_errors(response) response end
Private Instance Methods
port_segment()
click to toggle source
# File lib/couchy/server.rb, line 59 def port_segment return if port.nil? || port.empty? ":#{port}" end
raise_response_errors(response)
click to toggle source
# File lib/couchy/server.rb, line 45 def raise_response_errors(response) return unless (error = response[:error]) exception = ERRORS.fetch(error.to_sym, ServerError) raise exception, response[:reason] end
request(method, path, data)
click to toggle source
# File lib/couchy/server.rb, line 35 def request(method, path, data) Curl.send(method, "#{url}/#{path}", data) do |curl| if require_request_authentication? curl.http_auth_types = :basic curl.username = username curl.password = password end end end
require_request_authentication?()
click to toggle source
# File lib/couchy/server.rb, line 51 def require_request_authentication? !username.nil? && !username.empty? end
url()
click to toggle source
# File lib/couchy/server.rb, line 55 def url "#{protocol}://#{host}#{port_segment}" end