ruby-office365 0.1.8 → 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/CHANGELOG.md +32 -23
- data/Gemfile.lock +4 -4
- data/README.md +49 -1
- data/lib/office365/models/subscription.rb +8 -0
- data/lib/office365/models.rb +1 -0
- data/lib/office365/rest/api.rb +2 -0
- data/lib/office365/rest/concerns/base.rb +7 -2
- data/lib/office365/rest/event.rb +20 -1
- data/lib/office365/rest/request.rb +19 -7
- data/lib/office365/rest/subscription.rb +29 -0
- data/lib/office365/utils/hash.rb +1 -1
- data/lib/office365/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3513de92b0360a54e0d374123fcf895427f951c47bb69b2f3e467898656ab943
|
4
|
+
data.tar.gz: '0600429d86539062c53f5507c02b9b711475ed40ddf2b69bdbad5aabe4f77042'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2a8a7ab82422310f3a2abcc14efe98cc009b137e543f3c3001846a5649f933730baddcf98c9341eda9992042b6d3fe85959d8c650dac94965ca549ee1389e90
|
7
|
+
data.tar.gz: c7fcbf2ad9effed4e531c805de17a023c77a3b067e18ea467057956209aeb9109dc06c9542c401b4e28c73fc5e0aada76f71e52dbe3ae4dd28f72fa67188b60d
|
data/CHANGELOG.md
CHANGED
@@ -1,27 +1,25 @@
|
|
1
1
|
# Office365 Library Changelog
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.2.0] - (2024-11-14)
|
4
4
|
|
5
|
-
-
|
5
|
+
- New feature on events: Allows users to get events by expected dates
|
6
|
+
- get events for the next week `client.events({ startdatetime: "2024-11-14T00:00:00.000Z", enddatetime: "2024-11-21T00:00:00.000Z" })`
|
6
7
|
|
7
|
-
## [0.1.
|
8
|
+
## [0.1.9] - (2024-08-08)
|
8
9
|
|
9
|
-
-
|
10
|
-
- get profile `client.me`
|
11
|
-
- get mailbox `client.messages`
|
12
|
-
- get calenders `client.calenders`
|
10
|
+
- able to get event by identifier `client.event('xxxxxxxx')`
|
13
11
|
|
14
|
-
## [0.1.
|
12
|
+
## [0.1.7] - (2022-11-11)
|
15
13
|
|
16
|
-
-
|
17
|
-
- get
|
18
|
-
- get
|
14
|
+
- Improve performance: supports select and sort in REST APIs
|
15
|
+
- get messages by select fields `client.messages({ select: %[id] })`
|
16
|
+
- get messages by custom order `client.messages({ order: 'id asc' })`
|
19
17
|
|
20
|
-
## [0.1.
|
18
|
+
## [0.1.6] - (2022-11-01)
|
21
19
|
|
22
|
-
- Integrate REST API to get
|
23
|
-
- get
|
24
|
-
- get
|
20
|
+
- Integrate REST API to get events
|
21
|
+
- get events `client.events`
|
22
|
+
- get events data with next link `client.events({next_link: 'xxx'})`
|
25
23
|
|
26
24
|
## [0.1.5] - (2022-10-27)
|
27
25
|
|
@@ -30,14 +28,25 @@
|
|
30
28
|
- get token URL `client.token_url`
|
31
29
|
- be able to refresh token `client.refresh_token!`
|
32
30
|
|
33
|
-
## [0.1.
|
31
|
+
## [0.1.3] - (2022-10-26)
|
34
32
|
|
35
|
-
- Integrate REST API to get
|
36
|
-
- get
|
37
|
-
- get
|
33
|
+
- Integrate REST API to get contacts
|
34
|
+
- get contacts `client.contacts`
|
35
|
+
- get contacts data with next link `client.contacts({next_link: 'xxx'})`
|
38
36
|
|
39
|
-
## [0.1.
|
37
|
+
## [0.1.2] - (2022-10-21)
|
40
38
|
|
41
|
-
-
|
42
|
-
- get
|
43
|
-
- get
|
39
|
+
- Integrate REST API to get mailbox with pagination
|
40
|
+
- get mailbox data with next link `client.messages({next_link: 'xxx'})`
|
41
|
+
- get calenders data with next link `client.calenders({next_link: 'xxx'})`
|
42
|
+
|
43
|
+
## [0.1.1] - (2022-10-21)
|
44
|
+
|
45
|
+
- Integrate REST API to get data from Graph API
|
46
|
+
- get profile `client.me`
|
47
|
+
- get mailbox `client.messages`
|
48
|
+
- get calenders `client.calenders`
|
49
|
+
|
50
|
+
## [0.1.0] - (2022-10-19)
|
51
|
+
|
52
|
+
- Project setup and push to rubugems
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-office365 (0.
|
4
|
+
ruby-office365 (0.2.0)
|
5
5
|
faraday
|
6
6
|
faraday_middleware
|
7
7
|
|
@@ -15,7 +15,7 @@ GEM
|
|
15
15
|
crack (0.4.5)
|
16
16
|
rexml
|
17
17
|
diff-lcs (1.5.0)
|
18
|
-
faraday (1.10.
|
18
|
+
faraday (1.10.3)
|
19
19
|
faraday-em_http (~> 1.0)
|
20
20
|
faraday-em_synchrony (~> 1.0)
|
21
21
|
faraday-excon (~> 1.1)
|
@@ -33,7 +33,7 @@ GEM
|
|
33
33
|
faraday-httpclient (1.0.1)
|
34
34
|
faraday-multipart (1.0.4)
|
35
35
|
multipart-post (~> 2)
|
36
|
-
faraday-net_http (1.0.
|
36
|
+
faraday-net_http (1.0.2)
|
37
37
|
faraday-net_http_persistent (1.2.0)
|
38
38
|
faraday-patron (1.0.0)
|
39
39
|
faraday-rack (1.0.0)
|
@@ -43,7 +43,7 @@ GEM
|
|
43
43
|
hashdiff (1.0.1)
|
44
44
|
json (2.6.2)
|
45
45
|
method_source (1.0.0)
|
46
|
-
multipart-post (2.
|
46
|
+
multipart-post (2.4.1)
|
47
47
|
parallel (1.22.1)
|
48
48
|
parser (3.1.2.1)
|
49
49
|
ast (~> 2.4.1)
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# Office 365 (
|
1
|
+
# Office 365 (2024) <img src="https://i.ibb.co/g3mpswn/microsoft-office-365-logo-2016-100727915-large.webp" align="right" width="250" height="150">
|
2
|
+
|
2
3
|
A simple ruby library to interact with Microsoft Graph **[Explorer](https://developer.microsoft.com/en-us/graph/graph-explorer)** and Office 365 API
|
3
4
|
|
4
5
|
## Installation
|
@@ -100,6 +101,23 @@ irb(main):005:0> client.events[:results]
|
|
100
101
|
irb(main):005:0> client.events[:next_link]
|
101
102
|
```
|
102
103
|
|
104
|
+
**Get my events for the next week**
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
irb(main):005:0> client.events({ startdatetime: "2024-11-14T00:00:00.000Z", enddatetime: "2024-11-21T00:00:00.000Z" })
|
108
|
+
irb(main):005:0> client.events[:results]
|
109
|
+
irb(main):005:0> client.events[:next_link]
|
110
|
+
```
|
111
|
+
|
112
|
+
**Get my event by id**
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
irb(main):005:0> client.event('identifier')
|
116
|
+
irb(main):005:0> client.event('identifier')[:results]
|
117
|
+
```
|
118
|
+
|
119
|
+
Results will return an array even if it is a single result.
|
120
|
+
|
103
121
|
**Get my mails by access token**
|
104
122
|
|
105
123
|
```ruby
|
@@ -171,6 +189,36 @@ irb(main):005:0> response.refresh_token
|
|
171
189
|
=> "0.ARgA7EiQdLv1qECnFqPfrznKsT9ERYaGfG9Ki5WzQtEllj8YAJk.AgABAAEAAAD--DLA3VO7QrddgJg7WevrAgDs_wQA9P-Q1ODlBsrdZi-5s2mfLtEsavBgiEhGcz1KEf26fMrGFU3LM_og5l6wjSAtQ83XHLuje0_KYGol26_LGV_uH0F1MwCFR1N3ctwg4_...."
|
172
190
|
```
|
173
191
|
|
192
|
+
**Create Subscription: it will create a webhook for Office365**
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
args = {
|
196
|
+
changeType: "updated,deleted",
|
197
|
+
notificationUrl: "https://hello-world.com/office365/notifications",
|
198
|
+
lifecycleNotificationUrl: "https://hello-world.com/office365/lifecycle_notifications",
|
199
|
+
resource: "/me/{type}",
|
200
|
+
expirationDateTime: "2024-08-07T12:00:00.0000000Z",
|
201
|
+
clientState: "SecretClientState"
|
202
|
+
}
|
203
|
+
|
204
|
+
irb(main):005:0> subscription = client.create_subscription(args)
|
205
|
+
```
|
206
|
+
|
207
|
+
will return the subscription object `Office365::Models::Subscription`
|
208
|
+
|
209
|
+
**Renew Subscription**
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
args = {
|
213
|
+
identifier: "subscription-identifier",
|
214
|
+
expirationDateTime: "2024-08-08T12:00:00.0000000Z"
|
215
|
+
}
|
216
|
+
|
217
|
+
irb(main):005:0> subscription = client.renew_subscription(args)
|
218
|
+
```
|
219
|
+
|
220
|
+
will return the subscription object `Office365::Models::Subscription`
|
221
|
+
|
174
222
|
## Development
|
175
223
|
|
176
224
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/office365/models.rb
CHANGED
data/lib/office365/rest/api.rb
CHANGED
@@ -5,6 +5,7 @@ require_relative "./mailbox"
|
|
5
5
|
require_relative "./calendar"
|
6
6
|
require_relative "./contact"
|
7
7
|
require_relative "./event"
|
8
|
+
require_relative "./subscription"
|
8
9
|
require_relative "./token"
|
9
10
|
|
10
11
|
module Office365
|
@@ -16,6 +17,7 @@ module Office365
|
|
16
17
|
include Office365::REST::Event
|
17
18
|
include Office365::REST::Contact
|
18
19
|
include Office365::REST::Token
|
20
|
+
include Office365::REST::Subscription
|
19
21
|
end
|
20
22
|
end
|
21
23
|
end
|
@@ -7,8 +7,13 @@ module Office365
|
|
7
7
|
private
|
8
8
|
|
9
9
|
def wrap_results(args)
|
10
|
-
kclass
|
11
|
-
|
10
|
+
kclass = args.delete(:kclass)
|
11
|
+
identifier = args.delete(:identifier)
|
12
|
+
|
13
|
+
response = get_request(args: args)
|
14
|
+
|
15
|
+
# If we are getting a single item by id, return the result as an array
|
16
|
+
return { results: [kclass.new(response)].flatten } unless identifier.nil?
|
12
17
|
|
13
18
|
{
|
14
19
|
results: response["value"].map { |v| kclass.new(v) },
|
data/lib/office365/rest/event.rb
CHANGED
@@ -6,11 +6,30 @@ module Office365
|
|
6
6
|
module REST
|
7
7
|
module Event
|
8
8
|
include Concerns::Base
|
9
|
+
BASE_URI = "/me/events"
|
10
|
+
CALENDARVIEW_URL = "/me/calendarview"
|
9
11
|
|
10
12
|
# params: args => { next_link: (nil / next_page_url) }
|
13
|
+
# startdatetime: 2024-11-14T07:59:41.313Z
|
14
|
+
# enddatetime: 2024-11-21T07:59:41.313Z
|
11
15
|
# response { results: [], next_link: '...' }
|
12
16
|
def events(args = {})
|
13
|
-
|
17
|
+
if args[:startdatetime] && args[:enddatetime]
|
18
|
+
wrap_results(
|
19
|
+
kclass: Models::Event,
|
20
|
+
base_uri: CALENDARVIEW_URL,
|
21
|
+
startdatetime: args[:startdatetime],
|
22
|
+
enddatetime: args[:enddatetime]
|
23
|
+
)
|
24
|
+
else
|
25
|
+
wrap_results(args.merge(kclass: Models::Event, base_uri: BASE_URI))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def event(identifier)
|
30
|
+
raise ArgumentError, "Identifier must be provided" if identifier.nil? || identifier.empty?
|
31
|
+
|
32
|
+
wrap_results(kclass: Models::Event, base_uri: [BASE_URI, identifier].join("/"), identifier: identifier)
|
14
33
|
end
|
15
34
|
end
|
16
35
|
end
|
@@ -28,23 +28,35 @@ module Office365
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def post(uri, args)
|
31
|
-
|
31
|
+
response = faraday_action(__method__, uri, args)
|
32
|
+
parse_respond(response)
|
33
|
+
end
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
faraday.response :json
|
36
|
-
faraday.response :logger, ::Logger.new($stdout), bodies: true if dev_developement?
|
37
|
-
end.post(req_url.request_uri, args.ms_hash_to_query)
|
35
|
+
def patch(uri, args)
|
36
|
+
response = faraday_action(__method__, uri, args)
|
38
37
|
|
39
38
|
parse_respond(response)
|
40
39
|
end
|
41
40
|
|
42
41
|
private
|
43
42
|
|
43
|
+
def faraday_action(method_name, uri, args)
|
44
|
+
req_url = URI(uri.start_with?("https") ? uri : (Office365::API_HOST + uri))
|
45
|
+
json_header = args.delete(:json_header)
|
46
|
+
|
47
|
+
faraday = Faraday.new(url: [req_url.scheme, "://", req_url.hostname].join, headers: json_header ? headers : post_headers) do |f|
|
48
|
+
f.adapter Faraday.default_adapter
|
49
|
+
f.response :json
|
50
|
+
f.response :logger, ::Logger.new($stdout), bodies: true if dev_developement?
|
51
|
+
end
|
52
|
+
|
53
|
+
faraday.send(method_name, req_url.request_uri, json_header ? args.to_json : args.ms_hash_to_query)
|
54
|
+
end
|
55
|
+
|
44
56
|
def parse_respond(response)
|
45
57
|
resp_body = response.body
|
46
58
|
|
47
|
-
return resp_body if response.status
|
59
|
+
return resp_body if [200, 201].include?(response.status)
|
48
60
|
|
49
61
|
raise InvaliRequestError, resp_body["error_description"] if response.status == 400
|
50
62
|
raise InvalidAuthenticationTokenError, resp_body.dig("error", "message") if response.status == 401
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Office365
|
4
|
+
module REST
|
5
|
+
module Subscription
|
6
|
+
def create_subscription(args = {})
|
7
|
+
raise ArgumentError, "Missing changeType" if args[:changeType].nil?
|
8
|
+
raise ArgumentError, "Missing notificationUrl" if args[:notificationUrl].nil?
|
9
|
+
raise ArgumentError, "Missing resource" if args[:resource].nil?
|
10
|
+
raise ArgumentError, "Missing expirationDateTime" if args[:expirationDateTime].nil?
|
11
|
+
raise ArgumentError, "Missing clientState" if args[:clientState].nil?
|
12
|
+
|
13
|
+
Models::Subscription.new(
|
14
|
+
Request.new(access_token, debug: debug).post("/v1.0/subscriptions", { json_header: true }.merge(args))
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
def renew_subscription(args = {})
|
19
|
+
raise ArgumentError, "Missing subscription identifier" if args[:identifier].nil?
|
20
|
+
|
21
|
+
identifier = args.delete(:identifier)
|
22
|
+
|
23
|
+
Models::Subscription.new(
|
24
|
+
Request.new(access_token, debug: debug).patch("/v1.0/subscriptions/#{identifier}", { json_header: true }.merge(args))
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/office365/utils/hash.rb
CHANGED
data/lib/office365/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-office365
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Encore Shao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/office365/models/event.rb
|
123
123
|
- lib/office365/models/mailbox.rb
|
124
124
|
- lib/office365/models/owner.rb
|
125
|
+
- lib/office365/models/subscription.rb
|
125
126
|
- lib/office365/models/user.rb
|
126
127
|
- lib/office365/rest.rb
|
127
128
|
- lib/office365/rest/api.rb
|
@@ -132,6 +133,7 @@ files:
|
|
132
133
|
- lib/office365/rest/event.rb
|
133
134
|
- lib/office365/rest/mailbox.rb
|
134
135
|
- lib/office365/rest/request.rb
|
136
|
+
- lib/office365/rest/subscription.rb
|
135
137
|
- lib/office365/rest/token.rb
|
136
138
|
- lib/office365/rest/user.rb
|
137
139
|
- lib/office365/utils.rb
|
@@ -163,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
165
|
- !ruby/object:Gem::Version
|
164
166
|
version: '0'
|
165
167
|
requirements: []
|
166
|
-
rubygems_version: 3.
|
168
|
+
rubygems_version: 3.1.6
|
167
169
|
signing_key:
|
168
170
|
specification_version: 4
|
169
171
|
summary: A simple ruby library to interact with Microsoft Graph and Office 365 API.
|