cronofy 0.1.1 → 0.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/cronofy/auth.rb +18 -2
- data/lib/cronofy/client.rb +25 -5
- data/lib/cronofy/version.rb +1 -1
- data/spec/lib/cronofy/auth_spec.rb +36 -0
- data/spec/lib/cronofy/client_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45bf57c6a8beff0b87cba2a4f20ce39f2d346c08
|
4
|
+
data.tar.gz: b44a0e902fdce56a5235777245da5401732c7e06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c9b7b89e732c1d5f2549e7490cdee7868fd8843b1fbe52dcda029452efad15aa201ed18a7fd2b3b21359a10e3d8beaa5e32754e530356264ded15bede98c491
|
7
|
+
data.tar.gz: 27595f37ddb805069debcd433fa7c72aac23d6914dea8ccc57260b8ea4af28bfdcf44b4ff08d1d59bfddb60c38f9d0831ce9e308f87749c287b1108449559f8e
|
data/lib/cronofy/auth.rb
CHANGED
@@ -12,7 +12,7 @@ module Cronofy
|
|
12
12
|
set_access_token(token, refresh_token) if token
|
13
13
|
end
|
14
14
|
|
15
|
-
#
|
15
|
+
# Internal: generate a URL for authorizing the application with Cronofy
|
16
16
|
#
|
17
17
|
# redirect_uri String, the URI to return to after authorization
|
18
18
|
# scope Array of String, the scope requested
|
@@ -31,7 +31,7 @@ module Cronofy
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
#
|
34
|
+
# Internal: Refreshes the access token
|
35
35
|
# Returns Hash of token elements to allow client to update in local store for user
|
36
36
|
def refresh!
|
37
37
|
do_request do
|
@@ -48,6 +48,22 @@ module Cronofy
|
|
48
48
|
@access_token = OAuth2::AccessToken.new(@api_client, token, refresh_token: refresh_token)
|
49
49
|
end
|
50
50
|
|
51
|
+
# Internal: Revokes the refresh token and corresponding access tokens.
|
52
|
+
#
|
53
|
+
# Returns nothing.
|
54
|
+
def revoke!
|
55
|
+
do_request do
|
56
|
+
body = {
|
57
|
+
client_id: @api_client.id,
|
58
|
+
client_secret: @api_client.secret,
|
59
|
+
token: access_token.refresh_token,
|
60
|
+
}
|
61
|
+
|
62
|
+
@api_client.request(:post, "/oauth/token/revoke", body: body)
|
63
|
+
@access_token = nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
51
67
|
private
|
52
68
|
|
53
69
|
def do_request(&block)
|
data/lib/cronofy/client.rb
CHANGED
@@ -133,6 +133,9 @@ module Cronofy
|
|
133
133
|
# :last_modified - The Time that events must be modified on or
|
134
134
|
# after in order to be returned (optional).
|
135
135
|
#
|
136
|
+
# The first page will be retrieved eagerly so that common errors will happen
|
137
|
+
# inline. However, subsequent pages (if any) will be requested lazily.
|
138
|
+
#
|
136
139
|
# See http://www.cronofy.com/developers/api#read-events for reference.
|
137
140
|
#
|
138
141
|
# Returns a lazily-evaluated Enumerable of Events
|
@@ -187,8 +190,7 @@ module Cronofy
|
|
187
190
|
#
|
188
191
|
# callback_url - A String specifing the callback URL for the channel.
|
189
192
|
#
|
190
|
-
# See http://www.cronofy.com/developers/api
|
191
|
-
# reference.
|
193
|
+
# See http://www.cronofy.com/developers/api#create-channel for reference.
|
192
194
|
#
|
193
195
|
# Returns a Channel.
|
194
196
|
#
|
@@ -208,8 +210,7 @@ module Cronofy
|
|
208
210
|
|
209
211
|
# Public: Lists all the notification channels for the account.
|
210
212
|
#
|
211
|
-
# See http://www.cronofy.com/developers/api
|
212
|
-
# reference.
|
213
|
+
# See http://www.cronofy.com/developers/api#list-channels for reference.
|
213
214
|
#
|
214
215
|
# Returns an Array of Channels.
|
215
216
|
#
|
@@ -229,6 +230,8 @@ module Cronofy
|
|
229
230
|
#
|
230
231
|
# channel_id - The String Cronofy ID for the channel to close.
|
231
232
|
#
|
233
|
+
# See http://www.cronofy.com/developers/api#close-channel for reference.
|
234
|
+
#
|
232
235
|
# Returns nothing.
|
233
236
|
#
|
234
237
|
# Raises Cronofy::CredentialsMissingError if no credentials available.
|
@@ -315,6 +318,22 @@ module Cronofy
|
|
315
318
|
@auth.refresh!
|
316
319
|
end
|
317
320
|
|
321
|
+
# Public: Revokes the account's refresh token and access token.
|
322
|
+
#
|
323
|
+
# After making this call the Client will become unusable. You should also
|
324
|
+
# delete the stored credentials used to create this instance.
|
325
|
+
#
|
326
|
+
# See http://www.cronofy.com/developers/api#revoke-authorization for
|
327
|
+
# reference.
|
328
|
+
#
|
329
|
+
# Returns nothing.
|
330
|
+
#
|
331
|
+
# Raises Cronofy::AuthenticationFailureError if the client ID and secret are
|
332
|
+
# not valid.
|
333
|
+
def revoke_authorization
|
334
|
+
@auth.revoke!
|
335
|
+
end
|
336
|
+
|
318
337
|
private
|
319
338
|
|
320
339
|
READ_EVENTS_DEFAULT_PARAMS = { tzid: "Etc/UTC" }.freeze
|
@@ -385,10 +404,11 @@ module Cronofy
|
|
385
404
|
@access_token = access_token
|
386
405
|
@url = url
|
387
406
|
@params = params
|
407
|
+
@first_page = get_page(url, params)
|
388
408
|
end
|
389
409
|
|
390
410
|
def each
|
391
|
-
page =
|
411
|
+
page = @first_page
|
392
412
|
|
393
413
|
page.events.each do |event|
|
394
414
|
yield event
|
data/lib/cronofy/version.rb
CHANGED
@@ -120,4 +120,40 @@ describe Cronofy::Auth do
|
|
120
120
|
|
121
121
|
it_behaves_like 'an authorization request'
|
122
122
|
end
|
123
|
+
|
124
|
+
describe "#revoke!" do
|
125
|
+
let(:auth) do
|
126
|
+
Cronofy::Auth.new(client_id, client_secret, access_token, refresh_token)
|
127
|
+
end
|
128
|
+
|
129
|
+
let!(:revocation_request) do
|
130
|
+
stub_request(:post, "https://api.cronofy.com/oauth/token/revoke")
|
131
|
+
.with(
|
132
|
+
body: {
|
133
|
+
client_id: client_id,
|
134
|
+
client_secret: client_secret,
|
135
|
+
token: refresh_token,
|
136
|
+
},
|
137
|
+
headers: {
|
138
|
+
'Content-Type' => 'application/x-www-form-urlencoded',
|
139
|
+
'User-Agent' => "Cronofy Ruby #{Cronofy::VERSION}",
|
140
|
+
}
|
141
|
+
)
|
142
|
+
.to_return(
|
143
|
+
status: response_status,
|
144
|
+
)
|
145
|
+
end
|
146
|
+
|
147
|
+
before do
|
148
|
+
auth.revoke!
|
149
|
+
end
|
150
|
+
|
151
|
+
it "unsets the access token" do
|
152
|
+
expect(auth.access_token).to be_nil
|
153
|
+
end
|
154
|
+
|
155
|
+
it "makes the revocation request" do
|
156
|
+
expect(revocation_request).to have_been_requested
|
157
|
+
end
|
158
|
+
end
|
123
159
|
end
|
@@ -396,6 +396,17 @@ describe Cronofy::Client do
|
|
396
396
|
expect(subject).to eq(first_event)
|
397
397
|
end
|
398
398
|
end
|
399
|
+
|
400
|
+
context "without calling #to_a to force full evaluation" do
|
401
|
+
subject { client.read_events(params) }
|
402
|
+
|
403
|
+
it_behaves_like 'a Cronofy request'
|
404
|
+
|
405
|
+
# We expect it to behave like a Cronofy request as the first page is
|
406
|
+
# requested eagerly so that the majority of errors will happen inline
|
407
|
+
# rather than lazily happening wherever the iterator may have been
|
408
|
+
# passed.
|
409
|
+
end
|
399
410
|
end
|
400
411
|
|
401
412
|
describe '#delete_event' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cronofy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergii Paryzhskyi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-04-
|
12
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|