add_to_calendar 0.1.0 → 0.2.0
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 +4 -4
- data/.github/FUNDING.yml +12 -0
- data/.gitignore +1 -0
- data/Gemfile.lock +3 -3
- data/README.md +13 -2
- data/add_to_calendar.gemspec +3 -1
- data/lib/add_to_calendar.rb +63 -10
- data/lib/add_to_calendar/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1fba2b9dfdd72ba02d3d29413d1035c6f726569610e18227802cfd85f11e7af
|
4
|
+
data.tar.gz: ab89af6a02c276049dbbcac88fca397e37c3305084836a5e8467629064d414f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddc95426b93e001ea114f67b587b721ddea084d2f7607316181ee8c56e002a5c881ae10653d0a4ba9f4fdfee57c918f92e3d3320f54e4cbf9a9bf79faea59b8d
|
7
|
+
data.tar.gz: 4b0015473216a8da08b990ee5e290e80e8e2b8b873971a2197c84da30aaa1489d6878a10c03ed5efbffa5f719148b60434ca99dbeee1eee6cdbd3fccdf3a3a03
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# These are supported funding model platforms
|
2
|
+
|
3
|
+
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
4
|
+
patreon: # Replace with a single Patreon username
|
5
|
+
open_collective: # Replace with a single Open Collective username
|
6
|
+
ko_fi: jaredlt
|
7
|
+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
8
|
+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
9
|
+
liberapay: # Replace with a single Liberapay username
|
10
|
+
issuehunt: # Replace with a single IssueHunt username
|
11
|
+
otechie: # Replace with a single Otechie username
|
12
|
+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
add_to_calendar (0.
|
4
|
+
add_to_calendar (0.2.0)
|
5
5
|
tzinfo (~> 2.0.2)
|
6
6
|
tzinfo-data (~> 1.2020.1)
|
7
7
|
|
@@ -15,7 +15,7 @@ GEM
|
|
15
15
|
pry (0.13.1)
|
16
16
|
coderay (~> 1.1)
|
17
17
|
method_source (~> 1.0)
|
18
|
-
rake (
|
18
|
+
rake (13.0.1)
|
19
19
|
tzinfo (2.0.2)
|
20
20
|
concurrent-ruby (~> 1.0)
|
21
21
|
tzinfo-data (1.2020.1)
|
@@ -29,7 +29,7 @@ DEPENDENCIES
|
|
29
29
|
bundler (~> 2.0)
|
30
30
|
minitest (~> 5.0)
|
31
31
|
pry (~> 0.13.1)
|
32
|
-
rake (~>
|
32
|
+
rake (~> 13.0.1)
|
33
33
|
|
34
34
|
BUNDLED WITH
|
35
35
|
2.0.2
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# AddToCalendar
|
2
2
|
|
3
|
-
A ruby gem to generate 'Add To Calendar' URLs for
|
3
|
+
A ruby gem to generate 'Add To Calendar' URLs for Apple, Google, Office 365, Outlook, Outlook.com and Yahoo calendars.
|
4
4
|
|
5
|
-
|
5
|
+
If this gem brings you some value feel free to buy me a coffee :) [](https://ko-fi.com/P5P71PK9T)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -41,6 +41,13 @@ Or install it yourself as:
|
|
41
41
|
@cal.yahoo_url
|
42
42
|
#=> "https://calendar.yahoo.com/?v=60&view=d&type=20&title=Christmas%20party%21&st=20201212T133000Z&dur=0100"
|
43
43
|
|
44
|
+
@cal.office365_url
|
45
|
+
#=> "https://outlook.office.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent&subject=Christmas%20party%21&startdt=2020-12-12T13:30:00Z&enddt=2020-12-12T14:30:00Z"
|
46
|
+
|
47
|
+
# For outlook.com, different to Outlook the desktop application below
|
48
|
+
@cal.outlook_com_url
|
49
|
+
#=> "https://outlook.live.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent&subject=Christmas%20party%21&startdt=2020-12-12T13:30:00Z&enddt=2020-12-12T14:30:00Z"
|
50
|
+
|
44
51
|
# ical provides a data-uri which will download a properly formatted *.ics file (see 'Creating HTML links' section)
|
45
52
|
@cal.ical_url
|
46
53
|
#=> "data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT%0ADTSTART=20201212T133000Z%0ADTEND=20201212T143000Z%0ASUMMARY=Christmas%20party%21%0AUID=-20201212T133000Z-Christmas%20party%21%0AEND:VEVENT%0AEND:VCALENDAR"
|
@@ -107,6 +114,10 @@ cal = AddToCalendar::URLs.new(event_attributes)
|
|
107
114
|
|
108
115
|
- Read the [Wiki](https://github.com/jaredlt/add_to_calendar/wiki) for more specific details
|
109
116
|
|
117
|
+
## Why build this?
|
118
|
+
|
119
|
+
I couldn't find an approriate gem or javascript library that did exactly what I wanted. So I decided to scratch my own itch to solve a problem for a startup I'm working on: https://www.littlefutures.org
|
120
|
+
|
110
121
|
## Development
|
111
122
|
|
112
123
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/add_to_calendar.gemspec
CHANGED
@@ -26,11 +26,13 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
|
+
spec.required_ruby_version = '>= 2.0'
|
30
|
+
|
29
31
|
spec.add_dependency "tzinfo", "~> 2.0.2"
|
30
32
|
spec.add_dependency "tzinfo-data", "~> 1.2020.1"
|
31
33
|
|
32
34
|
spec.add_development_dependency "bundler", "~> 2.0"
|
33
|
-
spec.add_development_dependency "rake", "~>
|
35
|
+
spec.add_development_dependency "rake", "~> 13.0.1"
|
34
36
|
spec.add_development_dependency "minitest", "~> 5.0"
|
35
37
|
spec.add_development_dependency "pry", "~> 0.13.1"
|
36
38
|
end
|
data/lib/add_to_calendar.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "add_to_calendar/version"
|
2
2
|
|
3
|
-
# needed for url_encode method
|
3
|
+
# erb util needed for url_encode method
|
4
|
+
# CGI::escape uses + instead of %20 which doesn't work for ical files
|
4
5
|
require "erb"
|
5
6
|
include ERB::Util
|
6
7
|
require 'tzinfo'
|
@@ -32,9 +33,9 @@ module AddToCalendar
|
|
32
33
|
params = {}
|
33
34
|
params[:text] = url_encode(title)
|
34
35
|
if end_datetime
|
35
|
-
params[:dates] = "#{
|
36
|
+
params[:dates] = "#{format_date_google(start_datetime)}/#{format_date_google(end_datetime)}"
|
36
37
|
else
|
37
|
-
params[:dates] = "#{
|
38
|
+
params[:dates] = "#{format_date_google(start_datetime)}/#{format_date_google(start_datetime + 60*60)}" # end time is 1 hour later
|
38
39
|
end
|
39
40
|
params[:ctz] = timezone.identifier
|
40
41
|
params[:location] = url_encode(location) if location
|
@@ -54,10 +55,6 @@ module AddToCalendar
|
|
54
55
|
return calendar_url
|
55
56
|
end
|
56
57
|
|
57
|
-
# def office_365_url
|
58
|
-
|
59
|
-
# end
|
60
|
-
|
61
58
|
def yahoo_url
|
62
59
|
# 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
|
63
60
|
calendar_url = "https://calendar.yahoo.com/?v=60&view=d&type=20"
|
@@ -87,6 +84,16 @@ module AddToCalendar
|
|
87
84
|
return calendar_url
|
88
85
|
end
|
89
86
|
|
87
|
+
def office365_url
|
88
|
+
# Eg. https://outlook.live.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent&subject=Holly%27s%208th%20Birthday%21&startdt=2020-05-12T12:30:00Z&enddt=2020-05-12T16:00:00Z&body=Come%20join%20us%20for%20lots%20of%20fun%20%26%20cake%21%0A%0Ahttps%3A%2F%2Fwww.example.com%2Fevent-details&location=Flat%204%2C%20The%20Edge%2C%2038%20Smith-Dorrien%20St%2C%20London%2C%20N1%207GU
|
89
|
+
microsoft("office365")
|
90
|
+
end
|
91
|
+
|
92
|
+
def outlook_com_url
|
93
|
+
# Eg. https://outlook.live.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent&subject=Holly%27s%208th%20Birthday%21&startdt=2020-05-12T12:30:00Z&enddt=2020-05-12T16:00:00Z&body=Come%20join%20us%20for%20lots%20of%20fun%20%26%20cake%21%0A%0Ahttps%3A%2F%2Fwww.example.com%2Fevent-details&location=Flat%204%2C%20The%20Edge%2C%2038%20Smith-Dorrien%20St%2C%20London%2C%20N1%207GU
|
94
|
+
microsoft("outlook.com")
|
95
|
+
end
|
96
|
+
|
90
97
|
def ical_url
|
91
98
|
# Downloads a *.ics file provided as a data:text href
|
92
99
|
# Eg. data:text/calendar;charset=utf8,BEGIN:VCALENDAR%0AVERSION:2.0%0ABEGIN:VEVENT%0ADTSTART=20200610T123000Z%0ADTEND=20200610T133000Z%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%2C%20The%20Edge%2C%2038%20Smith-Dorrien%20St%2C%20London%2C%20N1%207GU%0AUID=-https%3A%2F%2Fwww.example.com%2Fevent-details%0AEND:VEVENT%0AEND:VCALENDAR
|
@@ -152,6 +159,40 @@ module AddToCalendar
|
|
152
159
|
end
|
153
160
|
end
|
154
161
|
|
162
|
+
def microsoft(service)
|
163
|
+
# Eg.
|
164
|
+
if service == "outlook.com"
|
165
|
+
calendar_url = "https://outlook.live.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent"
|
166
|
+
elsif service == "office365"
|
167
|
+
calendar_url = "https://outlook.office.com/calendar/0/deeplink/compose?path=/calendar/action/compose&rru=addevent"
|
168
|
+
else
|
169
|
+
raise MicrosoftServiceError, ":service must be 'outlook.com' or 'office365'. '#{service}' given"
|
170
|
+
end
|
171
|
+
params = {}
|
172
|
+
params[:subject] = url_encode(title)
|
173
|
+
params[:startdt] = utc_datetime_microsoft(start_datetime)
|
174
|
+
if end_datetime
|
175
|
+
params[:enddt] = utc_datetime_microsoft(end_datetime)
|
176
|
+
else
|
177
|
+
params[:enddt] = utc_datetime_microsoft(start_datetime + 60*60) # 1 hour later
|
178
|
+
end
|
179
|
+
params[:body] = url_encode(description) if description
|
180
|
+
if add_url_to_description && url
|
181
|
+
if params[:body]
|
182
|
+
params[:body] << url_encode("\n\n#{url}")
|
183
|
+
else
|
184
|
+
params[:body] = url_encode(url)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
params[:location] = url_encode(location) if location
|
188
|
+
|
189
|
+
params.each do |key, value|
|
190
|
+
calendar_url << "&#{key}=#{value}"
|
191
|
+
end
|
192
|
+
|
193
|
+
return calendar_url
|
194
|
+
end
|
195
|
+
|
155
196
|
def utc_datetime(datetime)
|
156
197
|
t = timezone.local_time(
|
157
198
|
datetime.strftime("%Y").to_i,
|
@@ -162,11 +203,23 @@ module AddToCalendar
|
|
162
203
|
datetime.strftime("%S").to_i
|
163
204
|
).utc
|
164
205
|
|
165
|
-
|
206
|
+
return t.strftime('%Y%m%dT%H%M%SZ')
|
207
|
+
end
|
208
|
+
|
209
|
+
def utc_datetime_microsoft(datetime)
|
210
|
+
t = timezone.local_time(
|
211
|
+
datetime.strftime("%Y").to_i,
|
212
|
+
datetime.strftime("%m").to_i,
|
213
|
+
datetime.strftime("%d").to_i,
|
214
|
+
datetime.strftime("%H").to_i,
|
215
|
+
datetime.strftime("%M").to_i,
|
216
|
+
datetime.strftime("%S").to_i
|
217
|
+
).utc
|
218
|
+
|
219
|
+
return t.strftime('%Y-%m-%dT%H:%M:%SZ')
|
166
220
|
end
|
167
221
|
|
168
|
-
|
169
|
-
def format_date(start_datetime)
|
222
|
+
def format_date_google(start_datetime)
|
170
223
|
start_datetime.strftime('%Y%m%dT%H%M%S')
|
171
224
|
end
|
172
225
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: add_to_calendar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared Turner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 13.0.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 13.0.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: minitest
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,6 +101,7 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
+
- ".github/FUNDING.yml"
|
104
105
|
- ".gitignore"
|
105
106
|
- ".travis.yml"
|
106
107
|
- Gemfile
|
@@ -128,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
129
|
requirements:
|
129
130
|
- - ">="
|
130
131
|
- !ruby/object:Gem::Version
|
131
|
-
version: '0'
|
132
|
+
version: '2.0'
|
132
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
134
|
requirements:
|
134
135
|
- - ">="
|