Class: Sinew::Request
Constant Summary collapse
- HTML_ENTITIES =
HTMLEntities.new
- VALID_METHODS =
%w[get post patch put delete head options].freeze
Instance Attribute Summary collapse
-
#cache_key ⇒ Object
readonly
Returns the value of attribute cache_key.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#sinew ⇒ Object
readonly
Returns the value of attribute sinew.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(sinew, method, url, options = {}) ⇒ Request
constructor
Options are largely compatible with HTTParty, except for :method.
-
#perform ⇒ Object
run the request, return the result.
Constructor Details
#initialize(sinew, method, url, options = {}) ⇒ Request
Options are largely compatible with HTTParty, except for :method.
19 20 21 22 23 24 25 |
# File 'lib/sinew/request.rb', line 19 def initialize(sinew, method, url, = {}) @sinew = sinew @method = method @options = .dup @uri = parse_url(url) @cache_key = calculate_cache_key end |
Instance Attribute Details
#cache_key ⇒ Object (readonly)
Returns the value of attribute cache_key.
16 17 18 |
# File 'lib/sinew/request.rb', line 16 def cache_key @cache_key end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
16 17 18 |
# File 'lib/sinew/request.rb', line 16 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/sinew/request.rb', line 16 def @options end |
#sinew ⇒ Object (readonly)
Returns the value of attribute sinew.
16 17 18 |
# File 'lib/sinew/request.rb', line 16 def sinew @sinew end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
16 17 18 |
# File 'lib/sinew/request.rb', line 16 def uri @uri end |
Instance Method Details
#perform ⇒ Object
run the request, return the result
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sinew/request.rb', line 28 def perform validate! # merge optons = self..merge(sinew..) # merge headers headers = sinew..headers headers = headers.merge([:headers]) if [:headers] [:headers] = headers party_response = HTTParty.send(method, uri, ) Response.from_network(self, party_response) end |