Class: MineShaft::Shaft

Inherits:
Object
  • Object
show all
Defined in:
lib/mine_shaft/shaft.rb

Overview

Provides simple interface for deserializing an id’d HTML table from a specific page of a Redmine project site.

Constant Summary collapse

LOGIN_PAGE_URL =

The relative URL for the login page on a Redmine site

"/login"

Instance Method Summary collapse

Constructor Details

#initialize(username, password, base_uri) ⇒ Shaft

Public: Initializes new instance of Shaft class.

username - The username to log in with on the specified Redmine site. password - The password to log in with on the specified Redmine site. base_uri - The URL of the Redmine installation.

Examples

shaft = Shaft.new('uname', 'password', 'http://myredmineinstall.com')

Returns a new instance of the Shaft class.



19
20
21
22
# File 'lib/mine_shaft/shaft.rb', line 19

def initialize(username, password, base_uri)
  @agent    = UserAgent.new(username, password, base_uri)
  @login_action = @login_page = LOGIN_PAGE_URL
end

Instance Method Details

#grab(table_id, relative_wiki_page_url) ⇒ Object

Public: Logs in and parses the specified page for a <table> with the

specified ID.

table_id - The HTML id of the desired table as a String. relative_wiki_page_url - The relative URL of the page within the Redmine

site.

Examples

shaft.grab('names', '/projects/name-parser/Wiki/Name_Data')

Returns an Array of Hash objects. Each Hash element is a

key-value mapping of "table header"-"row content". (Note that the
the key is a downcased-symbol of the heading value).

Raises FailedLogin if the login failed Raises InvalidPage if the login page of the site renders a 404

OR if a table with the supplied ID is not found on the
specified page.


42
43
44
45
46
47
# File 'lib/mine_shaft/shaft.rb', line 42

def grab(table_id, relative_wiki_page_url)
  @agent.
  wiki_page = WebPage.new(@agent.get(relative_wiki_page_url))
  requested_table = wiki_page.find_table(table_id)
  requested_table.deserialize
end