calendav 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 605ae687dccd58f74c2c2ec01b44bf27b2cc71de6f5453d26c398b7828325d40
4
- data.tar.gz: '08c0253e9cc5479f1370a2acb5973901a4d9079078a9f51aba2ac28fccf75b9d'
3
+ metadata.gz: 6bae509ffc0254b00db9e4380a76278770a0868093ff69b597b6b10fcf9ecd01
4
+ data.tar.gz: 26cfe5ccbc19dba770cf2d255cbb36bc3529039903af8d28281536f70cb55c49
5
5
  SHA512:
6
- metadata.gz: 20d4fefd21bdf9d58a2c76e557b80be9a6f62c0a4c38667ab806f91e9081e34179941ad9238ca25007db41525a9ac21ec1fe2ce84ac311418e50458af55a413a
7
- data.tar.gz: e3584378cea92199c918f81df44394ccac34b20b2f963abd72d2488d0356dd2108e06ec038ea68e511e2548f9ee48684b3584950cd737d431530479d57430ae2
6
+ metadata.gz: 56fd5c731ad0d4b05d29a68df6624bad4809a6a146806c8190ba765b233e39598572711ff6f5f61a59df09a8d919090b45641bfbc2214a1ad746f4a7f5bf8662
7
+ data.tar.gz: fa897448f63e9c5a04f8c97acebb950d0213fbc8aa10eb8d4069aaaafbe9849148dafe526de9c78a6d947c4a43eaaa78260665dfd05d66b429c21d5e1caf5a7e
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  ## Unreleased
2
2
 
3
- ...
3
+ ## 0.3.0 - 2022-03-14
4
+
5
+ * Add location to event wrapper.
6
+ * Allow setting timeouts for client calls.
7
+ * Avoid external calls to calculate calendar URLs where possible.
4
8
 
5
9
  ## 0.2.0 - 2021-07-07
6
10
 
data/Gemfile CHANGED
@@ -3,3 +3,7 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
+
7
+ gem "icalendar",
8
+ git: "https://github.com/pat/icalendar.git",
9
+ branch: "fix/activesupport-7"
@@ -8,8 +8,9 @@ require_relative "./requests/current_user_principal"
8
8
 
9
9
  module Calendav
10
10
  class Client
11
- def initialize(credentials)
11
+ def initialize(credentials, timeout: nil)
12
12
  @credentials = credentials
13
+ @timeout = timeout
13
14
  end
14
15
 
15
16
  def calendars
@@ -34,10 +35,10 @@ module Calendav
34
35
 
35
36
  private
36
37
 
37
- attr_reader :credentials
38
+ attr_reader :credentials, :timeout
38
39
 
39
40
  def endpoint
40
- @endpoint ||= Endpoint.new(credentials)
41
+ @endpoint ||= Endpoint.new(credentials, timeout: timeout)
41
42
  end
42
43
  end
43
44
  end
@@ -64,7 +64,7 @@ module Calendav
64
64
  endpoint
65
65
  .propfind(request.to_xml, url: url, depth: depth)
66
66
  .select { |node| node.xpath(calendar_xpath).any? }
67
- .collect { |node| Calendar.from_xml(home_url, node) }
67
+ .collect { |node| Calendar.from_xml(url, node) }
68
68
  end
69
69
 
70
70
  def options
@@ -11,8 +11,9 @@ module Calendav
11
11
  xml: "application/xml; charset=utf-8"
12
12
  }.freeze
13
13
 
14
- def initialize(credentials)
14
+ def initialize(credentials, timeout: nil)
15
15
  @credentials = credentials
16
+ @timeout = timeout
16
17
  end
17
18
 
18
19
  def delete(url:, etag: nil)
@@ -76,7 +77,7 @@ module Calendav
76
77
 
77
78
  private
78
79
 
79
- attr_reader :credentials
80
+ attr_reader :credentials, :timeout
80
81
 
81
82
  def authenticated
82
83
  case credentials.authentication
@@ -93,6 +94,7 @@ module Calendav
93
94
  def with_headers(content_type: nil, depth: nil, etag: nil)
94
95
  http = authenticated
95
96
 
97
+ http = http.timeout(timeout) if timeout
96
98
  http = http.headers(depth: depth) if depth
97
99
  http = http.headers("If-Match" => etag) if etag
98
100
  if content_type
@@ -33,6 +33,10 @@ module Calendav
33
33
  inner_event.summary
34
34
  end
35
35
 
36
+ def location
37
+ inner_event.location
38
+ end
39
+
36
40
  def dtstart
37
41
  inner_event.dtstart
38
42
  end
data/lib/calendav.rb CHANGED
@@ -16,7 +16,7 @@ module Calendav
16
16
  PROVIDERS.fetch(provider).new(username: username, password: password)
