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) ⇒ Webmention::Response, Webmention::ErrorResponse
Send an HTTP GET request to the supplied URL.
-
.post(url, **options) ⇒ Webmention::Response, Webmention::ErrorResponse
Send an HTTP POST request with form-encoded data to the supplied URL.
Instance Method Summary collapse
-
#initialize(method, url, **options) ⇒ Webmention::Request
constructor
Create a new Webmention::Request.
-
#inspect ⇒ String
:nocov:.
-
#perform ⇒ Webmention::Response, Webmention::ErrorResponse
Submit the Webmention::Request.
Constructor Details
#initialize(method, url, **options) ⇒ Webmention::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) @options = end |
Instance Attribute Details
#method ⇒ Symbol (readonly)
24 25 26 |
# File 'lib/webmention/request.rb', line 24 def method @method end |
#options ⇒ Hash (readonly)
30 31 32 |
# File 'lib/webmention/request.rb', line 30 def @options end |
#uri ⇒ HTTP::URI (readonly)
27 28 29 |
# File 'lib/webmention/request.rb', line 27 def uri @uri end |
Class Method Details
.get(url) ⇒ Webmention::Response, Webmention::ErrorResponse
Send an HTTP GET request to the supplied URL.
40 41 42 |
# File 'lib/webmention/request.rb', line 40 def self.get(url) new(:get, url).perform end |
.post(url, **options) ⇒ Webmention::Response, Webmention::ErrorResponse
Send an HTTP POST request with form-encoded data to the supplied URL.
65 66 67 |
# File 'lib/webmention/request.rb', line 65 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 ⇒ Webmention::Response, Webmention::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 |