Class: Puree::REST::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/puree/rest/base.rb

Overview

Requests for a resource

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.

Parameters:

  • config (Hash)

Options Hash (config):

  • :url (String)

    URL of the Pure host

  • :username (String)

    Username of the Pure host account

  • :password (String)

    Password of the Pure host account

  • :api_key (String)

    API key of the Pure host account



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/puree/rest/base.rb', line 16

def initialize(config)
  @http_client = HTTP::Client.new
  if config[:username] || config[:password]
    options = {}
    options[:user] = config[:username]
    options[:pass] = config[:password]
    @http_client = @http_client.basic_auth options
  end
  @http_client = @http_client.headers(api_key_header(config[:api_key]))
  @url = config[:url]
end

Instance Method Details

#all(params: {}, accept: :xml) ⇒ HTTP::Response

Parameters:

  • params (Hash) (defaults to: {})
  • accept (Symbol) (defaults to: :xml)

Returns:

  • (HTTP::Response)


31
32
33
34
# File 'lib/puree/rest/base.rb', line 31

def all(params: {}, accept: :xml)
  get_request_collection params: params,
                         accept: accept
end

#find(id:, params: {}, accept: :xml) ⇒ HTTP::Response

Parameters:

  • id (String)
  • params (Hash) (defaults to: {})
  • accept (Symbol) (defaults to: :xml)

Returns:

  • (HTTP::Response)


40
41
42
43
44
# File 'lib/puree/rest/base.rb', line 40

def find(id:, params: {}, accept: :xml)
  get_request_singleton id: id,
                    params: params,
                    accept: accept
end

#orderings(accept: :xml) ⇒ HTTP::Response

Parameters:

  • accept (Symbol) (defaults to: :xml)

Returns:

  • (HTTP::Response)


48
49
50
51
# File 'lib/puree/rest/base.rb', line 48

def orderings(accept: :xml)
  get_request_meta meta_type: 'orderings',
               accept: accept
end

#renderings(accept: :xml) ⇒ HTTP::Response

Parameters:

  • accept (Symbol) (defaults to: :xml)

Returns:

  • (HTTP::Response)


55
56
57
58
# File 'lib/puree/rest/base.rb', line 55

def renderings(accept: :xml)
  get_request_meta meta_type: 'renderings',
               accept: accept
end