Class: Sinew::Request
Constant Summary collapse
- HTML_ENTITIES =
HTMLEntities.new
- VALID_METHODS =
%w[get post patch put delete head options].freeze
- METHODS_WITH_BODY =
%w[patch post put].freeze
Instance Attribute Summary collapse
-
#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
Supported options: body: Body of http post headers: Hash of HTTP headers (combined with runtime_options.headers) query: Hash of query parameters to add to url.
-
#perform(connection) ⇒ Object
run the request, return the result.
- #proxy ⇒ Object
Constructor Details
#initialize(sinew, method, url, options = {}) ⇒ Request
Supported options:
body: Body of http post
headers: Hash of HTTP headers (combined with .headers)
query: Hash of query parameters to add to url
22 23 24 25 26 27 |
# File 'lib/sinew/request.rb', line 22 def initialize(sinew, method, url, = {}) @sinew = sinew @method = method = .dup @uri = parse_url(url) end |
Instance Attribute Details
#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 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(connection) ⇒ Object
run the request, return the result
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sinew/request.rb', line 38 def perform(connection) validate! headers = sinew..headers headers = headers.merge([:headers]) if [:headers] body = .delete(:body) fday_response = connection.send(method, uri, body, headers) do _1.[:proxy] = proxy end Response.from_network(self, fday_response) end |
#proxy ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/sinew/request.rb', line 29 def proxy @proxy ||= begin if proxies = sinew.[:proxy] proxies.split(',').sample end end end |