caboodle 0.2.25 → 0.2.26

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.25
1
+ 0.2.26
@@ -4,6 +4,13 @@ require 'weary'
4
4
  require 'nokogiri'
5
5
 
6
6
  module Caboodle
7
+
8
+ class PosterousPostNotFound < Exception
9
+ end
10
+
11
+ class PosterousProblem < Exception
12
+ end
13
+
7
14
  class PosterousAPI < Weary::Base
8
15
 
9
16
  def initialize(opts={})
@@ -31,6 +38,7 @@ module Caboodle
31
38
  r.url = "http://posterous.com/api/getsites"
32
39
  r.via = :get
33
40
  r.authenticates = true
41
+ r.follows = true
34
42
  r.headers = {'Accept' => 'application/xml'}
35
43
  end
36
44
 
@@ -40,6 +48,7 @@ module Caboodle
40
48
  r.with = [:site_id,:tag,:num_posts,:page]
41
49
  r.requires = [:site_id]
42
50
  r.authenticates = true
51
+ r.follows = true
43
52
  r.headers = {'Accept' => 'application/xml'}
44
53
  end
45
54
 
@@ -54,6 +63,7 @@ module Caboodle
54
63
  end
55
64
 
56
65
  def self.from_slug(slug)
66
+ puts "Looking for http://#{Site.posterous_sitename}.posterous.com/#{slug}"
57
67
  doc = Caboodle.scrape("http://#{Site.posterous_sitename}.posterous.com/#{slug}")
58
68
  puts doc
59
69
  opts = {}
@@ -61,10 +71,14 @@ module Caboodle
61
71
  opts["title"] = doc.css('title').inner_html.split(" - ").first
62
72
  opts["link"] = "http://#{Site.posterous_sitename}.posterous.com/#{slug}"
63
73
  perma = doc.css('.permalink').inner_html
64
- date = doc.css('article time').first["datetime"] if doc.css('article time').first
65
- date ||= doc.css('.date .permalink').first.inner_html if doc.css('.date .permalink').first
66
- puts date
67
- opts["date"] = Date.parse(date) if date
74
+ begin
75
+ date = doc.css('article time').first["datetime"] if doc.css('article time').first
76
+ date ||= doc.css('.date .permalink').first.inner_html if doc.css('.date .permalink').first
77
+ opts["date"] = Date.parse(date) if date
78
+ rescue
79
+ opts["date"] = Date.parse(Time.now)
80
+ end
81
+ puts opts["date"]
68
82
  PosterousPost.new(opts)
69
83
  end
70
84
 
@@ -74,18 +88,26 @@ module Caboodle
74
88
  end
75
89
 
76
90
  def self.all(opts={})
77
- r = []
78
- p = PosterousAPI.new
79
- opts[:site_id] = Site.posterous_site_id
80
- rsp = p.all(opts).perform_sleepily.parse["rsp"]
81
- posts = rsp["post"]
82
- posts = [posts] if posts.class == Hash
83
- posts.each{|a| r << PosterousPost.new(a) } if posts
84
- r
91
+ begin
92
+ r = []
93
+ p = PosterousAPI.new
94
+ opts[:site_id] = Site.posterous_site_id
95
+ rsp = p.all(opts).perform.parse["rsp"]
96
+ posts = rsp["post"]
97
+ posts = [posts] if posts.class == Hash
98
+ posts.each{|a| r << PosterousPost.new(a) } if posts
99
+ r
100
+ rescue Exception => e
101
+ raise PosterousProblem.new(e.message)
102
+ end
85
103
  end
86
104
 
87
105
  def self.get(slug)
88
- PosterousPost.new(PosterousAPI.new.all().perform.parse)
106
+ begin
107
+ PosterousPost.new(PosterousAPI.new.all().perform.parse)
108
+ rescue Exception => e
109
+ raise PosterousProblem.new(e.message)
110
+ end
89
111
  end
90
112
 
91
113
  def [] k
@@ -109,24 +131,26 @@ module Caboodle
109
131
  def semantic_tags
110
132
  a = tags.collect{|t| "tag-#{t}"}
111
133
  a << "slug-#{slug}"
112
- a << "y#{date.year}"
113
- a << "m#{date.month}"
114
- a << "d#{date.day}"
134
+ if date
135
+ a << "y#{date.year}"
136
+ a << "m#{date.month}"
137
+ a << "d#{date.day}"
138
+ end
115
139
  a
116
140
  end
117
141
 
118
142
  def url
119
143
  d = date
120
- "/#{d.year}/#{d.month}/#{slug}"
144
+ if d
145
+ "/#{d.year}/#{d.month}/#{slug}"
146
+ else
147
+ "/#{slug}"
148
+ end
121
149
  end
122
150
 
123
151
  def date
124
- return @date if defined?(@date)
125
- if attributes["date"].class == String
126
- @date = Date.parse(attributes["date"])
127
- else
128
- @date = attributes["date"]
129
- end
152
+ puts attributes.inspect
153
+ @date ||= attributes["date"]
130
154
  end
131
155
 
132
156
  def full_url
@@ -152,18 +176,28 @@ module Caboodle
152
176
  haml :posts
153
177
  end
154
178
 
