Class: Brewerydb::HTTP

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

Instance Method Summary collapse

Constructor Details

#initializeHTTP

Returns a new instance of HTTP.



7
8
9
10
# File 'lib/brewerydb/http.rb', line 7

def initialize
  @host = 'api.brewerydb.com'
  @api_version = 'v2'
end

Instance Method Details

#delete(path) ⇒ Object



32
33
34
# File 'lib/brewerydb/http.rb', line 32

def delete(path)
res = Net::HTTP.new(@host).delete(path)
parse_response(res)    end

#get(path, params) ⇒ Object



12
13
14
15
16
17
# File 'lib/brewerydb/http.rb', line 12

def get(path, params)
  uri = base_uri(path)
  uri.query = URI.encode_www_form(params_with_key(params))
  res = Net::HTTP.get_response(uri)
  parse_response(res)
end

#post(path, params) ⇒ Object



19
20
21
22
23
# File 'lib/brewerydb/http.rb', line 19

def post(path, params)
  uri = base_uri(path)
  res = Net::HTTP.post_form(uri, params_with_key(params))
  parse_response(res)
end

#put(path, params) ⇒ Object



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

def put(path, params)
  request = Net::HTTP::Put.new(path)
  req.body = params_with_key(params)
  res = Net::HTTP.new(@host).start { |http| http.request(req)}
  parse_response(res)
end