google-ads-common 0.9.8 → 0.9.9
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 +8 -8
- data/ChangeLog +3 -0
- data/lib/ads_common/auth/oauth2_handler.rb +5 -0
- data/lib/ads_common/version.rb +1 -1
- data/test/test_oauth2_handler.rb +74 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmEwMDIzYWQwNzlmYjA4ZjE0OTMzZmMwZjg4YjQ4ZDIxNGRlMDdjOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTg0NmJiYmFlOWJkYjA4NDhjYTRiNzVhOTNjYmNhZWQ0Mjk0NjYzMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGZkMGUwMWQ2ZjkyNzk2MGMyMjU4YzFkMDEyYzAxMDY1ZGQ0NTdjZDRhMTMy
|
10
|
+
OGJkY2Q0NmU2NTZhYmZiYzEzODY4ZGZkN2EwMjVkNDY3NzAxZDBkYjcwM2E5
|
11
|
+
N2I2ZjFjMzAxNGQ1MzhjMjFjMWU0MmE4NmY2YmZlZWI5MjkxNzY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGEwNmUyZTVkYWE5Yzg1ODcxNWYyYjQ3ZTI0YWRhYjcxZDhiYmMyNDlkMTRj
|
14
|
+
OGM5OTM5NTRlODlmNTU4ZTdmYTZmZmM1ODk2NzM2M2M3Mjg1ZDJhYjYzM2Yw
|
15
|
+
Mzc3MDk0MGI2ZjRlMTA0YzU2NTg2OThkNDA2ZDA3OTM1ZGI3Y2Q=
|
data/ChangeLog
CHANGED
@@ -19,6 +19,8 @@
|
|
19
19
|
#
|
20
20
|
# This module manages OAuth2.0 authentication.
|
21
21
|
|
22
|
+
require 'time'
|
23
|
+
|
22
24
|
require 'faraday'
|
23
25
|
require 'signet/oauth_2/client'
|
24
26
|
|
@@ -88,6 +90,9 @@ module AdsCommon
|
|
88
90
|
def refresh_token!()
|
89
91
|
return nil if @token.nil? or @token[:refresh_token].nil?
|
90
92
|
begin
|
93
|
+
if @client.issued_at.is_a?(String)
|
94
|
+
@client.issued_at = Time.parse(@client.issued_at)
|
95
|
+
end
|
91
96
|
@client.refresh!
|
92
97
|
rescue Signet::AuthorizationError => e
|
93
98
|
raise AdsCommon::Errors::AuthError.new("OAuth2 token refresh failed",
|
data/lib/ads_common/version.rb
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.mcloonan@gmail.com (Michael Cloonan)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2015, Google Inc. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
17
|
+
# implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
# Test OAuth2 authentication.
|
22
|
+
|
23
|
+
require 'time'
|
24
|
+
|
25
|
+
require 'ads_common/auth/oauth2_handler'
|
26
|
+
require 'webmock/test_unit'
|
27
|
+
|
28
|
+
module AdsCommon
|
29
|
+
module Auth
|
30
|
+
class OAuth2Handler
|
31
|
+
def client()
|
32
|
+
@client
|
33
|
+
end
|
34
|
+
|
35
|
+
# Overrides to ensure @client stores issued_at as a string, to test
|
36
|
+
# converting it back.
|
37
|
+
def setup_client()
|
38
|
+
@client = Signet::OAuth2::Client.new({
|
39
|
+
:authorization_uri => 'https://accounts.google.com/o/oauth2/auth',
|
40
|
+
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
|
41
|
+
:client_id => 'client_id123',
|
42
|
+
:client_secret => 'client_secret123',
|
43
|
+
:scope => 'https://www.googleapis.com/auth/adwords'
|
44
|
+
})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class TestOAuth < Test::Unit::TestCase
|
51
|
+
def setup()
|
52
|
+
stub_request(:post, 'https://accounts.google.com/o/oauth2/auth').to_return(
|
53
|
+
:status => 200,
|
54
|
+
:body => '{"access_token":"access_token123",' +
|
55
|
+
'"token_type":"Bearer","expires_in":"3600"}\n',
|
56
|
+
:headers => {}
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_string_issued_at()
|
61
|
+
handler = AdsCommon::Auth::OAuth2Handler.new('', {})
|
62
|
+
|
63
|
+
# Modify @client in the handler to get around a full setup.
|
64
|
+
handler.setup_client()
|
65
|
+
assert_not_nil(handler.client)
|
66
|
+
handler.client.issued_at = Time.now.to_s
|
67
|
+
assert_equal(String, handler.client.issued_at.class)
|
68
|
+
|
69
|
+
# Make sure that we are still able to refresh the token.
|
70
|
+
assert_nothing_raised do
|
71
|
+
token = handler.refresh_token!();
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-ads-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Gomes
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- test/test_config.rb
|
91
91
|
- test/test_config.yml
|
92
92
|
- test/test_credential_handler.rb
|
93
|
+
- test/test_oauth2_handler.rb
|
93
94
|
- test/test_parameters_validator.rb
|
94
95
|
- test/test_results_extractor.rb
|
95
96
|
- test/test_savon_service.rb
|
@@ -124,4 +125,5 @@ test_files:
|
|
124
125
|
- test/test_credential_handler.rb
|
125
126
|
- test/test_utils.rb
|
126
127
|
- test/test_parameters_validator.rb
|
128
|
+
- test/test_oauth2_handler.rb
|
127
129
|
- test/test_results_extractor.rb
|