Class: Webmention::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/webmention/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url, **options) ⇒ Request

Create a new Webmention::Request.

Parameters:

  • method (Symbol)
  • url (String)
  • options (Hash{Symbol => String})


76
77
78
79
80
# File 'lib/webmention/request.rb', line 76

def initialize(method, url, **options)
  @method = method.to_sym
  @uri = HTTP::URI.parse(url.to_s)
  @options = options
end

Instance Attribute Details

#methodSymbol (readonly)

Returns:

  • (Symbol)


26
27
28
# File 'lib/webmention/request.rb', line 26

def method
  @method
end

#optionsHash (readonly)

Returns:

  • (Hash)


32
33
34
# File 'lib/webmention/request.rb', line 32

def options
  @options
end

#uriHTTP::URI (readonly)

Returns:

  • (HTTP::URI)


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.

Examples:

Webmention::Request.get("https://jgarber.example/posts/100")

Parameters:

  • url (String)

Returns:



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.

Examples:

Webmention::Request.post(
  "https://aaronpk.example/webmention",
  source: "https://jgarber.examples/posts/100",
  target: "https://aaronpk.example/notes/1",
  vouch: "https://tantek.example/notes/1"
)

Parameters:

  • url (String)
  • options (Hash{Symbol => String})

Options Hash (**options):

  • :source (String)

    An absolute URL representing a source document.

  • :target (String)

    An absolute URL representing a target document.

  • :vouch (String)

    An absolute URL representing a document vouching for the source document. See indieweb.org/Vouch for additional details.

Returns:



67
68
69
# File 'lib/webmention/request.rb', line 67

def self.post(url, **options)
  new(:post, url, form: options.slice(:source, :target, :vouch)).perform
end

Instance Method Details

#inspectString

:nocov:

Returns:

  • (String)


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

#performResponse, ErrorResponse

Submit the Webmention::Request.

Returns:



94
95
96
97
98
# File 'lib/webmention/request.rb', line 94

def perform
  Response.new(client.request(method, uri, options), self)
rescue HTTP::Error, OpenSSL::SSL::SSLError => e
  ErrorResponse.new(e.message, self)
end