etwin 0.0.3 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69cc4a2279c94d413db0a4481a1370c9fc3f4e941c51742bff6398d19c76df74
4
- data.tar.gz: c9c3e99a3f1242cb68adeb9b3edb8264855777698dc31df601e6845d5bc45e52
3
+ metadata.gz: 4c116defe51194b8f40c3496884b3a551fc0388c28a606a0dccfe2618b7700d8
4
+ data.tar.gz: 19151aa9323d4de434f1606d9943faedba65451d7b307bb8b302816bc4e366a6
5
5
  SHA512:
6
- metadata.gz: d3d1d50d6109fa53d73b009cdf2e7bb866ad9eb7e70a92a4ee00663799111023c74cdaba9cfb4683bff2ba607f8bc54ab9c9b96609f6ee48ee5b8649a304c842
7
- data.tar.gz: a24475b7fece1104fa8deca475d8de443a897c2c24c8908914094ed69dc5614c85f245575d86cccf5423c77f20c8a46cde7bcd9a0f434662cbd10ba994a05fba
6
+ metadata.gz: dbb9665963eb211d4ea1b1c271a48a747c62723614716a81ae100b6d7df9b6e39de8673128c95c1a96375fe3e14a1220305d7d0117c38638fb290c58dea29be7
7
+ data.tar.gz: 95a308a4d2ec53dfe51f189cb939b803b2f5adc8b9f18adbebae6455314067cebfe5844dd9330f73618f377cb6b7e3dc67959d5e722e9b1121259907f611d2de
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- etwin (0.0.2)
4
+ etwin (0.3.2)
5
5
  faraday (~> 1.1.0)
6
6
  sorbet-runtime (~> 0.5.6076)
7
7
 
data/README.md CHANGED
@@ -33,6 +33,7 @@ bundle exec rubocop
33
33
  bundle exec rspec
34
34
  # bundle exec rake release
35
35
  # bundle exec rake install
36
+ bundle exec srb rbi update
36
37
  bundle exec srb tc
37
38
  # gem build
38
39
  # gem push ...
@@ -21,6 +21,7 @@ require_relative './etwin/client'
21
21
  require_relative './etwin/core'
22
22
  require_relative './etwin/hammerfest'
23
23
  require_relative './etwin/link'
24
+ require_relative './etwin/oauth'
24
25
  require_relative './etwin/twinoid'
25
26
  require_relative './etwin/user'
26
27
  require_relative './etwin/version'
@@ -7,6 +7,7 @@ module Etwin
7
7
  end
8
8
  end
9
9
 
10
+ require_relative './auth/access_token_auth_context'
10
11
  require_relative './auth/auth_context'
11
12
  require_relative './auth/auth_scope'
12
13
  require_relative './auth/auth_type'
@@ -20,6 +20,7 @@ module Etwin
20
20
  def AuthContext.deserialize(raw)
21
21
  type = AuthType.deserialize(raw['type'])
22
22
  case type
23
+ when AuthType::AccessToken then AccessTokenAuthContext.deserialize(raw)
23
24
  when AuthType::Guest then GuestAuthContext.deserialize(raw)
24
25
  when AuthType::User then UserAuthContext.deserialize(raw)
25
26
  else T.absurd(type)