17
17
  end
18
18
 
19
- def self.client(credentials)
20
- Client.new(credentials)
19
+ def self.client(credentials, timeout: nil)
20
+ Client.new(credentials, timeout: timeout)
21
21
  end
22
22
  end
@@ -4,7 +4,7 @@ require "securerandom"
4
4
 
5
5
  require_relative "./shared"
6
6
 
7
- RSpec.describe "Apple" do
7
+ RSpec.describe "Apple", :vcr do
8
8
  let(:provider) { :apple }
9
9
  let(:username) { ENV.fetch("APPLE_USERNAME") }
10
10
  let(:password) { ENV.fetch("APPLE_PASSWORD") }
@@ -27,10 +27,14 @@ RSpec.describe "Apple" do
27
27
 
28
28
  context "with a calendar" do
29
29
  let(:calendar_url) do
30
- subject.calendars.create(SecureRandom.uuid, display_name: "Calendav Test")
30
+ subject.calendars.create(@name, display_name: "Calendav Test")
31
31
  end
32
32
  let(:calendar) { subject.calendars.find(calendar_url) }
33
33
 
34
+ before :each do |example|
35
+ @name = Digest::MD5.hexdigest(example.metadata[:full_description])
36
+ end
37
+
34
38
  after :each do
35
39
  subject.calendars.delete(calendar.url)
36
40
  end
@@ -8,7 +8,7 @@ require "uri"
8
8
 
9
9
  require_relative "./shared"
10
10
 
11
- RSpec.describe "Google" do
11
+ RSpec.describe "Google", :vcr do
12
12
  let(:provider) { :google }
13
13
  let(:username) { ENV.fetch("GOOGLE_USERNAME") }
14
14
  let(:access_token) { @access_token }
@@ -17,7 +17,7 @@ RSpec.describe "Google" do
17
17
 
18
18
  subject { Calendav.client(credentials) }
19
19
 
