Class: Quber::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/quber/http.rb

Defined Under Namespace

Classes: Response

Constant Summary collapse

VERBS =
{
  get:    Net::HTTP::Get,
  post:   Net::HTTP::Post,
  put:    Net::HTTP::Put,
  delete: Net::HTTP::Delete
}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HTTP

Returns a new instance of HTTP.



17
18
19
20
21
22
23
# File 'lib/quber/http.rb', line 17

def initialize options = {}
  @defaults = {
    connection: Net::HTTP::Persistent.new,
    api_uri:    ENV['QUBER_API_URI']   || 'http://localhost:5672/api/v1/',
    api_token:  ENV['QUBER_API_TOKEN'] || '1234567890'
  }.merge!(options)
end

Instance Method Details

#base_headersObject



25
26
27
28
29
30
31
# File 'lib/quber/http.rb', line 25

def base_headers
  {
    'X-Auth-Token' => @defaults[:api_token],
    'User-Agent'   => "Quber/#{Quber::VERSION}",
    'Content-Type' => 'application/json'
  }
end

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



45
46
47
# File 'lib/quber/http.rb', line 45

def delete(path, options = {})
  execute(path, :delete, options)
end

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



33
34
35
# File 'lib/quber/http.rb', line 33

def get(path, options = {})
  execute(path, :get, options)
end

#post(path, options = {}) ⇒ Object



37
38
39
# File 'lib/quber/http.rb', line 37

def post(path, options = {})
  execute(path, :post, options)
end

#put(path, options = {}) ⇒ Object



41
42
43
# File 'lib/quber/http.rb', line 41

def put(path, options = {})
  execute(path, :put, options)
end