155
- get "/:year/:month/:slug" do |year, month, slug|
156
- STDERR.puts "Get a post"
157
- post = PosterousPost.from_slug(slug)
158
- STDERR.puts "Slug not found: #{slug}"
159
- not_found unless post
160
- @title = post.title
179
+ get %r{/(\d+)/(\d+)/(.*$)} do |year, month, slug|
180
+ puts "Blog post: #{params.inspect}"
181
+ begin
182
+ post = PosterousPost.from_slug(slug)
183
+ @title = post.title
184
+ rescue Caboodle::PosterousPostNotFound
185
+ not_found unless post
186
+ rescue Caboodle::PosterousProblem
187
+ post = nil
188
+ end
161
189
  haml :post, :locals => { :post => post }
162
190
  end
163
191
 
164
192
  menu "Blog", "/posterous" do
165
- @posts = PosterousPost.all(:page=>(params[:page] || 1))
166
- haml :posts.to_sym
193
+ begin
194
+ @posts = PosterousPost.all(:page=>(params[:page] || 1))
195
+ rescue Caboodle::PosterousProblem
196
+ @posts = nil
197
+ puts "Problem accessing posts on Posterous.com"
198
+ end
199
+
200
+ haml :posts
167
201
  end
168
202
 
169
203
  stylesheets ["http://disqus.com/stylesheets/#{disqus}/disqus.css?v=2.0"] if disqus
@@ -1,5 +1,5 @@
1
1
  - post = locals[:post]
2
-
2
+
3
3
  %article.post.hentry.publish{:class=>post.semantic_tags}
4
4
  - if locals[:full]
5
5
 
@@ -18,8 +18,9 @@
18
18
  %a.url.fn.n{:href => "/about", :title => "About the author"}= Caboodle::Site.author
19
19
  %span.meta-sep.meta-sep-entry-date |
20
20
  %span.meta-prep.meta-prep-entry-date Published:
21
- %span.entry-date
22
- %abbr.published{:title => post.date.strftime("%d")}= post.date.strftime("%b")
21
+ - if post.date
22
+ %span.entry-date
23
+ %abbr.published{:title => post.date.strftime("%d")}= post.date.strftime("%b")
23
24
  %small
24
25
  %span.tag-links
25
26
  = post.linked_tags
@@ -1,9 +1,20 @@
1
1
  - if ENV["RACK_ENV"] == "development"
2
2
  :javascript
3
3
  var disqus_developer = true;
4
+
4
5
 
5
6
  %div.posterous
6
- = haml :_post, :locals=>{:post=>post, :full=>true}, :layout=>false
7
+
8
+ - if post.nil?
9
+ %h3
10
+ Sorry, there's a problem communicating with Posterous.com
11
+ %p
12
+ You can view this post at
13
+ %a{:href=>"http://#{Site.posterous_sitename}.posterous.com/#{params[:slug]}"}
14
+ = posterous_sitename
15
+ on Posterous.com
16
+ - else
17
+ = haml :_post, :locals=>{:post=>post, :full=>true}, :layout=>false
7
18
  - if Caboodle::Site.disqus
8
19
  #disqus_thread
9
20
  %script{:src => "http://disqus.com/forums/#{Caboodle::Site.disqus}/embed.js", :type => "text/javascript"}
@@ -2,6 +2,11 @@
2
2
  - if defined?(@posts) && @posts.nil?
3
3
  %h3
4
4
  Sorry, there's a problem communicating with Posterous.com
5
+ %p
6
+ You can view all of the posts at
7
+ %a{:href=>"http://#{Caboodle::Site.posterous_sitename}.posterous.com"}
8
+ = Caboodle::Site.posterous_sitename
9
+ on Posterous.com
5
10
  - else
6
11
  - @posts.each do |post|
7
12
  - puts post.inspect
@@ -1,10 +1,32 @@
1
1
  require 'nokogiri'
2
2
  require 'hashie'
3
3
  require 'net/http'
4
+ require 'open-uri'
4
5
 
5
6
  module Caboodle
7
+
8
+ def self.round_time(integer, factor)
9
+ return integer if(integer % factor == 0)
10
+ return integer - (integer % factor)
11
+ end
12
+
6
13
  def self.scrape url
7
- ::Nokogiri::HTML(Weary.get(url).perform_sleepily.body)
14
+ begin
15
+ if HAS_MEMCACHE
16
+ timeout = 60*60*1000
17
+ sleepy = Memcached.new
18
+ response = sleepy.get("#{round_time(Time.new.to_i, timeout)}:#{url}") rescue nil
19
+ response ||= open(url).read
20
+ sleepy.set("#{round_time(Time.new.to_i, timeout)}:#{url}", response)
21
+ sleepy.set("0:#{url}", response)
22
+ else
23
+ response = open(url).read
24
+ end
25
+ ::Nokogiri::HTML(response)
26
+ rescue Exception => e
27
+ puts e.inspect
28
+ ::Nokogiri::HTML("")
29
+ end
8
30
  end
9
31
 
10
32
  def self.mash req
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboodle
3
3
  version: !ruby/object:Gem::Version
4
- hash: 37
4
+ hash: 35
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 25
10
- version: 0.2.25
9
+ - 26
10
+ version: 0.2.26
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stef Lewandowski
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-12 00:00:00 +01:00
18
+ date: 2010-09-18 00:00:00 +01:00
19
19
  default_executable: caboodle
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency