Class: Motion::HTTP::Client
- Inherits:
-
Object
- Object
- Motion::HTTP::Client
- Defined in:
- lib/common/http/client.rb
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
Instance Method Summary collapse
- #add_header(key, value) ⇒ Object
-
#get(path, params = nil, &callback) ⇒ Object
FIXME: doesn’t work on Android [:get, :post, :put, :patch, :delete].each do |method| define_method “#method”, do |path, params = nil, &callback| Request.new(method, base_url + path, headers, params, &callback).call end end.
- #header(key, value) ⇒ Object
-
#initialize(base_url = nil) ⇒ Client
constructor
A new instance of Client.
- #post(path, params = nil, &callback) ⇒ Object
Constructor Details
#initialize(base_url = nil) ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/common/http/client.rb', line 6 def initialize(base_url = nil) @base_url = base_url || "" @headers = Headers.new end |
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 |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
4 5 6 |
# File 'lib/common/http/client.rb', line 4 def headers @headers 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 |
#get(path, params = nil, &callback) ⇒ Object
FIXME: doesn’t work on Android [:get, :post, :put, :patch, :delete].each do |method|
define_method "#{method}", do |path, params = nil, &callback|
Request.new(method, base_url + path, headers, params, &callback).call
end
end
26 27 28 |
# File 'lib/common/http/client.rb', line 26 def get(path, params = nil, &callback) Request.new(:get, base_url + path, headers, params, &callback).call 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 |
#post(path, params = nil, &callback) ⇒ Object
30 31 32 |
# File 'lib/common/http/client.rb', line 30 def post(path, params = nil, &callback) Request.new(:post, base_url + path, headers, params, &callback).call end |