Class: WebClient::Request
- Inherits:
-
Object
- Object
- WebClient::Request
- Defined in:
- lib/web_client/request.rb
Constant Summary collapse
- TYPES =
[:get, :post, :put, :delete]
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#type ⇒ Object
Returns the value of attribute type.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(options = {}, &block) ⇒ Request
constructor
A new instance of Request.
- #to_http ⇒ Object
Constructor Details
#initialize(options = {}, &block) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 16 17 18 |
# File 'lib/web_client/request.rb', line 11 def initialize(={}, &block) @type = [:type] || :get @url = [:url] @body = [:body] @headers = [:headers] || {} block.call(self) if block_given? end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
8 9 10 |
# File 'lib/web_client/request.rb', line 8 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
9 10 11 |
# File 'lib/web_client/request.rb', line 9 def headers @headers end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/web_client/request.rb', line 6 def type @type end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/web_client/request.rb', line 7 def url @url end |
Instance Method Details
#to_http ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/web_client/request.rb', line 20 def to_http klass = eval("Net::HTTP::#{type.to_s.capitalize}") request = klass.new url request.set_form_data(body) if body.is_a? Hash request.body = body if body.is_a? String headers.each { |k, v| request.send("#{k}=", v) } request end |