ruby-office365 0.1.4 → 0.1.5
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 +1 -1
- data/Gemfile.lock +1 -1
- data/README.md +7 -1
- data/lib/office365/models/access_token.rb +9 -0
- data/lib/office365/models.rb +1 -0
- data/lib/office365/rest/request.rb +22 -12
- data/lib/office365/rest/token.rb +14 -7
- data/lib/office365/version.rb +1 -1
- data/lib/office365.rb +5 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86ee47df4ac96c36024adb5c0595afa78889dc9659aebcdbdf01a59e407a0db9
|
4
|
+
data.tar.gz: 42ab9271c0d32b6035ad9caecc837137774bde57d0894fd49f34782d8c0f1f1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dd5a3b6d974b91bf6c2846b1b9b3f433fcc1abe11d6dfc85f3fe3a7b023313db0079b6056a1e27d3d8a36506a434a4ef0e45f327f4d2dd25b0416f681ff5906
|
7
|
+
data.tar.gz: fc2997832814ec584184584546ca7443841914191056f5fd3c080017cf21b273a05f9dd5612b928ad7570fb3cbc202ff0cbaba01e86a62b250c409f1e87776b9
|
data/CHANGELOG.md
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
- get profile `client.contacts`
|
24
24
|
- get contacts data with next link `client.contacts({next_link: 'xxx'})`
|
25
25
|
|
26
|
-
## [0.1.
|
26
|
+
## [0.1.5] - (2022-10-27)
|
27
27
|
|
28
28
|
- Generate URLs for token and able to refresh token
|
29
29
|
- get authorize URL `client.authorize_url`
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -135,7 +135,13 @@ irb(main):018:0> response[:results][0].as_json
|
|
135
135
|
**Refresh User Token**
|
136
136
|
|
137
137
|
```ruby
|
138
|
-
irb(main):005:0> client.refresh_token!
|
138
|
+
irb(main):005:0> response = client.refresh_token!
|
139
|
+
irb(main):005:0> response.scope
|
140
|
+
=> "openid User.Read profile email"
|
141
|
+
irb(main):005:0> response.access_token
|
142
|
+
=> "eyJ0eXAiOiJKV1QiLCJub25jZSI6ImFDYUladFJ6M3RSc3dFaktxUHdGbF9kVlFmbjJabG85Mjlkb2xaeFBhZm8iLCJhbGciOiJSUzI1NiIsIng1dCI6IjJaUXBKM1VwYmpBWVhZR2FYRUpsOGxWMFRPSSIsImtpZCI6IjJaUXBKM1VwYmpBWVhZR2FYRUpsOGxWMFRPSSJ9..."
|
143
|
+
irb(main):005:0> response.refresh_token
|
144
|
+
=> "0.ARgA7EiQdLv1qECnFqPfrznKsT9ERYaGfG9Ki5WzQtEllj8YAJk.AgABAAEAAAD--DLA3VO7QrddgJg7WevrAgDs_wQA9P-Q1ODlBsrdZi-5s2mfLtEsavBgiEhGcz1KEf26fMrGFU3LM_og5l6wjSAtQ83XHLuje0_KYGol26_LGV_uH0F1MwCFR1N3ctwg4_...."
|
139
145
|
```
|
140
146
|
|
141
147
|
## Copyright
|
data/lib/office365/models.rb
CHANGED
@@ -16,37 +16,41 @@ module Office365
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def get(uri, args: {})
|
19
|
-
|
19
|
+
req_url = URI(uri.start_with?("https") ? uri : (Office365::API_HOST + uri))
|
20
20
|
|
21
|
-
response = Faraday.new(url: [
|
21
|
+
response = Faraday.new(url: [req_url.scheme, "://", req_url.hostname].join, headers: headers) do |faraday|
|
22
22
|
faraday.adapter Faraday.default_adapter
|
23
23
|
faraday.response :json
|
24
24
|
faraday.response :logger, ::Logger.new($stdout), bodies: true if dev_developement?
|
25
|
-
end.get(
|
25
|
+
end.get(req_url.request_uri, *args)
|
26
26
|
|
27
|
-
|
28
|
-
return resp_body if response.status == 200
|
29
|
-
raise InvalidAuthenticationTokenError, resp_body.dig("error", "message") if response.status == 401
|
30
|
-
|
31
|
-
raise Error, resp_body["error"]
|
27
|
+
parse_respond(response)
|
32
28
|
end
|
33
29
|
|
34
30
|
def post(uri, args)
|
35
|
-
|
31
|
+
req_url = URI(uri.start_with?("https") ? uri : (Office365::API_HOST + uri))
|
32
|
+
|
33
|
+
response = Faraday.new(url: [req_url.scheme, "://", req_url.hostname].join, headers: post_headers) do |faraday|
|
36
34
|
faraday.adapter Faraday.default_adapter
|
37
35
|
faraday.response :json
|
38
36
|
faraday.response :logger, ::Logger.new($stdout), bodies: true if dev_developement?
|
39
|
-
end.post(
|
37
|
+
end.post(req_url.request_uri, args.to_query)
|
38
|
+
|
39
|
+
parse_respond(response)
|
40
|
+
end
|
40
41
|
|
42
|
+
private
|
43
|
+
|
44
|
+
def parse_respond(response)
|
41
45
|
resp_body = response.body
|
46
|
+
|
42
47
|
return resp_body if response.status == 200
|
43
48
|
raise InvalidAuthenticationTokenError, resp_body.dig("error", "message") if response.status == 401
|
49
|
+
raise InvaliRequestError, resp_body["error_description"] if response.status == 400
|
44
50
|
|
45
51
|
raise Error, resp_body["error"]
|
46
52
|
end
|
47
53
|
|
48
|
-
private
|
49
|
-
|
50
54
|
def headers
|
51
55
|
{
|
52
56
|
"Content-Type" => "application/json",
|
@@ -57,6 +61,12 @@ module Office365
|
|
57
61
|
def dev_developement?
|
58
62
|
debug
|
59
63
|
end
|
64
|
+
|
65
|
+
def post_headers
|
66
|
+
{
|
67
|
+
"Content-Type" => "application/x-www-form-urlencoded"
|
68
|
+
}
|
69
|
+
end
|
60
70
|
end
|
61
71
|
end
|
62
72
|
end
|
data/lib/office365/rest/token.rb
CHANGED
@@ -23,13 +23,20 @@ module Office365
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def refresh_token!
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
Models::AccessToken.new(
|
27
|
+
Request.new(nil, debug: debug).post(token_url, token_params)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def token_params
|
34
|
+
{
|
35
|
+
refresh_token: refresh_token,
|
36
|
+
client_id: client_id,
|
37
|
+
client_secret: client_secret,
|
38
|
+
grant_type: "refresh_token"
|
39
|
+
}
|
33
40
|
end
|
34
41
|
end
|
35
42
|
end
|
data/lib/office365/version.rb
CHANGED
data/lib/office365.rb
CHANGED
@@ -8,13 +8,14 @@ require "office365/rest"
|
|
8
8
|
require "office365/models"
|
9
9
|
|
10
10
|
module Office365
|
11
|
+
class Error < StandardError; end
|
12
|
+
class InvalidAuthenticationTokenError < StandardError; end
|
13
|
+
class InvaliRequestError < StandardError; end
|
14
|
+
|
11
15
|
API_HOST = "https://graph.microsoft.com"
|
12
16
|
API_VERSION = "v1.0"
|
13
17
|
|
14
18
|
LOGIN_HOST = "https://login.microsoftonline.com"
|
15
|
-
SCOPE = "User.read Calendars.read Mail.ReadBasic Contacts.Read"
|
16
|
-
|
17
|
-
class Error < StandardError; end
|
18
|
-
class InvalidAuthenticationTokenError < StandardError; end
|
19
|
+
SCOPE = "offline_access User.read Calendars.read Mail.ReadBasic Contacts.Read"
|
19
20
|
# Your code goes here...
|
20
21
|
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.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Encore Shao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/office365.rb
|
114
114
|
- lib/office365/client.rb
|
115
115
|
- lib/office365/models.rb
|
116
|
+
- lib/office365/models/access_token.rb
|
116
117
|
- lib/office365/models/calendar.rb
|
117
118
|
- lib/office365/models/concerns/base.rb
|
118
119
|
- lib/office365/models/contact.rb
|