oauth2_china 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Oauth2China
2
2
 
3
- TODO: Write a gem description
3
+ Weibo OAuth2 API Ruby wrapper.
4
+ Currently support Sina and Tencent Weibo APIs.
4
5
 
5
6
  ## Installation
6
7
 
@@ -18,7 +19,8 @@ Or install it yourself as:
18
19
 
19
20
  ## Usage
20
21
 
21
- TODO: Write usage instructions here
22
+ Oauth2China::Sina.new("ACCESS_TOKEN").statuses_update "hello world"
23
+
22
24
 
23
25
  ## Contributing
24
26
 
data/examples/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "http://ruby.taobao.org"
2
2
 
3
- gem 'oauth2_china', path: "/Users/mike/dev/workspace/oauth2_china/"
3
+ gem 'oauth2_china'
data/examples/test.rb ADDED
@@ -0,0 +1,7 @@
1
+ #coding: utf-8
2
+ require 'oauth2_china'
3
+
4
+ sina = Oauth2China::Sina.new 'SINA_ACCESS_TOKEN'
5
+ res = sina.get_uid
6
+
7
+ puts res
@@ -0,0 +1,135 @@
1
+ module Oauth2China
2
+ class Sina < Oauth2China::Base
3
+ def initialize(access_token)
4
+ @access_token = access_token
5
+
6
+ @tmpl = Hashie::Mash.new({
7
+ access_token: access_token,
8
+ })
9
+
10
+ @conn = Faraday.new(:url => 'https://api.weibo.com') do |faraday|
11
+ faraday.request :multipart
12
+ faraday.request :url_encoded # form-encode POST params
13
+ #faraday.response :logger # log requests to STDOUT
14
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
15
+ end
16
+ end
17
+
18
+ def statuses_update(status, latitude = nil, longitutde = nil, annotation = nil)
19
+ params = @tmpl.clone
20
+ params.status = status
21
+ params.lat = latitude if latitude
22
+ params.long = longitutde if longitutde
23
+ params.annotation = annotation if annotation
24
+
25
+ res = @conn.post("/2/statuses/update.json", params).body
26
+ Hashie::Mash.new(JSON.parse res)
27
+ end
28
+
29
+ def statuses_upload(status, picture, latitude = nil, longitutde = nil, annotation = nil)
30
+ params = @tmpl.clone
31
+ params.pic = Faraday::UploadIO.new(picture, 'image/jpeg')
32
+ params.status = status
33
+ params.lat = latitude if latitude
34
+ params.long = longitutde if longitutde
35
+ params.annotation = annotation if annotation
36
+
37
+ res = @conn.post("/2/statuses/upload.json", params).body
38
+ Hashie::Mash.new(JSON.parse res)
39
+ end
40
+
41
+ def friendships_create(uid)
42
+ params = @tmpl.clone
43
+
44
+ if uid.is_a? String
45
+ params.uid = uid
46
+ else
47
+ params.screen_name = uid
48
+ end
49
+
50
+ res = @conn.post("/2/friendships/create.json", params).body
51
+ Hashie::Mash.new(JSON.parse res)
52
+ end
53
+
54
+ def users_show(uid)
55
+ params = @tmpl.clone
56
+ params.uid = uid
57
+ res = @conn.get("/2/users/show.json", params).body
58
+ Hashie::Mash.new(JSON.parse res)
59
+ end
60
+
61
+ def get_uid
62
+ params = @tmpl.clone
63
+ res = @conn.get("/2/account/get_uid.json", params).body
64
+ Hashie::Mash.new(JSON.parse res)
65
+ end
66
+
67
+ def comments_create(id, comment, comment_ori = 0)
68
+ params = @tmpl.clone
69
+
70
+ params.id = id
71
+ params.comment = comment
72
+ params.comment_ori = comment_ori
73
+
74
+ res = @conn.post("/2/comments/create.json", params).body
75
+ Hashie::Mash.new(JSON.parse res)
76
+ end
77
+
78
+ # since_id false int64 若指定此参数,则返回ID比since_id大的微博(即比since_id时间晚的微博),默认为0。
79
+ # max_id false int64 若指定此参数,则返回ID小于或等于max_id的微博,默认为0。
80
+ # count false int 单页返回的记录条数,默认为50。
81
+ # page false int 返回结果的页码,默认为1。
82
+ # filter_by_author false int 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。
83
+ # filter_by_source false int 来源筛选类型,0:全部、1:来自微博、2:来自微群,默认为0。
84
+ # filter_by_type false int 原创筛选类型,0:全部微博、1:原创的微博,默认为0。
85
+ # trim_user false int 返回值中user字段开关,0:返回完整user字段、1:user字段仅返回user_id,默认为0。
86
+ def statuses_mentions(options = {})
87
+ params = @tmpl.clone.merge(options)
88
+ res = @conn.get("/2/statuses/mentions.json", params).body
89
+ Hashie::Mash.new(JSON.parse res)
90
+ end
91
+
92
+ # since_id false int64 若指定此参数,则返回ID比since_id大的微博(即比since_id时间晚的微博),默认为0。
93
+ # max_id false int64 若指定此参数,则返回ID小于或等于max_id的微博,默认为0。
94
+ # count false int 单页返回的记录条数,默认为50。
95
+ # page false int 返回结果的页码,默认为1。
96
+ # base_app false int 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
97
+ # feature false int 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。
98
+ # trim_user false int 返回值中user字段开关,0:返回完整user字段、1:user字段仅返回user_id,默认为0。
99
+ def statuses_friends_timeline(options = {})
100
+ params = @tmpl.clone.merge(options)
101
+ res = @conn.get("/2/statuses/friends_timeline.json", params).body
102
+ Hashie::Mash.new(JSON.parse res)
103
+ end
104
+
105
+ # since_id false int64 若指定此参数,则返回ID比since_id大的微博(即比since_id时间晚的微博),默认为0。
106
+ # max_id false int64 若指定此参数,则返回ID小于或等于max_id的微博,默认为0。
107
+ # count false int 单页返回的记录条数,默认为50。
108
+ # page false int 返回结果的页码,默认为1。
109
+ # base_app false int 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
110
+ # feature false int 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。
111
+ # trim_user false int 返回值中user字段开关,0:返回完整user字段、1:user字段仅返回user_id,默认为0。
112
+ def home_timeline(options = {})
113
+ params = @tmpl.clone.merge(options)
114
+ res = @conn.get("/2/home/timeline.json", params).body
115
+ Hashie::Mash.new(JSON.parse res)
116
+ end
117
+
118
+ def place_pois_add_checkin(poiid, status, options = {})
119
+ params = @tmpl.clone.merge(options)
120
+
121
+ params.poiid = poiid
122
+ params.status = status
123
+
124
+ res = @conn.post("/2/place/pois/add_checkin.json", params).body
125
+ Hashie::Mash.new(JSON.parse res)
126
+ end
127
+
128
+ # 互粉好友ID列表
129
+ def mutual_friends_ids(count=1000,options = {})
130
+ params = @tmpl.clone.merge(options)
131
+ res = @conn.get("/2/friendships/friends/bilateral/ids.json", params).body
132
+ Hashie::Mash.new(JSON.parse res)
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,78 @@
1
+ module Oauth2China
2
+ class Tencent < Oauth2China::Base
3
+ def initialize(access_token, clientid, openid)
4
+ @conn = Faraday.new(:url => 'https://open.t.qq.com') do |faraday|
5
+ faraday.request :multipart
6
+ faraday.request :url_encoded # form-encode POST params
7
+ #faraday.response :logger # log requests to STDOUT
8
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
9
+ end
10
+
11
+ @tmpl = Hashie::Mash.new({
12
+ oauth_consumer_key: clientid,
13
+ access_token: access_token,
14
+ openid: openid,
15
+ clientip: '202.102.154.3',
16
+ oauth_version: '2.a',
17
+ format: "json"
18
+ })
19
+ end
20
+
21
+ def statuses_update(status, latitude = nil, longitutde = nil, annotation = nil)
22
+ params = @tmpl.clone
23
+ params.content = status
24
+ params.jing = latitude if latitude
25
+ params.wei = longitutde if longitutde
26
+
27
+ res = @conn.post("/api/t/add", params.to_hash).body
28
+ Hashie::Mash.new(JSON.parse res)
29
+ end
30
+
31
+ def statuses_upload(status, picture, latitude = nil, longitutde = nil, annotation = nil)
32
+ params = @tmpl.clone
33
+ params.content = status
34
+ params.pic = Faraday::UploadIO.new(picture, 'image/jpeg')
35
+ params.jing = latitude if latitude
36
+ params.wei = longitutde if longitutde
37
+
38
+ res = @conn.post("/api/t/add_pic", params.to_hash).body
39
+ Hashie::Mash.new(JSON.parse res)
40
+ end
41
+
42
+ def statuses_mentions(options={})
43
+ params = @tmpl.clone.merge(options)
44
+ res = @conn.get("/api/statuses/mentions_timeline", params.to_hash).body
45
+ Hashie::Mash.new(JSON.parse res)
46
+ end
47
+
48
+ def users_show(name)
49
+ params = @tmpl.clone
50
+ params.name = name
51
+
52
+ res = @conn.post("/api/user/other_info", params.to_hash).body
53
+ Hashie::Mash.new(JSON.parse res)
54
+ end
55
+
56
+ def get_uid
57
+ params = @tmpl.clone
58
+ res = @conn.post("/api/user/info", params.to_hash).body
59
+ Hashie::Mash.new(JSON.parse res)
60
+ end
61
+
62
+ def friendships_create(name)
63
+ params = @tmpl.clone
64
+ params.name = name
65
+ res = @conn.post("/api/friends/add", params.to_hash).body
66
+ Hashie::Mash.new(JSON.parse res)
67
+ end
68
+
69
+ # 互粉好友ID列表
70
+ def mutual_friends_ids(start=1, reqnum=30, options = {})
71
+ params = @tmpl.clone.merge(options)
72
+ params.startindex = start
73
+ params.reqnum = reqnum
74
+ res = @conn.get("/api/friends/mutual_list", params.to_hash).body
75
+ Hashie::Mash.new(JSON.parse res)
76
+ end
77
+ end
78
+ end
@@ -1,3 +1,3 @@
1
1
  module Oauth2China
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/oauth2_china.rb CHANGED
@@ -6,194 +6,6 @@ require "json"
6
6
  module Oauth2China
