Class: Pillow::Request
- Inherits:
-
Object
- Object
- Pillow::Request
- Defined in:
- lib/pillow/request.rb
Constant Summary collapse
- HTTP_METHODS =
[:options, :get, :head, :post, :put, :delete, :trace, :patch]
- HTTP_METHODS_WITH_BODY =
[:post, :put, :patch]
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#method ⇒ Object
Returns the value of attribute method.
-
#query_values ⇒ Object
readonly
Returns the value of attribute query_values.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #body ⇒ Object
- #body=(body) ⇒ Object
- #full_url ⇒ Object
-
#initialize(method, url) ⇒ Request
constructor
A new instance of Request.
- #raw_body ⇒ Object
- #raw_body=(raw_body) ⇒ Object
Constructor Details
#initialize(method, url) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 17 |
# File 'lib/pillow/request.rb', line 12 def initialize(method, url) self.method = method @url = url @query_values = {} @headers = {} end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
10 11 12 |
# File 'lib/pillow/request.rb', line 10 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
10 11 12 |
# File 'lib/pillow/request.rb', line 10 def method @method end |
#query_values ⇒ Object (readonly)
Returns the value of attribute query_values.
10 11 12 |
# File 'lib/pillow/request.rb', line 10 def query_values @query_values end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/pillow/request.rb', line 10 def url @url end |
Instance Method Details
#body ⇒ Object
27 28 29 30 31 |
# File 'lib/pillow/request.rb', line 27 def body if HTTP_METHODS_WITH_BODY.include?(method) @body || '' end end |
#body=(body) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pillow/request.rb', line 33 def body=(body) if HTTP_METHODS_WITH_BODY.include?(method) @body = body if headers['Content-Type'] == 'application/json' @raw_body = body.to_json else @raw_body = body end end end |
#full_url ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/pillow/request.rb', line 58 def full_url if query_values.empty? return url end full_url = Addressable::URI.parse(url) full_url.query_values = query_values full_url.to_s end |
#raw_body ⇒ Object
45 46 47 48 49 |
# File 'lib/pillow/request.rb', line 45 def raw_body if HTTP_METHODS_WITH_BODY.include?(method) @raw_body || '' end end |
#raw_body=(raw_body) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/pillow/request.rb', line 51 def raw_body=(raw_body) if HTTP_METHODS_WITH_BODY.include?(method) @raw_body = raw_body @body = raw_body end end |