etwin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +11 -0
  5. data/.travis.yml +6 -0
  6. data/Gemfile +9 -0
  7. data/Gemfile.lock +82 -0
  8. data/README.md +30 -0
  9. data/Rakefile +8 -0
  10. data/bin/console +15 -0
  11. data/bin/setup +8 -0
  12. data/etwin.gemspec +37 -0
  13. data/lib/etwin.rb +27 -0
  14. data/lib/etwin/_auth.rb +4 -0
  15. data/lib/etwin/auth.rb +14 -0
  16. data/lib/etwin/auth/_auth_context.rb +30 -0
  17. data/lib/etwin/auth/auth_context.rb +9 -0
  18. data/lib/etwin/auth/auth_scope.rb +25 -0
  19. data/lib/etwin/auth/auth_type.rb +26 -0
  20. data/lib/etwin/auth/guest_auth_context.rb +71 -0
  21. data/lib/etwin/auth/user_auth_context.rb +83 -0
  22. data/lib/etwin/client.rb +11 -0
  23. data/lib/etwin/client/auth.rb +66 -0
  24. data/lib/etwin/client/etwin_client.rb +17 -0
  25. data/lib/etwin/client/http_etwin_client.rb +36 -0
  26. data/lib/etwin/core.rb +10 -0
  27. data/lib/etwin/core/object_type.rb +35 -0
  28. data/lib/etwin/hammerfest.rb +13 -0
  29. data/lib/etwin/hammerfest/hammerfest_server.rb +27 -0
  30. data/lib/etwin/hammerfest/hammerfest_user_id.rb +57 -0
  31. data/lib/etwin/hammerfest/hammerfest_username.rb +57 -0
  32. data/lib/etwin/hammerfest/short_hammerfest_user.rb +103 -0
  33. data/lib/etwin/link.rb +15 -0
  34. data/lib/etwin/link/hammerfest_link.rb +106 -0
  35. data/lib/etwin/link/link_action.rb +93 -0
  36. data/lib/etwin/link/twinoid_link.rb +106 -0
  37. data/lib/etwin/link/versioned_hammerfest_link.rb +93 -0
  38. data/lib/etwin/link/versioned_links.rb +123 -0
  39. data/lib/etwin/link/versioned_twinoid_link.rb +93 -0
  40. data/lib/etwin/twinoid.rb +12 -0
  41. data/lib/etwin/twinoid/short_twinoid_user.rb +93 -0
  42. data/lib/etwin/twinoid/twinoid_user_display_name.rb +57 -0
  43. data/lib/etwin/twinoid/twinoid_user_id.rb +57 -0
  44. data/lib/etwin/user.rb +15 -0
  45. data/lib/etwin/user/short_user.rb +93 -0
  46. data/lib/etwin/user/user.rb +123 -0
  47. data/lib/etwin/user/user_display_name.rb +57 -0
  48. data/lib/etwin/user/user_display_name_version.rb +83 -0
  49. data/lib/etwin/user/user_display_name_versions.rb +83 -0
  50. data/lib/etwin/user/user_id.rb +57 -0
  51. data/lib/etwin/version.rb +6 -0
  52. data/sorbet/config +2 -0
  53. data/sorbet/rbi/gems/ast.rbi +48 -0
  54. data/sorbet/rbi/gems/debase.rbi +67 -0
  55. data/sorbet/rbi/gems/irb.rbi +352 -0
  56. data/sorbet/rbi/gems/parallel.rbi +83 -0
  57. data/sorbet/rbi/gems/parser.rbi +1405 -0
  58. data/sorbet/rbi/gems/rainbow.rbi +118 -0
  59. data/sorbet/rbi/gems/rake.rbi +644 -0
  60. data/sorbet/rbi/gems/regexp_parser.rbi +914 -0
  61. data/sorbet/rbi/gems/reline.rbi +556 -0
  62. data/sorbet/rbi/gems/rexml.rbi +605 -0
  63. data/sorbet/rbi/gems/rspec-core.rbi +1920 -0
  64. data/sorbet/rbi/gems/rspec-expectations.rbi +1148 -0
  65. data/sorbet/rbi/gems/rspec-mocks.rbi +1090 -0
  66. data/sorbet/rbi/gems/rspec-support.rbi +280 -0
  67. data/sorbet/rbi/gems/rspec.rbi +15 -0
  68. data/sorbet/rbi/gems/rubocop-ast.rbi +1338 -0
  69. data/sorbet/rbi/gems/rubocop.rbi +7491 -0
  70. data/sorbet/rbi/gems/ruby-debug-ide.rbi +608 -0
  71. data/sorbet/rbi/gems/ruby-progressbar.rbi +305 -0
  72. data/sorbet/rbi/gems/unicode-display_width.rbi +17 -0
  73. data/sorbet/rbi/hidden-definitions/errors.txt +4905 -0
  74. data/sorbet/rbi/hidden-definitions/hidden.rbi +9193 -0
  75. data/sorbet/rbi/sorbet-typed/lib/rainbow/all/rainbow.rbi +276 -0
  76. data/sorbet/rbi/todo.rbi +7 -0
  77. metadata +220 -0
