Module: Gerry::Client::Request
- Included in:
- Gerry::Client
- Defined in:
- lib/gerry/client/request.rb
Defined Under Namespace
Classes: RequestError
Instance Method Summary collapse
- #delete(url) ⇒ Object
- #get(url) ⇒ Object
-
#map_options(options) ⇒ String
Get the mapped options.
- #post(url, body) ⇒ Object
- #put(url, body = nil) ⇒ Object
Instance Method Details
#delete(url) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/gerry/client/request.rb', line 62 def delete(url) response = if @username && @password auth = { username: @username, password: @password } self.class.delete("/a#{url}", @auth_type => auth) else self.class.delete(url) end parse(response) end |
#get(url) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/gerry/client/request.rb', line 16 def get(url) response = if @username && @password auth = { username: @username, password: @password } self.class.get("/a#{url}", @auth_type => auth) else self.class.get(url) end parse(response) end |
#map_options(options) ⇒ String
Get the mapped options.
8 9 10 11 12 13 14 |
# File 'lib/gerry/client/request.rb', line 8 def () if .is_a?(Array) .map { |v| "#{v}" }.join('&') elsif .is_a?(Hash) .map { |k,v| "#{k}=#{v.join(',')}" }.join('&') end end |
#post(url, body) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/gerry/client/request.rb', line 44 def post(url, body) if @username && @password auth = { username: @username, password: @password } response = self.class.post("/a#{url}", body: body.to_json, headers: { 'Content-Type' => 'application/json' }, @auth_type => auth ) parse(response) else response = self.class.post(url, body: body.to_json, headers: { 'Content-Type' => 'application/json' } ) parse(response) end end |
#put(url, body = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gerry/client/request.rb', line 26 def put(url, body = nil) if @username && @password auth = { username: @username, password: @password } response = self.class.put("/a#{url}", body: body.to_json, headers: { 'Content-Type' => 'application/json' }, @auth_type => auth ) parse(response) else response = self.class.put(url, body: body.to_json, headers: { 'Content-Type' => 'application/json' } ) parse(response) end end |