20
- before :context do
20
+ before :each do
21
21
  @google_auth = Google::Auth::UserRefreshCredentials.new(
22
22
  client_id: ENV.fetch("GOOGLE_CLIENT_ID"),
23
23
  scope: [],
@@ -84,7 +84,7 @@ RSpec.describe "Google" do
84
84
 
85
85
  it "does not respect etag conditions for deletions" do
86
86
  event_url = subject.events.create(
87
- calendar.url, event_identifier, ical_event("Brunch", 10, 30)
87
+ calendar.url, "calendav-event.ics", ical_event("Brunch", 10, 30)
88
88
  )
89
89
  event = subject.events.find(event_url)
90
90
 
@@ -34,7 +34,7 @@ RSpec.describe "Radicale" do
34
34
 
35
35
  context "with a calendar" do
36
36
  let(:calendar_url) do
37
- subject.calendars.create(SecureRandom.uuid, display_name: "Calendav Test")
37
+ subject.calendars.create("calendav-test", display_name: "Calendav Test")
38
38
  end
39
39
  let(:calendar) { subject.calendars.find(calendar_url) }
40
40
 
@@ -11,7 +11,7 @@ RSpec.shared_examples "supporting calendar management" do
11
11
  end
12
12
 
13
13
  it "can create, find, update and delete calendars" do
14
- identifier = SecureRandom.uuid
14
+ identifier = "calendav-test"
15
15
  time_zone = TZInfo::Timezone.get "UTC"
16
16
  ical_time_zone = time_zone.ical_timezone Time.now.utc
17
17
 
@@ -51,7 +51,7 @@ RSpec.shared_examples "supporting event management" do
51
51
  it "can create, find, update and delete events" do
52
52
  # Create an event
53
53
  event_url = subject.events.create(
54
- calendar.url, event_identifier, ical_event("Brunch", 10, 30)
54
+ calendar.url, "calendav-event-1.ics", ical_event("Brunch", 10, 30)
55
55
  )
56
56
  expect(event_url).to include(URI.decode_www_form_component(calendar.url))
57
57
  event = subject.events.find(event_url)
@@ -79,7 +79,7 @@ RSpec.shared_examples "supporting event management" do
79
79
 
80
80
  # Create another event
81
81
  another_url = subject.events.create(
82
- calendar.url, event_identifier, ical_event("Brunch", 10, 30)
82
+ calendar.url, "calendav-event-2.ics", ical_event("Brunch", 10, 30)
83
83
  )
84
84
 
85
85
  # Search for all events
@@ -93,7 +93,7 @@ RSpec.shared_examples "supporting event management" do
93
93
 
94
94
  it "respects etag conditions with updates" do
95
95
  event_url = subject.events.create(
96
- calendar.url, event_identifier, ical_event("Brunch", 10, 30)
96
+ calendar.url, "calendav-event.ics", ical_event("Brunch", 10, 30)
97
97
  )
98
98
  event = subject.events.find(event_url)
99
99
 
@@ -122,7 +122,7 @@ RSpec.shared_examples "supporting event management" do
122
122
 
123
123
  it "handles synchronisation requests" do
124
124
  first_url = subject.events.create(
125
- calendar.url, event_identifier, ical_event("Brunch", 10, 30)
125
+ calendar.url, "calendav-event-1.ics", ical_event("Brunch", 10, 30)
126
126
  )
127
127
  first = subject.events.find(first_url)
128
128
  token = subject.calendars.find(calendar.url, sync: true).sync_token
@@ -131,7 +131,7 @@ RSpec.shared_examples "supporting event management" do
131
131
  expect(events.length).to eq(1)
132
132
 
133
133
  second_url = subject.events.create(
134
- calendar.url, event_identifier, ical_event("Brunch Again", 11, 30)
134
+ calendar.url, "calendav-event-2.ics", ical_event("Brunch Again", 11, 30)
135
135
  )
136
136
 
137
137
  subject.events.update(first_url, update_summary(first, "Coffee"))
@@ -163,7 +163,7 @@ end
163
163
  RSpec.shared_examples "supporting event deletion with etags" do
164
164
  it "respects etag conditions with deletions" do
165
165
  event_url = subject.events.create(
166
- calendar.url, event_identifier, ical_event("Brunch", 10, 30)
166
+ calendar.url, "calendav-event.ics", ical_event("Brunch", 10, 30)
167
167
  )
168
168
  event = subject.events.find(event_url)
169
169
 
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,7 @@ Dotenv.load
7
7
 
8
8
  require_relative "support/encoded_matchers"
9
9
  require_relative "support/event_helpers"
10
+ require_relative "support/vcr"
10
11
 
11
12
  RSpec.configure do |config|
12
13
  config.disable_monkey_patching!
@@ -1,13 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # require "active_support"
3
4
  require "icalendar"
4
5
  require "securerandom"
5
6
 
6
7
  module EventHelpers
7
- def event_identifier
8
- "#{SecureRandom.uuid}.ics"
9
- end
10
-
11
8
  def ical_event(summary, hour, minute)
12
9
  start = time_at(hour, minute)
13
10
 
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "timecop"
4
+ require "webmock/rspec"
5
+ require "vcr"
6
+ require "vcr_assistant/rspec"
7
+
8
+ VCR.configure do |config|
9
+ config.cassette_library_dir = File.expand_path(
10
+ File.join(__dir__, "../cassettes")
11
+ )
12
+ config.hook_into :webmock
13
+ config.ignore_hosts "127.0.0.1"
14
+ end
15
+
16
+ RSpec.configure do |config|
17
+ config.around(:each, :vcr) do |example|
18
+ assisted_cassette(example) do |_assistant|
19
+ Timecop.freeze(Time.gm(2022))
20
+
21
+ example.run
22
+
23
+ Timecop.return
24
+ end
25
+ end
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calendav
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-07 00:00:00.000000000 Z
11
+ date: 2022-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: timecop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: tzinfo
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +164,48 @@ dependencies:
150
164
  - - ">="
151
165
  - !ruby/object:Gem::Version
152
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: vcr
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: vcr_assistant
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: webmock
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
153
209
  description:
154
210
  email:
155
211
  - pat@freelancing-gods.com
@@ -199,6 +255,7 @@ files:
199
255
  - spec/spec_helper.rb
200
256
  - spec/support/encoded_matchers.rb
201
257
  - spec/support/event_helpers.rb
258
+ - spec/support/vcr.rb
202
259
  homepage: https://github.com/pat/calendav
203
260
  licenses:
204
261
  - Hippocratic-2.1
@@ -206,6 +263,7 @@ metadata:
206
263
  homepage_uri: https://github.com/pat/calendav
207
264
  source_code_uri: https://github.com/pat/calendav
208
265
  changelog_uri: https://github.com/pat/calendav/blob/main/CHANGELOG.md
266
+ rubygems_mfa_required: 'true'
209
267
  post_install_message:
210
268
  rdoc_options: []
211
269
  require_paths:
@@ -221,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
279
  - !ruby/object:Gem::Version
222
280
  version: '0'
223
281
  requirements: []
224
- rubygems_version: 3.2.15
282
+ rubygems_version: 3.2.32
225
283
  signing_key:
226
284
  specification_version: 4
227
285
  summary: CalDAV client
@@ -235,6 +293,7 @@ test_files:
235
293
  - spec/spec_helper.rb
236
294
  - spec/support/encoded_matchers.rb
237
295
  - spec/support/event_helpers.rb
296
+ - spec/support/vcr.rb
238
297
  - ".rspec"
239
298
  - Gemfile
240
299
  - Rakefile