add_to_calendar_links 0.3.6 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ae61335ecbe43a1ab464e1d7dad0c62308aca608150ccad48e7ec07a25811d1
4
- data.tar.gz: 7e23958684817312348d53b6bd78157e1779ef2c7fd4b3cc7e817bf60d60a8a7
3
+ metadata.gz: 47932762282ac0deb0990f5348ce278d8dec462187b40f8b77123009f7dccbbd
4
+ data.tar.gz: b0d2b899927994cb03ee0da37c8ef16c15d898701b9cd16ac75c5121ae32cab9
5
5
  SHA512:
6
- metadata.gz: bd1b787b1f8f8fe6f8e248ea2e6dbef1121a15a8b9c3f5f5c5907a485e5ae3772b584e41080f37166b636a2cb82957b062f5fcd90f529109e3eb37c1289c7a1b
7
- data.tar.gz: a467b4341c9a1a9cba5740be149ddc9a40d2d31703391e691d57aa316263dab5b1a29d7d88845b7de2041011fc7cbaf93a3019a65d550b7ee72d6961d7fa7546
6
+ metadata.gz: 316a5bb9b3c9b12a0ce6ed2aa1cce2af1284bb13cf84772f21ba7bf1cddd906a46a54b5ce004642dd18a02fb0058c77f52062a3d70a2f1a700966ea8d4bc0766
7
+ data.tar.gz: 3036b88a211fa84c271a9e7ac29090093c626adba389d758a682eac05e88c483abed7e60999f2dcc20b09a51dbfea5208bd81eee1857bb1349daea58c9767729
@@ -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
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)
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,8 +22,11 @@ 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
+ @sequence = sequence
28
+ @uid = uid
29
+ @last_modified = last_modified
27
30
  validate_attributes
28
31
  end
29
32
 
@@ -57,25 +60,28 @@ module AddToCalendarLinks
57
60
 
58
61
  def yahoo_url
59
62
  # Eg. https://calendar.yahoo.com/?v=60&view=d&type=20&title=Holly%27s%208th%20Birthday!&st=20200615T170000Z&dur=0100&desc=Join%20us%20to%20celebrate%20with%20lots%20of%20games%20and%20cake!&in_loc=7%20Apartments,%20London
60
- calendar_url = "https://calendar.yahoo.com/?v=60&view=d&type=20"
63
+ calendar_url = "https://calendar.yahoo.com/?v=60&VIEW=d&TYPE=20"
61
64
  params = {}
62
- params[:title] = url_encode(title)
63
- params[:st] = utc_datetime(start_datetime)
65
+ params[:TITLE] = url_encode(title)
66
+ params[:ST] = utc_datetime(start_datetime)
64
67
  if end_datetime
68
+ # params[:ET] = utc_datetime(end_datetime)
65
69
  seconds = duration_seconds(start_datetime, end_datetime)
66
- params[:dur] = seconds_to_hours_minutes(seconds)
70
+ params[:DUR] = seconds_to_hours_minutes(seconds)
67
71
  else
68
- params[:dur] = "0100"
72
+ # params[:ET] = utc_datetime(start_datetime + 60*60)
73
+ params[:DUR] = "0100"
69
74
  end
70
- params[:desc] = url_encode(description) if description
75
+ params[:DESC] = url_encode(strip_html_tags(description)).truncate(3000) if description
76
+
71
77
  if add_url_to_description && url
72
- if params[:desc]
73
- params[:desc] << url_encode("\n\n#{url}")
78
+ if params[:DESC]
79
+ params[:DESC] << url_encode("\n\n#{url}")
74
80
  else
75
- params[:desc] = url_encode(url)
81
+ params[:DESC] = url_encode(url)
76
82
  end
77
83
  end
78
- params[:in_loc] = url_encode(location) if location
84
+ params[:IN_LOC] = url_encode(location) if location
79
85
 
80
86
  params.each do |key, value|
81
87
  calendar_url << "&#{key}=#{value}"
@@ -94,10 +100,52 @@ module AddToCalendarLinks
94
100
  microsoft("outlook.com")
95
101
  end
96
102
 
