weibo_2 0.0.1

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,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,53 @@
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 expand(url_short, opt={})
15
+ hashie get("short_url/expand.json", :params => {:url_short => url_short}.merge(opt))
16
+ end
17
+
18
+ def clicks(url_short, opt={})
19
+ hashie get("short_url/expand.json", :params => {:url_short => url_short}.merge(opt))
20
+ end
21
+
22
+ def referers(url_short, opt={})
23
+ hashie get("short_url/expand.json", :params => {:url_short => url_short}.merge(opt))
24
+ end
25
+
26
+ def locations(url_short, opt={})
27
+ hashie get("short_url/expand.json", :params => {:url_short => url_short}.merge(opt))
28
+ end
29
+
30
+ def share_counts(url_short, opt={})
31
+ hashie get("short_url/share/counts.json", :params => {:url_short => url_short}.merge(opt))
32
+ end
33
+
34
+ def share_statuses(url_short, opt={})
35
+ hashie get("short_url/share/statuses.json", :params => {:url_short => url_short}.merge(opt))
36
+ end
37
+
38
+ def comment_counts(url_short, opt={})
39
+ hashie get("short_url/comment/counts.json", :params => {:url_short => url_short}.merge(opt))
40
+ end
41
+
42
+ def comment_comments(url_short, opt={})
43
+ hashie get("short_url/comment/comments.json", :params => {:url_short => url_short}.merge(opt))
44
+ end
45
+
46
+ def info(url_short, opt={})
47
+ hashie get("short_url/info.json", :params => {:url_short => url_short}.merge(opt))
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,117 @@
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 repost_timeline(opt={})
32
+ hashie get("statuses/repost_timeline.json", :params => opt)
33
+ end
34
+
35
+ def repost_timeline_ids(opt={})
36
+ hashie get("statuses/repost_timeline/ids.json", :params => 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 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,95 @@
1
+ require 'oauth2'
2
+
3
+ module WeiboOAuth2
4
+ class Client < OAuth2::Client
5
+
6
+ def initialize(client_id, client_secret, opts={}, &block)
7
+ super
8
+ @site = "https://api.weibo.com/2/"
9
+ @options[:authorize_url] = '/oauth2/authorize'
10
+ @options[:token_url] = '/oauth2/access_token'
11
+ end
12
+
13
+ def authorize_url(params=nil)
14
+ params[:client_id] = @id unless params[:client_id]
15
+ params[:response_type] = 'code' unless params[:response_type]
16
+ super
17
+ end
18
+
19
+ def get_token(params, access_token_opts={})
20
+ params = params.merge({:parse => :json})
21
+ access_token_opts = access_token_opts.merge({:header_format => "OAuth2 %s", :param_name => "access_token"})
22
+ super
23
+ end
24
+
25
+ def get_and_restore_token(params, access_token_opts={})
26
+ @access_token = get_token(params, access_token_opts={})
27
+ end
28
+
29
+ def get_token_from_hash(hash)
30
+ access_token = hash.delete('access_token') || hash.delete(:access_token)
31
+ opts = {:expires_at => hash["expires"] ||hash[:expires],
32
+ :header_format => "OAuth2 %s",
33
+ :param_name => "access_token"}
34
+
35
+ @access_token = OAuth2::AccessToken.new(self, access_token, opts)
36
+ end
37
+
38
+ def authorized?
39
+ !!@access_token
40
+ end
41
+
42
+ def users
43
+ @users ||= WeiboOAuth2::Api::V2::Users.new(@access_token) if @access_token
44
+ end
45
+
46
+ def statuses
47
+ @statues ||= WeiboOAuth2::Api::V2::Statuses.new(@access_token) if @access_token
48
+ end
49
+
50
+ def comments
51
+ @comments ||= WeiboOAuth2::Api::V2::Comments.new(@access_token) if @access_token
52
+ end
53
+
54
+ def friendships
55
+ @friendships ||= WeiboOAuth2::Api::V2::Friendships.new(@access_token) if @access_token
56
+ end
57
+
58
+ def account
59
+ @account ||= WeiboOAuth2::Api::V2::Account.new(@access_token) if @access_token
60
+ end
61
+
62
+ def favorites
63
+ @favorites ||= WeiboOAuth2::Api::V2::Favorites.new(@access_token) if @access_token
64
+ end
65
+
66
+ def trends
67
+ @trends ||= WeiboOAuth2::Api::V2::Trends.new(@access_token) if @access_token
68
+ end
69
+
70
+ def tags
71
+ @tags ||= WeiboOAuth2::Api::V2::Tags.new(@access_token) if @access_token
72
+ end
73
+
74
+ def register
75
+ @register ||= WeiboOAuth2::Api::V2::Register.new(@access_token) if @access_token
76
+ end
77
+
78
+ def search
79
+ @search ||= WeiboOAuth2::Api::V2::Search.new(@access_token) if @access_token
80
+ end
81
+
82
+ def suggestions
83
+ @suggestions ||= WeiboOAuth2::Api::V2::Suggestions.new(@access_token) if @access_token
84
+ end
85
+
86
+ def remind
87
+ @remind ||= WeiboOAuth2::Api::V2::Remind.new(@access_token) if @access_token
88
+ end
89
+
90
+ def auth_code
91
+ @auth_code ||= WeiboOAuth2::Strategy::AuthCode.new(self)
92
+ end
93
+
94
+ end
95
+ end
@@ -0,0 +1,6 @@
1
+ require 'oauth2'
2
+
3
+ module WeiboOAuth2
4
+ class Base
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ module WeiboOAuth2
2
+ module Strategy
3
+ class AuthCode < OAuth2::Strategy::AuthCode
4
+ def get_token(code, params={}, opts={})
5
+ params = {'grant_type' => 'authorization_code', 'code' => code}.merge(client_params).merge(params)
6
+ @client.get_and_restore_token(params, opts)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module WeiboOAuth2
2
+ VERSION = "0.0.1"
3
+ end
data/lib/weibo_2.rb ADDED
@@ -0,0 +1,17 @@
1
+ require "weibo_2/version"
2
+ require "weibo_2/base"
3
+ require "weibo_2/client"
4
+ require "weibo_2/api/v2/base.rb"
5
+ require "weibo_2/api/v2/statuses.rb"
6
+ require "weibo_2/api/v2/users.rb"
7
+ require "weibo_2/api/v2/comments.rb"
8
+ require "weibo_2/api/v2/friendships.rb"
9
+ require "weibo_2/api/v2/account.rb"
10
+ require "weibo_2/api/v2/favorites.rb"
11
+ require "weibo_2/api/v2/trends.rb"
12
+ require "weibo_2/api/v2/tags.rb"
13
+ require "weibo_2/api/v2/register.rb"
14
+ require "weibo_2/api/v2/search.rb"
15
+ require "weibo_2/api/v2/suggestions.rb"
16
+ require "weibo_2/api/v2/remind.rb"
17
+ require "weibo_2/strategy/auth_code.rb"
data/weibo_2.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/weibo_2/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["simsicon"]
6
+ gem.email = ["simsicon@gmail.com"]
7
+ gem.description = "A oauth2 gem for weibo"
8
+ gem.summary = "A oauth2 gem for weibo"
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "weibo_2"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = WeiboOAuth2::VERSION
17
+
18
+ gem.add_runtime_dependency 'oauth2', "~> 0.8.0"
19
+ gem.add_runtime_dependency 'hashie', "~> 1.2.0"
20
+ gem.add_runtime_dependency 'json' , "~> 1.7.3"
21
+ gem.add_runtime_dependency 'rest-client', "~> 1.6.7"
22
+ end