posterous_api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.infinity_test +5 -0
- data/.rspec +3 -0
- data/.rvmrc +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +44 -0
- data/Rakefile +22 -0
- data/Readme.markdown +27 -0
- data/VERSION.yml +5 -0
- data/lib/posterous_api.rb +9 -0
- data/lib/posterous_api/base_uri.rb +10 -0
- data/lib/posterous_api/connection.rb +25 -0
- data/lib/posterous_api/new_api.rb +44 -0
- data/lib/posterous_api/old_api.rb +65 -0
- data/lib/posterous_api/user.rb +61 -0
- data/posterous_api.gemspec +74 -0
- data/spec/posterous_api/base_uri_spec.rb +12 -0
- data/spec/posterous_api/connection_spec.rb +6 -0
- data/spec/posterous_api/new_api_spec.rb +44 -0
- data/spec/posterous_api/old_api_spec.rb +31 -0
- data/spec/posterous_api/posterous_api_spec.rb +4 -0
- data/spec/posterous_api/user_spec.rb +88 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/support/faker_response.rb +43 -0
- metadata +135 -0
data/.infinity_test
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create 1.9.2@posterous_api
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
crack (0.1.8)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
fakeweb (1.3.0)
|
7
|
+
fuubar (0.0.2)
|
8
|
+
rspec (~> 2.0)
|
9
|
+
rspec-instafail (~> 0.1.4)
|
10
|
+
ruby-progressbar (~> 0.0.9)
|
11
|
+
git (1.2.5)
|
12
|
+
httparty (0.6.1)
|
13
|
+
crack (= 0.1.8)
|
14
|
+
infinity_test (1.0.2)
|
15
|
+
notifiers (>= 1.1.0)
|
16
|
+
watchr (>= 0.7)
|
17
|
+
jeweler (1.5.1)
|
18
|
+
bundler (~> 1.0.0)
|
19
|
+
git (>= 1.2.5)
|
20
|
+
rake
|
21
|
+
notifiers (1.1.0)
|
22
|
+
rake (0.8.7)
|
23
|
+
rspec (2.1.0)
|
24
|
+
rspec-core (~> 2.1.0)
|
25
|
+
rspec-expectations (~> 2.1.0)
|
26
|
+
rspec-mocks (~> 2.1.0)
|
27
|
+
rspec-core (2.1.0)
|
28
|
+
rspec-expectations (2.1.0)
|
29
|
+
diff-lcs (~> 1.1.2)
|
30
|
+
rspec-instafail (0.1.4)
|
31
|
+
rspec-mocks (2.1.0)
|
32
|
+
ruby-progressbar (0.0.9)
|
33
|
+
watchr (0.7)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
fakeweb (= 1.3.0)
|
40
|
+
fuubar
|
41
|
+
httparty (= 0.6.1)
|
42
|
+
infinity_test (= 1.0.2)
|
43
|
+
jeweler
|
44
|
+
rspec (= 2.1.0)
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |gemspec|
|
6
|
+
gemspec.name = "posterous_api"
|
7
|
+
gemspec.summary = ""
|
8
|
+
gemspec.description = ""
|
9
|
+
gemspec.email = "tomasdestefi@gmail.com"
|
10
|
+
gemspec.homepage = "http://github.com/tomas-stefano/posterous_api"
|
11
|
+
gemspec.authors = ["Tomas D'Stefano"]
|
12
|
+
|
13
|
+
gemspec.add_dependency('httparty', '>= 0.6.1')
|
14
|
+
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts("-" * 80)
|
19
|
+
puts "Jeweler not available. Install it with:
|
20
|
+
[sudo] gem install jeweler"
|
21
|
+
puts("-" * 80)
|
22
|
+
end
|
data/Readme.markdown
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Posterous API
|
2
|
+
|
3
|
+
Posterous API is a extraction from Reblog application (that is not ready in production, but will be =] )
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
gem install posterous_api
|
8
|
+
|
9
|
+
## Require
|
10
|
+
|
11
|
+
require 'posterous_api'
|
12
|
+
|
13
|
+
## Using
|
14
|
+
|
15
|
+
user = Posterous::User.new('my_user@email.com', 'my_password')
|
16
|
+
|
17
|
+
user.blogs # => return all blogs from posterous
|
18
|
+
|
19
|
+
users.posts_from :blog => 'site_id'
|
20
|
+
|
21
|
+
user.tasgs_from :blog => 'site_id'
|
22
|
+
|
23
|
+
# More Features
|
24
|
+
|
25
|
+
Just read the source code man!
|
26
|
+
|
27
|
+
=p
|
data/VERSION.yml
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module Posterous
|
4
|
+
autoload :BaseURI, 'posterous_api/base_uri'
|
5
|
+
autoload :User, 'posterous_api/user'
|
6
|
+
autoload :Connection, 'posterous_api/connection'
|
7
|
+
autoload :NewAPI, 'posterous_api/new_api'
|
8
|
+
autoload :OldAPI, 'posterous_api/old_api'
|
9
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Posterous
|
2
|
+
module Connection
|
3
|
+
|
4
|
+
def get(uri, options={})
|
5
|
+
klass = options[:klass] || HTTParty
|
6
|
+
klass.get(uri, { :basic_auth => credentials }.merge(options))
|
7
|
+
end
|
8
|
+
|
9
|
+
def post(uri, options={})
|
10
|
+
klass = options[:klass] || HTTParty
|
11
|
+
klass.post(uri, {:basic_auth => credentials}.merge(options))
|
12
|
+
end
|
13
|
+
|
14
|
+
def put(uri, options)
|
15
|
+
klass = options[:klass] || HTTParty
|
16
|
+
klass.put(uri, :basic_auth => credentials)
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(uri, klass=HTTParty)
|
20
|
+
klass = options[:klass] || HTTParty
|
21
|
+
klass.delete(uri, :basic_auth => credentials)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Posterous
|
2
|
+
module NewAPI
|
3
|
+
include BaseURI
|
4
|
+
|
5
|
+
# The get sites uri to get all the sites from a user
|
6
|
+
#
|
7
|
+
# Fields:
|
8
|
+
# None
|
9
|
+
#
|
10
|
+
def get_sites_uri
|
11
|
+
@get_sites_uri ||= "#{base_uri}/2/users/me/sites"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Get the primary site from a user
|
15
|
+
#
|
16
|
+
def user_primary_site_uri
|
17
|
+
@user_primary_site_uri ||= "#{base_uri}/api/2/users/me/sites/primary"
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create a site url
|
21
|
+
#
|
22
|
+
def create_site_uri
|
23
|
+
@create_site_uri ||= "#{base_uri}/api/2/users/me/sites"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get a User Uri
|
27
|
+
#
|
28
|
+
def get_a_user_uri
|
29
|
+
@get_a_user_uri ||= "#{base_uri}/api/2/users/me"
|
30
|
+
end
|
31
|
+
|
32
|
+
# Public posts uri from your primary site
|
33
|
+
#
|
34
|
+
def public_posts_from_primary_site_uri
|
35
|
+
@public_posts_from_primary_site_uri ||= "#{base_uri}/api/2/users/me/sites/primary/posts/public"
|
36
|
+
end
|
37
|
+
|
38
|
+
# The auth token uri to get the token
|
39
|
+
#
|
40
|
+
def auth_token_uri
|
41
|
+
@auth_token_uri ||= "#{base_uri}/2/auth/token"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Old API of Posterous:
|
2
|
+
|
3
|
+
# http://posterous.com/api/reading
|
4
|
+
|
5
|
+
module Posterous
|
6
|
+
module OldAPI
|
7
|
+
include BaseURI
|
8
|
+
|
9
|
+
def get_all_sites_uri
|
10
|
+
@get_all_sites_uri ||= "#{base_uri}/getsites"
|
11
|
+
end
|
12
|
+
|
13
|
+
# The get tags uri to get all the tags
|
14
|
+
#
|
15
|
+
# Fields:
|
16
|
+
# "site_id" - Optional. Id of the site to read from
|
17
|
+
# "hostname" - Optional. Subdomain of the site to read from
|
18
|
+
#
|
19
|
+
def get_tags_uri
|
20
|
+
@get_tags_uri ||= "#{base_uri}/gettags"
|
21
|
+
end
|
22
|
+
|
23
|
+
# The read posts uri to get all the posts from a site
|
24
|
+
#
|
25
|
+
# Fields:
|
26
|
+
# "site_id" - Optional. Id of the site to read from
|
27
|
+
# "hostname" - Optional. Subdomain of the site to read from
|
28
|
+
# "num_posts" - Optional. How many posts you want. Default is 10, max is 50
|
29
|
+
# "page" - Optional. What 'page' you want (based on num_posts). Default is 1
|
30
|
+
# "tag" - Optional
|
31
|
+
#
|
32
|
+
def read_posts_uri
|
33
|
+
@read_posts_uri ||= "#{base_uri}/readposts"
|
34
|
+
end
|
35
|
+
|
36
|
+
# Fields:
|
37
|
+
# "site_id" - Optional. Id of the site to post to. If not supplied, posts to the user's default site
|
38
|
+
# "media" - Optional. File data for single file.
|
39
|
+
# "media[]" - Optional. File data for multiple file upload. Can be specified multiple times.
|
40
|
+
# "title" - Optional. Title of post
|
41
|
+
# "body" - Optional. Body of post
|
42
|
+
# "autopost" - Optional. 0 or 1.
|
43
|
+
# "private" - Optional. 0 or 1.
|
44
|
+
# "date" - Optional. In GMT. Any parsable format. Cannot be in the future.
|
45
|
+
# "tags" - Optional. Comma separate tags
|
46
|
+
# "source" - Optional. The name of your application or website
|
47
|
+
# "sourceLink" - Optional. Link to your application or website
|
48
|
+
#
|
49
|
+
def new_post_uri
|
50
|
+
@new_post_uri ||= "#{base_uri}/newpost"
|
51
|
+
end
|
52
|
+
|
53
|
+
# Fields:
|
54
|
+
# "post_id" - Id of the post to update.
|
55
|
+
# "media" - Optional. File data for single file. Will append to post.
|
56
|
+
# "media[]" - Optional. File data for multiple file upload. Can be specified multiple times. Will append to post.
|
57
|
+
# "title" - Optional. Title of post. Will update post if present.
|
58
|
+
# "body" - Optional. Body of post. Will update post if present.
|
59
|
+
#
|
60
|
+
def update_post_uri
|
61
|
+
@update_post_uri ||= "#{base_uri}/updatepost"
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Posterous
|
2
|
+
class User
|
3
|
+
attr_accessor :email, :password
|
4
|
+
include Connection
|
5
|
+
include OldAPI
|
6
|
+
|
7
|
+
# http://posterous.com/api/posting
|
8
|
+
|
9
|
+
# Initialize of a Client with email and password
|
10
|
+
#
|
11
|
+
def initialize(email, password)
|
12
|
+
@email = email
|
13
|
+
@password = password
|
14
|
+
end
|
15
|
+
|
16
|
+
# Return the credentials to use with the old API
|
17
|
+
#
|
18
|
+
# user.credentials
|
19
|
+
#
|
20
|
+
def credentials
|
21
|
+
{ :username => @email, :password => @password }
|
22
|
+
end
|
23
|
+
|
24
|
+
# Return all the sites for that user
|
25
|
+
#
|
26
|
+
# user.blogs
|
27
|
+
#
|
28
|
+
def blogs
|
29
|
+
get(get_all_sites_uri)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Return all the posts from a blog
|
33
|
+
#
|
34
|
+
# user.posts_from :blog => '123456'
|
35
|
+
#
|
36
|
+
def posts_from(options={})
|
37
|
+
get(read_posts_uri, { :site_id => options[:blog]})
|
38
|
+
end
|
39
|
+
alias :posts :posts_from
|
40
|
+
|
41
|
+
# Return all the tags from a blog
|
42
|
+
#
|
43
|
+
# user.tags_from :blog => '123456'
|
44
|
+
#
|
45
|
+
def tags_from(options={})
|
46
|
+
get(get_tags_uri, { :site_id => options[:blog]})
|
47
|
+
end
|
48
|
+
|
49
|
+
# Create a new post in a blog
|
50
|
+
#
|
51
|
+
# user.create_post_for :blog => '123456', :title => 'My title', :body => 'Body'
|
52
|
+
#
|
53
|
+
def create_post_for(options)
|
54
|
+
site_id = options[:blog]
|
55
|
+
options.delete(:blog)
|
56
|
+
options[:site_id] = site_id
|
57
|
+
post(new_post_uri, options)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{posterous_api}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Tomas D'Stefano"]
|
12
|
+
s.date = %q{2010-11-20}
|
13
|
+
s.description = %q{}
|
14
|
+
s.email = %q{tomasdestefi@gmail.com}
|
15
|
+
s.files = [
|
16
|
+
".infinity_test",
|
17
|
+
".rspec",
|
18
|
+
".rvmrc",
|
19
|
+
"Gemfile",
|
20
|
+
"Gemfile.lock",
|
21
|
+
"Rakefile",
|
22
|
+
"Readme.markdown",
|
23
|
+
"VERSION.yml",
|
24
|
+
"lib/posterous_api.rb",
|
25
|
+
"lib/posterous_api/base_uri.rb",
|
26
|
+
"lib/posterous_api/connection.rb",
|
27
|
+
"lib/posterous_api/new_api.rb",
|
28
|
+
"lib/posterous_api/old_api.rb",
|
29
|
+
"lib/posterous_api/user.rb",
|
30
|
+
"posterous_api.gemspec",
|
31
|
+
"spec/posterous_api/base_uri_spec.rb",
|
32
|
+
"spec/posterous_api/connection_spec.rb",
|
33
|
+
"spec/posterous_api/new_api_spec.rb",
|
34
|
+
"spec/posterous_api/old_api_spec.rb",
|
35
|
+
"spec/posterous_api/posterous_api_spec.rb",
|
36
|
+
"spec/posterous_api/user_spec.rb",
|
37
|
+
"spec/spec_helper.rb",
|
38
|
+
"spec/support/faker_response.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://github.com/tomas-stefano/posterous_api}
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.7}
|
43
|
+
s.summary = %q{}
|
44
|
+
s.test_files = [
|
45
|
+
"spec/posterous_api/base_uri_spec.rb",
|
46
|
+
"spec/posterous_api/connection_spec.rb",
|
47
|
+
"spec/posterous_api/new_api_spec.rb",
|
48
|
+
"spec/posterous_api/old_api_spec.rb",
|
49
|
+
"spec/posterous_api/posterous_api_spec.rb",
|
50
|
+
"spec/posterous_api/user_spec.rb",
|
51
|
+
"spec/spec_helper.rb",
|
52
|
+
"spec/support/faker_response.rb"
|
53
|
+
]
|
54
|
+
|
55
|
+
if s.respond_to? :specification_version then
|
56
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
57
|
+
s.specification_version = 3
|
58
|
+
|
59
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
|
+
s.add_runtime_dependency(%q<httparty>, ["= 0.6.1"])
|
61
|
+
s.add_runtime_dependency(%q<jeweler>, [">= 0"])
|
62
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<httparty>, ["= 0.6.1"])
|
65
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
66
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<httparty>, ["= 0.6.1"])
|
70
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
71
|
+
s.add_dependency(%q<httparty>, [">= 0.6.1"])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Posterous
|
4
|
+
describe NewAPI do
|
5
|
+
include NewAPI
|
6
|
+
|
7
|
+
it "should return the auth token uri" do
|
8
|
+
auth_token_uri.should == "#{@base_uri}/2/auth/token"
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'in sites' do
|
12
|
+
|
13
|
+
it "should return the get sites uri" do
|
14
|
+
get_sites_uri.should == "#{@base_uri}/2/users/me/sites"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return a uri from users primary site" do
|
18
|
+
user_primary_site_uri.should == "#{@base_uri}/api/2/users/me/sites/primary"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return a uri from create a site" do
|
22
|
+
create_site_uri.should == "#{@base_uri}/api/2/users/me/sites"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'in users' do
|
28
|
+
|
29
|
+
it "should return a uri to get a user" do
|
30
|
+
get_a_user_uri.should == "#{@base_uri}/api/2/users/me"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'in posts' do
|
36
|
+
|
37
|
+
it "should return the public posts from the primary site uri" do
|
38
|
+
public_posts_from_primary_site_uri.should == "#{@base_uri}/api/2/users/me/sites/primary/posts/public"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Posterous
|
4
|
+
describe OldAPI do
|
5
|
+
include OldAPI
|
6
|
+
context 'blogs' do
|
7
|
+
it "should return the get all blogs uri" do
|
8
|
+
get_all_sites_uri.should == "#{@base_uri}/getsites"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'posts' do
|
13
|
+
it "should return the read posts uri" do
|
14
|
+
read_posts_uri.should == "#{@base_uri}/readposts"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should return the get tags uri" do
|
18
|
+
get_tags_uri.should == "#{@base_uri}/gettags"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return the new post uri" do
|
22
|
+
new_post_uri.should == "#{@base_uri}/newpost"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return the update post uri" do
|
26
|
+
update_post_uri.should == "#{@base_uri}/updatepost"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
FakeWeb.allow_net_connect = false
|
4
|
+
|
5
|
+
module Posterous
|
6
|
+
describe User do
|
7
|
+
let(:user) { Posterous::User.new('fake_email@gmail.com', 'secret')}
|
8
|
+
let(:batman) { Posterous::User.new('batman@gmail.com', 'super_secret') }
|
9
|
+
include FakerResponse
|
10
|
+
|
11
|
+
describe '#initialize' do
|
12
|
+
|
13
|
+
it "should storage the email of the user" do
|
14
|
+
Posterous::User.new('my_email@gmail.com', 'password').email.should == "my_email@gmail.com"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should storage the password for user" do
|
18
|
+
Posterous::User.new('my_email@gmail.com', 'secret').password.should == 'secret'
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#credentials' do
|
24
|
+
it "should return a instance of Hash" do
|
25
|
+
user.credentials.should be_instance_of(Hash)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return a username in the key" do
|
29
|
+
user.credentials.should have_key(:username)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have the email in the username value" do
|
33
|
+
user.credentials.should have_value(user.email)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should return a username in the key" do
|
37
|
+
user.credentials.should have_key(:password)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have the password in the email value" do
|
41
|
+
user.credentials.should have_value(user.password)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#blogs' do
|
46
|
+
|
47
|
+
it "should call the Httparty" do
|
48
|
+
mock_sites(user)
|
49
|
+
user.blogs
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#posts' do
|
54
|
+
|
55
|
+
it "should return a post from a site in a instance of Array" do
|
56
|
+
mock_posts(user, '12345')
|
57
|
+
user.posts_from(:blog => '12345')
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#tags_from' do
|
63
|
+
it "should pass to HTTParty the uri and the site id" do
|
64
|
+
mock_tags(user, '126789')
|
65
|
+
user.tags_from(:blog => '126789')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '#create_post_for' do
|
70
|
+
|
71
|
+
it "should call the Httparty get method with the right uri" do
|
72
|
+
mock_create_post(user, :blog => '12345', :title => 'Just the title', :body => 'The body of the post!')
|
73
|
+
user.create_post_for :blog => '12345', :title => 'Just the title', :body => 'The body of the post!'
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#get' do
|
79
|
+
|
80
|
+
it "should get all the blogs from user" do
|
81
|
+
mock_sites(batman)
|
82
|
+
batman.get(batman.get_all_sites_uri).should == 'response'
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
module FakerResponse
|
3
|
+
def blogs_response
|
4
|
+
{
|
5
|
+
"rsp" => {
|
6
|
+
"site" => [
|
7
|
+
{ "id" => "2165389", "name" => "testandoreblog's posterous" }
|
8
|
+
] }
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def mock_sites(user)
|
13
|
+
HTTParty.should_receive(:get).with(user.get_all_sites_uri,
|
14
|
+
:basic_auth => { :username => user.email, :password => user.password
|
15
|
+
}).and_return('response')
|
16
|
+
end
|
17
|
+
|
18
|
+
def mock_posts(user, blog_id)
|
19
|
+
HTTParty.should_receive(:get).with(user.read_posts_uri,
|
20
|
+
:basic_auth => { :username => user.email, :password => user.password},
|
21
|
+
:site_id => blog_id
|
22
|
+
).and_return('response')
|
23
|
+
end
|
24
|
+
|
25
|
+
def mock_tags(user, blog_id)
|
26
|
+
HTTParty.should_receive(:get).with(user.get_tags_uri,
|
27
|
+
:basic_auth => { :username => user.email, :password => user.password},
|
28
|
+
:site_id => blog_id
|
29
|
+
).and_return('response')
|
30
|
+
end
|
31
|
+
|
32
|
+
def mock_create_post(user, options)
|
33
|
+
blog = options[:blog]
|
34
|
+
options.delete(:blog)
|
35
|
+
HTTParty.should_receive(:post).with(user.new_post_uri,
|
36
|
+
{:basic_auth => { :username => user.email, :password => user.password},
|
37
|
+
:site_id => blog,
|
38
|
+
:title => nil,
|
39
|
+
:body => nil }.merge(options)
|
40
|
+
).and_return('response')
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: posterous_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Tomas D'Stefano
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-20 00:00:00 -02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: httparty
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - "="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 6
|
30
|
+
- 1
|
31
|
+
version: 0.6.1
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: jeweler
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: httparty
|
50
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 6
|
58
|
+
- 1
|
59
|
+
version: 0.6.1
|
60
|
+
type: :runtime
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: *id003
|
63
|
+
description: ""
|
64
|
+
email: tomasdestefi@gmail.com
|
65
|
+
executables: []
|
66
|
+
|
67
|
+
extensions: []
|
68
|
+
|
69
|
+
extra_rdoc_files: []
|
70
|
+
|
71
|
+
files:
|
72
|
+
- .infinity_test
|
73
|
+
- .rspec
|
74
|
+
- .rvmrc
|
75
|
+
- Gemfile
|
76
|
+
- Gemfile.lock
|
77
|
+
- Rakefile
|
78
|
+
- Readme.markdown
|
79
|
+
- VERSION.yml
|
80
|
+
- lib/posterous_api.rb
|
81
|
+
- lib/posterous_api/base_uri.rb
|
82
|
+
- lib/posterous_api/connection.rb
|
83
|
+
- lib/posterous_api/new_api.rb
|
84
|
+
- lib/posterous_api/old_api.rb
|
85
|
+
- lib/posterous_api/user.rb
|
86
|
+
- posterous_api.gemspec
|
87
|
+
- spec/posterous_api/base_uri_spec.rb
|
88
|
+
- spec/posterous_api/connection_spec.rb
|
89
|
+
- spec/posterous_api/new_api_spec.rb
|
90
|
+
- spec/posterous_api/old_api_spec.rb
|
91
|
+
- spec/posterous_api/posterous_api_spec.rb
|
92
|
+
- spec/posterous_api/user_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- spec/support/faker_response.rb
|
95
|
+
has_rdoc: true
|
96
|
+
homepage: http://github.com/tomas-stefano/posterous_api
|
97
|
+
licenses: []
|
98
|
+
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.3.7
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: ""
|
127
|
+
test_files:
|
128
|
+
- spec/posterous_api/base_uri_spec.rb
|
129
|
+
- spec/posterous_api/connection_spec.rb
|
130
|
+
- spec/posterous_api/new_api_spec.rb
|
131
|
+
- spec/posterous_api/old_api_spec.rb
|
132
|
+
- spec/posterous_api/posterous_api_spec.rb
|
133
|
+
- spec/posterous_api/user_spec.rb
|
134
|
+
- spec/spec_helper.rb
|
135
|
+
- spec/support/faker_response.rb
|