103
+ def ical_file
104
+ calendar_url = "BEGIN:VCALENDAR\nVERSION:2.0\nMETHOD:REQUEST\nBEGIN:VEVENT"
105
+
106
+ params = {}
107
+ params[:DTSTART] = utc_datetime(start_datetime)
108
+ if end_datetime
109
+ params[:DTEND] = utc_datetime(end_datetime)
110
+ else
111
+ params[:DTEND] = utc_datetime(start_datetime + 60*60) # 1 hour later
112
+ end
113
+ params[:SUMMARY] = strip_html_tags(title) #ical doesnt support html so remove all markup. Optional for other formats
114
+ params[:URL] = url if url
115
+ params[:DESCRIPTION] = strip_html_tags(description).strip if description
116
+ if add_url_to_description && url
117
+ if params[:DESCRIPTION]
118
+ params[:DESCRIPTION] << "\\n\\n#{url}"
119
+ else
120
+ params[:DESCRIPTION] = url
121
+ end
122
+ end
123
+ params[:LOCATION] = strip_html_tags(location) if location
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
130
+ params[:ORGANIZER] = organizer if organizer
131
+ params[:SEQUENCE] = sequence if sequence
132
+ params["LAST-MODIFIED"] = format_date_google(last_modified) if last_modified
133
+ params[:METHOD] = "REQUEST"
134
+
135
+ params.each do |key, value|
136
+ calendar_url << "\n#{key}:#{value}"
137
+ end
138
+
139
+ calendar_url << "\nEND:VEVENT\nEND:VCALENDAR"
140
+
141
+ return calendar_url
142
+ end
143
+
97
144
  def ical_url
98
145
  # Downloads a *.ics file provided as a data-uri
99
146
  # 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"
100
- calendar_url = "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT"
147
+ calendar_url = "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0AMETHOD:REQUEST%0ABEGIN:VEVENT"
148
+
101
149
  params = {}
102
150
  params[:DTSTART] = utc_datetime(start_datetime)
103
151
  if end_datetime
@@ -107,7 +155,7 @@ module AddToCalendarLinks
107
155
  end
108
156
  params[:SUMMARY] = url_encode_ical(title, strip_html: true) #ical doesnt support html so remove all markup. Optional for other formats
109
157
  params[:URL] = url_encode(url) if url
110
- params[:DESCRIPTION] = url_encode_ical(description, strip_html: true) if description
158
+ params[:DESCRIPTION] = url_encode_ical(strip_html_tags(description, line_break_seperator: "\n")) if description
111
159
  if add_url_to_description && url
112
160
  if params[:DESCRIPTION]
113
161
  params[:DESCRIPTION] << "\\n\\n#{url_encode(url)}"
@@ -116,9 +164,15 @@ module AddToCalendarLinks
116
164
  end
117
165
  end
118
166
  params[:LOCATION] = url_encode_ical(location) if location
119
- params[:UID] = "-#{url_encode(url)}" if url
120
- 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
121
- params[:organizer] = organizer if organizer
167
+ if uid
168
+ params[:UID] = uid
169
+ else
170
+ params[:UID] = "-#{url_encode(url)}" if url
171
+ 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
172
+ end
173
+ params[:ORGANIZER] = organizer if organizer
174
+ params[:SEQUENCE] = sequence if sequence
175
+ params["LAST-MODIFIED"] = format_date_google(last_modified) if last_modified
122
176
 
123
177
  new_line = "%0A"
124
178
  params.each do |key, value|
@@ -254,11 +308,6 @@ module AddToCalendarLinks
254
308
  # per https://tools.ietf.org/html/rfc5545#section-3.3.11
255
309
  string = s.dup # don't modify original input
256
310
  if strip_html
257
- string.gsub!("<br>", "\n")
258
- string.gsub!("<p>", "\n")
259
- string.gsub!("</p>", "\n")
260
- string.gsub!("&amp;", "and")
261
- string.gsub!("&nbsp;", " ")
262
311
  string = strip_html_tags(string)
263
312
  end
264
313
  string.gsub!("\\", "\\\\\\") # \ >> \\ --yes, really: https://stackoverflow.com/questions/6209480/how-to-replace-backslash-with-double-backslash
@@ -272,8 +321,16 @@ module AddToCalendarLinks
272
321
  }.compact.join("\\n").gsub(/(\\n){2,}/, "\\n\\n").strip
273
322
  end
274
323
 
275
- def strip_html_tags(description)
276
- description.dup.gsub(/<\/?[^>]*>/, "")
324
+ def strip_html_tags(description, line_break_seperator: "\\n")
325
+ string = description.dup
326
+ string.gsub!("<br>", line_break_seperator)
327
+ string.gsub!("<p>", line_break_seperator)
328
+ string.gsub!("</p>", line_break_seperator)
329
+ string.gsub!("&amp;", "and")
330
+ string.gsub!("&nbsp;", " ")
331
+ string.gsub!(/<\/?[^>]*>/, "")
332
+ string.gsub!(/(\\n){2,}/, "\\n\\n")
333
+ string.strip
277
334
  end
278
335
  end
279
336
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AddToCalendarLinks
4
- VERSION = '0.3.6'
4
+ VERSION = '0.4.4'
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.3.6
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Turner
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-03-23 00:00:00.000000000 Z
12
+ date: 2021-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: tzinfo