omnievent-outlook 0.1.0.pre2 → 0.1.0.pre4

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: 110be6c15bfe7032d8b0515f2273c71380e77d4ef089de895f4baf53be0dcd8e
4
- data.tar.gz: 7efd60bb802eb86f9ba1be5b27d02a82ee69750a72e1c3f59e63f70526ecca6a
3
+ metadata.gz: 138cb638b2dfc9a9635e20bac17a645095aeac7f419147126fc59683efdd8d67
4
+ data.tar.gz: 17492542afa5f360b917e582b80a0e397e0f62f6412fe9a5c28221f6acc62845
5
5
  SHA512:
6
- metadata.gz: 5001b87f3265eacf74bcdbef5a37f1ea6083cd0b53da7d7955c70fa59096559c6c28d25a32b8058ef34fc63d4e2c5d1b1ea0903f857f8b913877d04ef0aea098
7
- data.tar.gz: 63e0ae827a676b843de1254623da2e7cbdf21112c940b0d816317c549d3469765a82b6f39ef438f00791ba61ed2837b7d9dc407fe4a7bb34dc2dca0af9fd37b8
6
+ metadata.gz: 9639f0ecc1bfee5f9215e453c0fe123bab75eec7c4d095488ea5b3d007f9c62a09d94be88a450abf6de9a63dda8d20656d10e5e1c2482623e07a672d637559bd
7
+ data.tar.gz: d06050e3398e079e39e8b0ccd409e6f35a704ade1c9d87b5f988fa06bff4e1f9d2a50eed8c91c1a89cfcb7da4244cf65aed85a5f18c89cabc32d2882a0e0a88f
data/Gemfile CHANGED
@@ -9,4 +9,4 @@ gem "rake", "~> 13.0"
9
9
 
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
- gem "rubocop", "~> 1.21"
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- omnievent-outlook (0.1.0.pre1)
4
+ omnievent-outlook (0.1.0.pre4)
5
5
  omnievent
6
6
  omnievent-api
7
7
 
@@ -24,11 +24,11 @@ GEM
24
24
  iso-639 (0.3.6)
25
25
  json (2.7.2)
26
26
  language_server-protocol (3.17.0.3)
27
- omnievent (0.1.0.pre3)
27
+ omnievent (0.1.0.pre5)
28
28
  hashie (>= 3.4.6)
29
29
  iso-639 (~> 0.3.5)
30
30
  tzinfo (~> 2.0)
31
- omnievent-api (0.1.0.pre2)
31
+ omnievent-api (0.1.0.pre3)
32
32
  excon
33
33
  omnievent
34
34
  parallel (1.26.3)
@@ -40,13 +40,13 @@ GEM
40
40
  rainbow (3.1.1)
41
41
  rake (13.2.1)
42
42
  regexp_parser (2.9.2)
43
- rexml (3.3.5)
43
+ rexml (3.3.6)
44
44
  strscan
45
45
  rspec (3.13.0)
46
46
  rspec-core (~> 3.13.0)
47
47
  rspec-expectations (~> 3.13.0)
48
48
  rspec-mocks (~> 3.13.0)
49
- rspec-core (3.13.0)
49
+ rspec-core (3.13.1)
50
50
  rspec-support (~> 3.13.0)
51
51
  rspec-expectations (3.13.2)
52
52
  diff-lcs (>= 1.2.0, < 2.0)
@@ -55,18 +55,17 @@ GEM
55
55
  diff-lcs (>= 1.2.0, < 2.0)
56
56
  rspec-support (~> 3.13.0)
57
57
  rspec-support (3.13.1)
58
- rubocop (1.65.1)
58
+ rubocop (1.66.0)
59
59
  json (~> 2.3)
60
60
  language_server-protocol (>= 3.17.0)
61
61
  parallel (~> 1.10)
62
62
  parser (>= 3.3.0.2)
63
63
  rainbow (>= 2.2.2, < 4.0)
64
64
  regexp_parser (>= 2.4, < 3.0)
65
- rexml (>= 3.2.5, < 4.0)
66
- rubocop-ast (>= 1.31.1, < 2.0)
65
+ rubocop-ast (>= 1.32.1, < 2.0)
67
66
  ruby-progressbar (~> 1.7)
68
67
  unicode-display_width (>= 2.4.0, < 3.0)
69
- rubocop-ast (1.32.1)
68
+ rubocop-ast (1.32.2)
70
69
  parser (>= 3.3.1.0)
71
70
  ruby-progressbar (1.13.0)
72
71
  strscan (3.1.0)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniEvent
4
4
  module Outlook
5
- VERSION = "0.1.0.pre2"
5
+ VERSION = "0.1.0.pre4"
6
6
  end
7
7
  end
@@ -14,7 +14,7 @@ module OmniEvent
14
14
  API_VERSION = "v1.0"
15
15
 
16
16
  def raw_events
17
- response = perform_request(path: events_request_path)
17
+ response = perform_request(path: "#{request_path}/events")
18
18
  events = response["value"]
19
19
  next_link = response["@odata.nextLink"]
20
20
 
@@ -27,15 +27,62 @@ module OmniEvent
27
27
  events
