homeaway-api 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/homeaway/api/client.rb +10 -21
- data/lib/homeaway/api/util/oauth.rb +20 -2
- data/lib/homeaway/api/version.rb +1 -1
- metadata +6 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03191fa72b667f0ea2cfbbfb7898e8314888e572
|
4
|
+
data.tar.gz: 358c23be39110cde5a6c91a86d6513e9f91f6a86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa63f013b0c56621c4fdd1e0f017213087cfedbcac22f59f1ae95e9de04bc0c012a13d3207d23e9f4a8684ea62f9182ff8be6a8549df920e835dde2c992a7bca
|
7
|
+
data.tar.gz: 4fab671b70eae3d34f52a808487f4141a7509dda0ecfc90e3a1ce99f2c674ee31ae9aa24ef8e68d549aa06b987438290734c5a72993f97c07931cc0848d19876
|
data/lib/homeaway/api/client.rb
CHANGED
@@ -33,7 +33,7 @@ module HomeAway
|
|
33
33
|
include HomeAway::API::Util::OAuth
|
34
34
|
|
35
35
|
attr_accessor :configuration
|
36
|
-
attr_reader :mode, :token, :token_expires
|
36
|
+
attr_reader :mode, :token, :token_expires, :refresh_token
|
37
37
|
|
38
38
|
# @!attribute [rw] configuration
|
39
39
|
# @return [Hash] the current client configuration
|
@@ -52,13 +52,14 @@ module HomeAway
|
|
52
52
|
#
|
53
53
|
# @option opts [String] :client_id Your HomeAway API OAuth client id. Required here if not set globally
|
54
54
|
# @option opts [String] :client_secret Your HomeAway API OAuth client secret. Required here if not set globally
|
55
|
-
# @option opts [String] :
|
55
|
+
# @option opts [String] :refresh_token An existing token if you already have one saved from a previous usage of the api
|
56
56
|
# @return [HomeAway::API::Client] a newly instantiated HomeAway API client
|
57
57
|
def initialize(opts={})
|
58
58
|
@configuration = Hashie::Mash.new(self.class.default_configuration.merge(opts))
|
59
|
-
if opts.has_key?(:
|
59
|
+
if opts.has_key?(:refresh_token)
|
60
60
|
@configuration[:manual_token_supplied] = true
|
61
|
-
|
61
|
+
@refresh_token = opts.delete(:refresh_token)
|
62
|
+
refresh
|
62
63
|
end
|
63
64
|
validate_configuration
|
64
65
|
logger.debug("client initialized with configuration: #{@configuration}")
|
@@ -85,6 +86,11 @@ module HomeAway
|
|
85
86
|
@token
|
86
87
|
end
|
87
88
|
|
89
|
+
# @return [String] The current refresh token
|
90
|
+
def refresh_token
|
91
|
+
@refresh_token
|
92
|
+
end
|
93
|
+
|
88
94
|
# @private
|
89
95
|
def marshal_dump
|
90
96
|
# we lose our logger instance naively here, marshal dump doesn't like
|
@@ -200,23 +206,6 @@ module HomeAway
|
|
200
206
|
end
|
201
207
|
end
|
202
208
|
|
203
|
-
def set_token(token)
|
204
|
-
@token = token
|
205
|
-
begin
|
206
|
-
listing '100000'
|
207
|
-
begin
|
208
|
-
me
|
209
|
-
logger.info('token supplied on client initialization provided 3-legged oauth')
|
210
|
-
@mode = :three_legged
|
211
|
-
rescue => e
|
212
|
-
logger.info('token supplied on client initialization provided 2-legged oauth')
|
213
|
-
@mode = :two_legged
|
214
|
-
end
|
215
|
-
rescue => e
|
216
|
-
logger.error("token supplied on client initialization was not valid: #{e.to_s}")
|
217
|
-
@mode = :unauthorized
|
218
|
-
end
|
219
|
-
end
|
220
209
|
end
|
221
210
|
end
|
222
211
|
end
|
@@ -39,6 +39,7 @@ module HomeAway
|
|
39
39
|
token = auth_code_strategy.get_token(code, :headers => {'Authorization' => "Basic #{credentials}"})
|
40
40
|
@token = token.token
|
41
41
|
@token_expires = Time.at token.expires_at
|
42
|
+
@refresh_token = token.refresh_token
|
42
43
|
@mode = :three_legged
|
43
44
|
return true
|
44
45
|
rescue => _
|
@@ -48,11 +49,14 @@ module HomeAway
|
|
48
49
|
|
49
50
|
private
|
50
51
|
|
52
|
+
def oauth_site
|
53
|
+
@configuration[:oauth_site] ||= @configuration[:site]
|
54
|
+
end
|
55
|
+
|
51
56
|
def oauth_client
|
52
|
-
site = @configuration[:oauth_site] ||= @configuration[:site]
|
53
57
|
OAuth2::Client.new(@configuration.client_id,
|
54
58
|
@configuration.client_secret,
|
55
|
-
:site =>
|
59
|
+
:site => oauth_site,
|
56
60
|
:raise_errors => false
|
57
61
|
)
|
58
62
|
end
|
@@ -69,12 +73,26 @@ module HomeAway
|
|
69
73
|
token = client_credentials_strategy.get_token
|
70
74
|
@token = token.token
|
71
75
|
@token_expires = Time.at token.expires_at
|
76
|
+
@refresh_token = token.refresh_token
|
72
77
|
@mode = :two_legged
|
73
78
|
return true
|
74
79
|
rescue => _
|
75
80
|
raise HomeAway::API::Errors::UnauthorizedError.new
|
76
81
|
end
|
77
82
|
end
|
83
|
+
|
84
|
+
def refresh
|
85
|
+
token = OAuth2::AccessToken.new(oauth_client, nil, {:refresh_token => @refresh_token})
|
86
|
+
params = {
|
87
|
+
:headers => {'Authorization' => "Basic #{credentials}"}
|
88
|
+
}
|
89
|
+
token = token.refresh!(params)
|
90
|
+
@token = token.token
|
91
|
+
@token_expires = Time.at token.expires_at
|
92
|
+
@refresh_token = token.refresh_token
|
93
|
+
@mode = :three_legged
|
94
|
+
true
|
95
|
+
end
|
78
96
|
end
|
79
97
|
end
|
80
98
|
end
|
data/lib/homeaway/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: homeaway-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -252,16 +252,16 @@ dependencies:
|
|
252
252
|
name: webmock
|
253
253
|
requirement: !ruby/object:Gem::Requirement
|
254
254
|
requirements:
|
255
|
-
- - "
|
255
|
+
- - "<"
|
256
256
|
- !ruby/object:Gem::Version
|
257
|
-
version:
|
257
|
+
version: 2.0.0
|
258
258
|
type: :development
|
259
259
|
prerelease: false
|
260
260
|
version_requirements: !ruby/object:Gem::Requirement
|
261
261
|
requirements:
|
262
|
-
- - "
|
262
|
+
- - "<"
|
263
263
|
- !ruby/object:Gem::Version
|
264
|
-
version:
|
264
|
+
version: 2.0.0
|
265
265
|
- !ruby/object:Gem::Dependency
|
266
266
|
name: simplecov
|
267
267
|
requirement: !ruby/object:Gem::Requirement
|
@@ -366,4 +366,3 @@ signing_key:
|
|
366
366
|
specification_version: 4
|
367
367
|
summary: Ruby SDK for interacting with the HomeAway API
|
368
368
|
test_files: []
|
369
|
-
has_rdoc:
|