Class: TypePadTemplate::Account
- Inherits:
-
Object
- Object
- TypePadTemplate::Account
- Defined in:
- lib/type_pad_template/account.rb
Instance Attribute Summary collapse
-
#login_cookies ⇒ Object
readonly
Returns the value of attribute login_cookies.
Class Method Summary collapse
Instance Method Summary collapse
- #blogs ⇒ Object
-
#initialize(login_cookies = nil) ⇒ Account
constructor
A new instance of Account.
- #logged_in? ⇒ Boolean
- #login(username, password) ⇒ Object
- #request(path, options = {}) ⇒ Object
Constructor Details
#initialize(login_cookies = nil) ⇒ Account
Returns a new instance of Account.
13 14 15 |
# File 'lib/type_pad_template/account.rb', line 13 def initialize( = nil) @login_cookies = end |
Instance Attribute Details
#login_cookies ⇒ Object (readonly)
Returns the value of attribute login_cookies.
11 12 13 |
# File 'lib/type_pad_template/account.rb', line 11 def @login_cookies end |
Class Method Details
.login(username, password) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/type_pad_template/account.rb', line 3 def self.login(username, password) account = new.tap do |a| a.login(username, password) end account if account.logged_in? end |
Instance Method Details
#blogs ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/type_pad_template/account.rb', line 41 def blogs return [] unless logged_in? request("/dashboard") do |response| response. doc. search("//ul[@id='blogs-list']//a[@class='blog-name']"). map do |element| if %r{/([0-9a-f]+)/dashboard$} === element["href"] id = $1 Blog.new(self, id, element.text) end end. compact end end |
#logged_in? ⇒ Boolean
58 59 60 |
# File 'lib/type_pad_template/account.rb', line 58 def logged_in? !@login_cookies.empty? end |
#login(username, password) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/type_pad_template/account.rb', line 17 def login(username, password) form_element = Request.new("/secure/services/signin", :ssl => true). dispatch. response. doc. at("//form[@id='signin-form-typepad']") form = Form.new(form_element).tap do |f| f[:username] = username f[:password] = password end @login_cookies = Request.new("/secure/services/signin/save", { :ssl => true, :method => :post, :params => form.to_hash }). dispatch. response. self end |
#request(path, options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/type_pad_template/account.rb', line 62 def request(path, = {}) # FIXME raise a proper exception instead. return nil unless logged_in? request = Request.new(path, ()) if block_given? yield request. dispatch. response else request end end |