28
28
  end
29
29
 
30
+ def create_event
31
+ %w[subject start].each do |attr|
32
+ raise ArgumentError, "Event #{attr} is required." unless request_body[attr]
33
+ end
34
+
35
+ response = perform_request(
36
+ method: "POST",
37
+ path: "#{request_path}/events",
38
+ content_type: "application/json",
39
+ body: request_body.to_json
40
+ )
41
+ return false unless response
42
+
43
+ event = event_hash(response)
44
+ return false unless event.valid?
45
+
46
+ event
47
+ end
48
+
49
+ def update_event
50
+ event_id = options.event.metadata&.uid
51
+ raise ArgumentError, "Event id is required." unless event_id
52
+ raise ArgumentError, "Event body is required." if request_body.empty?
53
+
54
+ response = perform_request(
55
+ method: "PATCH",
56
+ path: "#{request_path}/events/#{options.event.metadata.uid}",
57
+ content_type: "application/json",
58
+ body: request_body.to_json
59
+ )
60
+ return false unless response
61
+
62
+ event_hash(response)
63
+ end
64
+
65
+ def destroy_event
66
+ event_id = options.event.metadata&.uid
67
+ raise ArgumentError, "Event id is required." unless event_id
68
+
69
+ response = perform_request(
70
+ method: "DELETE",
71
+ path: "#{request_path}/events/#{options.event.metadata.uid}"
72
+ )
73
+ !!response
74
+ end
75
+
30
76
  def event_hash(raw_event)
31
77
  data = {
32
- start_time: format_outlook_datetime(raw_event["start"]["dateTime"]),
33
- end_time: format_outlook_datetime(raw_event["end"]["dateTime"]),
78
+ start_time: format_outlook_datetime_for_omnievent(raw_event["start"]["dateTime"]),
34
79
  name: raw_event["subject"],
35
80
  description: raw_event["bodyPreview"],
36
81
  url: raw_event["webLink"]
37
82
  }
38
83
 
84
+ data[:end_time] = format_outlook_datetime_for_omnievent(raw_event["end"]["dateTime"]) if raw_event["end"]
85
+
39
86
  metadata = {
40
87
  uid: raw_event["id"],
41
88
  status: convert_status(raw_event),
@@ -54,23 +101,36 @@ module OmniEvent
54
101
  )
55
102
  end
56
103
 
104
+ def request_body
105
+ @request_body ||= begin
106
+ body = {}
107
+ body["subject"] = options.event.data.name if options.event.data.name
108
+ if options.event.data.description
109
+ body["body"] = format_omnievent_description_for_outlook(options.event.data.description)
110
+ end
111
+ if options.event.data.start_time
112
+ body["start"] = format_omnievent_datetime_for_outlook(options.event.data.start_time)
113
+ end
114
+ if options.event.data.end_time
115
+ body["end"] = format_omnievent_datetime_for_outlook(options.event.data.end_time)
116
+ end
117
+ body
118
+ end
119
+ end
120
+
57
121
  def request_url
58
122
  "https://graph.microsoft.com"
59
123
  end
60
124
 
61
- def events_request_path
62
- @events_request_path ||= begin
125
+ def request_path
126
+ @request_path ||= begin
63
127
  path = "/#{API_VERSION}"
64
-
65
- # endpoint
66
128
  path += "/users/#{options.user_id}"
67
-
68
129
  path += if options.calendar_id
69
- "/calendars/#{options.calendar_id}/events"
130
+ "/calendars/#{options.calendar_id}"
70
131
  else
71
- "/calendar/events"
132
+ "/calendar"
72
133
  end
73
-
74
134
  path
75
135
  end
76
136
  end
@@ -86,13 +146,29 @@ module OmniEvent
86
146
  "published"
87
147
  end
88
148
 
89
- # All start and end times are returned in UTC
149
+ # All start and end times are returned in UTC unless request headers are set.
90
150
  # See https://learn.microsoft.com/en-us/graph/api/calendar-list-events?view=graph-rest-1.0&tabs=http#request-headers
91
- def format_outlook_datetime(datetime)
151
+ def format_outlook_datetime_for_omnievent(datetime)
92
152
  # DateTime parses to UTC by default
93
153
  utc_datetime = DateTime.parse(datetime)
94
154
  format_time(utc_datetime.to_s)
95
155
  end
156
+
157
+ # See https://learn.microsoft.com/en-us/graph/api/resources/datetimetimezone?view=graph-rest-1.0
158
+ def format_omnievent_datetime_for_outlook(datetime)
159
+ {
160
+ "dateTime": DateTime.parse(datetime),
161
+ "timeZone": "UTC"
162
+ }
163
+ end
164
+
165
+ # https://learn.microsoft.com/en-us/graph/api/resources/itembody?view=graph-rest-1.0
166
+ def format_omnievent_description_for_outlook(description)
167
+ {
168
+ "contentType": "HTML",
169
+ "content": description
170
+ }
171
+ end
96
172
  end
97
173
  end
98
174
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omnievent-outlook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre2
4
+ version: 0.1.0.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Angus McLeod
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-23 00:00:00.000000000 Z
11
+ date: 2024-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omnievent