7
7
  class Base
8
8
  end
9
-
10
- class Sina < Oauth2China::Base
11
- def initialize(access_token)
12
- @access_token = access_token
13
-
14
- @tmpl = Hashie::Mash.new({
15
- access_token: access_token,
16
- })
17
-
18
- @conn = Faraday.new(:url => 'https://api.weibo.com') do |faraday|
19
- faraday.request :multipart
20
- faraday.request :url_encoded # form-encode POST params
21
- #faraday.response :logger # log requests to STDOUT
22
- faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
23
- end
24
- end
25
-
26
- def statuses_update(status, latitude = nil, longitutde = nil, annotation = nil)
27
- params = @tmpl.clone
28
- params.status = status
29
- params.lat = latitude if latitude
30
- params.long = longitutde if longitutde
31
- params.annotation = annotation if annotation
32
-
33
- res = @conn.post("/2/statuses/update.json", params).body
34
- Hashie::Mash.new(JSON.parse res)
35
- end
36
-
37
- def statuses_upload(status, picture, latitude = nil, longitutde = nil, annotation = nil)
38
- params = @tmpl.clone
39
- params.pic = Faraday::UploadIO.new(picture, 'image/jpeg')
40
- params.status = status
41
- params.lat = latitude if latitude
42
- params.long = longitutde if longitutde
43
- params.annotation = annotation if annotation
44
-
45
- res = @conn.post("/2/statuses/upload.json", params).body
46
- Hashie::Mash.new(JSON.parse res)
47
- end
48
-
49
- def friendships_create(uid)
50
- params = @tmpl.clone
51
-
52
- if uid.is_a? String
53
- params.uid = uid
54
- else
55
- params.screen_name = uid
56
- end
57
-
58
- res = @conn.post("/2/friendships/create.json", params).body
59
- Hashie::Mash.new(JSON.parse res)
60
- end
61
-
62
- def users_show(uid)
63
- params = @tmpl.clone
64
- params.uid = uid
65
- res = @conn.get("/2/users/show.json", params).body
66
- Hashie::Mash.new(JSON.parse res)
67
- end
68
-
69
- def get_uid
70
- params = @tmpl.clone
71
- res = @conn.get("/2/account/get_uid.json", params).body
72
- Hashie::Mash.new(JSON.parse res)
73
- end
74
-
75
- def comments_create(id, comment, comment_ori = 0)
76
- params = @tmpl.clone
77
-
78
- params.id = id
79
- params.comment = comment
80
- params.comment_ori = comment_ori
81
-
82
- res = @conn.post("/2/comments/create.json", params).body
83
- Hashie::Mash.new(JSON.parse res)
84
- end
85
-
86
- # since_id false int64 若指定此参数,则返回ID比since_id大的微博(即比since_id时间晚的微博),默认为0。
87
- # max_id false int64 若指定此参数,则返回ID小于或等于max_id的微博,默认为0。
88
- # count false int 单页返回的记录条数,默认为50。
89
- # page false int 返回结果的页码,默认为1。
90
- # filter_by_author false int 作者筛选类型,0:全部、1:我关注的人、2:陌生人,默认为0。
91
- # filter_by_source false int 来源筛选类型,0:全部、1:来自微博、2:来自微群,默认为0。
92
- # filter_by_type false int 原创筛选类型,0:全部微博、1:原创的微博,默认为0。
93
- # trim_user false int 返回值中user字段开关,0:返回完整user字段、1:user字段仅返回user_id,默认为0。
94
- def statuses_mentions(options = {})
95
- params = @tmpl.clone.merge(options)
96
- res = @conn.get("/2/statuses/mentions.json", params).body
97
- Hashie::Mash.new(JSON.parse res)
98
- end
99
-
100
- # since_id false int64 若指定此参数,则返回ID比since_id大的微博(即比since_id时间晚的微博),默认为0。
101
- # max_id false int64 若指定此参数,则返回ID小于或等于max_id的微博,默认为0。
102
- # count false int 单页返回的记录条数,默认为50。
103
- # page false int 返回结果的页码,默认为1。
104
- # base_app false int 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
105
- # feature false int 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。
106
- # trim_user false int 返回值中user字段开关,0:返回完整user字段、1:user字段仅返回user_id,默认为0。
107
- def statuses_friends_timeline(options = {})
108
- params = @tmpl.clone.merge(options)
109
- res = @conn.get("/2/statuses/friends_timeline.json", params).body
110
- Hashie::Mash.new(JSON.parse res)
111
- end
112
-
113
- # since_id false int64 若指定此参数,则返回ID比since_id大的微博(即比since_id时间晚的微博),默认为0。
114
- # max_id false int64 若指定此参数,则返回ID小于或等于max_id的微博,默认为0。
115
- # count false int 单页返回的记录条数,默认为50。
116
- # page false int 返回结果的页码,默认为1。
117
- # base_app false int 是否只获取当前应用的数据。0为否(所有数据),1为是(仅当前应用),默认为0。
118
- # feature false int 过滤类型ID,0:全部、1:原创、2:图片、3:视频、4:音乐,默认为0。
119
- # trim_user false int 返回值中user字段开关,0:返回完整user字段、1:user字段仅返回user_id,默认为0。
120
- def home_timeline(options = {})
121
- params = @tmpl.clone.merge(options)
122
- res = @conn.get("/2/home/timeline.json", params).body
123
- Hashie::Mash.new(JSON.parse res)
124
- end
125
-
126
- def place_pois_add_checkin(poiid, status, options = {})
127
- params = @tmpl.clone.merge(options)
128
-
129
- params.poiid = poiid
130
- params.status = status
131
-
132
- res = @conn.post("/2/place/pois/add_checkin.json", params).body
133
- Hashie::Mash.new(JSON.parse res)
134
- end
135
- end
136
-
137
- class Tencent < Oauth2China::Base
138
- def initialize(access_token, clientid, openid)
139
- @conn = Faraday.new(:url => 'https://open.t.qq.com') do |faraday|
140
- faraday.request :multipart
141
- faraday.request :url_encoded # form-encode POST params
142
- #faraday.response :logger # log requests to STDOUT
143
- faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
144
- end
145
-
146
- @tmpl = Hashie::Mash.new({
147
- oauth_consumer_key: clientid,
148
- access_token: access_token,
149
- openid: openid,
150
- clientip: '202.102.154.3',
151
- oauth_version: '2.a',
152
- format: "json"
153
- })
154
- end
155
-
156
- def statuses_update(status, latitude = nil, longitutde = nil, annotation = nil)
157
- params = @tmpl.clone
158
- params.content = status
159
- params.jing = latitude if latitude
160
- params.wei = longitutde if longitutde
161
-
162
- res = @conn.post("/api/t/add", params.to_hash).body
163
- Hashie::Mash.new(JSON.parse res)
164
- end
165
-
166
- def statuses_upload(status, picture, latitude = nil, longitutde = nil, annotation = nil)
167
- params = @tmpl.clone
168
- params.content = status
169
- params.pic = Faraday::UploadIO.new(picture, 'image/jpeg')
170
- params.jing = latitude if latitude
171
- params.wei = longitutde if longitutde
172
-
173
- res = @conn.post("/api/t/add_pic", params.to_hash).body
174
- Hashie::Mash.new(JSON.parse res)
175
- end
176
-
177
- def users_show(name)
178
- params = @tmpl.clone
179
- params.name = name
180
-
181
- res = @conn.post("/api/user/other_info", params.to_hash).body
182
- Hashie::Mash.new(JSON.parse res)
183
- end
184
-
185
- def get_uid
186
- params = @tmpl.clone
187
- res = @conn.post("/api/user/info", params.to_hash).body
188
- Hashie::Mash.new(JSON.parse res)
189
- end
190
-
191
- def friendships_create(name)
192
- params = @tmpl.clone
193
- params.name = name
194
- res = @conn.post("/api/friends/add", params.to_hash).body
195
- Hashie::Mash.new(JSON.parse res)
196
- end
197
- end
198
-
9
+ autoload :Sina, 'oauth2_china/strategies/sina'
10
+ autoload :Tencent, 'oauth2_china/strategies/tencent'
199
11
  end
