ruby_outlook 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +41 -0
- data/lib/ruby_outlook.rb +184 -163
- data/lib/ruby_outlook/version.rb +1 -1
- data/ruby_outlook.gemspec +2 -2
- metadata +5 -5
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
The RubyOutlook gem is a light-weight implementation of the Office 365 [Mail](https://msdn.microsoft.com/office/office365/APi/mail-rest-operations), [Calendar](https://msdn.microsoft.com/office/office365/APi/calendar-rest-operations), and [Contacts](https://msdn.microsoft.com/office/office365/APi/contacts-rest-operations) REST APIs. It provides basic CRUD functionality for all three APIs, along with the ability to extend functionality by making any arbitrary API call.
|
4
4
|
|
5
|
+
For a sample app that uses this gem, see the [Office 365 VCF Import/Export Sample](https://github.com/jasonjoh/o365-vcftool).
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -31,6 +33,45 @@ outlook_client = RubyOutlook::Client.new
|
|
31
33
|
|
32
34
|
In addition, you can set the `enable_fiddler` property on the `Client` to true if you want to capture Fiddler traces. Setting this property to true sets the proxy for all traffic to `http://127.0.0.1:8888` (the default Fiddler proxy value), and turns off SSL verification. Note that if you set this property to true and do not have Fiddler running, all requests will fail.
|
33
35
|
|
36
|
+
### Get an OAuth2 token ###
|
37
|
+
|
38
|
+
The Outlook APIs require an OAuth2 token for authentication. This gem doesn't handle the OAuth2 flow for you. For a full example that implements the OAuth2 [Authorization Code Grant Flow](https://msdn.microsoft.com/en-us/library/azure/dn645542.aspx), see the [Office 365 VCF Import/Export Sample](https://github.com/jasonjoh/o365-vcftool).
|
39
|
+
|
40
|
+
For convenience, here's the relevant steps and code, which uses the [oauth2](https://rubygems.org/gems/oauth2) gem.
|
41
|
+
|
42
|
+
- Generate a login URL:
|
43
|
+
```ruby
|
44
|
+
# Generates the login URL for the app.
|
45
|
+
def get_login_url
|
46
|
+
client = OAuth2::Client.new(CLIENT_ID,
|
47
|
+
CLIENT_SECRET,
|
48
|
+
:site => "https://login.microsoftonline.com",
|
49
|
+
:authorize_url => "/common/oauth2/authorize",
|
50
|
+
:token_url => "/common/oauth2/token")
|
51
|
+
|
52
|
+
login_url = client.auth_code.authorize_url(:redirect_uri => "http://yourapp.com/authorize")
|
53
|
+
end
|
54
|
+
```
|
55
|
+
- User browses to the login URL, authenticates, and provides consent to your app.
|
56
|
+
- The user's browser is redirected back to "http://yourapp.com/authorize", a page in your web app that extracts the `code` parameter from the request URL.
|
57
|
+
- Exchange the `code` value for an access token:
|
58
|
+
```ruby
|
59
|
+
# Exchanges an authorization code for a token
|
60
|
+
def get_token_from_code(auth_code)
|
61
|
+
client = OAuth2::Client.new(CLIENT_ID,
|
62
|
+
CLIENT_SECRET,
|
63
|
+
:site => "https://login.microsoftonline.com",
|
64
|
+
:authorize_url => "/common/oauth2/authorize",
|
65
|
+
:token_url => "/common/oauth2/token")
|
66
|
+
|
67
|
+
token = client.auth_code.get_token(auth_code,
|
68
|
+
:redirect_uri => "http://yourapp.com/authorize",
|
69
|
+
:resource => 'https://outlook.office365.com')
|
70
|
+
|
71
|
+
access_token = token
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
34
75
|
### Using a built-in function
|
35
76
|
|
36
77
|
All of the built-in functions have a required `token` parameter and an optional `user` parameter. The `token` parameter is the OAuth2 access token required for authentication. The `user` parameter is an email address. If passed, the library will make the call to that user's mailbox using the `/Users/user@domain.com/` URL. If omitted, the library will make the call using the `'/Me'` URL.
|
data/lib/ruby_outlook.rb
CHANGED
@@ -4,7 +4,6 @@ require "uuidtools"
|
|
4
4
|
require "json"
|
5
5
|
|
6
6
|
module RubyOutlook
|
7
|
-
|
8
7
|
class Client
|
9
8
|
# User agent
|
10
9
|
attr_reader :user_agent
|
@@ -12,43 +11,49 @@ module RubyOutlook
|
|
12
11
|
# Always "https://outlook.office365.com"
|
13
12
|
attr_writer :api_host
|
14
13
|
attr_writer :enable_fiddler
|
15
|
-
|
16
|
-
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@user_agent = "RubyOutlookGem/" << RubyOutlook::VERSION
|
17
|
+
@api_host = "https://outlook.office365.com"
|
18
|
+
@enable_fiddler = false
|
19
|
+
end
|
20
|
+
|
21
|
+
# method (string): The HTTP method to use for the API call.
|
17
22
|
# Must be 'GET', 'POST', 'PATCH', or 'DELETE'
|
18
23
|
# url (string): The URL to use for the API call. Must not contain
|
19
|
-
# the host. For example: '/api/
|
24
|
+
# the host. For example: '/api/v2.0/me/messages'
|
20
25
|
# token (string): access token
|
21
26
|
# params (hash) a Ruby hash containing any query parameters needed for the API call
|
22
27
|
# payload (hash): a JSON hash representing the API call's payload. Only used
|
23
28
|
# for POST or PATCH.
|
24
29
|
def make_api_call(method, url, token, params = nil, payload = nil)
|
25
|
-
|
30
|
+
|
26
31
|
conn_params = {
|
27
32
|
:url => 'https://outlook.office365.com'
|
28
33
|
}
|
29
|
-
|
34
|
+
|
30
35
|
if @enable_fiddler
|
31
36
|
conn_params[:proxy] = 'http://127.0.0.1:8888'
|
32
37
|
conn_params[:ssl] = {:verify => false}
|
33
38
|
end
|
34
|
-
|
39
|
+
|
35
40
|
conn = Faraday.new(conn_params) do |faraday|
|
36
41
|
# Uses the default Net::HTTP adapter
|
37
|
-
faraday.adapter Faraday.default_adapter
|
38
|
-
|
42
|
+
faraday.adapter Faraday.default_adapter
|
43
|
+
|
39
44
|
end
|
40
|
-
|
45
|
+
|
41
46
|
conn.headers = {
|
42
47
|
'Authorization' => "Bearer #{token}",
|
43
48
|
'Accept' => "application/json",
|
44
|
-
|
49
|
+
|
45
50
|
# Client instrumentation
|
46
51
|
# See https://msdn.microsoft.com/EN-US/library/office/dn720380(v=exchg.150).aspx
|
47
52
|
'User-Agent' => @user_agent,
|
48
53
|
'client-request-id' => UUIDTools::UUID.timestamp_create.to_str,
|
49
54
|
'return-client-request-id' => "true"
|
50
55
|
}
|
51
|
-
|
56
|
+
|
52
57
|
case method.upcase
|
53
58
|
when "GET"
|
54
59
|
response = conn.get do |request|
|
@@ -71,16 +76,16 @@ module RubyOutlook
|
|
71
76
|
request.url url, params
|
72
77
|
end
|
73
78
|
end
|
74
|
-
|
79
|
+
|
75
80
|
if response.status >= 300
|
76
81
|
return JSON.dump({ 'ruby_outlook_error' => response.status})
|
77
82
|
end
|
78
|
-
|
79
|
-
|
83
|
+
|
84
|
+
response.body
|
80
85
|
end
|
81
|
-
|
86
|
+
|
82
87
|
#----- Begin Contacts API -----#
|
83
|
-
|
88
|
+
|
84
89
|
# token (string): access token
|
85
90
|
# view_size (int): maximum number of results
|
86
91
|
# page (int): What page to fetch (multiple of view size)
|
@@ -88,202 +93,227 @@ module RubyOutlook
|
|
88
93
|
# sort (hash): { sort_on => field_to_sort_on, sort_order => 'ASC' | 'DESC' }
|
89
94
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
90
95
|
def get_contacts(token, view_size, page, fields = nil, sort = nil, user = nil)
|
91
|
-
request_url = "/api/
|
96
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Contacts"
|
92
97
|
request_params = {
|
93
98
|
'$top' => view_size,
|
94
99
|
'$skip' => (page - 1) * view_size
|
95
100
|
}
|
96
|
-
|
97
|
-
|
101
|
+
|
102
|
+
unless fields.nil?
|
98
103
|
request_params['$select'] = fields.join(',')
|
99
|
-
end
|
100
|
-
|
101
|
-
|
104
|
+
end
|
105
|
+
|
106
|
+
unless sort.nil?
|
102
107
|
request_params['$orderby'] = sort[:sort_field] + " " + sort[:sort_order]
|
103
108
|
end
|
104
|
-
|
109
|
+
|
105
110
|
get_contacts_response = make_api_call "GET", request_url, token, request_params
|
106
|
-
|
107
|
-
|
111
|
+
|
112
|
+
JSON.parse(get_contacts_response)
|
108
113
|
end
|
109
|
-
|
114
|
+
|
110
115
|
# token (string): access token
|
111
116
|
# id (string): The Id of the contact to retrieve
|
112
117
|
# fields (array): An array of field names to include in results
|
113
118
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
114
119
|
def get_contact_by_id(token, id, fields = nil, user = nil)
|
115
|
-
request_url = "/api/
|
120
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Contacts/" << id
|
116
121
|
request_params = nil
|
117
|
-
|
118
|
-
|
122
|
+
|
123
|
+
unless fields.nil?
|
119
124
|
request_params = { '$select' => fields.join(',') }
|
120
125
|
end
|
121
|
-
|
126
|
+
|
122
127
|
get_contact_response = make_api_call "GET", request_url, token, request_params
|
123
|
-
|
124
|
-
|
128
|
+
|
129
|
+
JSON.parse(get_contact_response)
|
125
130
|
end
|
126
|
-
|
131
|
+
|
127
132
|
# token (string): access token
|
128
133
|
# payload (hash): a JSON hash representing the contact entity
|
129
134
|
# folder_id (string): The Id of the contact folder to create the contact in.
|
130
135
|
# If nil, contact is created in the default contacts folder.
|
131
136
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
132
137
|
def create_contact(token, payload, folder_id = nil, user = nil)
|
133
|
-
request_url = "/api/
|
134
|
-
|
138
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user))
|
139
|
+
|
140
|
+
unless folder_id.nil?
|
135
141
|
request_url << "/ContactFolders/" << folder_id
|
136
142
|
end
|
143
|
+
|
137
144
|
request_url << "/Contacts"
|
138
|
-
|
145
|
+
|
139
146
|
create_contact_response = make_api_call "POST", request_url, token, nil, payload
|
140
|
-
|
141
|
-
|
147
|
+
|
148
|
+
JSON.parse(create_contact_response)
|
142
149
|
end
|
143
|
-
|
150
|
+
|
144
151
|
# token (string): access token
|
145
152
|
# payload (hash): a JSON hash representing the updated contact fields
|
146
153
|
# id (string): The Id of the contact to update.
|
147
154
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
148
155
|
def update_contact(token, payload, id, user = nil)
|
149
|
-
request_url = "/api/
|
150
|
-
|
156
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Contacts/" << id
|
157
|
+
|
151
158
|
update_contact_response = make_api_call "PATCH", request_url, token, nil, payload
|
152
|
-
|
153
|
-
|
159
|
+
|
160
|
+
JSON.parse(update_contact_response)
|
154
161
|
end
|
155
|
-
|
162
|
+
|
156
163
|
# token (string): access token
|
157
164
|
# id (string): The Id of the contact to delete.
|
158
165
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
159
166
|
def delete_contact(token, id, user = nil)
|
160
|
-
request_url = "/api/
|
161
|
-
|
167
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Contacts/" << id
|
168
|
+
|
162
169
|
delete_response = make_api_call "DELETE", request_url, token
|
163
|
-
|
164
|
-
if
|
165
|
-
|
166
|
-
|
167
|
-
return nil
|
168
|
-
end
|
170
|
+
|
171
|
+
return nil if delete_response.nil? || delete_response.empty?
|
172
|
+
|
173
|
+
JSON.parse(delete_response)
|
169
174
|
end
|
170
|
-
|
175
|
+
|
171
176
|
#----- End Contacts API -----#
|
172
|
-
|
177
|
+
|
173
178
|
#----- Begin Mail API -----#
|
174
|
-
|
179
|
+
|
175
180
|
# token (string): access token
|
176
181
|
# view_size (int): maximum number of results
|
177
182
|
# page (int): What page to fetch (multiple of view size)
|
178
183
|
# fields (array): An array of field names to include in results
|
179
|
-
# sort (hash): {
|
184
|
+
# sort (hash): { sort_field: field_to_sort_on, sort_order: 'ASC' | 'DESC' }
|
180
185
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
181
186
|
def get_messages(token, view_size, page, fields = nil, sort = nil, user = nil)
|
182
|
-
request_url = "/api/
|
187
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Messages"
|
188
|
+
request_params = {
|
189
|
+
'$top' => view_size,
|
190
|
+
'$skip' => (page - 1) * view_size
|
191
|
+
}
|
192
|
+
|
193
|
+
unless fields.nil?
|
194
|
+
request_params['$select'] = fields.join(',')
|
195
|
+
end
|
196
|
+
|
197
|
+
unless sort.nil?
|
198
|
+
request_params['$orderby'] = sort[:sort_field] + " " + sort[:sort_order]
|
199
|
+
end
|
200
|
+
|
201
|
+
get_messages_response = make_api_call "GET", request_url, token, request_params
|
202
|
+
|
203
|
+
JSON.parse(get_messages_response)
|
204
|
+
end
|
205
|
+
|
206
|
+
# token (string): access token
|
207
|
+
# view_size (int): maximum number of results
|
208
|
+
# page (int): What page to fetch (multiple of view size)
|
209
|
+
# fields (array): An array of field names to include in results
|
210
|
+
# sort (hash): { sort_on => field_to_sort_on, sort_order => 'ASC' | 'DESC' }
|
211
|
+
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
212
|
+
# folder_id (string): The folder to get mail for. (inbox, drafts, sentitems, deleteditems)
|
213
|
+
def get_messages_for_folder(token, view_size, page, fields = nil, sort = nil, user = nil, folder_id)
|
214
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/MailFolders/#{folder_id}/messages"
|
183
215
|
request_params = {
|
184
216
|
'$top' => view_size,
|
185
217
|
'$skip' => (page - 1) * view_size
|
186
218
|
}
|
187
|
-
|
188
|
-
|
219
|
+
|
220
|
+
unless fields.nil?
|
189
221
|
request_params['$select'] = fields.join(',')
|
190
|
-
end
|
191
|
-
|
192
|
-
|
222
|
+
end
|
223
|
+
|
224
|
+
unless sort.nil?
|
193
225
|
request_params['$orderby'] = sort[:sort_field] + " " + sort[:sort_order]
|
194
226
|
end
|
195
|
-
|
227
|
+
|
196
228
|
get_messages_response = make_api_call "GET", request_url, token, request_params
|
197
|
-
|
198
|
-
|
229
|
+
|
230
|
+
JSON.parse(get_messages_response)
|
199
231
|
end
|
200
|
-
|
232
|
+
|
201
233
|
# token (string): access token
|
202
234
|
# id (string): The Id of the message to retrieve
|
203
235
|
# fields (array): An array of field names to include in results
|
204
236
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
205
237
|
def get_message_by_id(token, id, fields = nil, user = nil)
|
206
|
-
request_url = "/api/
|
238
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Messages/" << id
|
207
239
|
request_params = nil
|
208
|
-
|
209
|
-
|
240
|
+
|
241
|
+
unless fields.nil?
|
210
242
|
request_params = { '$select' => fields.join(',') }
|
211
243
|
end
|
212
|
-
|
244
|
+
|
213
245
|
get_message_response = make_api_call "GET", request_url, token, request_params
|
214
|
-
|
215
|
-
|
246
|
+
|
247
|
+
JSON.parse(get_message_response)
|
216
248
|
end
|
217
|
-
|
249
|
+
|
218
250
|
# token (string): access token
|
219
251
|
# payload (hash): a JSON hash representing the contact entity
|
220
252
|
# folder_id (string): The Id of the folder to create the message in.
|
221
253
|
# If nil, message is created in the default drafts folder.
|
222
254
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
223
255
|
def create_message(token, payload, folder_id = nil, user = nil)
|
224
|
-
request_url = "/api/
|
225
|
-
|
226
|
-
|
256
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user))
|
257
|
+
|
258
|
+
unless folder_id.nil?
|
259
|
+
request_url << "/MailFolders/" << folder_id
|
227
260
|
end
|
261
|
+
|
228
262
|
request_url << "/Messages"
|
229
|
-
|
263
|
+
|
230
264
|
create_message_response = make_api_call "POST", request_url, token, nil, payload
|
231
|
-
|
232
|
-
|
265
|
+
|
266
|
+
JSON.parse(create_message_response)
|
233
267
|
end
|
234
|
-
|
268
|
+
|
235
269
|
# token (string): access token
|
236
270
|
# payload (hash): a JSON hash representing the updated message fields
|
237
271
|
# id (string): The Id of the message to update.
|
238
272
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
239
273
|
def update_message(token, payload, id, user = nil)
|
240
|
-
request_url = "/api/
|
241
|
-
|
274
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Messages/" << id
|
275
|
+
|
242
276
|
update_message_response = make_api_call "PATCH", request_url, token, nil, payload
|
243
|
-
|
244
|
-
|
277
|
+
|
278
|
+
JSON.parse(update_message_response)
|
245
279
|
end
|
246
|
-
|
280
|
+
|
247
281
|
# token (string): access token
|
248
282
|
# id (string): The Id of the message to delete.
|
249
283
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
250
284
|
def delete_message(token, id, user = nil)
|
251
|
-
request_url = "/api/
|
252
|
-
|
285
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Messages/" << id
|
286
|
+
|
253
287
|
delete_response = make_api_call "DELETE", request_url, token
|
254
|
-
|
255
|
-
if
|
256
|
-
|
257
|
-
|
258
|
-
return nil
|
259
|
-
end
|
288
|
+
|
289
|
+
return nil if delete_response.nil? || delete_response.empty?
|
290
|
+
|
291
|
+
JSON.parse(delete_response)
|
260
292
|
end
|
261
|
-
|
293
|
+
|
262
294
|
# token (string): access token
|
263
295
|
# payload (hash): a JSON hash representing the message to send
|
264
296
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
265
297
|
def send_message(token, payload, save_to_sentitems = true, user = nil)
|
266
|
-
request_url = "/api/
|
267
|
-
|
298
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/SendMail"
|
299
|
+
|
268
300
|
# Wrap message in the sendmail JSON structure
|
269
301
|
send_mail_json = {
|
270
302
|
'Message' => payload,
|
271
303
|
'SaveToSentItems' => save_to_sentitems
|
272
304
|
}
|
273
|
-
|
305
|
+
|
274
306
|
send_response = make_api_call "POST", request_url, token, nil, send_mail_json
|
275
|
-
|
276
|
-
if
|
277
|
-
|
278
|
-
|
279
|
-
return nil
|
280
|
-
end
|
307
|
+
|
308
|
+
return nil if send_response.nil? || send_response.empty?
|
309
|
+
|
310
|
+
JSON.parse(send_response)
|
281
311
|
end
|
282
|
-
|
312
|
+
|
283
313
|
#----- End Mail API -----#
|
284
|
-
|
314
|
+
|
285
315
|
#----- Begin Calendar API -----#
|
286
|
-
|
316
|
+
|
287
317
|
# token (string): access token
|
288
318
|
# view_size (int): maximum number of results
|
289
319
|
# page (int): What page to fetch (multiple of view size)
|
@@ -291,42 +321,42 @@ module RubyOutlook
|
|
291
321
|
# sort (hash): { sort_on => field_to_sort_on, sort_order => 'ASC' | 'DESC' }
|
292
322
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
293
323
|
def get_events(token, view_size, page, fields = nil, sort = nil, user = nil)
|
294
|
-
request_url = "/api/
|
324
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Events"
|
295
325
|
request_params = {
|
296
326
|
'$top' => view_size,
|
297
327
|
'$skip' => (page - 1) * view_size
|
298
328
|
}
|
299
|
-
|
300
|
-
|
329
|
+
|
330
|
+
unless fields.nil?
|
301
331
|
request_params['$select'] = fields.join(',')
|
302
|
-
end
|
303
|
-
|
304
|
-
|
332
|
+
end
|
333
|
+
|
334
|
+
unless sort.nil?
|
305
335
|
request_params['$orderby'] = sort[:sort_field] + " " + sort[:sort_order]
|
306
336
|
end
|
307
|
-
|
337
|
+
|
308
338
|
get_events_response = make_api_call "GET", request_url, token, request_params
|
309
|
-
|
310
|
-
|
339
|
+
|
340
|
+
JSON.parse(get_events_response)
|
311
341
|
end
|
312
|
-
|
342
|
+
|
313
343
|
# token (string): access token
|
314
344
|
# id (string): The Id of the event to retrieve
|
315
345
|
# fields (array): An array of field names to include in results
|
316
346
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
317
347
|
def get_event_by_id(token, id, fields = nil, user = nil)
|
318
|
-
request_url = "/api/
|
348
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Events/" << id
|
319
349
|
request_params = nil
|
320
|
-
|
321
|
-
|
350
|
+
|
351
|
+
unless fields.nil?
|
322
352
|
request_params = { '$select' => fields.join(',') }
|
323
353
|
end
|
324
|
-
|
354
|
+
|
325
355
|
get_event_response = make_api_call "GET", request_url, token, request_params
|
326
|
-
|
327
|
-
|
356
|
+
|
357
|
+
JSON.parse(get_event_response)
|
328
358
|
end
|
329
|
-
|
359
|
+
|
330
360
|
# token (string): access token
|
331
361
|
# window_start (DateTime): The earliest time (UTC) to include in the view
|
332
362
|
# window_end (DateTime): The latest time (UTC) to include in the view
|
@@ -335,80 +365,71 @@ module RubyOutlook
|
|
335
365
|
# fields (array): An array of field names to include in results
|
336
366
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
337
367
|
def get_calendar_view(token, window_start, window_end, id = nil, fields = nil, user = nil)
|
338
|
-
request_url = "/api/
|
339
|
-
|
340
|
-
|
368
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user))
|
369
|
+
|
370
|
+
unless id.nil?
|
341
371
|
request_url << "/Calendars/" << id
|
342
372
|
end
|
343
|
-
|
373
|
+
|
344
374
|
request_url << "/CalendarView"
|
345
|
-
|
375
|
+
|
346
376
|
request_params = {
|
347
377
|
'startDateTime' => window_start.strftime('%Y-%m-%dT00:00:00Z'),
|
348
378
|
'endDateTime' => window_end.strftime('%Y-%m-%dT00:00:00Z')
|
349
379
|
}
|
350
|
-
|
351
|
-
|
380
|
+
|
381
|
+
unless fields.nil?
|
352
382
|
request_params['$select'] = fields.join(',')
|
353
383
|
end
|
354
|
-
|
384
|
+
|
355
385
|
get_view_response =make_api_call "GET", request_url, token, request_params
|
356
|
-
|
357
|
-
|
386
|
+
|
387
|
+
JSON.parse(get_view_response)
|
358
388
|
end
|
359
|
-
|
389
|
+
|
360
390
|
# token (string): access token
|
361
391
|
# payload (hash): a JSON hash representing the event entity
|
362
392
|
# folder_id (string): The Id of the calendar folder to create the event in.
|
363
393
|
# If nil, event is created in the default calendar folder.
|
364
394
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
365
395
|
def create_event(token, payload, folder_id = nil, user = nil)
|
366
|
-
request_url = "/api/
|
367
|
-
|
396
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user))
|
397
|
+
|
398
|
+
unless folder_id.nil?
|
368
399
|
request_url << "/Calendars/" << folder_id
|
369
400
|
end
|
401
|
+
|
370
402
|
request_url << "/Events"
|
371
|
-
|
403
|
+
|
372
404
|
create_event_response = make_api_call "POST", request_url, token, nil, payload
|
373
|
-
|
374
|
-
|
405
|
+
|
406
|
+
JSON.parse(create_event_response)
|
375
407
|
end
|
376
|
-
|
408
|
+
|
377
409
|
# token (string): access token
|
378
410
|
# payload (hash): a JSON hash representing the updated event fields
|
379
411
|
# id (string): The Id of the event to update.
|
380
412
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
381
413
|
def update_event(token, payload, id, user = nil)
|
382
|
-
request_url = "/api/
|
383
|
-
|
414
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Events/" << id
|
415
|
+
|
384
416
|
update_event_response = make_api_call "PATCH", request_url, token, nil, payload
|
385
|
-
|
386
|
-
|
417
|
+
|
418
|
+
JSON.parse(update_event_response)
|
387
419
|
end
|
388
|
-
|
420
|
+
|
389
421
|
# token (string): access token
|
390
422
|
# id (string): The Id of the event to delete.
|
391
423
|
# user (string): The user to make the call for. If nil, use the 'Me' constant.
|
392
424
|
def delete_event(token, id, user = nil)
|
393
|
-
request_url = "/api/
|
394
|
-
|
425
|
+
request_url = "/api/v2.0/" << (user.nil? ? "Me" : ("users/" << user)) << "/Events/" << id
|
426
|
+
|
395
427
|
delete_response = make_api_call "DELETE", request_url, token
|
396
|
-
|
397
|
-
if
|
398
|
-
|
399
|
-
|
400
|
-
return nil
|
401
|
-
end
|
428
|
+
|
429
|
+
return nil if delete_response.nil? || delete_response.empty?
|
430
|
+
|
431
|
+
JSON.parse(delete_response)
|
402
432
|
end
|
403
|
-
|
404
433
|
#----- End Calendar API -----#
|
405
|
-
|
406
|
-
private
|
407
|
-
def initialize
|
408
|
-
@user_agent = "RubyOutlookGem/" << RubyOutlook::VERSION
|
409
|
-
@api_host = "https://outlook.office365.com"
|
410
|
-
@enable_fiddler = false
|
411
|
-
super
|
412
|
-
end
|
413
434
|
end
|
414
435
|
end
|
data/lib/ruby_outlook/version.rb
CHANGED
data/ruby_outlook.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Jason Johnston"]
|
10
10
|
spec.email = ["jasonjoh@microsoft.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{A ruby gem to invoke the
|
13
|
-
spec.description = %q{This ruby gem provides functions for common operations with the
|
12
|
+
spec.summary = %q{A ruby gem to invoke the Outlook REST APIs.}
|
13
|
+
spec.description = %q{This ruby gem provides functions for common operations with the Outlook Mail, Calendar, and Contacts APIs.}
|
14
14
|
spec.homepage = "https://github.com/jasonjoh/ruby_outlook"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_outlook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -75,8 +75,8 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '10.0'
|
78
|
-
description: This ruby gem provides functions for common operations with the
|
79
|
-
|
78
|
+
description: This ruby gem provides functions for common operations with the Outlook
|
79
|
+
Mail, Calendar, and Contacts APIs.
|
80
80
|
email:
|
81
81
|
- jasonjoh@microsoft.com
|
82
82
|
executables: []
|
@@ -119,5 +119,5 @@ rubyforge_project:
|
|
119
119
|
rubygems_version: 1.8.29
|
120
120
|
signing_key:
|
121
121
|
specification_version: 3
|
122
|
-
summary: A ruby gem to invoke the
|
122
|
+
summary: A ruby gem to invoke the Outlook REST APIs.
|
123
123
|
test_files: []
|