Class: Smesser::Provider
- Inherits:
-
Object
- Object
- Smesser::Provider
- Defined in:
- lib/smesser/provider.rb
Class Attribute Summary collapse
-
.description ⇒ Object
Returns the value of attribute description.
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #agent ⇒ Object
- #click(spec) ⇒ Object
- #get(address) ⇒ Object
-
#initialize(username, password) ⇒ Provider
constructor
A new instance of Provider.
- #log ⇒ Object
- #logged_in? ⇒ Boolean
- #login ⇒ Object
- #page ⇒ Object
- #post_form(spec) {|form| ... } ⇒ Object
- #send(message, *recipients) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Provider
Returns a new instance of Provider.
25 26 27 28 |
# File 'lib/smesser/provider.rb', line 25 def initialize(username, password) @username = username @password = password end |
Class Attribute Details
.description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/smesser/provider.rb', line 7 def description @description end |
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
10 11 12 |
# File 'lib/smesser/provider.rb', line 10 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
10 11 12 |
# File 'lib/smesser/provider.rb', line 10 def username @username end |
Class Method Details
.load_all ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/smesser/provider.rb', line 16 def self.load_all Smesser.log.debug("Loading all provider files in #{paths.inspect}") paths.each do |path| Dir["#{path}/*.rb"].each do |f| require f end end end |
.paths ⇒ Object
12 13 14 |
# File 'lib/smesser/provider.rb', line 12 def self.paths @paths ||= [File.(File.join(File.dirname(__FILE__), '..', '..', 'providers'))] end |
Instance Method Details
#agent ⇒ Object
68 69 70 |
# File 'lib/smesser/provider.rb', line 68 def agent @agent ||= Mechanize.new end |
#click(spec) ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/smesser/provider.rb', line 49 def click(spec) spec = { :text => spec } if spec.is_a? String log.debug("Looking for a form with #{spec.inspect}") link = page.link_with(spec) raise "Link not found: #{spec.inspect} on #{page.uri} (links: #{page.links.map(&:text).inspect})" unless link log.debug("Clicking link #{link.text} => #{link.href}") link.click log.debug("Clicked link #{link.href} (#{page.code})") page.code end |
#get(address) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/smesser/provider.rb', line 30 def get(address) log.debug("Getting #{address}") agent.get(address) unless agent.page and agent.page.uri == URI.parse(address) log.debug("Got #{address} (#{page.code})") page.code end |
#logged_in? ⇒ Boolean
80 81 82 |
# File 'lib/smesser/provider.rb', line 80 def logged_in? false end |
#login ⇒ Object
60 61 62 |
# File 'lib/smesser/provider.rb', line 60 def login raise "You need to override #{this}#login" end |
#page ⇒ Object
72 73 74 |
# File 'lib/smesser/provider.rb', line 72 def page agent.page end |
#post_form(spec) {|form| ... } ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/smesser/provider.rb', line 37 def post_form(spec, &block) spec = { :name => spec } if spec.is_a? String log.debug("Looking for form with #{spec.inspect}") form = page.form_with(spec) raise "Form not found: #{spec.inspect} on #{page.uri} (forms: #{page.forms.map(&:name).inspect})" unless form yield form log.debug("Submitting form: #{form.action} #{form.request_data}") form.submit log.debug("Submitted #{form.action} (#{page.code})") page.code end |
#send(message, *recipients) ⇒ Object
64 65 66 |
# File 'lib/smesser/provider.rb', line 64 def send(, *recipients) raise "You need to override #{this}#send" end |