ruby-office365 0.1.8 → 0.2.0

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: 3513de92b0360a54e0d374123fcf895427f951c47bb69b2f3e467898656ab943
4
+ data.tar.gz: '0600429d86539062c53f5507c02b9b711475ed40ddf2b69bdbad5aabe4f77042'
5
5
  SHA512:
6
- metadata.gz: b970531fc4df3e763a6b15a997e3bf0557e3e0b08772eb1d5fe4b37d17bdde9c78d95f8bd3729b2764f0a8378aa4ccd9baa56ce7abae5f35d5e21a4259fcf1c5
7
- data.tar.gz: 9ad0c123acddf7965596ccd0be7ff1a0ffb710f1f665cbda60c52a6f6d4ef94641818d0404e9bd6a9b33bb1d5d15a0e43d7c36f5c7418b2a074db01d93d43fab
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.1.0] - (2022-10-19)
3
+ ## [0.2.0] - (2024-11-14)
4
4
 
5
- - Project setup and push to rubugems
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.1] - (2022-10-21)
8
+ ## [0.1.9] - (2024-08-08)
8
9
 
9
- - Integrate REST API to get data from Graph API
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.2] - (2022-10-21)
12
+ ## [0.1.7] - (2022-11-11)
15
13
 
16
- - Integrate REST API to get mailbox with pagination
17
- - get mailbox data with next link `client.messages({next_link: 'xxx'})`
18
- - get calenders data with next link `client.calenders({next_link: 'xxx'})`
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.3] - (2022-10-26)
18
+ ## [0.1.6] - (2022-11-01)
21
19
 
22
- - Integrate REST API to get contacts
23
- - get contacts `client.contacts`
24
- - get contacts data with next link `client.contacts({next_link: 'xxx'})`
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.6] - (2022-11-01)
31
+ ## [0.1.3] - (2022-10-26)
34
32
 
35
- - Integrate REST API to get events
36
- - get events `client.events`
37
- - get events data with next link `client.events({next_link: 'xxx'})`
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.7] - (2022-11-11)
37
+ ## [0.1.2] - (2022-10-21)
40
38
 
41
- - Improve performance: supports select and sort in REST APIs
42
- - get messages by select fields `client.messages({ select: %[id] })`
43
- - get messages by custom order `client.messages({ order: 'id asc' })`
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.1.8)
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.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
@@ -1,4 +1,5 @@
1
- # Office 365 (2022) <img src="https://i.ibb.co/g3mpswn/microsoft-office-365-logo-2016-100727915-large.webp" align="right" width="250" height="150">
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.
@@ -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,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
- wrap_results(args.merge(kclass: Models::Event, base_uri: "/me/events"))
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
- 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.2.0"
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.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: 2023-02-20 00:00:00.000000000 Z
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.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.