shixian_weibo_2 0.1.7

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.
@@ -0,0 +1,123 @@
1
+ module WeiboOAuth2
2
+ module Api
3
+ module V2
4
+ class Place < Base
5
+ #read interfaces
6
+ def public_timeline(opt={})
7
+ hashie get("place/public_timeline.json", :params => opt)
8
+ end
9
+
10
+ def friends_timeline(opt={})
11
+ hashie get("place/friends_timeline.json", :params => opt)
12
+ end
13
+
14
+ def user_timeline(uid, opt={})
15
+ hashie get("place/user_timeline.json", :params => {:uid => uid}.merge(opt))
16
+ end
17
+
18
+ def poi_timeline(poiid, opt={})
19
+ hashie get("place/poi_timeline.json", :params => {:poiid => poiid}.merge(opt))
20
+ end
21
+
22
+ def nearby_timeline(lat, long, opt={})
23
+ hashie get("place/nearby_timeline.json", :params => {:lat => lat, :long => long}.merge(opt))
24
+ end
25
+
26
+ def statuses_show(id, opt={})
27
+ hashie get("place/statuses/show.json", :params => {:id => id}.merge(opt))
28
+ end
29
+
30
+ def users_show(uid, opt={})
31
+ hashie get("place/users/show.json", :params => {:uid => uid}.merge(opt))
32
+ end
33
+
34
+ def users_checkins(uid, opt={})
35
+ hashie get("place/users/checkins.json", :params => {:uid => uid}.merge(opt))
36
+ end
37
+
38
+ def users_photos(uid, opt={})
39
+ hashie get("place/users/photos.json", :params => {:uid => uid}.merge(opt))
40
+ end
41
+
42
+ def users_tips(uid, opt={})
43
+ hashie get("place/users/tips.json", :params => {:uid => uid}.merge(opt))
44
+ end
45
+
46
+ def users_todos(uid, opt={})
47
+ hashie get("place/users/todos.json", :params => {:uid => uid}.merge(opt))
48
+ end
49
+
50
+ def pois_show(poiid, opt={})
51
+ hashie get("place/pois/show.json", :params => {:poiid => poiid}.merge(opt))
52
+ end
53
+
54
+ def pois_users(poiid, opt={})
55
+ hashie get("place/pois/users.json", :params => {:poiid => poiid}.merge(opt))
56
+ end
57
+
58
+ def pois_tips(poiid, opt={})
59
+ hashie get("place/pois/tips.json", :params => {:poiid => poiid}.merge(opt))
60
+ end
61
+
62
+ def pois_photos(poiid, opt={})
63
+ hashie get("place/pois/photos.json", :params => {:poiid => poiid}.merge(opt))
64
+ end
65
+
66
+ def pois_search(keyword, opt={})
67
+ hashie get("place/pois/search.json", :params => {:keyword => keyword}.merge(opt))
68
+ end
69
+
70
+ def pois_category(opt={})
71
+ hashie get("place/pois/category.json", :params => opt)
72
+ end
73
+
74
+ def nearby_pois(lat, long, opt={})
75
+ hashie get("place/nearby/pois.json", :params => {:lat => lat, :long => long}.merge(opt))
76
+ end
77
+
78
+ def nearby_users(lat, long, opt={})
79
+ hashie get("place/nearby/users.json", :params => {:lat => lat, :long => long}.merge(opt))
80
+ end
81
+
82
+ def nearby_photos(lat, long, opt={})
83
+ hashie get("place/nearby/photos.json", :params => {:lat => lat, :long => long}.merge(opt))
84
+ end
85
+
86
+ def nearby_users_list(lat, long, opt={})
87
+ hashie get("place/nearby_users/list.json", :params => {:lat => lat, :long => long}.merge(opt))
88
+ end
89
+
90
+
91
+ #write interfaces
92
+ def pois_create(title, lat, long, city, opt={})
93
+ hashie post("place/pois/create.json", :params => {:title => title, :lat => lat, :long => long, :city => city}.merge(opt))
94
+ end
95
+
96
+ def pois_add_checkin(poiid, status, opt={})
97
+ hashie post("place/pois/add_checkin.json", :params => {:poiid => poiid, :status => status}.merge(opt))
98
+ end
99
+
100
+ def pois_add_photo(poiid, status, pic, opt={})
101
+ multipart = build_multipart_bodies({"poiid" => poiid, "status" => status, "pic" => pic}, opt)
102
+ hashie post("place/pois/add_photo.json", :headers => multipart[:headers], :body => multipart[:body])
103
+ end
104
+
105
+ def pois_add_tip(poiid, status, opt={})
106
+ hashie post("place/pois/add_tip.json", :params => {:poiid => poiid, :status => status}.merge(opt))
107
+ end
108
+
109
+ def pois_add_todo(poiid, status, opt={})
110
+ hashie post("place/pois/create.json", :params => {:poiid => poiid, :status => status}.merge(opt))
111
+ end
112
+
113
+ def nearby_users_create(lat, long, opt={})
114
+ hashie post("place/nearby_users/create.json", :params => {:lat => lat, :long => long}.merge(opt))
115
+ end
116
+
117
+ def nearby_users_destroy(opt={})
118
+ hashie post("place/nearby_users/destroy.json", :params => opt)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,14 @@
1
+ module WeiboOAuth2
2
+ module Api
3
+ module V2
4
+ class Register < Base
5
+
6
+ #read interfaces
7
+ def verify_nickname(nickname, opt={})
8
+ hashie get("register/verify_nickname.json", :params => {:nickname => CGI::escape(nickname)}.merge(opt))
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ require 'rest_client'
2
+
3
+ module WeiboOAuth2
4
+ module Api
5
+ module V2
6
+ class Remind < Base
7
+
8
+ #read interfaces
9
+
10
+ #http://open.weibo.com/wiki/2/remind/unread_count
11
+ #this interface is different, it has a different domain, and frequently changed, it should be usually called from javascript. so I removed all parameters.
12
+ def unread_count()
13
+ hashie RestClient.get "https://rm.api.weibo.com/2/remind/unread_count.json?access_token=#{@access_token.token}"
14
+ end
15
+
16
+ #write interfaces
17
+ def set_count()
18
+ hashie RestClient.post "https://rm.api.weibo.com/2/remind/set_count.json", :access_token => access_token.token
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ module WeiboOAuth2
2
+ module Api
3
+ module V2
4
+ class Search < Base
5
+
6
+ #read interfaces
7
+ def suggestions_users(q, opt={})
8
+ hashie get("search/suggestions/users.json", :params => {:q => CGI::escape(q)}.merge(opt))
9
+ end
10
+
11
+ def suggestions_statuses(q, opt={})
12
+ hashie get("search/suggestions/statuses.json", :params => {:q => CGI::escape(q)}.merge(opt))
13
+ end
14
+
15
+ def suggestions_schools(q, opt={})
16
+ hashie get("search/suggestions/schools.json", :params => {:q => CGI::escape(q)}.merge(opt))
17
+ end
18
+
19
+ def suggestions_companies(q, opt={})
20
+ hashie get("search/suggestions/companies.json", :params => {:q => CGI::escape(q)}.merge(opt))
21
+ end
22
+
23
+ def suggestions_apps(q, opt={})
24
+ hashie get("search/suggestions/apps.json", :params => {:q => CGI::escape(q)}.merge(opt))
25
+ end
26
+
27
+ def suggestions_at_users(q, type, opt={})
28
+ hashie get("search/suggestions/at_users.json", :params => {:q => CGI::escape(q), :type => type}.merge(opt))
29
+ end
30
+
31
+ def topics(q, opt={})
32
+ hashie get("search/topics.json", :params => {:q => CGI::escape(q)}.merge(opt))
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,49 @@
1
+ module WeiboOAuth2
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,121 @@
1
+ module WeiboOAuth2
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 timeline_batch(opt={})
32
+ hashie get("statuses/timeline_batch.json", :params => opt)
33
+ end
34
+
35
+ def repost_timeline(id, opt={})
36
+ hashie get("statuses/repost_timeline.json", :params => {:id => id}.merge(opt))
37
+ end
38
+
39
+ def repost_timeline_ids(id, opt={})
40
+ hashie get("statuses/repost_timeline/ids.json", :params => {:id => id}.merge(opt))
41
+ end
42
+
43
+ def repost_by_me(opt={})
44
+ hashie get("statuses/repost_by_me.json", :params => opt)
45
+ end
46
+
47
+ def mentions(opt={})
48
+ hashie get("statuses/mentions.json", :params => opt)
49
+ end
50
+
51
+ def mentions_ids(opt={})
52
+ hashie get("statuses/mentions/ids.json", :params => opt)
53
+ end
54
+
55
+ def bilateral_timeline(opt={})
56
+ hashie get("statuses/bilateral_timeline.json", :params => opt)
57
+ end
58
+
59
+ def show(opt={})
60
+ hashie get("statuses/show.json", :params => opt)
61
+ end
62
+
63
+ def querymid(opt={})
64
+ hashie get("statuses/querymid.json", :params => opt)
65
+ end
66
+
67
+ def queryid(opt={})
68
+ hashie get("statuses/queryid.json", :params => opt)
69
+ end
70
+
71
+ def hot_repost_daily(opt={})
72
+ hashie get("statuses/hot/repost_daily.json", :params => opt)
73
+ end
74
+
75
+ def hot_repost_weekly(opt={})
76
+ hashie get("statuses/hot/repost_weekly.json", :params => opt)
77
+ end
78
+
79
+ def hot_comments_daily(opt={})
80
+ hashie get("statuses/hot/comments_daily.json", :params => opt)
81
+ end
82
+
83
+ def hot_comments_weekly(opt={})
84
+ hashie get("statuses/hot/comments_weekly.json", :params => opt)
85
+ end
86
+
87
+ def count(opt={})
88
+ hashie get("statuses/count.json", :params => opt)
89
+ end
90
+
91
+ #write interfaces
92
+ def repost(id, opt={})
93
+ hashie post("statuses/repost.json", :params => {"id" => id}.merge(opt))
94
+ end
95
+
96
+ def destroy(id)
97
+ hashie post("statuses/destroy.json", :params => {"id" => id})
98
+ end
99
+
100
+ def update(status, opt={})
101
+ hashie post("statuses/update.json", :params => {"status" => status}.merge(opt))
102
+ end
103
+
104
+
105
+ def upload(status, pic, opt={})
106
+ multipart = build_multipart_bodies({"status" => status, "pic" => pic}, opt)
107
+ hashie post("statuses/upload.json", :headers => multipart[:headers], :body => multipart[:body])
108
+ end
109
+
110
+ def upload_url_text(opt={})
111
+ hashie post("statuses/upload_url_text.json", :params => opt)
112
+ end
113
+
114
+ def emotions(opt={})
115
+ hashie get("emotions.json", :params => opt)
116
+ end
117
+
118
+ end
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,45 @@
1
+ module WeiboOAuth2
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 WeiboOAuth2
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 WeiboOAuth2
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 WeiboOAuth2
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,6 @@
1
+ require 'oauth2'
2
+
3
+ module WeiboOAuth2
4
+ class Base
5
+ end
6
+ end
@@ -0,0 +1,138 @@
1
+ require 'oauth2'
2
+
3
+ module WeiboOAuth2
4
+ class Client < OAuth2::Client
5
+
6
+ attr_accessor :access_token
7
+
8
+ def initialize(client_id='', client_secret='', opts={}, &block)
9
+ client_id = WeiboOAuth2::Config.api_key if client_id.empty?
10
+ client_secret = WeiboOAuth2::Config.api_secret if client_secret.empty?
11
+ super
12
+ @site = "https://api.weibo.com/2/"
13
+ @options[:authorize_url] = '/oauth2/authorize'
14
+ @options[:token_url] = '/oauth2/access_token'
15
+ end
16
+
17
+ def self.from_code(code, opts={}, &block)
18
+ client = self.new(opts, &block)
19
+ client.auth_code.get_token(code)
20
+
21
+ client
22
+ end
23
+
24
+ def self.from_hash(hash, opts={}, &block)
25
+ client = self.new(opts, &block)
26
+ client.get_token_from_hash(hash)
27
+
28
+ client
29
+ end
30
+
31
+ def request(verb, url, opts = {})
32
+ super
33
+ rescue OAuth2::Error => e
34
+ error_code = e.response.parsed["error_code"]
35
+ case error_code
36
+ when 21315, 21316, 21317, 21327, 21332
37
+ raise WeiboOAuth2::Errors::UnauthorizedError.new(e.response.parsed)
38
+ when 10022, 10023, 10024, 20016, 20505
39
+ raise WeiboOAuth2::Errors::RateLimitedError.new(e.response.parsed)
40
+ when 10013, 10014, 20508, 21301
41
+ raise WeiboOAuth2::Errors::PermissionError.new(e.response.parsed)
42
+ else
43
+ raise WeiboOAuth2::Errors::GeneralError.new(e.response.parsed)
44
+ end
45
+ end
46
+
47
+ def authorize_url(params={})
48
+ params[:client_id] = @id unless params[:client_id]
49
+ params[:response_type] = 'code' unless params[:response_type]
50
+ params[:redirect_uri] = WeiboOAuth2::Config.redirect_uri unless params[:redirect_uri]
51
+ super
52
+ end
53
+
54
+ def get_token(params, access_token_opts={})
55
+ params = params.merge({:parse => :json})
56
+ access_token_opts = access_token_opts.merge({:header_format => "OAuth2 %s", :param_name => "access_token"})
57
+ super
58
+ end
59
+
60
+ def get_and_restore_token(params, access_token_opts={})
61
+ @access_token = get_token(params, access_token_opts={})
62
+ end
63
+
64
+ def get_token_from_hash(hash)
65
+ access_token = hash.delete(:access_token) || hash.delete('access_token')
66
+ @access_token = WeiboOAuth2::AccessToken.new( self, access_token, hash.merge(:header_format => 'OAuth2 %s', :param_name => 'access_token') )
67
+ end
68
+
69
+ def authorized?
70
+ @access_token && @access_token.validated?
71
+ end
72
+
73
+ def users
74
+ @users ||= WeiboOAuth2::Api::V2::Users.new(@access_token) if @access_token
75
+ end
76
+
77
+ def statuses
78
+ @statues ||= WeiboOAuth2::Api::V2::Statuses.new(@access_token) if @access_token
79
+ end
80
+
81
+ def comments
82
+ @comments ||= WeiboOAuth2::Api::V2::Comments.new(@access_token) if @access_token
83
+ end
84
+
85
+ def friendships
86
+ @friendships ||= WeiboOAuth2::Api::V2::Friendships.new(@access_token) if @access_token
87
+ end
88
+
89
+ def account
90
+ @account ||= WeiboOAuth2::Api::V2::Account.new(@access_token) if @access_token
91
+ end
92
+
93
+ def favorites
94
+ @favorites ||= WeiboOAuth2::Api::V2::Favorites.new(@access_token) if @access_token
95
+ end
96
+
97
+ def trends
98
+ @trends ||= WeiboOAuth2::Api::V2::Trends.new(@access_token) if @access_token
99
+ end
100
+
101
+ def tags
102
+ @tags ||= WeiboOAuth2::Api::V2::Tags.new(@access_token) if @access_token
103
+ end
104
+
105
+ def register
106
+ @register ||= WeiboOAuth2::Api::V2::Register.new(@access_token) if @access_token
107
+ end
108
+
109
+ def search
110
+ @search ||= WeiboOAuth2::Api::V2::Search.new(@access_token) if @access_token
111
+ end
112
+
113
+ def short_url
114
+ @short_url ||= WeiboOAuth2::Api::V2::ShortUrl.new(@access_token) if @access_token
115
+ end
116
+
117
+ def suggestions
118
+ @suggestions ||= WeiboOAuth2::Api::V2::Suggestions.new(@access_token) if @access_token
119
+ end
120
+
121
+ def remind
122
+ @remind ||= WeiboOAuth2::Api::V2::Remind.new(@access_token) if @access_token
123
+ end
124
+
125
+ def auth_code
126
+ @auth_code ||= WeiboOAuth2::Strategy::AuthCode.new(self)
127
+ end
128
+
129
+ def place
130
+ @place ||= WeiboOAuth2::Api::V2::Place.new(@access_token) if @access_token
131
+ end
132
+
133
+ def location
134
+ @location ||= WeiboOAuth2::Api::V2::Location.new(@access_token) if @access_token
135
+ end
136
+
137
+ end
138
+ end