@@ -0,0 +1,93 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ module Link
6
+ # Versioned Twinoid link
7
+ class VersionedTwinoidLink
8
+ extend T::Helpers
9
+ extend T::Sig
10
+
11
+ final!
12
+
13
+ sig(:final) { returns(T.nilable(TwinoidLink)) }
14
+ attr_reader :current
15
+
16
+ sig(:final) { returns(T::Array[TwinoidLink]) }
17
+ attr_reader :old
18
+
19
+ sig(:final) { params(current: T.nilable(TwinoidLink), old: T::Array[TwinoidLink]).void }
20
+ def initialize(current, old)
21
+ @current = T.let(current, T.nilable(TwinoidLink))
22
+ @old = T.let(old.freeze, T::Array[TwinoidLink])
23
+ freeze
24
+ end
25
+
26
+ sig(:final) { params(other: BasicObject).returns(T::Boolean) }
27
+ def ==(other)
28
+ case other
29
+ when VersionedTwinoidLink
30
+ @current == other.current && @old == other.old
31
+ else
32
+ false
33
+ end
34
+ end
35
+
36
+ sig(:final) { returns(Integer) }
37
+ def hash
38
+ [@current, @old].hash
39
+ end
40
+
41
+ # https://github.com/sorbet/sorbet/blob/master/rbi/stdlib/json.rbi#L194
42
+ sig(:final) { params(opts: T.untyped).returns(String) }
43
+ def to_json(opts = nil)
44
+ JSON.generate(as_json, opts)
45
+ end
46
+
47
+ sig(:final) { returns(T::Hash[String, T.untyped]) }
48
+ def as_json
49
+ {
50
+ 'current' => @current.nil? ? nil : @current.as_json,
51
+ 'old' => @old.map(&:as_json)
52
+ }
53
+ end
54
+
55
+ sig(:final) { returns(String) }
56
+ def inspect
57
+ PP.singleline_pp(self, String.new)
58
+ end
59
+
60
+ sig(:final) { params(pp: T.untyped).returns(T.untyped) }
61
+ def pretty_print(pp) # rubocop:disable Metrics/MethodLength
62
+ pp.group(0, "#{self.class.name}(", ')') do
63
+ pp.nest 1 do
64
+ pp.breakable ''
65
+ pp.text 'current='
66
+ pp.pp @current
67
+ pp.text ','
68
+ pp.breakable ''
69
+ pp.text 'old='
70
+ pp.pp @old
71
+ end
72
+ pp.breakable ''
73
+ end
74
+ end
75
+
76
+ class << self
77
+ extend T::Sig
78
+
79
+ sig(:final) { params(json_str: String).returns(T.attached_class) }
80
+ def from_json(json_str)
81
+ deserialize JSON.parse(json_str)
82
+ end
83
+
84
+ sig(:final) { params(raw: T.untyped).returns(T.attached_class) }
85
+ def deserialize(raw)
86
+ raw_current = raw['current']
87
+ current = raw_current.nil? ? nil : TwinoidLink.deserialize(raw_current)
88
+ new(current, [])
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,12 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ # Twinoid module
6
+ module Twinoid
7
+ end
8
+ end
9
+
10
+ require_relative './twinoid/twinoid_user_id'
11
+ require_relative './twinoid/twinoid_user_display_name'
12
+ require_relative './twinoid/short_twinoid_user'
@@ -0,0 +1,93 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ module Twinoid
6
+ # Twinoid user reference with enough data to display it
7
+ class ShortTwinoidUser
8
+ extend T::Helpers
9
+ extend T::Sig
10
+
11
+ final!
12
+
13
+ sig(:final) { returns(TwinoidUserId) }
14
+ attr_reader :id
15
+
16
+ sig(:final) { returns(TwinoidUserDisplayName) }
17
+ attr_reader :display_name
18
+
19
+ sig(:final) { params(id: TwinoidUserId, display_name: TwinoidUserDisplayName).void }
20
+ def initialize(id, display_name)
21
+ @id = T.let(id, TwinoidUserId)
22
+ @display_name = T.let(display_name, TwinoidUserDisplayName)
23
+ freeze
24
+ end
25
+
26
+ sig(:final) { params(other: BasicObject).returns(T::Boolean) }
27
+ def ==(other)
28
+ case other
29
+ when ShortTwinoidUser
30
+ @id == other.id && @display_name == other.display_name
31
+ else
32
+ false
33
+ end
34
+ end
35
+
36
+ sig(:final) { returns(Integer) }
37
+ def hash
38
+ [@id, @display_name].hash
39
+ end
40
+
41
+ # https://github.com/sorbet/sorbet/blob/master/rbi/stdlib/json.rbi#L194
42
+ sig(:final) { params(opts: T.untyped).returns(String) }
43
+ def to_json(opts = nil)
44
+ JSON.generate(as_json, opts)
45
+ end
46
+
47
+ sig(:final) { returns(T::Hash[String, T.untyped]) }
48
+ def as_json
49
+ {
50
+ 'id' => @id.as_json,
51
+ 'display_name' => @display_name.as_json
52
+ }
53
+ end
54
+
55
+ sig(:final) { returns(String) }
56
+ def inspect
57
+ PP.singleline_pp(self, String.new)
58
+ end
59
+
60
+ sig(:final) { params(pp: T.untyped).returns(T.untyped) }
61
+ def pretty_print(pp) # rubocop:disable Metrics/MethodLength
62
+ pp.group(0, "#{self.class.name}(", ')') do
63
+ pp.nest 1 do
64
+ pp.breakable ''
65
+ pp.text 'id='
66
+ pp.pp @id
67
+ pp.text ','
68
+ pp.breakable ''
69
+ pp.text 'display_name='
70
+ pp.pp @display_name
71
+ end
72
+ pp.breakable ''
73
+ end
74
+ end
75
+
76
+ class << self
77
+ extend T::Sig
78
+
79
+ sig(:final) { params(json_str: String).returns(T.attached_class) }
80
+ def from_json(json_str)
81
+ deserialize JSON.parse(json_str)
82
+ end
83
+
84
+ sig(:final) { params(raw: T.untyped).returns(T.attached_class) }
85
+ def deserialize(raw)
86
+ id = TwinoidUserId.new(raw['id'])
87
+ display_name = TwinoidUserDisplayName.new(raw['display_name'])
88
+ new(id, display_name)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,57 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ module Twinoid
6
+ # A valid Twinoid username
7
+ class TwinoidUserDisplayName
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 TwinoidUserDisplayName
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
+ "TwinoidUserDisplayName(#{@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 Twinoid
6
+ # A valid Twinoid user id
7
+ class TwinoidUserId
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 TwinoidUserId
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
+ "TwinoidUserId(#{@inner})"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ # User module
6
+ module User
7
+ end
8
+ end
9
+
10
+ require_relative './user/short_user'
11
+ require_relative './user/user'
12
+ require_relative './user/user_display_name'
13
+ require_relative './user/user_display_name_version'
14
+ require_relative './user/user_display_name_versions'
15
+ require_relative './user/user_id'
@@ -0,0 +1,93 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ module User
6
+ # User with minimum data to identify and display them
7
+ class ShortUser
8
+ extend T::Helpers
9
+ extend T::Sig
10
+
11
+ final!
12
+
13
+ sig(:final) { returns(UserId) }
14
+ attr_reader :id
15
+
16
+ sig(:final) { returns(UserDisplayNameVersions) }
17
+ attr_reader :display_name
18
+
19
+ sig(:final) { params(id: UserId, display_name: UserDisplayNameVersions).void }
20
+ def initialize(id, display_name)
21
+ @id = T.let(id, UserId)
22
+ @display_name = T.let(display_name, UserDisplayNameVersions)
23
+ freeze
24
+ end
25
+
26
+ sig(:final) { params(other: BasicObject).returns(T::Boolean) }
27
+ def ==(other)
28
+ case other
29
+ when ShortUser
30
+ @id == other.id && @display_name == other.display_name
31
+ else
32
+ false
33
+ end
34
+ end
35
+
36
+ sig(:final) { returns(Integer) }
37
+ def hash
38
+ [@id, @display_name].hash
39
+ end
40
+
41
+ # https://github.com/sorbet/sorbet/blob/master/rbi/stdlib/json.rbi#L194
42
+ sig(:final) { params(opts: T.untyped).returns(String) }
43
+ def to_json(opts = nil)
44
+ JSON.generate(as_json, opts)
45
+ end
46
+
47
+ sig(:final) { returns(T::Hash[String, T.untyped]) }
48
+ def as_json
49
+ {
50
+ 'id' => @id.as_json,
51
+ 'display_name' => @display_name.as_json
52
+ }
53
+ end
54
+
55
+ sig(:final) { returns(String) }
56
+ def inspect
57
+ PP.singleline_pp(self, String.new)
58
+ end
59
+
60
+ sig(:final) { params(pp: T.untyped).returns(T.untyped) }
61
+ def pretty_print(pp) # rubocop:disable Metrics/MethodLength
62
+ pp.group(0, "#{self.class.name}(", ')') do
63
+ pp.nest 1 do
64
+ pp.breakable ''
65
+ pp.text 'id='
66
+ pp.pp @id
67
+ pp.text ','
68
+ pp.breakable ''
69
+ pp.text 'display_name='
70
+ pp.pp @display_name
71
+ end
72
+ pp.breakable ''
73
+ end
74
+ end
75
+
76
+ class << self
77
+ extend T::Sig
78
+
79
+ sig(:final) { params(json_str: String).returns(T.attached_class) }
80
+ def from_json(json_str)
81
+ deserialize JSON.parse(json_str)
82
+ end
83
+
84
+ sig(:final) { params(raw: T.untyped).returns(T.attached_class) }
85
+ def deserialize(raw)
86
+ id = UserId.new(raw['id'])
87
+ display_name = UserDisplayNameVersions.deserialize(raw['display_name'])
88
+ new(id, display_name)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,123 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ module Etwin
5
+ module User
6
+ # Main user class
7
+ class User
8
+ extend T::Helpers
9
+ extend T::Sig
10
+
11
+ final!
12
+
13
+ sig(:final) { returns(UserId) }
14
+ attr_reader :id
15
+
16
+ sig(:final) { returns(UserDisplayNameVersions) }
17
+ attr_reader :display_name
18
+
19
+ sig(:final) { returns(T::Boolean) }
20
+ attr_reader :is_administrator
21
+
22
+ sig(:final) { returns(Etwin::Link::VersionedLinks) }
23
+ attr_reader :links
24
+
25
+ sig(:final) do
26
+ params(
27
+ id: UserId,
28
+ display_name: UserDisplayNameVersions,
29
+ is_administrator: T::Boolean,
30
+ links: Etwin::Link::VersionedLinks
31
+ ).void
32
+ end
33
+ def initialize(id, display_name, is_administrator, links)
34
+ @id = T.let(id, UserId)
35
+ @display_name = T.let(display_name, UserDisplayNameVersions)
36
+ @is_administrator = T.let(is_administrator, T::Boolean)
37
+ @links = T.let(links, Etwin::Link::VersionedLinks)
38
+ freeze
39
+ end
40
+
41
+ sig(:final) { params(other: BasicObject).returns(T::Boolean) }
42
+ def ==(other)
43
+ case other
44
+ when User
45
+ @id == other.id &&
46
+ @display_name == other.display_name &&
47
+ @is_administrator == other.is_administrator &&
48
+ @links == other.links
49
+ else
50
+ false
51
+ end
52
+ end
53
+
54
+ sig(:final) { returns(Integer) }
55
+ def hash
56
+ [@id, @display_name, @is_administrator, @links].hash
57
+ end
58
+
59
+ # https://github.com/sorbet/sorbet/blob/master/rbi/stdlib/json.rbi#L194
60
+ sig(:final) { params(opts: T.untyped).returns(String) }
61
+ def to_json(opts = nil)
62
+ JSON.generate(as_json, opts)
63
+ end
64
+
65
+ sig(:final) { returns(T::Hash[String, T.untyped]) }
66
+ def as_json
67
+ {
68
+ 'id' => @id.as_json,
69
+ 'display_name' => @display_name.as_json,
70
+ 'is_administrator' => @is_administrator,
71
+ 'links' => @links.as_json
72
+ }
73
+ end
74
+
75
+ sig(:final) { returns(String) }
76
+ def inspect
77
+ PP.singleline_pp(self, String.new)
78
+ end
79
+
80
+ sig(:final) { params(pp: T.untyped).returns(T.untyped) }
81
+ def pretty_print(pp) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
82
+ pp.group(0, "#{self.class.name}(", ')') do
83
+ pp.nest 1 do
84
+ pp.breakable ''
85
+ pp.text 'id='
86
+ pp.pp @id
87
+ pp.text ','
88
+ pp.breakable ''
89
+ pp.text 'display_name='
90
+ pp.pp @display_name
91
+ pp.text ','
92
+ pp.breakable ''
93
+ pp.text 'is_administrator='
94
+ pp.pp @is_administrator
95
+ pp.text ','
96
+ pp.breakable ''
97
+ pp.text 'links='
98
+ pp.pp @links
99
+ end
100
+ pp.breakable ''
101
+ end
102
+ end
103
+
104
+ class << self
105
+ extend T::Sig
106
+
107
+ sig(:final) { params(json_str: String).returns(T.attached_class) }
108
+ def from_json(json_str)
109
+ deserialize JSON.parse(json_str)
110
+ end
111
+
112
+ sig(:final) { params(raw: T.untyped).returns(T.attached_class) }
113
+ def deserialize(raw)
114
+ id = UserId.new(raw['id'])
115
+ display_name = UserDisplayNameVersions.deserialize(raw['display_name'])
116
+ is_administrator = raw['is_administrator']
117
+ links = Etwin::Link::VersionedLinks.deserialize(raw['links'])
118
+ new(id, display_name, is_administrator, links)
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end