Class: Motion::HTTP::Client
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #add_header(key, value) ⇒ Object
- #delete(path, params = nil, options = nil, &callback) ⇒ Object
-
#get(path, params = nil, options = nil, &callback) ⇒ Object
FIXME: doesn't work on Android for some reason [:get, :post, :put, :patch, :delete].each do |method| define_method "#method", do |path, params = nil, options = nil, &callback| Request.new(method, base_url + path, headers, params, options).perform(&callback) end end.
- #header(key, value) ⇒ Object
- #headers(hash = nil) ⇒ Object
-
#initialize(base_url = nil) ⇒ Client
constructor
A new instance of Client.
- #patch(path, params = nil, options = nil, &callback) ⇒ Object
- #post(path, params = nil, options = nil, &callback) ⇒ Object
- #put(path, params = nil, options = nil, &callback) ⇒ Object
Constructor Details
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
4 5 6 |
# File 'lib/common/http/client.rb', line 4 def base_url @base_url end |
Instance Method Details
#add_header(key, value) ⇒ Object
15 16 17 |
# File 'lib/common/http/client.rb', line 15 def add_header(key, value) @headers.add(key, value) end |
#delete(path, params = nil, options = nil, &callback) ⇒ Object
51 52 53 |
# File 'lib/common/http/client.rb', line 51 def delete(path, params = nil, = nil, &callback) Request.new(:delete, base_url + path, headers, params, ).perform(&callback) end |
#get(path, params = nil, options = nil, &callback) ⇒ Object
FIXME: doesn't work on Android for some reason [:get, :post, :put, :patch, :delete].each do |method| define_method "#method", do |path, params = nil, options = nil, &callback| Request.new(method, base_url + path, headers, params, options).perform(&callback) end end
35 36 37 |
# File 'lib/common/http/client.rb', line 35 def get(path, params = nil, = nil, &callback) Request.new(:get, base_url + path, headers, params, ).perform(&callback) end |
#header(key, value) ⇒ Object
11 12 13 |
# File 'lib/common/http/client.rb', line 11 def header(key, value) @headers.set(key, value) end |
#headers(hash = nil) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/common/http/client.rb', line 19 def headers(hash = nil) if hash hash.each do |key, value| @headers.set(key, value) end end @headers end |
#patch(path, params = nil, options = nil, &callback) ⇒ Object
47 48 49 |
# File 'lib/common/http/client.rb', line 47 def patch(path, params = nil, = nil, &callback) Request.new(:patch, base_url + path, headers, params, ).perform(&callback) end |