Class: Purevolume::Client
- Inherits:
-
Object
- Object
- Purevolume::Client
- Defined in:
- lib/purevolume.rb
Constant Summary collapse
- SITE =
'http://www.purevolume.com'
- LOGIN =
'/login'
- POSTS =
'/dashboard?s=posts&tab='
- ADD =
'add_post'
- LIST =
'posts'
- GENERAL =
'General'
- SUCCESS =
'div.success_message'
- DASHBOARD =
'/dashboard'
Instance Method Summary collapse
- #account_info ⇒ Object
- #authenticate ⇒ Object
-
#initialize(username, password) ⇒ Client
constructor
A new instance of Client.
- #post(title, body) ⇒ Object
- #valid_user? ⇒ Boolean
Constructor Details
#initialize(username, password) ⇒ Client
Returns a new instance of Client.
17 18 19 20 21 22 |
# File 'lib/purevolume.rb', line 17 def initialize username, password @agent = WWW::Mechanize.new @username = username @password = password @login_pg = @add_post_pg = @dashboard = @profile_url = @blog_url = @type = @valid = nil end |
Instance Method Details
#account_info ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/purevolume.rb', line 55 def account_info { "rsp" => { "site" => { "name" => profile_name, "profile" => profile_url, "type" => profile_type, "blog" => profile_blog_url }, "stat" => "ok" } } if @valid end |
#authenticate ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/purevolume.rb', line 28 def authenticate @login_pg || login_page login_form = @login_pg.forms_with( :action => LOGIN ).first if login_form login_form.username = @username login_form.password = @password response_page = @agent.submit( login_form ) @dashboard = response_page if response_page.uri.to_s == "#{SITE}#{DASHBOARD}" end @valid = can_post? end |
#post(title, body) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/purevolume.rb', line 41 def post title, body @add_post_pg || add_post_page post_form = @add_post_pg.forms_with( :action => "#{POSTS}#{ADD}" ).first if post_form category = post_form.field_with( :name => 'category' ) category..each { |opt| opt.select if opt.value == GENERAL } if category post_form.blog_title = title post_form.blog_post = body response = !@agent.submit( post_form, post_form..first ).search( SUCCESS ).empty? end response ? success_response(title) : error_response(title) end |
#valid_user? ⇒ Boolean
24 25 26 |
# File 'lib/purevolume.rb', line 24 def valid_user? @valid || authenticate end |