weibo2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ module Weibo2
3
+ module Interface
4
+
5
+ # Suggestions API
6
+ #
7
+ # @see http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3_V2#.E6.8E.A8.E8.8D.90
8
+ class Suggestions < Base
9
+
10
+ # 返回系统推荐的热门用户列表
11
+ #
12
+ # @param [Hash] opts
13
+ # @option opts [String] :category 推荐分类,返回某一类别的推荐用户
14
+ #
15
+ # @see http://open.weibo.com/wiki/2/suggestions/users/hot
16
+ def users_hot(opts={})
17
+ get 'suggestions/users/hot.json', :params => opts
18
+ end
19
+
20
+ # 获取用户可能感兴趣的人
21
+ #
22
+ # @param [Hash] opts
23
+ # @option opts [int] :count 单页返回的记录条数,默认为10
24
+ # @option opts [int] :page 返回结果的页码,默认为1
25
+ #
26
+ # @see http://open.weibo.com/wiki/2/suggestions/users/may_interested
27
+ def users_may_interested(opts={})
28
+ get 'suggestions/users/may_interested.json', :params => opts
29
+ end
30
+
31
+ # 根据一段微博正文推荐相关微博用户
32
+ #
33
+ # @param [String] content 微博正文内容
34
+ # @param [Hash] opts
35
+ # @option opts [int] :num 返回结果数目,默认为10
36
+ #
37
+ # @see http://open.weibo.com/wiki/2/suggestions/users/by_status
38
+ def users_by_status(content, opts={})
39
+ get 'suggestions/users/by_status.json', :params => {:content => content}.merge(opts)
40
+ end
41
+
42
+ # 返回系统推荐的热门收藏
43
+ #
44
+ # @param [Hash] opts
45
+ # @option opts [int] :count 每页返回结果数,默认20
46
+ # @option opts [int] :page 返回页码,默认1
47
+ #
48
+ # @see http://open.weibo.com/wiki/2/suggestions/favorites/hot
49
+ def favorites_hot(opts={})
50
+ get 'suggestions/favorites/hot.json', :params => opts
51
+ end
52
+
53
+
54
+ #
55
+ # write
56
+ #
57
+
58
+ # 把某人标识为不感兴趣的人
59
+ #
60
+ # @param [int64] uid 不感兴趣的用户的UID
61
+ #
62
+ # @see http://open.weibo.com/wiki/2/suggestions/users/not_interested
63
+ def users_not_interested(uid)
64
+ post 'suggestions/users/not_interested.json', :body => {:uid => uid}
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+ module Weibo2
3
+ module Interface
4
+
5
+ # Tags API
6
+ #
7
+ # @see http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3_V2#.E6.A0.87.E7.AD.BE
8
+ class Tags < Base
9
+
10
+ # 返回指定用户的标签列表
11
+ #
12
+ # @param [int64] uid 要获取的标签列表所属的用户ID
13
+ # @param [Hash] opts
14
+ # @option opts [int] :count 单页返回的记录条数,默认为20
15
+ # @option opts [int] :page 返回结果的页码,默认为1
16
+ # @see http://open.weibo.com/wiki/2/tags
17
+ def tags(uid, opts={})
18
+ get 'tags.json', :params => {:uid => uid}.merge(opts)
19
+ end
20
+
21
+ # 批量获取用户的标签列表
22
+ #
23
+ # @param [String] uids 要获取标签的用户ID。最大20,逗号分隔
24
+ #
25
+ # @see http://open.weibo.com/wiki/2/tags/tags_batch
26
+ def tags_batch(uids)
27
+ get 'tags/tags_batch.json', :params => {:uids => uids}
28
+ end
29
+
30
+ # 获取系统推荐的标签列表
31
+ #
32
+ # @param [Hash] opts
33
+ # @option opts [int] :count 返回记录数,默认10,最大10
34
+ #
35
+ # @see http://open.weibo.com/wiki/2/tags/suggestions
36
+ def suggestions(opts={})
37
+ get 'tags/suggestions.json', :params => opts
38
+ end
39
+
40
+ #
41
+ # write
42
+ #
43
+
44
+ # 为当前登录用户添加新的用户标签
45
+ #
46
+ # @param [String] tags 要创建的一组标签,用半角逗号隔开,每个标签的长度不可超过7个汉字,14个半角字符
47
+ #
48
+ # @see http://open.weibo.com/wiki/2/tags/create
49
+ def create(tags)
50
+ post 'tags/create.json', :body => {:tags => tags}
51
+ end
52
+
53
+ # 删除一个用户标签
54
+ #
55
+ # @param [int64] tag_id 要删除的标签ID
56
+ #
57
+ # @see http://open.weibo.com/wiki/2/tags/destroy
58
+ def destroy(tag_id)
59
+ post 'tags/destroy.json', :body => {:tag_id => tag_id}
60
+ end
61
+
62
+ # 批量删除一组标签
63
+ #
64
+ # @param [String] ids 要删除的一组标签ID,以半角逗号隔开,一次最多提交10个ID
65
+ #
66
+ def destroy_batch(ids)
67
+ post 'tags/destroy_batch.json', :body => {:ids => ids}
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,83 @@
1
+ # encoding: utf-8
2
+ module Weibo2
3
+ module Interface
4
+
5
+ # Trends API
6
+ #
7
+ # @see http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3_V2#.E8.AF.9D.E9.A2.98
8
+ class Trends < Base
9
+
10
+ # 获取某人的话题列表
11
+ #
12
+ # @param [int64] uid 需要获取话题的用户的UID
13
+ # @param [Hash] opts
14
+ # @option opts [int] :count 单页返回的记录条数,默认为10
15
+ # @option opts [int] :page 返回结果的页码,默认为1
16
+ # @see http://open.weibo.com/wiki/2/trends
17
+ def trends(uid, opts={})
18
+ get 'trends.json', :params => {:uid => uid}.merge(opts)
19
+ end
20
+
21
+ # 判断当前用户是否关注某话题
22
+ #
23
+ # @param [String] trend_name 话题关键字
24
+ #
25
+ # @see http://open.weibo.com/wiki/2/trends/is_follow
26
+ def is_follow(trend_name)
27
+ get 'trends/is_follow.json', :params => {:trend_name => trend_name}
28
+ end
29
+
30
+ # 返回最近一小时内的热门话题
31
+ #
32
+ # @param [Hash] opts
33
+ # @option opts [int] :base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0
34
+ #
35
+ # @see http://open.weibo.com/wiki/2/trends/hourly
36
+ def hourly(opts={})
37
+ get 'trends/hourly.json', :params => opts
38
+ end
39
+
40
+ # 返回最近一天内的热门话题
41
+ #
42
+ # @param [Hash] opts
43
+ # @option opts [int] :base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0
44
+ #
45
+ # @see http://open.weibo.com/wiki/2/trends/daily
46
+ def daily(opts={})
47
+ get 'trends/daily.json', :params => opts
48
+ end
49
+
50
+ # 返回最近一周内的热门话题
51
+ #
52
+ # @param [Hash] opts
53
+ # @option opts [int] :base_app 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0
54
+ #
55
+ # @see http://open.weibo.com/wiki/2/trends/weekly
56
+ def weekly(opts={})
57
+ get 'trends/weekly.json', :params => opts
58
+ end
59
+
60
+ #
61
+ # write
62
+ #
63
+
64
+ # 关注某话题
65
+ #
66
+ # @param [String] trend_name 要关注的话题关键词
67
+ # @see http://open.weibo.com/wiki/2/trends/follow
68
+ def follow(trend_name)
69
+ post 'trends/follow.json', :body => {:trend_name => trend_name}
70
+ end
71
+
72
+ # 8485304 no pass
73
+ # 取消对某话题的关注
74
+ #
75
+ # @param [int64] trend_id 要取消关注的话题ID
76
+ #
77
+ # @see http://open.weibo.com/wiki/2/trends/destroy
78
+ def destroy(trend_id)
79
+ post 'trends/destroy.json', :body => {:trend_id => trend_id}
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ module Weibo2
3
+ module Interface
4
+
5
+ # Users API
6
+ #
7
+ # @see http://open.weibo.com/wiki/API%E6%96%87%E6%A1%A3_V2#.E7.94.A8.E6.88.B7
8
+ class Users < Base
9
+
10
+ # 根据用户ID获取用户信息
11
+ #
12
+ # @param [Hash] opts
13
+ # @option opts [String] :uid 需要查询的用户ID
14
+ # @option opts [String] :screen_name 需要查询的用户昵称
15
+ #
16
+ # @see http://open.weibo.com/wiki/2/users/show
17
+ def show(opts={})
18
+ get "users/show.json", :params => opts
19
+ end
20
+
21
+ # 通过个性化域名获取用户资料以及用户最新的一条微博
22
+ #
23
+ # @param [String] domain 需要查询的个性化域名
24
+ #
25
+ # @see http://open.weibo.com/wiki/2/users/domain_show
26
+ def domain_show(domain)
27
+ get "users/domain_show.json", :params => {:domain => domain}
28
+ end
29
+
30
+ # 批量获取用户的基本信息 [Privilege]
31
+ #
32
+ # @param [Hash] opts
33
+ # @option opts [String] :uids 需要查询的用户ID,用半角逗号分隔,一次最多20个
34
+ # @option opts [String] :screen_name 需要查询的用户昵称,用半角逗号分隔,一次最多20个
35
+ #
36
+ # @see http://open.weibo.com/wiki/2/users/show_batch
37
+ def show_batch(opts={})
38
+ get "users/show_batch.json", :params => opts
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ module Weibo2
2
+ module Strategy
3
+ # The Authorization Code Strategy
4
+ #
5
+ # @see http://tools.ietf.org/html/draft-ietf-oauth-v2-15#section-4.1
6
+ class AuthCode < OAuth2::Strategy::AuthCode
7
+
8
+ # The authorization URL endpoint of the provider
9
+ #
10
+ # @param [Hash] params additional query parameters for the URL
11
+ def authorize_url(params={})
12
+ params = {:redirect_uri => @client.redirect_uri}.merge(params)
13
+ super params
14
+ end
15
+
16
+ # Retrieve an access token given the specified validation code.
17
+ #
18
+ # @param [String] code The Authorization Code value
19
+ # @param [Hash] params additional params
20
+ # @param [Hash] opts options
21
+ # @note that you must also provide a :redirect_uri with most OAuth 2.0 providers
22
+ def get_token(code, params={}, opts={})
23
+ params = {:redirect_uri => @client.redirect_uri}.merge(params)
24
+ super(code, params, opts)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,49 @@
1
+ module Weibo2
2
+ module Strategy
3
+ class SignedRequest < OAuth2::Strategy::Base
4
+ attr_reader :unsigned_request
5
+
6
+ # Not used for this strategy
7
+ #
8
+ # @raise [NotImplementedError]
9
+ def authorize_url
10
+ raise NotImplementedError, "The authorization endpoint is not used in this strategy"
11
+ end
12
+
13
+ # Retrieve an access token given the specified signed_request.
14
+ #
15
+ # @param [String] signed_request
16
+ def get_token(signed_request)
17
+ data = parse_signed_request(signed_request)
18
+ unless ["-1", "-2"].include? data
19
+ @unsigned_request = data
20
+ @client.get_token_from_hash(data)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ # parsing the signed_request to a hash
27
+ #
28
+ # @param [String] signed_request
29
+ # @return [Hash] a hash if no error occured
30
+ # [String] "-1" for algorithm mismatch, "-2" for wrong signature
31
+ def parse_signed_request(signed_request)
32
+ encoded_sig, payload = signed_request.split('.')
33
+ sig = base64decode(encoded_sig)
34
+ data = JSON.parse base64decode(payload)
35
+ return "-1" if data['algorithm'].upcase != "HMAC-SHA256"
36
+
37
+ digest = OpenSSL::Digest.new("SHA256")
38
+ expected_sig = OpenSSL::HMAC.digest(digest, @client.secret, payload)
39
+ (sig != expected_sig) ? "-2" : data
40
+ end
41
+
42
+ def base64decode(str)
43
+ (4 - str.length % 4).times {|i| str += "="}
44
+ str = str.gsub('-', '+').gsub('_', '/')
45
+ Base64.decode64(str)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Weibo2
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weibo2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Acenqiu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth2
16
+ requirement: &82302770 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.5.1
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *82302770
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec-rails
27
+ requirement: &82302540 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *82302540
36
+ description: ! 'A Ruby wrapper for Sina weibo API(OAuth2) '
37
+ email:
38
+ - acenqiu@gmail.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - lib/weibo2.rb
44
+ - lib/weibo2/client.rb
45
+ - lib/weibo2/error.rb
46
+ - lib/weibo2/version.rb
47
+ - lib/weibo2/strategy/signed_request.rb
48
+ - lib/weibo2/strategy/auth_code.rb
49
+ - lib/weibo2/config.rb
50
+ - lib/weibo2/interface/tags.rb
51
+ - lib/weibo2/interface/users.rb
52
+ - lib/weibo2/interface/account.rb
53
+ - lib/weibo2/interface/base.rb
54
+ - lib/weibo2/interface/register.rb
55
+ - lib/weibo2/interface/suggestions.rb
56
+ - lib/weibo2/interface/trends.rb
57
+ - lib/weibo2/interface/comments.rb
58
+ - lib/weibo2/interface/favorites.rb
59
+ - lib/weibo2/interface/search.rb
60
+ - lib/weibo2/interface/statuses.rb
61
+ - lib/weibo2/interface/friendships.rb
62
+ - lib/tasks/weibo2_tasks.rake
63
+ - MIT-LICENSE
64
+ - Rakefile
65
+ - README.rdoc
66
+ homepage: https://github.com/acenqiu/weibo2
67
+ licenses: []
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.10
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: A Ruby wrapper for Sina weibo API(OAuth2)
90
+ test_files: []