Class: Webmention::Request
- Inherits:
-
Object
- Object
- Webmention::Request
- Defined in:
- lib/webmention/request.rb
Instance Attribute Summary collapse
- #method ⇒ Symbol readonly
- #options ⇒ Hash readonly
- #uri ⇒ HTTP::URI readonly
Class Method Summary collapse
-
.get(url) ⇒ Response, ErrorResponse
Send an HTTP GET request to the supplied URL.
-
.post(url, **options) ⇒ Response, ErrorResponse
Send an HTTP POST request with form-encoded data to the supplied URL.
Instance Method Summary collapse
-
#initialize(method, url, **options) ⇒ Request
constructor
Create a new Request.
-
#inspect ⇒ String
:nocov:.
-
#perform ⇒ Response, ErrorResponse
Submit the Request.
Constructor Details
#initialize(method, url, **options) ⇒ Request
Create a new Webmention::Request.
76 77 78 79 80 |
# File 'lib/webmention/request.rb', line 76 def initialize(method, url, **) @method = method.to_sym @uri = HTTP::URI.parse(url.to_s) = end |
Instance Attribute Details
#method ⇒ Symbol (readonly)
26 27 28 |
# File 'lib/webmention/request.rb', line 26 def method @method end |
#options ⇒ Hash (readonly)
32 33 34 |
# File 'lib/webmention/request.rb', line 32 def end |
#uri ⇒ HTTP::URI (readonly)
29 30 31 |
# File 'lib/webmention/request.rb', line 29 def uri @uri end |
Class Method Details
.get(url) ⇒ Response, ErrorResponse
Send an HTTP GET request to the supplied URL.
42 43 44 |
# File 'lib/webmention/request.rb', line 42 def self.get(url) new(:get, url).perform end |
.post(url, **options) ⇒ Response, ErrorResponse
Send an HTTP POST request with form-encoded data to the supplied URL.
67 68 69 |
# File 'lib/webmention/request.rb', line 67 def self.post(url, **) new(:post, url, form: .slice(:source, :target, :vouch)).perform end |
Instance Method Details
#inspect ⇒ String
:nocov:
84 85 86 87 88 |
# File 'lib/webmention/request.rb', line 84 def inspect "#<#{self.class}:#{format("%#0x", object_id)} " \ "method: #{method.upcase}, " \ "url: #{uri}>" end |
#perform ⇒ Response, ErrorResponse
Submit the Webmention::Request.
94 95 96 97 98 |
# File 'lib/webmention/request.rb', line 94 def perform Response.new(client.request(method, uri, ), self) rescue HTTP::Error, OpenSSL::SSL::SSLError => e ErrorResponse.new(e., self) end |