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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d51b843c237dae5d0af62db257a4ae5889d03e00b62fdce26f679717139a9fe6
4
- data.tar.gz: 1cdb8e3c0229f929acd5354fcea731253c7535e57fbe355cc2ee816ef54597a6
3
+ metadata.gz: 5ae4eff73f21d319447f7b789178a0befbc9f480631c72b9556e091f395c2905
4
+ data.tar.gz: b2eeb9e486a6cace523a577c1c08453f6a0061b05d7212302b4fc7cc918f6d7a
5
5
  SHA512:
6
- metadata.gz: b970531fc4df3e763a6b15a997e3bf0557e3e0b08772eb1d5fe4b37d17bdde9c78d95f8bd3729b2764f0a8378aa4ccd9baa56ce7abae5f35d5e21a4259fcf1c5
7
- data.tar.gz: 9ad0c123acddf7965596ccd0be7ff1a0ffb710f1f665cbda60c52a6f6d4ef94641818d0404e9bd6a9b33bb1d5d15a0e43d7c36f5c7418b2a074db01d93d43fab
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.8)
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.2)
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.1)
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.2.3)
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.
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Office365
4
+ module Models
5
+ class Subscription < Base
6
+ end
7
+ end
8
+ end
@@ -12,5 +12,6 @@ module Office365
12
12
  autoload :Contact, "office365/models/contact"
13
13
  autoload :AccessToken, "office365/models/access_token"
14
14
  autoload :Event, "office365/models/event"
15
+ autoload :Subscription, "office365/models/subscription"
15
16
  end
16
17
  end
@@ -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 = args.delete(:kclass)
11
- response = get_request(args: args)
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) },
@@ -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: "/me/events"))
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
- req_url = URI(uri.start_with?("https") ? uri : (Office365::API_HOST + uri))
31
+ response = faraday_action(__method__, uri, args)
32
+ parse_respond(response)
33
+ end
32
34
 
33
- response = Faraday.new(url: [req_url.scheme, "://", req_url.hostname].join, headers: post_headers) do |faraday|
34
- faraday.adapter Faraday.default_adapter
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 == 200
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
@@ -11,4 +11,4 @@ class Hash
11
11
  end
12
12
  query_str.join("&")
13
13
  end
14
- end
14
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Office365
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.9"
5
5
  end
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.8
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: 2023-02-20 00:00:00.000000000 Z
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.2.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.