data/oauth2_china.gemspec CHANGED
@@ -3,9 +3,9 @@ require File.expand_path('../lib/oauth2_china/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Chagel"]
6
- gem.email = ["chagel@gmail.com"]
7
- gem.description = %q{weibo client for china.}
8
- gem.summary = %q{weibo client for china. Currently support sina and qq apis.}
6
+ gem.email = ["mike@gmail.com"]
7
+ gem.description = %q{Weibo OAuth2 API Ruby wrapper.}
8
+ gem.summary = %q{Weibo OAuth2 API Ruby wrapper. Currently support Sina and Tencent Weibo APIs.}
9
9
  gem.homepage = ""
10
10
 
11
11
  gem.files = `git ls-files`.split($\)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oauth2_china
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-19 00:00:00.000000000 Z
12
+ date: 2013-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
16
- requirement: &70344330196040 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70344330196040
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: hashie
27
- requirement: &70344330195600 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70344330195600
36
- description: weibo client for china.
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Weibo OAuth2 API Ruby wrapper.
37
47
  email:
38
- - chagel@gmail.com
48
+ - mike@gmail.com
39
49
  executables: []
40
50
  extensions: []
41
51
  extra_rdoc_files: []
@@ -45,11 +55,11 @@ files:
45
55
  - LICENSE
46
56
  - README.md
47
57
  - Rakefile
48
- - examples/016.gif
49
58
  - examples/Gemfile
50
- - examples/img.jpeg
51
- - examples/tester.rb
59
+ - examples/test.rb
52
60
  - lib/oauth2_china.rb
61
+ - lib/oauth2_china/strategies/sina.rb
62
+ - lib/oauth2_china/strategies/tencent.rb
53
63
  - lib/oauth2_china/version.rb
54
64
  - oauth2_china.gemspec
55
65
  homepage: ''
@@ -72,9 +82,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
82
  version: '0'
73
83
  requirements: []
74
84
  rubyforge_project:
75
- rubygems_version: 1.8.17
85
+ rubygems_version: 1.8.25
76
86
  signing_key:
77
87
  specification_version: 3
78
- summary: weibo client for china. Currently support sina and qq apis.
88
+ summary: Weibo OAuth2 API Ruby wrapper. Currently support Sina and Tencent Weibo APIs.
79
89
  test_files: []
80
90
  has_rdoc:
data/examples/016.gif DELETED
Binary file
data/examples/img.jpeg DELETED
Binary file
data/examples/tester.rb DELETED
@@ -1,13 +0,0 @@
1
- #coding: utf-8
2
- require 'oauth2_china'
3
-
4
- #sina = Oauth2China::Sina.new "2.00PvDQzBee3piCd9690cd4fcq5DwtB"
5
- ##res = sina.statuses_update("ello wd")
6
- ##p res
7
- #res = sina.statuses_upload("come on gif", "./016.gif")
8
- #p res
9
-
10
- qq = Oauth2China::Tencent.new "88f6c1b65ff3dbd0ebdda3db123f791a", "7547D743583717EA820A834BE4B50255"
11
- #qq = Oauth2China::Tencent.new "a92e335ad63b4d7dbf9ac9d299fe7817", "565f61c64aa43838af462b355022c562"
12
- res = qq.statuses_update "hello world"
13
- p res