add_to_calendar_links 0.4.1 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/add_to_calendar_links.rb +30 -14
- data/lib/add_to_calendar_links/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3935ec3af4f96608e045c493af0023ded0d4e7bc1ab5a0a54eea0a4fda76f152
|
4
|
+
data.tar.gz: 527d15154d5761d981cdd45d07efe8a4ac80137c39764c7e7fd4cb2fd4ffc973
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93780860c00aaa06c46d0a93345484530b7640b4b096c94a793c12e60b2999bc5dc651782dbd8f2bef15a91e96da9867b99b6c45be30f01a2cbd0d47690368ec
|
7
|
+
data.tar.gz: 7f2e84c53eb136bc07c78e5398a03dff59beccd1410a2652234cd1df8f08e3cc22124095747aacd544a3272307ab58ec24046a13a98a9c9c93d4e462f5ef3f98
|
@@ -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 =
|
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
|
-
|
124
|
-
|
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[
|
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
|
-
|
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,16 +168,23 @@ module AddToCalendarLinks
|
|
159
168
|
end
|
160
169
|
end
|
161
170
|
params[:LOCATION] = url_encode_ical(location) if location
|
162
|
-
|
163
|
-
|
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[
|
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|
|
171
|
-
|
183
|
+
if key == :ORGANIZER
|
184
|
+
calendar_url << "\n#{key}#{value}"
|
185
|
+
else
|
186
|
+
calendar_url << "\n#{key}:#{value}"
|
187
|
+
end
|
172
188
|
end
|
173
189
|
|
174
190
|
calendar_url << "%0AEND:VEVENT%0AEND:VCALENDAR"
|