qihu360 0.3.16 → 0.4.0

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: 608d937acd6b11c607f50bb6bcce140037aa298d
4
- data.tar.gz: abbf0b233894ab66a411c38e0d2f276e3335b51a
3
+ metadata.gz: 243732175d9fe1d94ad688e68f6a7f3aa3dce2a7
4
+ data.tar.gz: 70378a3818685183d66012403677b5eb9c6ebeb7
5
5
  SHA512:
6
- metadata.gz: 9891b3eb7aa54f240deb0e2e3cceaa2f55877d67c395ed10c3d13edfe96abc6a1fb16fb1857543f9149290b406d5b32b0388508b1429dec9f4422f3b706f15f9
7
- data.tar.gz: dc90d8905e6c8398e7967c7db4e73798dd329dcbd90206cf390aedca1ec21c6c36329213cff80e0a22ca750d3944789aeba86a89b2d5dcbc3b9852fff7a0bcca
6
+ metadata.gz: b8a7121f6da926a1e75a50ba50190a374e79b13ba88ac19915bef748dc1c822cabbae995899e45065f1d172f35761750f7a17c2b5181188cea12816994e06773
7
+ data.tar.gz: 9bf63cfc46700ee442b0ea0bacbf65557d169e342360d151598f7b6a310bf9cdff8661876ddedf747f1384d9389c024e425b94b37833d384f1a4ede6fa730a0d
data/README.md CHANGED
@@ -23,6 +23,10 @@
23
23
 
24
24
  ## 代码实例
25
25
 
26
+ ### 导入
27
+
28
+ require 'qihu'
29
+
26
30
  ### 验证 OAuth 2
27
31
 
28
32
  # 处理 oauth2
@@ -35,7 +39,21 @@
35
39
  auth_url = auth.authorize_url(redirect_uri:'http://icyleaf.com', display:'desktop')
36
40
 
37
41
  # 获取的 access token
38
- auth.get_token('code')
42
+ token = auth.get_token('code')
43
+
44
+ ### 使用用户名和密码获得 access token
45
+
46
+ # 处理 oauth2
47
+ auth = Qihu::Auth.new(id:'xxx', secret:'yyy')
48
+
49
+ # 默认 redirect_uri 是 oob
50
+ code = auth.get_code_from_account('username', 'password')
51
+
52
+ # 获取的 access token
53
+ token = auth.get_token(code)
54
+
55
+ # 或者直接一步到位
56
+ token = auth.get_token_from_account('username', 'password')
39
57
 
40
58
 
41
59
  #### 使用 access token 初始化
@@ -74,7 +92,12 @@
74
92
  response = client.campign.add(name:'Beijing', budget:10000)
75
93
 
76
94
  # 更改提交的方法
77
- response = client.campign.add(name:'Beijing', bugget:20000, method:'get')
95
+ begin
96
+ response = client.campign.add(name:'Beijing', bugget:20000, method:'get')
97
+ resure Qihu::FailuresError => e
98
+ # 捕获 API 接口返回的异常
99
+ puts e.message
100
+ end
78
101
 
79
102
  # 获得返回信息
80
103
  status = response.status
@@ -82,6 +105,8 @@
82
105
  body = response.body
83
106
 
84
107
 
108
+
109
+
85
110
  ## 贡献代码
86
111
 
87
112
  1. Fork 本仓库
data/lib/qihu/auth.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'oauth2'
2
+ require 'uri'
3
+
2
4
 
3
5
  module Qihu
4
6
  class Auth
@@ -39,6 +41,25 @@ module Qihu
39
41
  return self
40
42
  end
41
43
 
44
+ def get_code_from_account(username, password, options={})
45
+ @redirect_uri = options[:redirect_uri] if options[:redirect_uri]
46
+ conn = Faraday.new(@oauth2.site)
47
+ res = conn.post(@oauth2.authorize_url, {
48
+ :client_id => @oauth2.id,
49
+ :redirect_uri => @redirect_uri,
50
+ :response_type => 'code',
51
+ :username => username,
52
+ :password => password,
53
+ })
54
+
55
+ query = CGI.parse(URI(res.headers[:location]).query)
56
+ query["code"].pop
57
+ end
58
+
59
+ def get_token_from_account(username, password, options={})
60
+ self.get_token(self.get_code_from_account(username, password, options))
61
+ end
62
+
42
63
  def get_token_from_hash(token={})
43
64
  @token = OAuth2::AccessToken.from_hash(@oauth2, token)
44
65
  return self
data/lib/qihu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qihu
2
- VERSION = "0.3.16"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qihu360
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.16
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - icyleaf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-21 00:00:00.000000000 Z
11
+ date: 2014-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  requirements: []
133
133
  rubyforge_project:
134
- rubygems_version: 2.0.3
134
+ rubygems_version: 2.0.14
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: Qihu 360.cn OAuth2 & Dianjing API wrapper