Project

hyper_api

0.02
No commit activity in last 3 years
No release in over 3 years
Hypertext API. A sweet DSL to create objects off HTML.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 3.0.0.beta1

Runtime

~> 1.6.0
 Project Readme

HyperAPI

Hypertext API. A sweet DSL to create objects off HTML.

Installation

Add the hyper_api gem to your app. For example, using Bundler:

$ echo "gem 'hyper_api'" >> Gemfile
$ bundle install

Usage

The HyperAPI gem uses Nokogiri to parse HTML with CSS or XPath selectors.

Create objects on-the-go:

Torrent = HyperAPI.new_class do
  string title: 'div#title'
  string description: 'div.info'
  string hash: '#details dd'
  integer imdb_id: "//[@id='details']/a[@title='IMDB']" do
    attribute('href').value
  end
end
# => Torrent

fringe = Torrent.new(html_string)
# => #<TPB::Torrent title: 'Fringe Season 1', description: 'The complete season 1 of Fri...', imdb_id: 1119644>

torrent = HyperAPI.new_class do
  string title: 'div#title'
  string description: 'div.info'
  string hash: '#details dd'
  integer imdb_id: '#details a[title=IMDB]' do
    attribute('href').value
  end
end
# => #<Class:0x007fda34829c48> // (anonymous class)

fringe = torrent.new(html_string)
# => #<Class:0x007fda34829c48 title: 'Fringe Season 1', description: 'The complete season 1 of Fri...', imdb_id: 1119644>

Or create a new class:

class Torrent < HyperApi::Base
  string title: 'div#title'
  string description: 'div.info'
  string hash: '#details dd'
  integer imdb_id: '#details a[title=IMDB]' do
    attribute('href').value
  end

  def some_calculated_method
    "#{title}: #{hash}"
  end
end

fringe = Torrent.new(html_string)
# => #<TPB::Torrent title: 'Fringe Season 1', description: 'The complete season 1 of Fri...', imdb_id: 1119644>

fringe.some_calculated_method
# => "Fringe Season 1: B4C04A34DD8824C28E9A8A528"

Contributing

If you've found a bug or have a question, please open an issue on the issue tracker. Or, clone the HyperAPI repository, write a failing test case, fix the bug, and submit a pull request.

Version History

0.1.1 (Feb 17, 2014)

  • Allow empty values for attributes when not found in HTML source.

0.1.0 (Feb 16, 2014)

  • Initial public release.

License

Copyright © 2014 Javier Saldana

Released under the MIT license. See LICENSE for details.