Method: Unchained::Request#get
- Defined in:
- lib/unchained/request.rb
#get(url, params = {}) ⇒ Object
Use RestClient to actually make the request to the API. If the response is a 200 (success), we will parse the response as JSON and return it. If the response is a known error (i.e. a 404), we will raise a custom Unchained error (found in error.rb). If the response is an unkonwn error, we will return it exactly as we found it.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/unchained/request.rb', line 11 def get(url, params={}) RestClient.get(url, build_params(params)) do |resp, req, res, &block| case resp.code when 200 JSON.parse(resp) when 404 raise Unchained::NotFound.new(res.) else resp.return!(req, res, &block) end end end |