add_to_calendar_links 0.4 → 0.4.5

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: ff19e9aa3a6c509b5469cd27ff8f0b01cc82f07141cd0ed67e34f5eb43bfa65e
4
- data.tar.gz: 94432081f0b675201b9aada3180aa03b4ddd28b6f22a74712510686c6c3e9faf
3
+ metadata.gz: 423f11257d10d8dfee4255bc96b497c91c88a92f0fc2d6efeffb201954b806fb
4
+ data.tar.gz: 92879e7e0a0e9fdc37491ea9f08a8bcade115c13042e520a64b592f4909967b8
5
5
  SHA512:
6
- metadata.gz: da4489eeed48856d3ecb2a34bef48d25eb31cedb38096f8e5bc77337099401729a054402f63456163ac42641b73a53290f13329241b63fe3737121632df88450
7
- data.tar.gz: 48777ad3226a53f48e5bfc46d9e81df16d82f1dd40600dac72313a9d48a7198ec647ff2ada13a4502dac022a5c1c9e0314d7134182bbd8bf9c206a52a0a02908
6
+ metadata.gz: 39be1c44951c564f8f702f692b82599d842758640fd7d53b6fe7e5acbf0dca1a6bc3989908ad130971b3b108ec25d9fb45e93f836fae8bd03205ff6c61a33a08
7
+ data.tar.gz: 847d3f5cbc60407c601177c9d9beaf065f10d4e153f2df93dbb337f28dadb009d16d1543d887c0f81137da4ecb7c8e4f164fadfd7a4df40033a57bb7b5e41890
@@ -12,8 +12,8 @@ module AddToCalendarLinks
12
12
  class Error < StandardError; end
13
13
 
14
14
  class URLs
15
- attr_accessor :start_datetime, :end_datetime, :title, :timezone, :location, :url, :description, :add_url_to_description, :organizer, :strip_html, :sequence, :last_modified
16
- def initialize(start_datetime:, end_datetime: nil, title:, timezone:, location: nil, url: nil, description: nil, add_url_to_description: true, organizer: nil, strip_html: false, sequence: nil, last_modified: Time.now.utc)
15
+ attr_accessor :start_datetime, :end_datetime, :title, :timezone, :location, :url, :description, :add_url_to_description, :organizer, :strip_html, :sequence, :last_modified, :uid
16
+ def initialize(start_datetime:, end_datetime: nil, title:, timezone:, location: nil, url: nil, description: nil, add_url_to_description: true, organizer: nil, strip_html: false, sequence: nil, last_modified: Time.now.utc, uid:)
17
17
  @start_datetime = start_datetime
18
18
  @end_datetime = end_datetime
19
19
  @title = title
@@ -22,9 +22,10 @@ module AddToCalendarLinks
22
22
  @url = url
23
23
  @description = description
24
24
  @add_url_to_description = add_url_to_description
25
- @organizer = URI.parse(organizer) if organizer
25
+ @organizer = organizer if organizer
26
26
  @strip_html = strip_html
27
27
  @sequence = sequence
28
+ @uid = uid
28
29
  @last_modified = last_modified
29
30
  validate_attributes
30
31
  end
@@ -100,7 +101,7 @@ module AddToCalendarLinks
100
101
  end
101
102
 
102
103
  def ical_file
103
- calendar_url = "BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT"
104
+ calendar_url = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:REQUEST\nBEGIN:VEVENT"
104
105
 
105
106
  params = {}
106
107
  params[:DTSTART] = utc_datetime(start_datetime)
@@ -120,15 +121,23 @@ module AddToCalendarLinks
120
121
  end
121
122
  end
122
123
  params[:LOCATION] = strip_html_tags(location) if location
123
- params[:UID] = "-#{url}" if url
124
- params[:UID] = "-#{utc_datetime(start_datetime)}-#{title}" unless params[:UID] # set uid based on starttime and title only if url is unavailable
124
+ if uid
125
+ params[:UID] = uid
126
+ else
127
+ params[:UID] = "-#{urlc}" if url
128
+ params[:UID] = "-#{utc_datetime(start_datetime)}-#{title}" unless params[:UID] # set uid based on starttime and title only if url is unavailable
129
+ end
125
130
  params[:ORGANIZER] = organizer if organizer
126
131
  params[:SEQUENCE] = sequence if sequence
127
- params[:LASTMODIFIED] = format_date_google(last_modified) if last_modified
132
+ params["LAST-MODIFIED"] = format_date_google(last_modified) if last_modified
128
133
  params[:METHOD] = "REQUEST"
129
134
 
130
135
  params.each do |key, value|
131
- calendar_url << "\n#{key}:#{value}"
136
+ if key == :ORGANIZER
137
+ calendar_url << "\n#{key}#{value}"
138
+ else
139
+ calendar_url << "\n#{key}:#{value}"
140
+ end
132
141
  end
133
142
 
134
143
  calendar_url << "\nEND:VEVENT\nEND:VCALENDAR"
@@ -139,7 +148,7 @@ module AddToCalendarLinks
139
148
  def ical_url
140
149
  # Downloads a *.ics file provided as a data-uri
141
150
  # Eg. "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT%0ADTSTART:20200512T123000Z%0ADTEND:20200512T160000Z%0ASUMMARY:Holly%27s%208th%20Birthday%21%0AURL:https%3A%2F%2Fwww.example.com%2Fevent-details%0ADESCRIPTION:Come%20join%20us%20for%20lots%20of%20fun%20%26%20cake%21\\n\\nhttps%3A%2F%2Fwww.example.com%2Fevent-details%0ALOCATION:Flat%204%5C%2C%20The%20Edge%5C%2C%2038%20Smith-Dorrien%20St%5C%2C%20London%5C%2C%20N1%207GU%0AUID:-https%3A%2F%2Fwww.example.com%2Fevent-details%0AEND:VEVENT%0AEND:VCALENDAR"
142
- calendar_url = "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT"
151
+ calendar_url = "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0AMETHOD:REQUEST%0ABEGIN:VEVENT"
143
152
 
144
153
  params = {}
145
154
  params[:DTSTART] = utc_datetime(start_datetime)
@@ -159,12 +168,15 @@ module AddToCalendarLinks
159
168
  end
160
169
  end
161
170
  params[:LOCATION] = url_encode_ical(location) if location
162
- params[:UID] = "-#{url_encode(url)}" if url
163
- params[:UID] = "-#{utc_datetime(start_datetime)}-#{url_encode_ical(title)}" unless params[:UID] # set uid based on starttime and title only if url is unavailable
171
+ if uid
172
+ params[:UID] = uid
173
+ else
174
+ params[:UID] = "-#{url_encode(url)}" if url
175
+ params[:UID] = "-#{utc_datetime(start_datetime)}-#{url_encode_ical(title)}" unless params[:UID] # set uid based on starttime and title only if url is unavailable
176
+ end
164
177
  params[:ORGANIZER] = organizer if organizer
165
178
  params[:SEQUENCE] = sequence if sequence
166
- params[:LASTMODIFIED] = format_date_google(last_modified) if last_modified
167
- params[:METHOD] = "REQUEST"
179
+ params["LAST-MODIFIED"] = format_date_google(last_modified) if last_modified
168
180
 
169
181
  new_line = "%0A"
170
182
  params.each do |key, value|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AddToCalendarLinks
4
- VERSION = '0.4'
4
+ VERSION = '0.4.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: add_to_calendar_links
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Turner