@@ -0,0 +1,103 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ module Auth
6
+ # Access token authentication context
7
+ class AccessTokenAuthContext
8
+ extend T::Helpers
9
+ extend T::Sig
10
+
11
+ final!
12
+
13
+ sig(:final) { returns(AuthScope) }
14
+ attr_reader :scope
15
+
16
+ sig(:final) { returns(Etwin::Oauth::ShortOauthClient) }
17
+ attr_reader :client
18
+
19
+ sig(:final) { returns(Etwin::User::ShortUser) }
20
+ attr_reader :user
21
+
22
+ sig(:final) { params(scope: AuthScope, client: Etwin::Oauth::ShortOauthClient, user: Etwin::User::ShortUser).void }
23
+ def initialize(scope, client, user)
24
+ @scope = T.let(scope, AuthScope)
25
+ @client = T.let(client, Etwin::Oauth::ShortOauthClient)
26
+ @user = T.let(user, Etwin::User::ShortUser)
27
+ freeze
28
+ end
29
+
30
+ sig(:final) { params(other: BasicObject).returns(T::Boolean) }
31
+ def ==(other)
32
+ case other
33
+ when AccessTokenAuthContext
34
+ @scope == other.scope && @client == other.client && @user == other.user
35
+ else
36
+ false
37
+ end
38
+ end
39
+
40
+ sig(:final) { returns(Integer) }
41
+ def hash
42
+ [@scope, @client, @user].hash
43
+ end
44
+
45
+ # https://github.com/sorbet/sorbet/blob/master/rbi/stdlib/json.rbi#L194
46
+ sig(:final) { params(opts: T.untyped).returns(String) }
47
+ def to_json(opts = nil)
48
+ JSON.generate(as_json, opts)
49
+ end
50
+
51
+ sig(:final) { returns(T::Hash[String, T.untyped]) }
52
+ def as_json
53
+ {
54
+ 'scope' => @scope.serialize,
55
+ 'client' => @client.as_json,
56
+ 'user' => @user.as_json
57
+ }
58
+ end
59
+
60
+ sig(:final) { returns(String) }
61
+ def inspect
62
+ PP.singleline_pp(self, String.new)
63
+ end
64
+
65
+ sig(:final) { params(pp: T.untyped).returns(T.untyped) }
66
+ def pretty_print(pp) # rubocop:disable Metrics/MethodLength
67
+ pp.group(0, "#{self.class.name}(", ')') do
68
+ pp.nest 1 do
69
+ pp.breakable ''
70
+ pp.text 'scope='
71
+ pp.pp @scope
72
+ pp.text ','
73
+ pp.breakable ''
74
+ pp.text 'client='
75
+ pp.pp @client
76
+ pp.text ','
77
+ pp.breakable ''
78
+ pp.text 'user='
79
+ pp.pp @user
80
+ end
81
+ pp.breakable ''
82
+ end
83
+ end
84
+
85
+ class << self
86
+ extend T::Sig
87
+
88
+ sig(:final) { params(json_str: String).returns(T.attached_class) }
89
+ def from_json(json_str)
90
+ deserialize JSON.parse(json_str)
91
+ end
92
+
93
+ sig(:final) { params(raw: T.untyped).returns(T.attached_class) }
94
+ def deserialize(raw)
95
+ scope = AuthScope.deserialize(raw['scope'])
96
+ client = Etwin::Oauth::ShortOauthClient.deserialize(raw['client'])
97
+ user = Etwin::User::ShortUser.deserialize(raw['user'])
98
+ new(scope, client, user)
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -8,6 +8,7 @@ module Etwin
8
8
  extend T::Sig
9
9
 
10
10
  enums do
11
+ AccessToken = new('AccessToken')
11
12
  Guest = new('Guest')
12
13
  User = new('User')
13
14
  end
@@ -51,7 +51,7 @@ module Etwin
51
51
  end
52
52
  end
53
53
 
54
- Guest = new(nil)
54
+ Guest = T.let(new(nil), Auth)
55
55
 
56
56
  class << self
57
57
  extend T::Sig
@@ -36,7 +36,7 @@ module Etwin
36
36
 
37
37
  sig(:final) { params(segments: T::Array[String]).returns(URI::HTTP) }
38
38
  def resolve(segments)
39
- @base_uri.merge("api/v1/#{ segments * '/'}")
39
+ T.cast(@base_uri.merge("api/v1/#{ segments * '/'}"), URI::HTTP)
40
40
  end
41
41
  end
42
42
  end
