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.
- #proxy ⇒ Object
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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sinew/request.rb', line 36 def perform validate! = .dup # merge proxy if proxy = self.proxy addr, port = proxy.split(':') [:http_proxyaddr] = addr [:http_proxyport] = port || 80 end # now merge runtime_options = .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 |
#proxy ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/sinew/request.rb', line 27 def proxy @proxy ||= begin if proxies = sinew.[:proxy] proxies.split(',').sample end end end |