add_to_calendar_links 0.3.6 → 0.4

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: 2ae61335ecbe43a1ab464e1d7dad0c62308aca608150ccad48e7ec07a25811d1
4
- data.tar.gz: 7e23958684817312348d53b6bd78157e1779ef2c7fd4b3cc7e817bf60d60a8a7
3
+ metadata.gz: ff19e9aa3a6c509b5469cd27ff8f0b01cc82f07141cd0ed67e34f5eb43bfa65e
4
+ data.tar.gz: 94432081f0b675201b9aada3180aa03b4ddd28b6f22a74712510686c6c3e9faf
5
5
  SHA512:
6
- metadata.gz: bd1b787b1f8f8fe6f8e248ea2e6dbef1121a15a8b9c3f5f5c5907a485e5ae3772b584e41080f37166b636a2cb82957b062f5fcd90f529109e3eb37c1289c7a1b
7
- data.tar.gz: a467b4341c9a1a9cba5740be149ddc9a40d2d31703391e691d57aa316263dab5b1a29d7d88845b7de2041011fc7cbaf93a3019a65d550b7ee72d6961d7fa7546
6
+ metadata.gz: da4489eeed48856d3ecb2a34bef48d25eb31cedb38096f8e5bc77337099401729a054402f63456163ac42641b73a53290f13329241b63fe3737121632df88450
7
+ data.tar.gz: 48777ad3226a53f48e5bfc46d9e81df16d82f1dd40600dac72313a9d48a7198ec647ff2ada13a4502dac022a5c1c9e0314d7134182bbd8bf9c206a52a0a02908
@@ -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
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)
17
17
  @start_datetime = start_datetime
18
18
  @end_datetime = end_datetime
19
19
  @title = title
@@ -24,6 +24,8 @@ module AddToCalendarLinks
24
24
  @add_url_to_description = add_url_to_description
25
25
  @organizer = URI.parse(organizer) if organizer
26
26
  @strip_html = strip_html
27
+ @sequence = sequence
28
+ @last_modified = last_modified
27
29
  validate_attributes
28
30
  end
29
31
 
@@ -57,25 +59,28 @@ module AddToCalendarLinks
57
59
 
58
60
  def yahoo_url
59
61
  # 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"
62
+ calendar_url = "https://calendar.yahoo.com/?v=60&VIEW=d&TYPE=20"
61
63
  params = {}
62
- params[:title] = url_encode(title)
63
- params[:st] = utc_datetime(start_datetime)
64
+ params[:TITLE] = url_encode(title)
65
+ params[:ST] = utc_datetime(start_datetime)
64
66
  if end_datetime
67
+ # params[:ET] = utc_datetime(end_datetime)
65
68
  seconds = duration_seconds(start_datetime, end_datetime)
66
- params[:dur] = seconds_to_hours_minutes(seconds)
69
+ params[:DUR] = seconds_to_hours_minutes(seconds)
67
70
  else
68
- params[:dur] = "0100"
71
+ # params[:ET] = utc_datetime(start_datetime + 60*60)
72
+ params[:DUR] = "0100"
69
73
  end
70
- params[:desc] = url_encode(description) if description
74
+ params[:DESC] = url_encode(strip_html_tags(description)).truncate(3000) if description
75
+
71
76
  if add_url_to_description && url
72
- if params[:desc]
73
- params[:desc] << url_encode("\n\n#{url}")
77
+ if params[:DESC]
78
+ params[:DESC] << url_encode("\n\n#{url}")
74
79
  else
75
- params[:desc] = url_encode(url)
80
+ params[:DESC] = url_encode(url)
76
81
  end
77
82
  end
78
- params[:in_loc] = url_encode(location) if location
83
+ params[:IN_LOC] = url_encode(location) if location
79
84
 
80
85
  params.each do |key, value|
81
86
  calendar_url << "&#{key}=#{value}"
@@ -94,10 +99,48 @@ module AddToCalendarLinks
94
99
  microsoft("outlook.com")
95
100
  end
96
101
 