@@ -0,0 +1,13 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ # Oauth module
6
+ module Oauth
7
+ end
8
+ end
9
+
10
+ require_relative './oauth/oauth_client_display_name'
11
+ require_relative './oauth/oauth_client_id'
12
+ require_relative './oauth/oauth_client_key'
13
+ require_relative './oauth/short_oauth_client'
@@ -0,0 +1,57 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ module Oauth
6
+ # A valid Eternal-Twin OAuth client display name
7
+ class OauthClientDisplayName
8
+ extend T::Helpers
9
+ extend T::Sig
10
+
11
+ final!
12
+
13
+ protected
14
+
15
+ sig(:final) { returns(String) }
16
+ attr_reader :inner
17
+
18
+ public
19
+
20
+ sig(:final) { params(inner: String).void }
21
+ def initialize(inner)
22
+ @inner = T.let(inner.freeze, String)
23
+ freeze
24
+ end
25
+
26
+ sig(:final) { params(other: BasicObject).returns(T::Boolean) }
27
+ def ==(other)
28
+ case other
29
+ when OauthClientDisplayName
30
+ @inner == other.inner
31
+ else
32
+ false
33
+ end
34
+ end
35
+
36
+ sig(:final) { returns(Integer) }
37
+ def hash
38
+ @inner.hash
39
+ end
40
+
41
+ sig(:final) { returns(String) }
42
+ def to_s
43
+ @inner
44
+ end
45
+
46
+ sig(:final) { returns(String) }
47
+ def as_json
48
+ @inner
49
+ end
50
+
51
+ sig(:final) { returns(String) }
52
+ def inspect
53
+ "OauthClientDisplayName(#{@inner})"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,57 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ module Oauth
6
+ # A valid Eternal-Twin OAuth client id
7
+ class OauthClientId
8
+ extend T::Helpers
9
+ extend T::Sig
10
+
11
+ final!
12
+
13
+ protected
14
+
15
+ sig(:final) { returns(String) }
16
+ attr_reader :inner
17
+
18
+ public
19
+
20
+ sig(:final) { params(inner: String).void }
21
+ def initialize(inner)
22
+ @inner = T.let(inner.freeze, String)
23
+ freeze
24
+ end
25
+
26
+ sig(:final) { params(other: BasicObject).returns(T::Boolean) }
27
+ def ==(other)
28
+ case other
29
+ when OauthClientId
30
+ @inner == other.inner
31
+ else
32
+ false
33
+ end
34
+ end
35
+
36
+ sig(:final) { returns(Integer) }
37
+ def hash
38
+ @inner.hash
39
+ end
40
+
41
+ sig(:final) { returns(String) }
42
+ def to_s
43
+ @inner
44
+ end
45
+
46
+ sig(:final) { returns(String) }
47
+ def as_json
48
+ @inner
49
+ end
50
+
51
+ sig(:final) { returns(String) }
52
+ def inspect
53
+ "OauthClientId(#{@inner})"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,57 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ module Oauth
6
+ # A valid Eternal-Twin OAuth client key
7
+ class OauthClientKey
8
+ extend T::Helpers
9
+ extend T::Sig
10
+
11
+ final!
12
+
13
+ protected
14
+
15
+ sig(:final) { returns(String) }
16
+ attr_reader :inner
17
+
18
+ public
19
+
20
+ sig(:final) { params(inner: String).void }
21
+ def initialize(inner)
22
+ @inner = T.let(inner.freeze, String)
23
+ freeze
24
+ end
25
+
26
+ sig(:final) { params(other: BasicObject).returns(T::Boolean) }
27
+ def ==(other)
28
+ case other
29
+ when OauthClientKey
30
+ @inner == other.inner
31
+ else
32
+ false
33
+ end
34
+ end
35
+
36
+ sig(:final) { returns(Integer) }
37
+ def hash
38
+ @inner.hash
39
+ end
40
+
41
+ sig(:final) { returns(String) }
42
+ def to_s
43
+ @inner
44
+ end
45
+
46
+ sig(:final) { returns(String) }
47
+ def as_json
48
+ @inner
49
+ end
50
+
51
+ sig(:final) { returns(String) }
52
+ def inspect
53
+ "OauthClientKey(#{@inner})"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,104 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ module Oauth
6
+ # OAuth client with minimum data to identify and display it
7
+ class ShortOauthClient
8
+ extend T::Helpers
9
+ extend T::Sig
10
+
11
+ final!
12
+
13
+ sig(:final) { returns(OauthClientId) }
14
+ attr_reader :id
15
+
16
+ sig(:final) { returns(T.nilable(OauthClientKey)) }
17
+ attr_reader :key
18
+
19
+ sig(:final) { returns(OauthClientDisplayName) }
20
+ attr_reader :display_name
21
+
22
+ sig(:final) { params(id: OauthClientId, key: T.nilable(OauthClientKey), display_name: OauthClientDisplayName).void }
23
+ def initialize(id, key, display_name)
24
+ @id = T.let(id, OauthClientId)
25
+ @key = T.let(key, T.nilable(OauthClientKey))
26
+ @display_name = T.let(display_name, OauthClientDisplayName)
27
+ freeze
28
+ end
29
+
30
+ sig(:final) { params(other: BasicObject).returns(T::Boolean) }
31
+ def ==(other)
32
+ case other
33
+ when ShortOauthClient
34
+ @id == other.id && @key == other.key && @display_name == other.display_name
35
+ else
36
+ false
37
+ end
38
+ end
39
+
40
+ sig(:final) { returns(Integer) }
41
+ def hash
42
+ [@id, @key, @display_name].hash
43
+ end
44
+
45
+ # https://github.com/sorbet/sorbet/blob/master/rbi/stdlib/json.rbi#L194
46
+ sig(:final) { params(opts: T.untyped).returns(String) }
47
+ def to_json(opts = nil)
48
+ JSON.generate(as_json, opts)
49
+ end
50
+
51
+ sig(:final) { returns(T::Hash[String, T.untyped]) }
52
+ def as_json
53
+ {
54
+ 'id' => @id.as_json,
55
+ 'key' => @key.nil? ? nil : @key.as_json,
56
+ 'display_name' => @display_name.as_json
57
+ }
58
+ end
59
+
60
+ sig(:final) { returns(String) }
61
+ def inspect
62
+ PP.singleline_pp(self, String.new)
63
+ end
64
+
65
+ sig(:final) { params(pp: T.untyped).returns(T.untyped) }
66
+ def pretty_print(pp) # rubocop:disable Metrics/MethodLength
67
+ pp.group(0, "#{self.class.name}(", ')') do
68
+ pp.nest 1 do
69
+ pp.breakable ''
70
+ pp.text 'id='
71
+ pp.pp @id
72
+ pp.text ','
73
+ pp.breakable ''
74
+ pp.text 'key='
75
+ pp.pp @key
76
+ pp.text ','
77
+ pp.breakable ''
78
+ pp.text 'display_name='
79
+ pp.pp @display_name
80
+ end
81
+ pp.breakable ''
82
+ end
83
+ end
84
+
85
+ class << self
86
+ extend T::Sig
87
+
88
+ sig(:final) { params(json_str: String).returns(T.attached_class) }
89
+ def from_json(json_str)
90
+ deserialize JSON.parse(json_str)
91
+ end
92
+
93
+ sig(:final) { params(raw: T.untyped).returns(T.attached_class) }
94
+ def deserialize(raw)
95
+ id = OauthClientId.new(raw['id'])
96
+ raw_key = raw['key']
97
+ key = raw_key.nil? ? nil : OauthClientKey.new(raw_key)
98
+ display_name = OauthClientDisplayName.new(raw['display_name'])
99
+ new(id, key, display_name)
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end