class CQ::Client
Constants
- DEFAULT_OPTIONS
Attributes
options[R]
The configuration options for this client instance
Public Class Methods
new(options={})
click to toggle source
# File lib/cq/client.rb, line 15 def initialize(options={}) options = DEFAULT_OPTIONS.merge(options) options[:site] ||= 'http://localhost:4502' @options = options case options[:auth_type] when :basic @request_client = HttpClient.new(@options) end @options.freeze end
Public Instance Methods
delete(path, headers = {})
click to toggle source
HTTP methods without a body
# File lib/cq/client.rb, line 29 def delete(path, headers = {}) request(:delete, path, nil, merge_default_headers(headers)) end
get(path, headers = {})
click to toggle source
# File lib/cq/client.rb, line 33 def get(path, headers = {}) request(:get, path, nil, merge_default_headers(headers)) end
head(path, headers = {})
click to toggle source
# File lib/cq/client.rb, line 37 def head(path, headers = {}) request(:head, path, nil, merge_default_headers(headers)) end
post(path, body = '', headers = {})
click to toggle source
HTTP methods with a body
# File lib/cq/client.rb, line 42 def post(path, body = '', headers = {}) headers = {'Content-Type' => 'application/json'}.merge(headers) request(:post, path, body, merge_default_headers(headers)) end
put(path, body = '', headers = {})
click to toggle source
# File lib/cq/client.rb, line 47 def put(path, body = '', headers = {}) headers = {'Content-Type' => 'application/json'}.merge(headers) request(:put, path, body, merge_default_headers(headers)) end
request(http_method, path, body = '', headers={})
click to toggle source
Sends the specified HTTP request to the REST API through the appropriate method (oauth, basic).
# File lib/cq/client.rb, line 54 def request(http_method, path, body = '', headers={}) @request_client.request(http_method, path, body, headers) end
Protected Instance Methods
merge_default_headers(headers)
click to toggle source
# File lib/cq/client.rb, line 60 def merge_default_headers(headers) {'Accept' => 'application/json'}.merge(headers) end