Module: Gerry::Api::Request
- Included in:
- Client
- Defined in:
- lib/gerry/api/request.rb
Overview
:nodoc:
Defined Under Namespace
Classes: RequestError
Instance Method Summary collapse
- #auth_url(url) ⇒ Object
- #delete(url) ⇒ Object
- #get(url) ⇒ Object
-
#map_options(options) ⇒ String
Get the mapped options.
- #options(body = nil, is_json = true) ⇒ Object
- #post(url, body, is_json = true) ⇒ Object
- #put(url, body = nil, is_json = true) ⇒ Object
Instance Method Details
#auth_url(url) ⇒ Object
37 38 39 |
# File 'lib/gerry/api/request.rb', line 37 def auth_url(url) self.class.[:basic_auth] ? "/a#{url}" : url end |
#delete(url) ⇒ Object
51 52 53 54 |
# File 'lib/gerry/api/request.rb', line 51 def delete(url) self.class.delete(auth_url(url)) parse(response) end |
#get(url) ⇒ Object
32 33 34 35 |
# File 'lib/gerry/api/request.rb', line 32 def get(url) response = self.class.get(auth_url(url)) parse(response) end |
#map_options(options) ⇒ String
Get the mapped options.
13 14 15 16 17 18 19 |
# File 'lib/gerry/api/request.rb', line 13 def () if .is_a?(Array) .map { |v| "#{v}" }.join('&') elsif .is_a?(Hash) .map { |k,v| "#{k}=#{v.join(',')}" }.join('&') end end |
#options(body = nil, is_json = true) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gerry/api/request.rb', line 21 def (body = nil, is_json = true) return {} unless body = { headers: { 'Content-Type' => is_json ? 'application/json' : 'text/plain' } } [:body] = is_json ? body.to_json : body end |
#post(url, body, is_json = true) ⇒ Object
46 47 48 49 |
# File 'lib/gerry/api/request.rb', line 46 def post(url, body, is_json = true) response = self.class.post(auth_url(url), (body, is_json)) parse(response) end |
#put(url, body = nil, is_json = true) ⇒ Object
41 42 43 44 |
# File 'lib/gerry/api/request.rb', line 41 def put(url, body = nil, is_json = true) response = self.class.put(auth_url(url), (body, is_json)) parse(response) end |