posterboard 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -7
- data/VERSION +1 -1
- data/lib/posterboard/connection.rb +17 -6
- data/lib/posterboard/error.rb +7 -0
- data/lib/posterboard.rb +1 -0
- data/posterboard.gemspec +3 -2
- data/spec/posterboard/connection_spec.rb +21 -2
- metadata +5 -4
data/README.rdoc
CHANGED
@@ -1,21 +1,28 @@
|
|
1
1
|
= posterboard
|
2
2
|
|
3
|
-
Ruby API for reading posts from
|
3
|
+
Ruby API for reading posts from Posterous accounts.
|
4
4
|
|
5
5
|
== How To
|
6
6
|
Install the gem
|
7
|
-
[sudo] gem install posterboard
|
7
|
+
[sudo] gem install posterboard
|
8
8
|
|
9
9
|
Create a connection
|
10
|
-
connection = Posterboard::Connection.new('turkey2000', 'g0bbl3g0bbl3')
|
10
|
+
connection = Posterboard::Connection.new('turkey2000', 'g0bbl3g0bbl3')
|
11
11
|
|
12
12
|
Get posts by site name
|
13
|
-
connection.turkey_blog
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
posts = connection.turkey_blog
|
14
|
+
|
15
|
+
Get the posts' data...
|
16
|
+
posts.each do |post|
|
17
|
+
title = post.title
|
18
|
+
body = post.body
|
19
|
+
end
|
20
|
+
|
21
|
+
...and do your thing!
|
17
22
|
|
18
23
|
== Future features
|
24
|
+
* Posts by tag.
|
25
|
+
* Posts by Date range?
|
19
26
|
* Command line tools for retrieving API token and site id. Library interfaces accepting these constants so they are not looked up on each request.
|
20
27
|
|
21
28
|
== Note
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'json'
|
3
|
+
require 'logger'
|
3
4
|
|
4
5
|
module Posterboard
|
5
6
|
class Connection
|
@@ -11,19 +12,29 @@ module Posterboard
|
|
11
12
|
# get the API token
|
12
13
|
response = Connection.get('/auth/token')
|
13
14
|
Connection.default_params :api_token => response['api_token']
|
15
|
+
|
16
|
+
@logger = ::Logger.new(STDOUT)
|
17
|
+
@logger.level = ::Logger::DEBUG
|
18
|
+
@logger.debug("Created logger")
|
14
19
|
end
|
15
20
|
|
16
21
|
# try to find posts on a site with a name that matches the method name
|
17
22
|
# posts are returned as an array of hashes each with a :title and :body
|
18
23
|
def method_missing(name)
|
19
|
-
|
20
|
-
|
24
|
+
@logger.debug "Looking for site (#{name})."
|
25
|
+
site = sites.find do |site|
|
26
|
+
@logger.debug "Found (#{site["name"]})."
|
27
|
+
site['name'] == name.to_s
|
28
|
+
end
|
29
|
+
raise SiteNotFoundError unless site
|
30
|
+
raise MissingSiteIDError, "Is the Posterous service broken?" unless site.key? "id"
|
21
31
|
response = Connection.get("/users/me/sites/#{site["id"]}/posts")
|
22
|
-
posts = []
|
32
|
+
posts = []
|
23
33
|
::JSON.parse(response.body).each do |body|
|
24
|
-
post
|
25
|
-
post
|
26
|
-
post
|
34
|
+
# => TODO: BlankSlate and define these as methods on post, i.e. post.title, or use OpenStruct
|
35
|
+
post = OpenStruct.new
|
36
|
+
post.title = body['title']
|
37
|
+
post.body = body['body_full']
|
27
38
|
posts << post
|
28
39
|
end
|
29
40
|
posts
|
data/lib/posterboard.rb
CHANGED
data/posterboard.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{posterboard}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Waylon Calabrese"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-12}
|
13
13
|
s.description = %q{Ruby API for reading posts from your Posterous account.}
|
14
14
|
s.email = %q{hiwaylon@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"VERSION",
|
28
28
|
"lib/posterboard.rb",
|
29
29
|
"lib/posterboard/connection.rb",
|
30
|
+
"lib/posterboard/error.rb",
|
30
31
|
"posterboard.gemspec",
|
31
32
|
"spec/posterboard/connection_spec.rb",
|
32
33
|
"spec/spec_helper.rb"
|
@@ -30,10 +30,29 @@ describe Posterboard::Connection do
|
|
30
30
|
|
31
31
|
it "should should give access to the posts' data" do
|
32
32
|
@connection.your_site_name.each do |post|
|
33
|
-
post
|
34
|
-
post
|
33
|
+
post.title.should_not be_nil
|
34
|
+
post.body.should_not be_nil
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
38
|
+
|
39
|
+
context "when something goes wrong" do
|
40
|
+
it "should raise an error when requesting a site that does not exist" do
|
41
|
+
stub_request(:get, "http://user:pass@www.posterous.com/api/2/users/me/sites?api_token=").
|
42
|
+
to_return(:status => 200,
|
43
|
+
:body => [{"id" => "5432", "name" => "this_one"}, {"id" => "9876", "name" => "that_one"}])
|
44
|
+
|
45
|
+
lambda {@connection.but_not_this}.should raise_error(Posterboard::SiteNotFoundError)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should raise an error when the API returns a site without an id" do
|
49
|
+
stub_request(:get, "http://user:pass@www.posterous.com/api/2/users/me/sites?api_token=").
|
50
|
+
to_return(:status => 200,
|
51
|
+
:body => [{"id" => "99", "name" => "a_good_one"}, {"name" => "bad_site", "pointless" => "parameter"}])
|
52
|
+
|
53
|
+
lambda {@connection.bad_site}.should raise_error(Posterboard::MissingSiteIDError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
38
57
|
end
|
39
58
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: posterboard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Waylon Calabrese
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-12 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -148,6 +148,7 @@ files:
|
|
148
148
|
- VERSION
|
149
149
|
- lib/posterboard.rb
|
150
150
|
- lib/posterboard/connection.rb
|
151
|
+
- lib/posterboard/error.rb
|
151
152
|
- posterboard.gemspec
|
152
153
|
- spec/posterboard/connection_spec.rb
|
153
154
|
- spec/spec_helper.rb
|