class Posterboard::Connection
Public Class Methods
new(username, password)
click to toggle source
default behavior is to query the API key upon initialization
# File lib/posterboard/connection.rb, line 12 def initialize(username, password) Connection.basic_auth username, password # get the API token response = Connection.get('/auth/token') Connection.default_params :api_token => response['api_token'] @logger = ::Logger.new(STDOUT) @logger.level = ::Logger::DEBUG @logger.debug("Created logger") end
Public Instance Methods
method_missing(name)
click to toggle source
try to find posts on a site with a name that matches the method name posts are returned as an array of hashes each with a :title and :body
# File lib/posterboard/connection.rb, line 25 def method_missing(name) @logger.debug "Looking for site (#{name})." site = sites.find do |site| @logger.debug "Found (#{site["name"]})." site['name'] == name.to_s end raise SiteNotFoundError unless site raise MissingSiteIDError, "Is the Posterous service broken?" unless site.key? "id" response = Connection.get("/users/me/sites/#{site["id"]}/posts") posts = [] ::JSON.parse(response.body).each do |content| # => TODO: BlankSlate and define these as methods on post, i.e. post.title, or use OpenStruct post = OpenStruct.new post.title = content['title'] post.body = content['body_full'] post.date = Time.parse(content['display_date']) posts << post end posts end
Private Instance Methods
sites()
click to toggle source
# File lib/posterboard/connection.rb, line 48 def sites Connection.get('/users/me/sites') end