Class: Caboodle::PosterousPost

Inherits:
Object
  • Object
show all
Defined in:
lib/caboodle/kits/posterous/posterous.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(res) ⇒ PosterousPost

Returns a new instance of PosterousPost.



61
62
63
# File 'lib/caboodle/kits/posterous/posterous.rb', line 61

def initialize(res)
  @attributes = res
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(arg) ⇒ Object



123
124
125
# File 'lib/caboodle/kits/posterous/posterous.rb', line 123

def method_missing arg
  self[arg.to_s]
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



59
60
61
# File 'lib/caboodle/kits/posterous/posterous.rb', line 59

def attributes
  @attributes
end

Class Method Details

.all(opts = {}) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/caboodle/kits/posterous/posterous.rb', line 90

def self.all(opts={})
  begin
    r = []
    p = PosterousAPI.new
    opts[:site_id] = Site.posterous_site_id 
    rsp = p.all(opts).perform_sleepily.parse["rsp"]
    posts = rsp["post"]
    posts = [posts] if posts.class == Hash
    posts.each{|a| r << PosterousPost.new(a) } if posts
    r
  rescue Exception => e
    raise PosterousProblem.new(e.message)
  end
end

.from_slug(slug) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/caboodle/kits/posterous/posterous.rb', line 65

def self.from_slug(slug)
  puts "Looking for http://#{Site.posterous_sitename}.posterous.com/#{slug}"
  doc = Caboodle.scrape("http://#{Site.posterous_sitename}.posterous.com/#{slug}")
  #puts doc
  opts = {}
  opts["body"] = doc.css('div.bodytext').inner_html
  opts["title"] = doc.css('title').inner_html.split(" - ").first
  opts["link"] = "http://#{Site.posterous_sitename}.posterous.com/#{slug}"
  perma = doc.css('.permalink').inner_html
  begin
    date = doc.css('article time').first["datetime"] if doc.css('article time').first
    date ||= doc.css('.date .permalink').first.inner_html if doc.css('.date .permalink').first
    opts["date"] = Date.parse(date) if date
  rescue
    opts["date"] = Date.parse(Time.now)
  end
  #puts opts["date"]
  PosterousPost.new(opts)
end

.get(slug) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/caboodle/kits/posterous/posterous.rb', line 105

def self.get(slug)
  begin
    PosterousPost.new(PosterousAPI.new.all().perform.parse)
  rescue Exception => e
    raise PosterousProblem.new(e.message)
  end
end

.page(num) ⇒ Object



85
86
87
88
# File 'lib/caboodle/kits/posterous/posterous.rb', line 85

def self.page(num)
  raise "must be page 1 or more" if num.to_i < 1
  PosterousPost.all(:page=>num.to_i)
end

Instance Method Details

#[](k) ⇒ Object



113
114
115
116
# File 'lib/caboodle/kits/posterous/posterous.rb', line 113

def [] k
  @attributes = {} if @attributes.nil?
  @attributes[k]
end

#[]=(l, v) ⇒ Object



118
119
120
121
# File 'lib/caboodle/kits/posterous/posterous.rb', line 118

def []= l,v
  @attributes = {} if @attributes.nil?
  @attributes[l] = v
end

#dateObject



151
152
153
# File 'lib/caboodle/kits/posterous/posterous.rb', line 151

def date
 @date ||= Date.parse(attributes["date"]) rescue nil
end

#full_urlObject



155
156
157
# File 'lib/caboodle/kits/posterous/posterous.rb', line 155

def full_url
	Site.url_base.gsub(/\/$/, '') + url
end

#semantic_tagsObject



131
132
133
134
135
136
137
138
139
140
# File 'lib/caboodle/kits/posterous/posterous.rb', line 131

def semantic_tags
  a = tags.collect{|t| "tag-#{t}"}
  a << "slug-#{slug}"
  if date
    a << "y#{date.year}"
    a << "m#{date.month}"
    a << "d#{date.day}"
  end
  a
end

#slugObject



159
160
161
# File 'lib/caboodle/kits/posterous/posterous.rb', line 159

def slug
  self.link.split(".posterous.com/").last.split("/").last
end

#tagsObject



127
128
129
# File 'lib/caboodle/kits/posterous/posterous.rb', line 127

def tags
  []
end

#urlObject



142
143
144
145
146
147
148
149
# File 'lib/caboodle/kits/posterous/posterous.rb', line 142

def url
	d = date
	if d
	  "/#{d.year}/#{d.month}/#{slug}"
	else
	  "/#{slug}"
 end
end