Class: Wordpress::Post
- Inherits:
-
Object
- Object
- Wordpress::Post
- Defined in:
- lib/wordpress.rb
Constant Summary collapse
- DEFAULT_URL =
'http://wordpress.com/wp-login.php'
- LOGIN_FORM =
'loginform'
- POST_FORM =
'post'
- IS_ADMIN =
'body.wp-admin'
- IS_LOGIN =
'body.login'
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#body ⇒ Object
Returns the value of attribute body.
-
#login_url ⇒ Object
readonly
Returns the value of attribute login_url.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#post_url ⇒ Object
readonly
Returns the value of attribute post_url.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #blog_url ⇒ Object
-
#initialize(usr, pwd, login_url = DEFAULT_URL) ⇒ Post
constructor
A new instance of Post.
- #submit ⇒ Object
- #valid_login_page? ⇒ Boolean
- #valid_user? ⇒ Boolean
Constructor Details
#initialize(usr, pwd, login_url = DEFAULT_URL) ⇒ Post
Returns a new instance of Post.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wordpress.rb', line 24 def initialize usr, pwd, login_url = DEFAULT_URL raise AuthError, "Blank Username or Password or not a string." \ unless usr.is_a?(String) && pwd.is_a?(String) && !usr.empty? && !pwd.empty? raise AuthError, "Url should end with wp-login.php" \ unless login_url =~ /\/wp-login[.]php$/ @username = usr @password = pwd @login_url = login_url @agent = WWW::Mechanize.new @post_url = @tags = @title = @body = nil end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
22 23 24 |
# File 'lib/wordpress.rb', line 22 def agent @agent end |
#body ⇒ Object
Returns the value of attribute body.
21 22 23 |
# File 'lib/wordpress.rb', line 21 def body @body end |
#login_url ⇒ Object (readonly)
Returns the value of attribute login_url.
22 23 24 |
# File 'lib/wordpress.rb', line 22 def login_url @login_url end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
22 23 24 |
# File 'lib/wordpress.rb', line 22 def password @password end |
#post_url ⇒ Object (readonly)
Returns the value of attribute post_url.
22 23 24 |
# File 'lib/wordpress.rb', line 22 def post_url @post_url end |
#tags ⇒ Object
Returns the value of attribute tags.
22 23 24 |
# File 'lib/wordpress.rb', line 22 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
21 22 23 |
# File 'lib/wordpress.rb', line 21 def title @title end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
22 23 24 |
# File 'lib/wordpress.rb', line 22 def username @username end |
Instance Method Details
#blog_url ⇒ Object
51 52 53 |
# File 'lib/wordpress.rb', line 51 def blog_url dashboard_page.search("#{IS_ADMIN} #wphead h1 a").first['href'] rescue nil end |
#submit ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/wordpress.rb', line 55 def submit raise PostError, "A post requires a title or body." unless @title || @body post_form = dashboard_page.form(POST_FORM) raise HostError, "Missing QuickPress on dashboard page or bad account." unless post_form post_form = build_post(post_form) post_response @agent.submit(post_form, post_form..last) end |
#valid_login_page? ⇒ Boolean
43 44 45 |
# File 'lib/wordpress.rb', line 43 def valid_login_page? !login_page.search("form[name=#{LOGIN_FORM}]").empty? end |
#valid_user? ⇒ Boolean
47 48 49 |
# File 'lib/wordpress.rb', line 47 def valid_user? logged_into? dashboard_page end |