Class: Brewerydb::HTTP
- Inherits:
-
Object
- Object
- Brewerydb::HTTP
- Defined in:
- lib/brewerydb/http.rb
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path, params) ⇒ Object
-
#initialize ⇒ HTTP
constructor
A new instance of HTTP.
- #post(path, params) ⇒ Object
- #put(path, params) ⇒ Object
Constructor Details
#initialize ⇒ HTTP
Returns a new instance of HTTP.
22 23 24 25 |
# File 'lib/brewerydb/http.rb', line 22 def initialize @host = 'api.brewerydb.com' @api_version = 'v2' end |
Instance Method Details
#delete(path) ⇒ Object
47 48 49 |
# File 'lib/brewerydb/http.rb', line 47 def delete(path) res = Net::HTTP.new(@host).delete(path) parse_response(res) end |
#get(path, params) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/brewerydb/http.rb', line 27 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
34 35 36 37 38 |
# File 'lib/brewerydb/http.rb', line 34 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
40 41 42 43 44 45 |
# File 'lib/brewerydb/http.rb', line 40 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 |