oneroster 2.3.1 → 2.3.2

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
  SHA1:
3
- metadata.gz: ac81a3a6a046beb01b2ae6d34e6ff2f373921d41
4
- data.tar.gz: 35e4d0240dc30cfe9aa5bf38af83de2ab19dcb31
3
+ metadata.gz: 3d9b2a06cf3a50f5e78071d6a74349c39079a687
4
+ data.tar.gz: fb2d03aca728cf15aa886cf72010ede9ee14359e
5
5
  SHA512:
6
- metadata.gz: dcd9b28d5b6d2607fff300142b0978a97b01d0227fa0ed1f89f828bdcad656b1955b9951864afd3a7ef75277cf4312d6b121ce12e61a882376adce66d9f46f7e
7
- data.tar.gz: b8bc51ac42ea3b4aa4609f6b8d999368b2b181c35006d951133c1169151a02a85a41ba1c24fc035a00263185a26d776801203a3aa27094a05d08710d23919375
6
+ metadata.gz: 472c0969f9ce2256f1b52615a135c61411be0c4dc04466b72aea5c24bf534cb205586d1727c32b71217fa1663d9db8fbcc9fe1a350858a551e8b7929f8f7cd44
7
+ data.tar.gz: b07e234e1a1c5323e341a8fb3e0a34fd3e194c13b17431db8fea10030d73b7a1cd80ade3b21d8dc64ec88db06cfb98c139463fe3a3ae9c0d9e29a38a1f8e5cd5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oneroster (2.3.1)
4
+ oneroster (2.3.2)
5
5
  dry-inflector
6
6
  faraday
7
7
  faraday_middleware
@@ -4,7 +4,7 @@ module OneRoster
4
4
  class Client
5
5
  attr_accessor :app_id, :app_token, :api_url,
6
6
  :app_secret, :logger, :vendor_key,
7
- :username_source, :oauth_strategy
7
+ :username_source, :oauth_strategy, :staff_username_source
8
8
 
9
9
  attr_reader :authenticated
10
10
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OneRoster
4
- VERSION = '2.3.1'
4
+ VERSION = '2.3.2'
5
5
  end
@@ -9,12 +9,59 @@ module OneRoster
9
9
  :last_name,
10
10
  :provider
11
11
 
12
- def initialize(attributes = {}, *)
13
- @uid = attributes['sourcedId']
14
- @email = attributes['email']
15
- @first_name = attributes['givenName']
16
- @last_name = attributes['familyName']
17
- @provider = 'oneroster'
12
+ def initialize(attributes = {}, *, client: nil)
13
+ @uid = attributes['sourcedId']
14
+ @email = attributes['email']
15
+ @first_name = attributes['givenName']
16
+ @last_name = attributes['familyName']
17
+ @api_username = attributes['username']
18
+ @username = username(client)
19
+ @provider = 'oneroster'
20
+ end
21
+
22
+ def username(client = nil)
23
+ username_source = client&.staff_username_source
24
+ @username ||= presence(username_from(username_source))
25
+ end
26
+
27
+ def to_h
28
+ {
29
+ uid: @uid,
30
+ email: @email,
31
+ first_name: @first_name,
32
+ last_name: @last_name,
33
+ username: @username,
34
+ provider: @provider
35
+ }
36
+ end
37
+
38
+ private
39
+
40
+ def presence(field)
41
+ field unless blank?(field)
42
+ end
43
+
44
+ def blank?(field)
45
+ field.nil? || field == ''
46
+ end
47
+
48
+ def username_from(username_source)
49
+ return unless presence(username_source)
50
+
51
+ source = username_source(username_source)
52
+
53
+ presence(instance_variable_get("@#{source}"))
54
+ end
55
+
56
+ # if the username_source is `sourcedId`, we want to return `uid`
57
+ # so we can grab the right instance variable
58
+ def username_source(source)
59
+ case source
60
+ when 'sourcedId' then 'uid'
61
+ when 'username' then 'api_username'
62
+ else
63
+ source
64
+ end
18
65
  end
19
66
  end
20
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oneroster
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.1
4
+ version: 2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Julius
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-27 00:00:00.000000000 Z
11
+ date: 2020-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday