ruby-office365 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +40 -0
- 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 +8 -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: 5ae4eff73f21d319447f7b789178a0befbc9f480631c72b9556e091f395c2905
|
4
|
+
data.tar.gz: b2eeb9e486a6cace523a577c1c08453f6a0061b05d7212302b4fc7cc918f6d7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4f935c0fb140ef8e7758f6d2f481a9f38ca5acc256a58b1f9679c0efd1d37a60ec1bf06b22be7fd9812c909cde5162e0c4bcc9bd10b3cd1d3badc90e885132a
|
7
|
+
data.tar.gz: a19af99ccc99cacf0beaddca0fa5288d8d0e3020dc01dd6c4eef183a38f1dee0b9144011471d966b16f72a72a400dc6b8e9afc80aced0f9eea1ae08d289cad15
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ruby-office365 (0.1.
|
4
|
+
ruby-office365 (0.1.9)
|
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
@@ -100,6 +100,15 @@ irb(main):005:0> client.events[:results]
|
|
100
100
|
irb(main):005:0> client.events[:next_link]
|
101
101
|
```
|
102
102
|
|
103
|
+
**Get my event by id**
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
irb(main):005:0> client.event('identifier')
|
107
|
+
irb(main):005:0> client.event('identifier')[:results]
|
108
|
+
```
|
109
|
+
|
110
|
+
Results will return an array even if it is a single result.
|
111
|
+
|
103
112
|
**Get my mails by access token**
|
104
113
|
|
105
114
|
```ruby
|
@@ -171,6 +180,37 @@ irb(main):005:0> response.refresh_token
|
|
171
180
|
=> "0.ARgA7EiQdLv1qECnFqPfrznKsT9ERYaGfG9Ki5WzQtEllj8YAJk.AgABAAEAAAD--DLA3VO7QrddgJg7WevrAgDs_wQA9P-Q1ODlBsrdZi-5s2mfLtEsavBgiEhGcz1KEf26fMrGFU3LM_og5l6wjSAtQ83XHLuje0_KYGol26_LGV_uH0F1MwCFR1N3ctwg4_...."
|
172
181
|
```
|
173
182
|
|
183
|
+
**Create Subscription: it will create a webhook for Office365**
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
args = {
|
187
|
+
changeType: "updated,deleted",
|
188
|
+
notificationUrl: "https://hello-world.com/office365/notifications",
|
189
|
+
lifecycleNotificationUrl: "https://hello-world.com/office365/lifecycle_notifications",
|
190
|
+
resource: "/me/{type}",
|
191
|
+
expirationDateTime: "2024-08-07T12:00:00.0000000Z",
|
192
|
+
clientState: "SecretClientState"
|
193
|
+
}
|
194
|
+
|
195
|
+
irb(main):005:0> subscription = client.create_subscription(args)
|
196
|
+
```
|
197
|
+
|
198
|
+
will return the subscription object `Office365::Models::Subscription`
|
199
|
+
|
200
|
+
**Renew Subscription**
|
201
|
+
|
202
|
+
```ruby
|
203
|
+
args = {
|
204
|
+
identifier: "subscription-identifier",
|
205
|
+
expirationDateTime: "2024-08-08T12:00:00.0000000Z"
|
206
|
+
}
|
207
|
+
|
208
|
+
irb(main):005:0> subscription = client.renew_subscription(args)
|
209
|
+
```
|
210
|
+
|
211
|
+
will return the subscription object `Office365::Models::Subscription`
|
212
|
+
|
213
|
+
|
174
214
|
## Development
|
175
215
|
|
176
216
|
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,18 @@ module Office365
|
|
6
6
|
module REST
|
7
7
|
module Event
|
8
8
|
include Concerns::Base
|
9
|
+
BASE_URI = "/me/events"
|
9
10
|
|
10
11
|
# params: args => { next_link: (nil / next_page_url) }
|
11
12
|
# response { results: [], next_link: '...' }
|
12
13
|
def events(args = {})
|
13
|
-
wrap_results(args.merge(kclass: Models::Event, base_uri:
|
14
|
+
wrap_results(args.merge(kclass: Models::Event, base_uri: BASE_URI))
|
15
|
+
end
|
16
|
+
|
17
|
+
def event(identifier)
|
18
|
+
raise ArgumentError, "Identifier must be provided" if identifier.nil? || identifier.empty?
|
19
|
+
|
20
|
+
wrap_results(kclass: Models::Event, base_uri: [BASE_URI, identifier].join("/"), identifier: identifier)
|
14
21
|
end
|
15
22
|
end
|
16
23
|
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.1.
|
4
|
+
version: 0.1.9
|
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-08-08 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.
|