kounta_rest 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/kounta.gemspec +2 -1
- data/lib/kounta.rb +0 -1
- data/lib/kounta/rest/client.rb +10 -11
- data/lib/kounta/version.rb +1 -1
- metadata +17 -1
data/kounta.gemspec
CHANGED
data/lib/kounta.rb
CHANGED
data/lib/kounta/rest/client.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'oauth2'
|
2
|
-
require 'yell'
|
3
2
|
require 'oj'
|
3
|
+
require 'faraday_middleware'
|
4
4
|
|
5
5
|
module Kounta
|
6
6
|
module REST
|
@@ -8,9 +8,7 @@ module Kounta
|
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
raise Kounta::Errors::MissingOauthDetails unless has_required_oauth_details?
|
11
|
-
@logger = Yell.new STDOUT
|
12
11
|
@conn = OAuth2::AccessToken.new(client, Kounta.client_token, {:refresh_token => Kounta.client_refresh_token})
|
13
|
-
|
14
12
|
end
|
15
13
|
|
16
14
|
def client
|
@@ -18,7 +16,12 @@ module Kounta
|
|
18
16
|
:site => Kounta::SITE_URI,
|
19
17
|
:authorize_url => Kounta::AUTHORIZATION_URI,
|
20
18
|
:token_url => Kounta::TOKEN_URI
|
21
|
-
})
|
19
|
+
}) do |faraday|
|
20
|
+
faraday.request :json
|
21
|
+
faraday.use Faraday::Request::UrlEncoded
|
22
|
+
faraday.use Faraday::Response::Logger if Kounta.enable_logging
|
23
|
+
faraday.adapter Faraday.default_adapter
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
def path_from_hash(url_hash)
|
@@ -30,11 +33,11 @@ module Kounta
|
|
30
33
|
options[:headers].merge!(Kounta::REQUEST_HEADERS)
|
31
34
|
|
32
35
|
begin
|
33
|
-
|
34
|
-
|
36
|
+
response = @conn.request(request_method, "#{path_from_hash(url_hash)}.#{FORMAT.to_s}", options) do |request|
|
37
|
+
|
38
|
+
end
|
35
39
|
rescue OAuth2::Error => ex
|
36
40
|
if ex.message.include? 'The access token provided has expired'
|
37
|
-
log(ex.message)
|
38
41
|
@conn = refreshed_token
|
39
42
|
retry
|
40
43
|
end
|
@@ -71,10 +74,6 @@ module Kounta
|
|
71
74
|
Kounta.client_id && Kounta.client_secret && Kounta.client_token && Kounta.client_refresh_token
|
72
75
|
end
|
73
76
|
|
74
|
-
def log(message)
|
75
|
-
@logger.info(message) unless !Kounta.enable_logging
|
76
|
-
end
|
77
|
-
|
78
77
|
def refreshed_token
|
79
78
|
OAuth2::AccessToken.from_hash(client, :refresh_token => Kounta.client_refresh_token).refresh!
|
80
79
|
end
|
data/lib/kounta/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kounta_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -171,6 +171,22 @@ dependencies:
|
|
171
171
|
- - '='
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: 1.5.1
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: faraday_middleware
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - '='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: 0.9.0
|
182
|
+
type: :runtime
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - '='
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: 0.9.0
|
174
190
|
description: Library for accessing Kounta's RESTful API
|
175
191
|
email:
|
176
192
|
- sam@richardson.co.nz
|