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) ⇒ Webmention::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)


24
25
26
# File 'lib/webmention/request.rb', line 24

def method
  @method
end

#optionsHash (readonly)

Returns:

  • (Hash)


30
31
32
# File 'lib/webmention/request.rb', line 30

def options
  @options
end

#uriHTTP::URI (readonly)

Returns:

  • (HTTP::URI)


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.

Examples:

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

Parameters:

  • url (String)

Returns:



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.

Examples:

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:



65
66
67
# File 'lib/webmention/request.rb', line 65

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

#performWebmention::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, options), self)
rescue HTTP::Error, OpenSSL::SSL::SSLError => e
  ErrorResponse.new(e.message, self)
end