weibo_focus 1.0.8 → 1.0.9
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/.gitignore +17 -0
- data/example/.sass-cache/0d4365dd4f25a1b2574fe0fe2e903692b6df08f1/screen.sassc +0 -0
- data/example/.sass-cache/80b2331c862c6e430e0af18caf62d12d982610f0/screen.sassc +0 -0
- data/example/.sass-cache/faf9751221db0b5ce76d45351b9591c3bfc59441/screen.sassc +0 -0
- data/example/Gemfile +7 -0
- data/example/Gemfile~ +7 -0
- data/example/config.ru +2 -0
- data/example/example.rb +84 -0
- data/example/example.rb~ +84 -0
- data/example/views/index.haml +42 -0
- data/example/views/layout.haml +12 -0
- data/example/views/screen.sass +13 -0
- data/example/weibo.rb +7 -0
- data/lib/weibo_focus/access_token.rb +20 -0
- data/lib/weibo_focus/api/v2/account.rb +31 -0
- data/lib/weibo_focus/api/v2/base.rb +64 -0
- data/lib/weibo_focus/api/v2/comments.rb +51 -0
- data/lib/weibo_focus/api/v2/common.rb +28 -0
- data/lib/weibo_focus/api/v2/favorites.rb +59 -0
- data/lib/weibo_focus/api/v2/friendships.rb +64 -0
- data/lib/weibo_focus/api/v2/location.rb +83 -0
- data/lib/weibo_focus/api/v2/notification.rb +12 -0
- data/lib/weibo_focus/api/v2/place.rb +123 -0
- data/lib/weibo_focus/api/v2/register.rb +14 -0
- data/lib/weibo_focus/api/v2/remind.rb +23 -0
- data/lib/weibo_focus/api/v2/search.rb +38 -0
- data/lib/weibo_focus/api/v2/short_url.rb +49 -0
- data/lib/weibo_focus/api/v2/statuses.rb +117 -0
- data/lib/weibo_focus/api/v2/suggestions.rb +45 -0
- data/lib/weibo_focus/api/v2/tags.rb +36 -0
- data/lib/weibo_focus/api/v2/trends.rb +39 -0
- data/lib/weibo_focus/api/v2/users.rb +30 -0
- data/lib/weibo_focus/base.rb +6 -0
- data/lib/weibo_focus/client.rb +102 -0
- data/lib/weibo_focus/config.rb +28 -4
- data/lib/weibo_focus/config.rb~ +30 -0
- data/lib/weibo_focus/oauth.rb +6 -0
- data/lib/weibo_focus/strategy/auth_code.rb +12 -0
- data/lib/weibo_focus/version.rb +1 -1
- data/lib/weibo_focus/version.rb~ +3 -0
- data/lib/weibo_focus.rb +20 -9
- data/lib/weibo_focus.rb~ +51 -0
- data/spec/weibo_spec.rb +44 -0
- data/weibo_focus.gemspec +11 -13
- data/weibo_focus.gemspec~ +25 -0
- metadata +128 -6
@@ -0,0 +1,49 @@
|
|
1
|
+
module Weibo
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class ShortUrl < Base
|
5
|
+
#read interfaces
|
6
|
+
def shorten(url_long, opt={})
|
7
|
+
hashie get("short_url/shorten.json", :params => {:url_long => url_long}.merge(opt))
|
8
|
+
end
|
9
|
+
|
10
|
+
def expand(url_short, opt={})
|
11
|
+
hashie get("short_url/expand.json", :params => {:url_short => url_short}.merge(opt))
|
12
|
+
end
|
13
|
+
|
14
|
+
def clicks(url_short, opt={})
|
15
|
+
hashie get("short_url/clicks.json", :params => {:url_short => url_short}.merge(opt))
|
16
|
+
end
|
17
|
+
|
18
|
+
def referers(url_short, opt={})
|
19
|
+
hashie get("short_url/referers.json", :params => {:url_short => url_short}.merge(opt))
|
20
|
+
end
|
21
|
+
|
22
|
+
def locations(url_short, opt={})
|
23
|
+
hashie get("short_url/locations.json", :params => {:url_short => url_short}.merge(opt))
|
24
|
+
end
|
25
|
+
|
26
|
+
def share_counts(url_short, opt={})
|
27
|
+
hashie get("short_url/share/counts.json", :params => {:url_short => url_short}.merge(opt))
|
28
|
+
end
|
29
|
+
|
30
|
+
def share_statuses(url_short, opt={})
|
31
|
+
hashie get("short_url/share/statuses.json", :params => {:url_short => url_short}.merge(opt))
|
32
|
+
end
|
33
|
+
|
34
|
+
def comment_counts(url_short, opt={})
|
35
|
+
hashie get("short_url/comment/counts.json", :params => {:url_short => url_short}.merge(opt))
|
36
|
+
end
|
37
|
+
|
38
|
+
def comment_comments(url_short, opt={})
|
39
|
+
hashie get("short_url/comment/comments.json", :params => {:url_short => url_short}.merge(opt))
|
40
|
+
end
|
41
|
+
|
42
|
+
def info(url_short, opt={})
|
43
|
+
hashie get("short_url/info.json", :params => {:url_short => url_short}.merge(opt))
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module Weibo
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class Statuses < Base
|
5
|
+
|
6
|
+
#read interfaces
|
7
|
+
def public_timeline(opt={})
|
8
|
+
hashie get("statuses/public_timeline.json", :params => opt)
|
9
|
+
end
|
10
|
+
|
11
|
+
def friends_timeline(opt={})
|
12
|
+
hashie get("statuses/friends_timeline.json", :params => opt)
|
13
|
+
end
|
14
|
+
|
15
|
+
def home_timeline(opt={})
|
16
|
+
hashie get("statuses/home_timeline.json", :params => opt)
|
17
|
+
end
|
18
|
+
|
19
|
+
def friends_timeline_ids(opt={})
|
20
|
+
hashie get("statuses/friends_timeline/ids.json", :params => opt)
|
21
|
+
end
|
22
|
+
|
23
|
+
def user_timeline(opt={})
|
24
|
+
hashie get("statuses/user_timeline.json", :params => opt)
|
25
|
+
end
|
26
|
+
|
27
|
+
def user_timeline_ids(opt={})
|
28
|
+
hashie get("statuses/user_timeline/ids.json", :params => opt)
|
29
|
+
end
|
30
|
+
|
31
|
+
def repost_timeline(id, opt={})
|
32
|
+
hashie get("statuses/repost_timeline.json", :params => {:id => id}.merge(opt))
|
33
|
+
end
|
34
|
+
|
35
|
+
def repost_timeline_ids(id, opt={})
|
36
|
+
hashie get("statuses/repost_timeline/ids.json", :params => {:id => id}.merge(opt))
|
37
|
+
end
|
38
|
+
|
39
|
+
def repost_by_me(opt={})
|
40
|
+
hashie get("statuses/repost_by_me.json", :params => opt)
|
41
|
+
end
|
42
|
+
|
43
|
+
def mentions(opt={})
|
44
|
+
hashie get("statuses/mentions.json", :params => opt)
|
45
|
+
end
|
46
|
+
|
47
|
+
def mentions_ids(opt={})
|
48
|
+
hashie get("statuses/mentions/ids.json", :params => opt)
|
49
|
+
end
|
50
|
+
|
51
|
+
def bilateral_timeline(opt={})
|
52
|
+
hashie get("statuses/bilateral_timeline.json", :params => opt)
|
53
|
+
end
|
54
|
+
|
55
|
+
def show(opt={})
|
56
|
+
hashie get("statuses/show.json", :params => opt)
|
57
|
+
end
|
58
|
+
|
59
|
+
def querymid(opt={})
|
60
|
+
hashie get("statuses/querymid.json", :params => opt)
|
61
|
+
end
|
62
|
+
|
63
|
+
def queryid(opt={})
|
64
|
+
hashie get("statuses/queryid.json", :params => opt)
|
65
|
+
end
|
66
|
+
|
67
|
+
def hot_repost_daily(opt={})
|
68
|
+
hashie get("statuses/hot/repost_daily.json", :params => opt)
|
69
|
+
end
|
70
|
+
|
71
|
+
def hot_repost_weekly(opt={})
|
72
|
+
hashie get("statuses/hot/repost_weekly.json", :params => opt)
|
73
|
+
end
|
74
|
+
|
75
|
+
def hot_comments_daily(opt={})
|
76
|
+
hashie get("statuses/hot/comments_daily.json", :params => opt)
|
77
|
+
end
|
78
|
+
|
79
|
+
def hot_comments_weekly(opt={})
|
80
|
+
hashie get("statuses/hot/comments_weekly.json", :params => opt)
|
81
|
+
end
|
82
|
+
|
83
|
+
def count(opt={})
|
84
|
+
hashie get("statuses/count.json", :params => opt)
|
85
|
+
end
|
86
|
+
|
87
|
+
#write interfaces
|
88
|
+
def repost(id, opt={})
|
89
|
+
hashie post("statuses/repost.json", :params => {"id" => id}.merge(opt))
|
90
|
+
end
|
91
|
+
|
92
|
+
def destroy(id)
|
93
|
+
hashie post("statuses/destroy.json", :params => {"id" => id})
|
94
|
+
end
|
95
|
+
|
96
|
+
def update(status, opt={})
|
97
|
+
hashie post("statuses/update.json", :params => {"status" => status}.merge(opt))
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def upload(status, pic, opt={})
|
102
|
+
multipart = Base.build_multipart_bodies({"status" => status, "pic" => pic}.merge(opt))
|
103
|
+
hashie post("statuses/upload.json", :headers => multipart[:headers], :body => multipart[:body])
|
104
|
+
end
|
105
|
+
|
106
|
+
def upload_url_text(opt={})
|
107
|
+
hashie post("statuses/upload_url_text.json", :params => opt)
|
108
|
+
end
|
109
|
+
|
110
|
+
def emotions(opt={})
|
111
|
+
hashie get("emotions.json", :params => opt)
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Weibo
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class Suggestions < Base
|
5
|
+
|
6
|
+
#read interfaces
|
7
|
+
def users_hot(opt={})
|
8
|
+
hashie get("suggestions/users/hot.json", :params => opt)
|
9
|
+
end
|
10
|
+
|
11
|
+
def users_may_interested(opt={})
|
12
|
+
hashie get("suggestions/users/may_interested.json", :params => opt)
|
13
|
+
end
|
14
|
+
|
15
|
+
def users_by_status(content, opt={})
|
16
|
+
hashie get("suggestions/users/by_status.json", :params => {:content => CGI::escape(content)}.merge(opt))
|
17
|
+
end
|
18
|
+
|
19
|
+
#http://open.weibo.com/wiki/2/suggestions/statuses/hot
|
20
|
+
def statuses_hot(type, is_pic, opt={})
|
21
|
+
hashie get("suggestions/statuses/hot.json", :params => {:type => type, :is_pic => is_pic}.merge(opt))
|
22
|
+
end
|
23
|
+
|
24
|
+
#http://open.weibo.com/wiki/2/suggestions/statuses/reorder
|
25
|
+
def statuses_reorder(section, opt={})
|
26
|
+
hashie get("suggestions/statuses/reorder.json", :params => {:section => section}.merge(opt))
|
27
|
+
end
|
28
|
+
|
29
|
+
def statuses_reorder_ids(section, opt={})
|
30
|
+
hashie get("suggestions/statuses/reorder/ids.json", :params => {:section => section}.merge(opt))
|
31
|
+
end
|
32
|
+
|
33
|
+
def favorites_hot(opt={})
|
34
|
+
hashie get("suggestions/favorites/hot.json", :params => opt)
|
35
|
+
end
|
36
|
+
|
37
|
+
#write interfaces
|
38
|
+
def users_not_interested(uid, opt={})
|
39
|
+
hashie post("suggestions/users/not_interested.json", :params => {:uid => uid}.merge(opt))
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Weibo
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class Tags < Base
|
5
|
+
|
6
|
+
#read interfaces
|
7
|
+
def tags(uid, opt={})
|
8
|
+
hashie get("tags.json", :params => {:uid => uid}.merge(opt))
|
9
|
+
end
|
10
|
+
|
11
|
+
def tags_batch(uids, opt={})
|
12
|
+
hashie get("tags/tags_batch.json", :params => {:uids => uids}.merge(opt))
|
13
|
+
end
|
14
|
+
|
15
|
+
def suggestions(opt={})
|
16
|
+
hashie get("tags/suggestions.json", :params => opt)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
#write interfaces
|
21
|
+
def create(tags, opt={})
|
22
|
+
hashie post("tags/create.json", :params => {:tags => tags}.merge(opt))
|
23
|
+
end
|
24
|
+
|
25
|
+
def destroy(tag_id, opt={})
|
26
|
+
hashie post("tags/destroy.json", :params => {:tag_id => tag_id}.merge(opt))
|
27
|
+
end
|
28
|
+
|
29
|
+
def destroy_batch(ids, opt={})
|
30
|
+
hashie post("tags/destroy_batch.json", :params => {:ids => ids}.merge(opt))
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Weibo
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class Trends < Base
|
5
|
+
|
6
|
+
#read interfaces
|
7
|
+
def trends(uid, opt={})
|
8
|
+
hashie get("trends.json", :params => {:uid => uid}.merge(opt))
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_follow(trend_name, opt={})
|
12
|
+
hashie get("trends/is_follow.json", :params => {:trend_name => CGI::escape(trend_name)}.merge(opt))
|
13
|
+
end
|
14
|
+
|
15
|
+
def hourly(opt={})
|
16
|
+
hashie get("trends/hourly.json", :params => opt)
|
17
|
+
end
|
18
|
+
|
19
|
+
def daily(opt={})
|
20
|
+
hashie get("trends/daily.json", :params => opt)
|
21
|
+
end
|
22
|
+
|
23
|
+
def weekly(opt={})
|
24
|
+
hashie get("trends/weekly.json", :params => opt)
|
25
|
+
end
|
26
|
+
|
27
|
+
#write interfaces
|
28
|
+
def follow(trend_name, opt={})
|
29
|
+
hashie post("trends/follow.json", :params => {:trend_name => trend_name}.merge(opt))
|
30
|
+
end
|
31
|
+
|
32
|
+
def destroy(trend_id, opt={})
|
33
|
+
hashie post("trends/destroy.json", :params => {:trend_id => trend_id}.merge(opt))
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Weibo
|
2
|
+
module Api
|
3
|
+
module V2
|
4
|
+
class Users < Base
|
5
|
+
|
6
|
+
def show(opt={})
|
7
|
+
hashie get("users/show.json", :params => opt)
|
8
|
+
end
|
9
|
+
|
10
|
+
def show_by_uid(uid)
|
11
|
+
show({"uid" => uid.to_i})
|
12
|
+
end
|
13
|
+
|
14
|
+
def show_by_screen_name(screen_name)
|
15
|
+
show({"screen_name" => screen_name})
|
16
|
+
end
|
17
|
+
|
18
|
+
def domain_show(domain, opt={})
|
19
|
+
hashie get("users/domain_show.json", :params => {:domain => domain}.merge(opt))
|
20
|
+
end
|
21
|
+
|
22
|
+
def counts(uids, opt={})
|
23
|
+
hashie get("users/counts.json", :params => {:uids => uids}.merge(opt))
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
|
3
|
+
module Weibo
|
4
|
+
class Client < OAuth2::Client
|
5
|
+
|
6
|
+
def initialize(client_id='', client_secret='', opts={}, &block)
|
7
|
+
client_id = Weibo::Config.api_key if client_id.empty?
|
8
|
+
client_secret = Weibo::Config.api_secret if client_secret.empty?
|
9
|
+
super
|
10
|
+
@site = "https://api.weibo.com/2/"
|
11
|
+
@options[:authorize_url] = '/oauth2/authorize'
|
12
|
+
@options[:token_url] = '/oauth2/access_token'
|
13
|
+
end
|
14
|
+
|
15
|
+
def authorize_url(params={})
|
16
|
+
params[:client_id] = @id unless params[:client_id]
|
17
|
+
params[:response_type] = 'code' unless params[:response_type]
|
18
|
+
params[:redirect_uri] = Weibo::Config.redirect_uri unless params[:redirect_uri]
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_token(params, access_token_opts={})
|
23
|
+
params = params.merge({:parse => :json})
|
24
|
+
access_token_opts = access_token_opts.merge({:header_format => "OAuth2 %s", :param_name => "access_token"})
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_and_restore_token(params, access_token_opts={})
|
29
|
+
@access_token = get_token(params, access_token_opts={})
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_token_from_hash(hash)
|
33
|
+
access_token = hash.delete(:access_token) || hash.delete('access_token')
|
34
|
+
opts = {:expires_at => (hash.delete(:expires_at) || hash.delete('expires_at')),
|
35
|
+
:header_format => "OAuth2 %s",
|
36
|
+
:param_name => "access_token"}
|
37
|
+
|
38
|
+
@access_token = Weibo::AccessToken.new(self, access_token, opts)
|
39
|
+
end
|
40
|
+
|
41
|
+
def authorized?
|
42
|
+
!!@access_token
|
43
|
+
end
|
44
|
+
|
45
|
+
def users
|
46
|
+
@users ||= Weibo::Api::V2::Users.new(@access_token) if @access_token
|
47
|
+
end
|
48
|
+
|
49
|
+
def statuses
|
50
|
+
@statues ||= Weibo::Api::V2::Statuses.new(@access_token) if @access_token
|
51
|
+
end
|
52
|
+
|
53
|
+
def comments
|
54
|
+
@comments ||= Weibo::Api::V2::Comments.new(@access_token) if @access_token
|
55
|
+
end
|
56
|
+
|
57
|
+
def friendships
|
58
|
+
@friendships ||= Weibo::Api::V2::Friendships.new(@access_token) if @access_token
|
59
|
+
end
|
60
|
+
|
61
|
+
def account
|
62
|
+
@account ||= Weibo::Api::V2::Account.new(@access_token) if @access_token
|
63
|
+
end
|
64
|
+
|
65
|
+
def favorites
|
66
|
+
@favorites ||= Weibo::Api::V2::Favorites.new(@access_token) if @access_token
|
67
|
+
end
|
68
|
+
|
69
|
+
def trends
|
70
|
+
@trends ||= Weibo::Api::V2::Trends.new(@access_token) if @access_token
|
71
|
+
end
|
72
|
+
|
73
|
+
def tags
|
74
|
+
@tags ||= Weibo::Api::V2::Tags.new(@access_token) if @access_token
|
75
|
+
end
|
76
|
+
|
77
|
+
def register
|
78
|
+
@register ||= Weibo::Api::V2::Register.new(@access_token) if @access_token
|
79
|
+
end
|
80
|
+
|
81
|
+
def search
|
82
|
+
@search ||= Weibo::Api::V2::Search.new(@access_token) if @access_token
|
83
|
+
end
|
84
|
+
|
85
|
+
def short_url
|
86
|
+
@short_url ||= Weibo::Api::V2::ShortUrl.new(@access_token) if @access_token
|
87
|
+
end
|
88
|
+
|
89
|
+
def suggestions
|
90
|
+
@suggestions ||= Weibo::Api::V2::Suggestions.new(@access_token) if @access_token
|
91
|
+
end
|
92
|
+
|
93
|
+
def remind
|
94
|
+
@remind ||= Weibo::Api::V2::Remind.new(@access_token) if @access_token
|
95
|
+
end
|
96
|
+
|
97
|
+
def auth_code
|
98
|
+
@auth_code ||= Weibo::Strategy::AuthCode.new(self)
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
data/lib/weibo_focus/config.rb
CHANGED
@@ -1,6 +1,30 @@
|
|
1
|
+
#encoding:utf-8
|
1
2
|
module Weibo
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Config
|
4
|
+
|
5
|
+
def self.api_key=(val)
|
6
|
+
@@api_key = val
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.api_key
|
10
|
+
@@api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.api_secret=(val)
|
14
|
+
@@api_secret = val
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.api_secret
|
18
|
+
@@api_secret
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.redirect_uri=(val)
|
22
|
+
@@redirect_uri = val
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.redirect_uri
|
26
|
+
@@redirect_uri
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
6
30
|
end
|