userlist 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +1 -1
- data/lib/userlist/config.rb +8 -2
- data/lib/userlist/push/client.rb +3 -0
- data/lib/userlist/push/company.rb +2 -2
- data/lib/userlist/push/event.rb +3 -3
- data/lib/userlist/push/strategies/threaded.rb +1 -1
- data/lib/userlist/push/user.rb +2 -2
- data/lib/userlist/token.rb +66 -0
- data/lib/userlist/version.rb +1 -1
- data/lib/userlist.rb +27 -0
- data/userlist.gemspec +3 -2
- metadata +27 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8436f1e9a2b5dff59fcceedbe0ce2d334c8288ce231eb0db7da388881efb099
|
4
|
+
data.tar.gz: 882e26f3f57562b399c43ad9e47aa16f008e1593042d490ea2b1f0611239347d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3224339ad8347c83f530907f0a968b0e245d1082c4337becc9be5395437cf39ef6370195e9fcf7a0361d60c34f6acf112a28ca43a3ed202af157bcd192ed0e68
|
7
|
+
data.tar.gz: 433c0b6ee940f418f2d4de5ed6dd5cf161f1cc4f10c68a938106591e5518e8e653697cc8b625f3cee591082b528b914d937c01d331ad053cfc6ddfed90d808f5
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
2
|
+
TargetRubyVersion: 2.3
|
3
3
|
Exclude:
|
4
4
|
- 'bin/*'
|
5
5
|
- 'Guardfile'
|
6
6
|
|
7
|
-
|
7
|
+
Layout/LineLength:
|
8
8
|
Enabled: false
|
9
9
|
|
10
10
|
Metrics/ModuleLength:
|
@@ -32,13 +32,13 @@ Layout/ElseAlignment:
|
|
32
32
|
Lint/AssignmentInCondition:
|
33
33
|
Enabled: false
|
34
34
|
|
35
|
-
|
35
|
+
Layout/EndAlignment:
|
36
36
|
EnforcedStyleAlignWith: start_of_line
|
37
37
|
|
38
38
|
Layout/AccessModifierIndentation:
|
39
39
|
EnforcedStyle: outdent
|
40
40
|
|
41
|
-
Layout/
|
41
|
+
Layout/ParameterAlignment:
|
42
42
|
EnforcedStyle: with_fixed_indentation
|
43
43
|
|
44
44
|
Style/FrozenStringLiteralComment:
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/lib/userlist/config.rb
CHANGED
@@ -2,9 +2,11 @@ module Userlist
|
|
2
2
|
class Config
|
3
3
|
DEFAULT_CONFIGURATION = {
|
4
4
|
push_key: nil,
|
5
|
+
push_id: nil,
|
5
6
|
push_endpoint: 'https://push.userlist.io/',
|
6
7
|
push_strategy: :threaded,
|
7
|
-
log_level: :warn
|
8
|
+
log_level: :warn,
|
9
|
+
token_lifetime: 3600
|
8
10
|
}.freeze
|
9
11
|
|
10
12
|
def initialize(config_from_initialize = {})
|
@@ -36,6 +38,10 @@ module Userlist
|
|
36
38
|
config == other.config && parent == other.parent
|
37
39
|
end
|
38
40
|
|
41
|
+
def token_lifetime
|
42
|
+
self[:token_lifetime]&.to_i
|
43
|
+
end
|
44
|
+
|
39
45
|
protected
|
40
46
|
|
41
47
|
attr_reader :config, :parent
|
@@ -52,7 +58,7 @@ module Userlist
|
|
52
58
|
end
|
53
59
|
|
54
60
|
def key?(key)
|
55
|
-
config.key?(key) || parent
|
61
|
+
config.key?(key) || parent&.key?(key)
|
56
62
|
end
|
57
63
|
|
58
64
|
def [](key)
|
data/lib/userlist/push/client.rb
CHANGED
@@ -10,6 +10,9 @@ module Userlist
|
|
10
10
|
|
11
11
|
def initialize(config = {})
|
12
12
|
@config = Userlist.config.merge(config)
|
13
|
+
|
14
|
+
raise Userlist::ConfigurationError, :push_key unless config.push_key
|
15
|
+
raise Userlist::ConfigurationError, :push_endpoint unless config.push_endpoint
|
13
16
|
end
|
14
17
|
|
15
18
|
def get(endpoint)
|
@@ -6,8 +6,8 @@ module Userlist
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def initialize(attributes = {})
|
9
|
-
raise ArgumentError, 'Missing required attributes hash' unless attributes
|
10
|
-
raise ArgumentError, 'Missing required parameter :identifier' unless attributes[:identifier]
|
9
|
+
raise Userlist::ArgumentError, 'Missing required attributes hash' unless attributes
|
10
|
+
raise Userlist::ArgumentError, 'Missing required parameter :identifier' unless attributes[:identifier]
|
11
11
|
|
12
12
|
super
|
13
13
|
end
|
data/lib/userlist/push/event.rb
CHANGED
@@ -2,9 +2,9 @@ module Userlist
|
|
2
2
|
class Push
|
3
3
|
class Event < Resource
|
4
4
|
def initialize(attributes = {})
|
5
|
-
raise ArgumentError, 'Missing required attributes hash' unless attributes
|
6
|
-
raise ArgumentError, 'Missing required parameter :name' unless attributes[:name]
|
7
|
-
raise ArgumentError, 'Missing required parameter :user' unless attributes[:user]
|
5
|
+
raise Userlist::ArgumentError, 'Missing required attributes hash' unless attributes
|
6
|
+
raise Userlist::ArgumentError, 'Missing required parameter :name' unless attributes[:name]
|
7
|
+
raise Userlist::ArgumentError, 'Missing required parameter :user' unless attributes[:user]
|
8
8
|
|
9
9
|
attributes[:occured_at] ||= Time.now
|
10
10
|
|
data/lib/userlist/push/user.rb
CHANGED
@@ -2,8 +2,8 @@ module Userlist
|
|
2
2
|
class Push
|
3
3
|
class User < Resource
|
4
4
|
def initialize(attributes = {})
|
5
|
-
raise ArgumentError, 'Missing required attributes hash' unless attributes
|
6
|
-
raise ArgumentError, 'Missing required parameter :identifier' unless attributes[:identifier]
|
5
|
+
raise Userlist::ArgumentError, 'Missing required attributes hash' unless attributes
|
6
|
+
raise Userlist::ArgumentError, 'Missing required parameter :identifier' unless attributes[:identifier]
|
7
7
|
|
8
8
|
super
|
9
9
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Userlist
|
2
|
+
class Token
|
3
|
+
def self.generate(identifier, configuration = {})
|
4
|
+
config = Userlist.config.merge(configuration)
|
5
|
+
|
6
|
+
raise Userlist::ConfigurationError, :push_key unless config.push_key
|
7
|
+
raise Userlist::ConfigurationError, :push_id unless config.push_id
|
8
|
+
raise Userlist::ArgumentError, 'Missing required identifier' unless identifier
|
9
|
+
|
10
|
+
now = Time.now.utc.to_i
|
11
|
+
|
12
|
+
header = {
|
13
|
+
kid: config.push_id,
|
14
|
+
alg: 'HS256'
|
15
|
+
}
|
16
|
+
|
17
|
+
payload = {
|
18
|
+
sub: identifier,
|
19
|
+
exp: now + config.token_lifetime,
|
20
|
+
iat: now
|
21
|
+
}
|
22
|
+
|
23
|
+
new(payload: payload, header: header, key: config.push_key).to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(payload:, header:, key:, algorithm: 'HS256')
|
27
|
+
@payload = payload
|
28
|
+
@header = header
|
29
|
+
@algorithm = algorithm
|
30
|
+
@key = key
|
31
|
+
end
|
32
|
+
|
33
|
+
def encoded_header
|
34
|
+
encode(header)
|
35
|
+
end
|
36
|
+
|
37
|
+
def encoded_payload
|
38
|
+
encode(payload)
|
39
|
+
end
|
40
|
+
|
41
|
+
def encoded_header_and_payload
|
42
|
+
"#{encoded_header}.#{encoded_payload}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def signature
|
46
|
+
digest = OpenSSL::Digest.new(algorithm.sub('HS', 'SHA'))
|
47
|
+
signature = OpenSSL::HMAC.digest(digest, key, encoded_header_and_payload)
|
48
|
+
|
49
|
+
encode(signature)
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
"#{encoded_header_and_payload}.#{signature}"
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
attr_reader :payload, :header, :algorithm, :key
|
59
|
+
|
60
|
+
def encode(payload)
|
61
|
+
payload = JSON.generate(payload) unless payload.is_a?(String)
|
62
|
+
|
63
|
+
Base64.urlsafe_encode64(payload).tr('=', '')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/userlist/version.rb
CHANGED
data/lib/userlist.rb
CHANGED
@@ -4,8 +4,35 @@ require 'userlist/version'
|
|
4
4
|
require 'userlist/config'
|
5
5
|
require 'userlist/logging'
|
6
6
|
require 'userlist/push'
|
7
|
+
require 'userlist/token'
|
7
8
|
|
8
9
|
module Userlist
|
10
|
+
class Error < StandardError; end
|
11
|
+
class ArgumentError < Error; end
|
12
|
+
class ConfigurationError < Error
|
13
|
+
attr_reader :key
|
14
|
+
|
15
|
+
def initialize(key)
|
16
|
+
@key = key.to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
def message
|
20
|
+
<<~MESSAGE
|
21
|
+
Missing required configuration value for `#{key}`
|
22
|
+
|
23
|
+
Please set a value for `#{key}` using an environment variable:
|
24
|
+
|
25
|
+
USERLIST_#{key.to_s.upcase}=some-value-here
|
26
|
+
|
27
|
+
or via the `Userlist.configure` method:
|
28
|
+
|
29
|
+
Userlist.configure do |config|
|
30
|
+
config.#{key} = 'some-value-here'
|
31
|
+
end
|
32
|
+
MESSAGE
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
9
36
|
class << self
|
10
37
|
def config
|
11
38
|
@config ||= Userlist::Config.new
|
data/userlist.gemspec
CHANGED
@@ -19,10 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.required_ruby_version = '>= 2.
|
22
|
+
spec.required_ruby_version = '>= 2.3'
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '>= 1.15'
|
25
|
-
spec.add_development_dependency '
|
25
|
+
spec.add_development_dependency 'jwt', '~> 2.2'
|
26
|
+
spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
|
26
27
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
28
|
spec.add_development_dependency 'webmock', '~> 1.22'
|
28
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: userlist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benedikt Deicke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,20 +24,40 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jwt
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '12.3'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 12.3.3
|
34
51
|
type: :development
|
35
52
|
prerelease: false
|
36
53
|
version_requirements: !ruby/object:Gem::Requirement
|
37
54
|
requirements:
|
38
55
|
- - "~>"
|
39
56
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
57
|
+
version: '12.3'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 12.3.3
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: rspec
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,6 +122,7 @@ files:
|
|
102
122
|
- lib/userlist/push/strategies/threaded.rb
|
103
123
|
- lib/userlist/push/strategies/threaded/worker.rb
|
104
124
|
- lib/userlist/push/user.rb
|
125
|
+
- lib/userlist/token.rb
|
105
126
|
- lib/userlist/version.rb
|
106
127
|
- userlist.gemspec
|
107
128
|
homepage: http://github.com/userlistio/userlist-ruby
|
@@ -116,14 +137,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
137
|
requirements:
|
117
138
|
- - ">="
|
118
139
|
- !ruby/object:Gem::Version
|
119
|
-
version: '2.
|
140
|
+
version: '2.3'
|
120
141
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
142
|
requirements:
|
122
143
|
- - ">="
|
123
144
|
- !ruby/object:Gem::Version
|
124
145
|
version: '0'
|
125
146
|
requirements: []
|
126
|
-
rubygems_version: 3.0.
|
147
|
+
rubygems_version: 3.0.4
|
127
148
|
signing_key:
|
128
149
|
specification_version: 4
|
129
150
|
summary: Ruby wrapper for the Userlist.io API
|