cronofy 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cronofy/auth.rb +9 -0
- data/lib/cronofy/version.rb +1 -1
- data/spec/lib/cronofy/auth_spec.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ae2a778d8655f5597b36536b2863ea149b65ca7
|
4
|
+
data.tar.gz: a8b1bcb188baeebfe217c5604c7610afda612f70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf72f4d548b137c384258013ea0096b7756c0e712b0f2f9c509be671c2678bf673d9358104dfb0b21f71acfa12ece8f1419b42fe4882fe2e6bee5fe50ed9be7c
|
7
|
+
data.tar.gz: d807871a023cc56bb82cd165bafd474cdda14cb6ff9bce1743f69ac5892b65958c64f9a6f205a8365382823c4dd95aa1ab682218ce25fa7f68e6df2412131ef7
|
data/lib/cronofy/auth.rb
CHANGED
@@ -6,6 +6,8 @@ module Cronofy
|
|
6
6
|
attr_reader :access_token
|
7
7
|
|
8
8
|
def initialize(client_id, client_secret, token = nil, refresh_token = nil)
|
9
|
+
@client_credentials_missing = blank?(client_id) || blank?(client_secret)
|
10
|
+
|
9
11
|
@auth_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.app_url, connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
|
10
12
|
@api_client = OAuth2::Client.new(client_id, client_secret, site: ::Cronofy.api_url, connection_opts: { headers: { "User-Agent" => "Cronofy Ruby #{::Cronofy::VERSION}" } })
|
11
13
|
|
@@ -81,9 +83,16 @@ module Cronofy
|
|
81
83
|
private
|
82
84
|
|
83
85
|
def do_request(&block)
|
86
|
+
if @client_credentials_missing
|
87
|
+
raise CredentialsMissingError.new("OAuth client_id and client_secret must be set")
|
88
|
+
end
|
84
89
|
block.call
|
85
90
|
rescue OAuth2::Error => e
|
86
91
|
raise Errors.map_error(e)
|
87
92
|
end
|
93
|
+
|
94
|
+
def blank?(value)
|
95
|
+
value.nil? || value.strip.empty?
|
96
|
+
end
|
88
97
|
end
|
89
98
|
end
|
data/lib/cronofy/version.rb
CHANGED
@@ -163,6 +163,15 @@ describe Cronofy::Auth do
|
|
163
163
|
expect{ subject }.to raise_error(Cronofy::UnknownError)
|
164
164
|
end
|
165
165
|
end
|
166
|
+
|
167
|
+
context "client_id and client_secret not set" do
|
168
|
+
let(:client_id) { " " }
|
169
|
+
let(:client_secret) { " " }
|
170
|
+
|
171
|
+
it "throws a credentials missing error" do
|
172
|
+
expect { subject }.to raise_error(Cronofy::CredentialsMissingError, "OAuth client_id and client_secret must be set")
|
173
|
+
end
|
174
|
+
end
|
166
175
|
end
|
167
176
|
end
|
168
177
|
|