Class: CQ::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cq/client.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  :auth_type          => :basic
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
21
22
23
24
25
26
# 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

Instance Attribute Details

#optionsObject (readonly)

The configuration options for this client instance



9
10
11
# File 'lib/cq/client.rb', line 9

def options
  @options
end

Instance Method Details

#delete(path, headers = {}) ⇒ Object

HTTP methods without a body



29
30
31
# File 'lib/cq/client.rb', line 29

def delete(path, headers = {})
  request(:delete, path, nil, merge_default_headers(headers))
end

#get(path, headers = {}) ⇒ Object



33
34
35
# File 'lib/cq/client.rb', line 33

def get(path, headers = {})
  request(:get, path, nil, merge_default_headers(headers))
end

#head(path, headers = {}) ⇒ Object



37
38
39
# File 'lib/cq/client.rb', line 37

def head(path, headers = {})
  request(:head, path, nil, merge_default_headers(headers))
end

#post(path, body = '', headers = {}) ⇒ Object

HTTP methods with a body



42
43
44
45
# 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 = {}) ⇒ Object



47
48
49
50
# 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 = {}) ⇒ Object

Sends the specified HTTP request to the REST API through the appropriate method (oauth, basic).



54
55
56
# File 'lib/cq/client.rb', line 54

def request(http_method, path, body = '', headers={})
  @request_client.request(http_method, path, body, headers)
end