102
+ def ical_file
103
+ calendar_url = "BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT"
104
+
105
+ params = {}
106
+ params[:DTSTART] = utc_datetime(start_datetime)
107
+ if end_datetime
108
+ params[:DTEND] = utc_datetime(end_datetime)
109
+ else
110
+ params[:DTEND] = utc_datetime(start_datetime + 60*60) # 1 hour later
111
+ end
112
+ params[:SUMMARY] = strip_html_tags(title) #ical doesnt support html so remove all markup. Optional for other formats
113
+ params[:URL] = url if url
114
+ params[:DESCRIPTION] = strip_html_tags(description).strip if description
115
+ if add_url_to_description && url
116
+ if params[:DESCRIPTION]
117
+ params[:DESCRIPTION] << "\\n\\n#{url}"
118
+ else
119
+ params[:DESCRIPTION] = url
120
+ end
121
+ end
122
+ 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
125
+ params[:ORGANIZER] = organizer if organizer
126
+ params[:SEQUENCE] = sequence if sequence
127
+ params[:LASTMODIFIED] = format_date_google(last_modified) if last_modified
128
+ params[:METHOD] = "REQUEST"
129
+
130
+ params.each do |key, value|
131
+ calendar_url << "\n#{key}:#{value}"
132
+ end
133
+
134
+ calendar_url << "\nEND:VEVENT\nEND:VCALENDAR"
135
+
136
+ return calendar_url
137
+ end
138
+
97
139
  def ical_url
98
140
  # Downloads a *.ics file provided as a data-uri
99
141
  # 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
142
  calendar_url = "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT"
143
+
101
144
  params = {}
102
145
  params[:DTSTART] = utc_datetime(start_datetime)
103
146
  if end_datetime
@@ -107,7 +150,7 @@ module AddToCalendarLinks
107
150
  end
108
151
  params[:SUMMARY] = url_encode_ical(title, strip_html: true) #ical doesnt support html so remove all markup. Optional for other formats
109
152
  params[:URL] = url_encode(url) if url
110
- params[:DESCRIPTION] = url_encode_ical(description, strip_html: true) if description
153
+ params[:DESCRIPTION] = url_encode_ical(strip_html_tags(description, line_break_seperator: "\n")) if description
111
154
  if add_url_to_description && url
112
155
  if params[:DESCRIPTION]
113
156
  params[:DESCRIPTION] << "\\n\\n#{url_encode(url)}"
@@ -118,7 +161,10 @@ module AddToCalendarLinks
118
161
  params[:LOCATION] = url_encode_ical(location) if location
119
162
  params[:UID] = "-#{url_encode(url)}" if url
120
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
121
- params[:organizer] = organizer if organizer
164
+ params[:ORGANIZER] = organizer if organizer
165
+ params[:SEQUENCE] = sequence if sequence
166
+ params[:LASTMODIFIED] = format_date_google(last_modified) if last_modified
167
+ params[:METHOD] = "REQUEST"
122
168
 
123
169
  new_line = "%0A"
124
170
  params.each do |key, value|
@@ -254,11 +300,6 @@ module AddToCalendarLinks
254
300
  # per https://tools.ietf.org/html/rfc5545#section-3.3.11
255
301
  string = s.dup # don't modify original input
256
302
  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
303
  string = strip_html_tags(string)
263
304
  end
264
305
  string.gsub!("\\", "\\\\\\") # \ >> \\ --yes, really: https://stackoverflow.com/questions/6209480/how-to-replace-backslash-with-double-backslash
@@ -272,8 +313,16 @@ module AddToCalendarLinks
272
313
  }.compact.join("\\n").gsub(/(\\n){2,}/, "\\n\\n").strip
273
314
  end
274
315
 
275
- def strip_html_tags(description)
276
- description.dup.gsub(/<\/?[^>]*>/, "")
316
+ def strip_html_tags(description, line_break_seperator: "\\n")
317
+ string = description.dup
318
+ string.gsub!("<br>", line_break_seperator)
319
+ string.gsub!("<p>", line_break_seperator)
320
+ string.gsub!("</p>", line_break_seperator)
321
+ string.gsub!("&amp;", "and")
322
+ string.gsub!("&nbsp;", " ")
323
+ string.gsub!(/<\/?[^>]*>/, "")
324
+ string.gsub!(/(\\n){2,}/, "\\n\\n")
325
+ string.strip
277
326
  end
278
327
  end
279
328
  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'
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'
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