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

  • :http_read_timeout (Float)

    Read timeout in seconds

  • :http_write_timeout (Float)

    Write timeout in seconds

  • :http_connection_timeout (Float)

    Connection timeout in seconds



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/puree/rest/base.rb', line 19

def initialize(config)
  config = http_defaults.merge 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]))
  @http_client = @http_client.timeout read: config[:http_read_timeout],
                                      write: config[:http_write_timeout],
                                      connect: config[:http_connection_timeout]
  @url = config[:url]
end

Instance Method Details

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

Parameters:

  • params (Hash) (defaults to: {})

    GET parameters for all records

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

Returns:

  • (HTTP::Response)


46
47
48
49
# File 'lib/puree/rest/base.rb', line 46

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

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

Parameters:

  • params (Hash) (defaults to: {})

    Combined GET and POST parameters for all records

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

Returns:

  • (HTTP::Response)


38
39
40
41
# File 'lib/puree/rest/base.rb', line 38

def all_complex(params: {}, accept: :xml)
  post_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)


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

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)


63
64
65
66
# File 'lib/puree/rest/base.rb', line 63

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)


70
71
72
73
# File 'lib/puree/rest/base.rb', line 70

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