baidu-sdk 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3af6ada389f6a63f94e817ce4a13d344b73461f5
4
- data.tar.gz: c769fddcdea66b5cb027fd123f7e366e17bae183
3
+ metadata.gz: fd923023cb20bb234f9baf2e88e3195666872466
4
+ data.tar.gz: 7cb2233114d45ea5fd5dd63547a327ce19c20e9c
5
5
  SHA512:
6
- metadata.gz: 3f354a1ae052d10dacc1160c23f94f90c2eeea602dd437e134383e4771d5bc43e1ece0e168445f7c9c6ce74518855e47175911e825bac7f45a1f157e1b078abb
7
- data.tar.gz: 613e6c1f4b7ab7a2b0bdc5c72c9f8382cf26fdc0e2006922ac85cd9cedc02d920f57cfa1066df76b516154c5847d87bd34496810a9b22fb0b5c4ee085fe9ee14
6
+ metadata.gz: 288ed76d45973ac06e749b69be34fb18cb912249817b8bd09b56a0f716088c9fb5ccf884e8d9057ab0f514f818c4a92a3109712b6ba3497ef6857e9be901abe3
7
+ data.tar.gz: 9fd6f960f649373f8d448ded8cf30c39c45c1ae7e55fc74a287ede131109f3037d54571efa64fe80dbe41ff6ffbb48443295a0665e665d0f8150c9d8d6d5e0e4
@@ -4,8 +4,8 @@ script: 'bundle exec rake spec'
4
4
 
5
5
  rvm:
6
6
  - 1.9.3
7
- - 2.0.0
8
- - 2.1.0
7
+ - 2.0
8
+ - 2.1
9
9
  - rbx-2
10
10
  - jruby-19mode
11
11
  - ruby-head
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  group :test, :development do
9
9
  gem 'rake'
10
- gem 'rspec'
10
+ gem 'rspec', '~> 2.14.1'
11
11
  gem 'webmock'
12
12
  end
13
13
 
data/HISTORY.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.0.4 (2014-06-22)
2
+ * **OAuth** token_info 验证的 access token 过期或无效返回 nil
3
+
1
4
  ## 0.0.3 (2013-12-30)
2
5
  * 添加部分 REST API, `Baidu::OAuth::RESTClient`
3
6
  * get_logged_in_user
@@ -97,12 +97,18 @@ module Baidu
97
97
  # :expires_in Access Token剩余的有效时间,以秒为单位
98
98
  #
99
99
  # @param [String] access_token 授权之后应用得到的Access Token
100
- # @return [Hash]
100
+ # @return [Hash] 如上描述
101
+ # @return [nil] 若参数中传递的 Access Token 已经过期或者无效,则返回 nil
101
102
  # @see http://developer.baidu.com/wiki/index.php?title=docs/oauth/tokeninfo 校验Access Token
102
103
  # @see http://developer.baidu.com/wiki/index.php?title=docs/oauth/list 权限列表
103
104
  def token_info(access_token)
104
105
  body = { access_token: access_token }
105
- return post Baidu::OAuth::TOKEN_INFO_ENDPOINT, nil, body
106
+ begin
107
+ post Baidu::OAuth::TOKEN_INFO_ENDPOINT, nil, body
108
+ rescue Baidu::Errors::ClientError => e
109
+ return nil if e.code == 'invalid_grant'
110
+ raise e
111
+ end
106
112
  end
107
113
  end
108
114
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module Baidu
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
@@ -237,10 +237,18 @@ describe Baidu::OAuth::Client do
237
237
  context '#token_info' do
238
238
  it 'requests token info' do
239
239
  stub = stub_post(:oauth, '/oauth/2.0/tokeninfo', access_token: 'xxxx').
240
- to_return(status: 200, body: ft('token_info.json'))
240
+ to_return(status: 200, body: ft('token_info.json'))
241
241
  rest = @client.token_info('xxxx')
242
242
  stub.should have_been_requested
243
243
  expect(rest).to be_instance_of(Hash)
244
244
  end
245
+
246
+ it 'requests token info with expired or invalid access token' do
247
+ stub = stub_post(:oauth, '/oauth/2.0/tokeninfo', access_token: 'expired_or_invalid_access_token').
248
+ to_return(status: 400, body: ft('token_info_400.json'))
249
+ rest = @client.token_info('expired_or_invalid_access_token')
250
+ stub.should have_been_requested
251
+ expect(rest).to be_nil
252
+ end
245
253
  end
246
254
  end
@@ -0,0 +1,4 @@
1
+ {
2
+ "error": "invalid_grant",
3
+ "error_description": "Invalid Access Token: xxx..."
4
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baidu-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lonre Wang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-29 00:00:00.000000000 Z
11
+ date: 2014-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multipart-post
@@ -110,6 +110,7 @@ files:
110
110
  - spec/fixtures/stream_list.json
111
111
  - spec/fixtures/streaming.m3u8
112
112
  - spec/fixtures/token_info.json
113
+ - spec/fixtures/token_info_400.json
113
114
  - spec/fixtures/upload.json
114
115
  - spec/fixtures/upload_block.json
115
116
  - spec/fixtures/user_and_device_code.json
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  version: '0'
135
136
  requirements: []
136
137
  rubyforge_project:
137
- rubygems_version: 2.2.0
138
+ rubygems_version: 2.3.0
138
139
  signing_key:
139
140
  specification_version: 4
140
141
  summary: Unofficial Baidu REST API SDK for Ruby.
@@ -175,8 +176,8 @@ test_files:
175
176
  - spec/fixtures/stream_list.json
176
177
  - spec/fixtures/streaming.m3u8
177
178
  - spec/fixtures/token_info.json
179
+ - spec/fixtures/token_info_400.json
178
180
  - spec/fixtures/upload.json
179
181
  - spec/fixtures/upload_block.json
180
182
  - spec/fixtures/user_and_device_code.json
181
183
  - spec/spec_helper.rb
182
- has_rdoc: