Class: Posterous::Client
Instance Attribute Summary collapse
-
#autopost ⇒ Object
readonly
Returns the value of attribute autopost.
-
#body ⇒ Object
Returns the value of attribute body.
-
#date ⇒ Object
Returns the value of attribute date.
-
#private_post ⇒ Object
readonly
Returns the value of attribute private_post.
-
#site_id ⇒ Object
Returns the value of attribute site_id.
-
#source ⇒ Object
Returns the value of attribute source.
-
#source_url ⇒ Object
Returns the value of attribute source_url.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #account_info ⇒ Object
- #add_post ⇒ Object
- #build_query ⇒ Object
- #has_site? ⇒ Boolean
-
#initialize(user, pass, site_id = nil, hostname = "") ⇒ Client
constructor
Authenticated initialization.
- #primary_site ⇒ Object
- #set_to(on) ⇒ Object
- #valid_user? ⇒ Boolean
Constructor Details
#initialize(user, pass, site_id = nil, hostname = "") ⇒ Client
Authenticated initialization
68 69 70 71 72 73 74 |
# File 'lib/posterous.rb', line 68 def initialize user, pass, site_id = nil, hostname = "" raise AuthError, 'Either Username or Password is blank and/or not a string.' if \ !user.is_a?(String) || !pass.is_a?(String) || user == "" || pass == "" self.class.basic_auth user, pass @site_id = site_id ? site_id.to_s : site_id @source = @body = @title = @source_url = @date = @media = @tags = @autopost = @private_post = nil end |
Instance Attribute Details
#autopost ⇒ Object (readonly)
Returns the value of attribute autopost.
65 66 67 |
# File 'lib/posterous.rb', line 65 def autopost @autopost end |
#body ⇒ Object
Returns the value of attribute body.
64 65 66 |
# File 'lib/posterous.rb', line 64 def body @body end |
#date ⇒ Object
Returns the value of attribute date.
64 65 66 |
# File 'lib/posterous.rb', line 64 def date @date end |
#private_post ⇒ Object (readonly)
Returns the value of attribute private_post.
65 66 67 |
# File 'lib/posterous.rb', line 65 def private_post @private_post end |
#site_id ⇒ Object
Returns the value of attribute site_id.
65 66 67 |
# File 'lib/posterous.rb', line 65 def site_id @site_id end |
#source ⇒ Object
Returns the value of attribute source.
64 65 66 |
# File 'lib/posterous.rb', line 64 def source @source end |
#source_url ⇒ Object
Returns the value of attribute source_url.
64 65 66 |
# File 'lib/posterous.rb', line 64 def source_url @source_url end |
#tags ⇒ Object
Returns the value of attribute tags.
65 66 67 |
# File 'lib/posterous.rb', line 65 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
64 65 66 |
# File 'lib/posterous.rb', line 64 def title @title end |
Instance Method Details
#account_info ⇒ Object
138 139 140 |
# File 'lib/posterous.rb', line 138 def account_info self.class.post(AUTH_PATH, :query => {})["rsp"] end |
#add_post ⇒ Object
142 143 144 |
# File 'lib/posterous.rb', line 142 def add_post self.class.post(POST_PATH, :query => build_query) end |
#build_query ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/posterous.rb', line 122 def build_query = { :site_id => @site_id, :autopost => @autopost, :private => @private_post, :date => @date, :tags => @tags } query = { :title => @title, :body => @body, :source => @source, :sourceLink => @source_url } .delete_if { |k,v| !v } query.merge!() end |
#has_site? ⇒ Boolean
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/posterous.rb', line 91 def has_site? res = account_info return false unless res.is_a?(Hash) case res["site"] when Hash return true unless @site_id return @site_id == res["site"]["id"] when Array res["site"].each do |site| return true if @site_id && @site_id == site["id"] end end false end |
#primary_site ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/posterous.rb', line 107 def primary_site res = account_info raise SiteError, "Couldn't find a primary site. Check login and password is valid." \ unless res.is_a?(Hash) && res["stat"] == "ok" && res["site"] [res["site"]].flatten.each do |site| return site["id"] if site["primary"] == "true" end nil end |
#set_to(on) ⇒ Object
117 118 119 120 |
# File 'lib/posterous.rb', line 117 def set_to on @private_post = 1 if on == :private @autopost = 1 if on == :autopost end |
#valid_user? ⇒ Boolean
85 86 87 88 89 |
# File 'lib/posterous.rb', line 85 def valid_user? res = account_info return false unless res.is_a?(Hash) res["stat"] == "ok" end |