Skip to content
This repository has been archived by the owner on Apr 25, 2019. It is now read-only.

jgarber623/micropub-endpoint-ruby

Repository files navigation

micropub-endpoint-ruby

⚠️ Deprecation Notice (2019-04-24) ⚠️ This gem is deprecated in favor of indieweb/indieweb-endpoints-ruby and will no longer receive updates.


A Ruby gem for discovering a URL's Micropub endpoint.

Gem Downloads Build Dependencies Maintainability Coverage

Key Features

Getting Started

Before installing and using micropub-endpoint-ruby, you'll want to have Ruby 2.4 (or newer) installed. It's recommended that you use a Ruby version managment tool like rbenv, chruby, or rvm.

micropub-endpoint-ruby is developed using Ruby 2.4.6 and is additionally tested against Ruby 2.5.5 and 2.6.2 using Travis CI.

Installation

If you're using Bundler, add micropub-endpoint-ruby to your project's Gemfile:

source 'https://rubygems.org'

gem 'micropub-endpoint'

…and hop over to your command prompt and run…

$ bundle install

Usage

Basic Usage

With micropub-endpoint-ruby added to your project's Gemfile and installed, you may discover a URL's Micropub endpoint by doing:

require 'micropub/endpoint'

endpoint = Micropub::Endpoint.discover('https://adactio.com')

puts endpoint # returns String: 'https://adactio.com/micropub'

This example will search https://adactio.com for a valid Micropub endpoint in accordance with the rules described in the W3C's Micropub Recommendation. In this case, the program returns a string: https://adactio.com/micropub.

If no endpoint is discovered at the provided URL, the program will return nil:

require 'micropub/endpoint'

endpoint = Micropub::Endpoint.discover('https://example.com')

puts endpoint.nil? # returns Boolean: true

Advanced Usage

Should the need arise, you may work directly with the Micropub::Endpoint::Client class:

require 'micropub/endpoint'

client = Micropub::Endpoint::Client.new('https://adactio.com')

puts client.response # returns HTTP::Response
puts client.endpoint # returns String: 'https://adactio.com/micropub'

Exception Handling

There are several exceptions that may be raised by micropub-endpoint-ruby's underlying dependencies. These errors are raised as subclasses of Micropub::Endpoint::Error (which itself is a subclass of StandardError).

From jgarber623/absolutely and sporkmonger/addressable:

  • Micropub::Endpoint::InvalidURIError

From httprb/http:

  • Micropub::Endpoint::ConnectionError
  • Micropub::Endpoint::TimeoutError
  • Micropub::Endpoint::TooManyRedirectsError

Contributing

Interested in helping improve micropub-endpoint-ruby? Awesome! Your help is greatly appreciated. See CONTRIBUTING.md for details.

Acknowledgments

micropub-endpoint-ruby wouldn't exist without Micropub and the hard work put in by everyone involved in the IndieWeb movement.

micropub-endpoint-ruby is written and maintained by Jason Garber.

License

micropub-endpoint-ruby is freely available under the MIT License. Use it, learn from it, fork it, improve it, change it, tailor it to your needs.