weibo 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +20 -1
- data/Rakefile +3 -0
- data/VERSION +1 -1
- data/example/example.rb +58 -0
- data/example/views/index.haml +32 -0
- data/example/views/layout.haml +10 -0
- data/example/views/screen.sass +24 -0
- data/lib/weibo/config.rb +8 -0
- data/weibo.gemspec +15 -2
- metadata +47 -3
data/README.rdoc
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
= weibo
|
2
2
|
|
3
|
-
|
3
|
+
One of the goals of this gem was to have the same syntax as the twitter gem wherever possible so that it would be easy to learn and use. Download the gem and give it a try. Also, I've put together a small demo of how you can use the weibo gem using sinatra.
|
4
|
+
|
5
|
+
|
6
|
+
gem install weibo
|
7
|
+
git clone git://github.com/ballantyne/weibo.git
|
8
|
+
cd weibo
|
9
|
+
ruby example/example.rb
|
10
|
+
open http://localhost:4567
|
11
|
+
|
12
|
+
Most of the 新浪微博 api is implemented by this gem. If I missed something, or Sina added something, please feel free to fork it and add it yourself. I will do my best to keep the gem up to date.
|
13
|
+
|
14
|
+
This gem was made in the process of creating {{叽叽喳喳.de}[http://jjzz.de], please take a moment and go and check out that project. I think that it is a very usful tool for interacting with 新浪微博.
|
4
15
|
|
5
16
|
== Note on Patches/Pull Requests
|
6
17
|
|
@@ -12,6 +23,14 @@ Description goes here.
|
|
12
23
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
24
|
* Send me a pull request. Bonus points for topic branches.
|
14
25
|
|
26
|
+
== Sites using the Weibo gem
|
27
|
+
* {叽叽喳喳.de}[http://jjzz.de]
|
28
|
+
|
29
|
+
(Please let me know if your site is using the gem so I can list you here)
|
30
|
+
|
31
|
+
== Special Thanks
|
32
|
+
This library was based upon and is an adaptation of John Nunemaker's twitter gem. It started as the twitter gem and has been adapted in the necessary ways to make it work with t.sina.com.cn's api. I'm using it with his blessing, thanks John.
|
33
|
+
|
15
34
|
== Copyright
|
16
35
|
|
17
36
|
Copyright (c) 2010 Scott Ballantyne. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -11,6 +11,9 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/ballantyne/weibo"
|
12
12
|
gem.authors = ["Scott Ballantyne"]
|
13
13
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
gem.add_dependency "oauth", "~> 0.4.1"
|
15
|
+
gem.add_dependency "hashie"
|
16
|
+
gem.add_dependency "httparty", ">= 0.5.2"
|
14
17
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
18
|
end
|
16
19
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/example/example.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
%w(rubygems sinatra haml sass oauth pp json).each { |dependency| require dependency }
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'weibo')
|
3
|
+
enable :sessions
|
4
|
+
Weibo::Config.api_key = "2942145647"
|
5
|
+
Weibo::Config.api_secret = "5cc0026c470a25a6070237e07ade5f27"
|
6
|
+
|
7
|
+
get '/' do
|
8
|
+
if session[:atoken]
|
9
|
+
redirect "/friends_timeline"
|
10
|
+
end
|
11
|
+
haml :index
|
12
|
+
end
|
13
|
+
|
14
|
+
get "/friends_timeline" do
|
15
|
+
oauth = Weibo::OAuth.new(Weibo::Config.api_key, Weibo::Config.api_secret)
|
16
|
+
oauth.authorize_from_access(session[:atoken], session[:asecret])
|
17
|
+
@timeline = Weibo::Base.new(oauth).friends_timeline
|
18
|
+
haml :index
|
19
|
+
end
|
20
|
+
|
21
|
+
get "/friends_timeline.json" do
|
22
|
+
content_type :json
|
23
|
+
oauth = Weibo::OAuth.new(Weibo::Config.api_key, Weibo::Config.api_secret)
|
24
|
+
oauth.authorize_from_access(session[:atoken], session[:asecret])
|
25
|
+
Weibo::Base.new(oauth).friends_timeline.to_json
|
26
|
+
end
|
27
|
+
|
28
|
+
post '/update' do
|
29
|
+
oauth = Weibo::OAuth.new(Weibo::Config.api_key, Weibo::Config.api_secret)
|
30
|
+
oauth.authorize_from_access(session[:atoken], session[:asecret])
|
31
|
+
Weibo::Base.new(oauth).update(params[:update])
|
32
|
+
redirect "/friends_timeline"
|
33
|
+
end
|
34
|
+
|
35
|
+
get '/connect' do
|
36
|
+
oauth = Weibo::OAuth.new(Weibo::Config.api_key, Weibo::Config.api_secret)
|
37
|
+
request_token = oauth.consumer.get_request_token
|
38
|
+
session[:rtoken], session[:rsecret] = request_token.token, request_token.secret
|
39
|
+
redirect "#{request_token.authorize_url}&oauth_callback=http://localhost:4567/callback"
|
40
|
+
end
|
41
|
+
|
42
|
+
get '/callback' do
|
43
|
+
oauth = Weibo::OAuth.new(Weibo::Config.api_key, Weibo::Config.api_secret)
|
44
|
+
oauth.authorize_from_request(session[:rtoken], session[:rsecret], params[:oauth_verifier])
|
45
|
+
session[:rtoken], session[:rsecret] = nil, nil
|
46
|
+
session[:atoken], session[:asecret] = oauth.access_token.token, oauth.access_token.secret
|
47
|
+
redirect "/"
|
48
|
+
end
|
49
|
+
|
50
|
+
get '/logout' do
|
51
|
+
session[:atoken], session[:asecret] = nil, nil
|
52
|
+
redirect "/"
|
53
|
+
end
|
54
|
+
|
55
|
+
get '/screen.css' do
|
56
|
+
content_type 'text/css'
|
57
|
+
sass :screen
|
58
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
-if session[:atoken]
|
2
|
+
%form{:action => "/update", :method => "POST"}
|
3
|
+
%textarea{:name => "update", :cols => "62", :rows => "5"}
|
4
|
+
%br
|
5
|
+
%input{:type => "submit", :value => "Send"}
|
6
|
+
%h1
|
7
|
+
friends_timeline
|
8
|
+
-@timeline.each do |weibo|
|
9
|
+
.weibo
|
10
|
+
%img{:src => weibo.user.profile_image_url, :class => "avatar" }
|
11
|
+
%span.text
|
12
|
+
%a{:href => "http://t.sina.com.cn/#{weibo.user.id}", :target => "_blank"}=weibo.user.screen_name
|
13
|
+
%span=weibo.text
|
14
|
+
%br
|
15
|
+
%span=weibo.created_at
|
16
|
+
-if weibo.thumbnail_pic
|
17
|
+
%br
|
18
|
+
%a{:href => weibo.original_pic, :target => "_blank"}
|
19
|
+
%img{:src => weibo.thumbnail_pic, :class => "thumbnail_pic", :alt => weibo.original_pic}
|
20
|
+
-if weibo.retweeted_status
|
21
|
+
.retweeted_status
|
22
|
+
%img{:src => weibo.retweeted_status.user.profile_image_url, :class => "avatar" }
|
23
|
+
%span.text
|
24
|
+
%a{:href => "http://t.sina.com.cn/#{weibo.user.id}", :target => "_blank"}=weibo.retweeted_status.user.screen_name
|
25
|
+
%span=weibo.retweeted_status.text
|
26
|
+
%br
|
27
|
+
%span=weibo.retweeted_status.created_at
|
28
|
+
-if weibo.retweeted_status.thumbnail_pic
|
29
|
+
%br
|
30
|
+
%a{:href => weibo.retweeted_status.original_pic, :target => "_blank"}
|
31
|
+
%img{:src => weibo.retweeted_status.thumbnail_pic, :class => "thumbnail_pic", :alt => weibo.retweeted_status.original_pic}
|
32
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
!!!
|
2
|
+
%html(xml:lang='en' lang='en' xmlns='http://www.w3.org/1999/xhtml')
|
3
|
+
%head
|
4
|
+
%meta(content='text/html;charset=UTF-8' http-equiv='content-type')
|
5
|
+
%title="weibo gem example"
|
6
|
+
%link{:href => "/screen.css", :rel =>"stylesheet", :type => "text/css", :media => "screen" }
|
7
|
+
%body
|
8
|
+
%h2="weibo gem example"
|
9
|
+
%a{:href => (session[:atoken] ? "/logout" : "/connect")}=(session[:atoken] ? "logout" : "connect")
|
10
|
+
= yield
|
@@ -0,0 +1,24 @@
|
|
1
|
+
.weibo
|
2
|
+
:float left
|
3
|
+
:clear left
|
4
|
+
:padding 10px
|
5
|
+
:width 483px
|
6
|
+
:border 1px solid #242424
|
7
|
+
:margin-bottom 10px
|
8
|
+
img.avatar
|
9
|
+
:float left
|
10
|
+
:display inline
|
11
|
+
span.text
|
12
|
+
:float left
|
13
|
+
:display inline
|
14
|
+
:width 400px
|
15
|
+
:margin-left 10px
|
16
|
+
img.thumbnail_pic
|
17
|
+
:clear left
|
18
|
+
:float left
|
19
|
+
.retweeted_status
|
20
|
+
:background #cccccc
|
21
|
+
:float left
|
22
|
+
:clear left
|
23
|
+
:padding 10px
|
24
|
+
:border 1px solid #242424
|
data/lib/weibo/config.rb
CHANGED
data/weibo.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{weibo}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Scott Ballantyne"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-22}
|
13
13
|
s.description = %q{this gem is an adaptation of John Nunemaker's Twitter gem. I modified it to make api integration for 新浪微博 (t.sina.com.cn) easier.}
|
14
14
|
s.email = %q{scott@ekohe.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -23,6 +23,10 @@ Gem::Specification.new do |s|
|
|
23
23
|
"README.rdoc",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
|
+
"example/example.rb",
|
27
|
+
"example/views/index.haml",
|
28
|
+
"example/views/layout.haml",
|
29
|
+
"example/views/screen.sass",
|
26
30
|
"lib/weibo.rb",
|
27
31
|
"lib/weibo/base.rb",
|
28
32
|
"lib/weibo/config.rb",
|
@@ -50,11 +54,20 @@ Gem::Specification.new do |s|
|
|
50
54
|
|
51
55
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
56
|
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<oauth>, ["~> 0.4.1"])
|
58
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
59
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
|
53
60
|
else
|
54
61
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
62
|
+
s.add_dependency(%q<oauth>, ["~> 0.4.1"])
|
63
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
64
|
+
s.add_dependency(%q<httparty>, [">= 0.5.2"])
|
55
65
|
end
|
56
66
|
else
|
57
67
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
68
|
+
s.add_dependency(%q<oauth>, ["~> 0.4.1"])
|
69
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
70
|
+
s.add_dependency(%q<httparty>, [">= 0.5.2"])
|
58
71
|
end
|
59
72
|
end
|
60
73
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Scott Ballantyne
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-22 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -29,6 +29,46 @@ dependencies:
|
|
29
29
|
version: "0"
|
30
30
|
type: :development
|
31
31
|
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: oauth
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
- 4
|
42
|
+
- 1
|
43
|
+
version: 0.4.1
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: hashie
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
type: :runtime
|
57
|
+
version_requirements: *id003
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: httparty
|
60
|
+
prerelease: false
|
61
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
- 5
|
68
|
+
- 2
|
69
|
+
version: 0.5.2
|
70
|
+
type: :runtime
|
71
|
+
version_requirements: *id004
|
32
72
|
description: "this gem is an adaptation of John Nunemaker's Twitter gem. I modified it to make api integration for \xE6\x96\xB0\xE6\xB5\xAA\xE5\xBE\xAE\xE5\x8D\x9A (t.sina.com.cn) easier."
|
33
73
|
email: scott@ekohe.com
|
34
74
|
executables: []
|
@@ -45,6 +85,10 @@ files:
|
|
45
85
|
- README.rdoc
|
46
86
|
- Rakefile
|
47
87
|
- VERSION
|
88
|
+
- example/example.rb
|
89
|
+
- example/views/index.haml
|
90
|
+
- example/views/layout.haml
|
91
|
+
- example/views/screen.sass
|
48
92
|
- lib/weibo.rb
|
49
93
|
- lib/weibo/base.rb
|
50
94
|
- lib/weibo/config.rb
|