userlist 0.2.2 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,37 @@
1
+ require 'sidekiq'
2
+
3
+ require 'userlist/push/strategies/sidekiq/worker'
4
+
5
+ module Userlist
6
+ class Push
7
+ module Strategies
8
+ class Sidekiq
9
+ def initialize(config = {})
10
+ @config = Userlist.config.merge(config)
11
+ end
12
+
13
+ def call(*args)
14
+ ::Sidekiq::Client.push(default_options.merge(options).merge('args' => args))
15
+ end
16
+
17
+ private
18
+
19
+ attr_reader :config
20
+
21
+ def options
22
+ @options ||= begin
23
+ options = config.push_strategy_options || {}
24
+ options.each_with_object({}) { |(k, v), h| h[k.to_s] = v }
25
+ end
26
+ end
27
+
28
+ def default_options
29
+ {
30
+ 'class' => 'Userlist::Push::Strategies::Sidekiq::Worker',
31
+ 'queue' => 'default'
32
+ }
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ require 'sidekiq'
2
+
3
+ module Userlist
4
+ class Push
5
+ module Strategies
6
+ class Sidekiq
7
+ class Worker
8
+ include ::Sidekiq::Worker
9
+
10
+ def perform(method, *args)
11
+ client = Userlist::Push::Client.new
12
+ client.public_send(method, *args)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -20,7 +20,7 @@ module Userlist
20
20
  attr_reader :queue, :worker
21
21
 
22
22
  def stop_worker
23
- worker && worker.stop
23
+ worker&.stop
24
24
  end
25
25
  end
26
26
  end
@@ -19,12 +19,12 @@ module Userlist
19
19
 
20
20
  loop do
21
21
  begin
22
- method, url, payload = *queue.pop
22
+ method, *args = *queue.pop
23
23
  break if method == :stop
24
24
 
25
- client.public_send(method, url, payload)
26
- rescue StandardError => exception
27
- logger.error "Failed to deliver payload: [#{exception.class.name}] #{exception.message}"
25
+ client.public_send(method, *args)
26
+ rescue StandardError => e
27
+ logger.error "Failed to deliver payload: [#{e.class.name}] #{e.message}"
28
28
  end
29
29
  end
30
30
 
@@ -0,0 +1,19 @@
1
+ module Userlist
2
+ class Push
3
+ class User < Resource
4
+ include Operations::Create
5
+ include Operations::Delete
6
+
7
+ has_many :relationships, type: 'Userlist::Push::Relationship', inverse: :user
8
+ has_many :companies, type: 'Userlist::Push::Company'
9
+ has_one :company, type: 'Userlist::Push::Company'
10
+
11
+ def initialize(payload = {}, config = Userlist.config)
12
+ raise Userlist::ArgumentError, 'Missing required payload' unless payload
13
+ raise Userlist::ArgumentError, 'Missing required parameter :identifier' unless payload[:identifier]
14
+
15
+ super
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,68 @@
1
+ module Userlist
2
+ class Token
3
+ def self.generate(user, 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 user or identifier' unless user
9
+
10
+ user = Userlist::Push::User.from_payload(user, config)
11
+
12
+ now = Time.now.utc.to_i
13
+
14
+ header = {
15
+ kid: config.push_id,
16
+ alg: 'HS256'
17
+ }
18
+
19
+ payload = {
20
+ sub: user.identifier,
21
+ exp: now + config.token_lifetime,
22
+ iat: now
23
+ }
24
+
25
+ new(payload: payload, header: header, key: config.push_key).to_s
26
+ end
27
+
28
+ def initialize(payload:, header:, key:, algorithm: 'HS256')
29
+ @payload = payload
30
+ @header = header
31
+ @algorithm = algorithm
32
+ @key = key
33
+ end
34
+
35
+ def encoded_header
36
+ encode(header)
37
+ end
38
+
39
+ def encoded_payload
40
+ encode(payload)
41
+ end
42
+
43
+ def encoded_header_and_payload
44
+ "#{encoded_header}.#{encoded_payload}"
45
+ end
46
+
47
+ def signature
48
+ digest = OpenSSL::Digest.new(algorithm.sub('HS', 'SHA'))
49
+ signature = OpenSSL::HMAC.digest(digest, key, encoded_header_and_payload)
50
+
51
+ encode(signature)
52
+ end
53
+
54
+ def to_s
55
+ "#{encoded_header_and_payload}.#{signature}"
56
+ end
57
+
58
+ private
59
+
60
+ attr_reader :payload, :header, :algorithm, :key
61
+
62
+ def encode(payload)
63
+ payload = JSON.generate(payload) unless payload.is_a?(String)
64
+
65
+ Base64.urlsafe_encode64(payload).tr('=', '')
66
+ end
67
+ end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module Userlist
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
data/userlist.gemspec CHANGED
@@ -6,9 +6,9 @@ Gem::Specification.new do |spec|
6
6
  spec.name = 'userlist'
7
7
  spec.version = Userlist::VERSION
8
8
  spec.authors = ['Benedikt Deicke']
9
- spec.email = ['benedikt@userlist.io']
9
+ spec.email = ['benedikt@userlist.com']
10
10
 
11
- spec.summary = 'Ruby wrapper for the Userlist.io API'
11
+ spec.summary = 'Ruby wrapper for the Userlist API'
12
12
  spec.homepage = 'http://github.com/userlistio/userlist-ruby'
13
13
  spec.license = 'MIT'
14
14
 
@@ -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.2'
22
+ spec.required_ruby_version = '>= 2.4'
23
23
 
24
- spec.add_development_dependency 'bundler', '~> 1.15'
25
- spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'bundler', '>= 1.15'
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,43 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: userlist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benedikt Deicke
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2021-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.15'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
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: '10.0'
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: '10.0'
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
@@ -66,17 +86,17 @@ dependencies:
66
86
  - - "~>"
67
87
  - !ruby/object:Gem::Version
68
88
  version: '1.22'
69
- description:
89
+ description:
70
90
  email:
71
- - benedikt@userlist.io
91
+ - benedikt@userlist.com
72
92
  executables: []
73
93
  extensions: []
74
94
  extra_rdoc_files: []
75
95
  files:
96
+ - ".github/workflows/test.yml"
76
97
  - ".gitignore"
77
98
  - ".rspec"
78
99
  - ".rubocop.yml"
79
- - ".travis.yml"
80
100
  - CODE_OF_CONDUCT.md
81
101
  - Gemfile
82
102
  - Guardfile
@@ -90,18 +110,31 @@ files:
90
110
  - lib/userlist/logging.rb
91
111
  - lib/userlist/push.rb
92
112
  - lib/userlist/push/client.rb
113
+ - lib/userlist/push/company.rb
114
+ - lib/userlist/push/event.rb
115
+ - lib/userlist/push/operations/create.rb
116
+ - lib/userlist/push/operations/delete.rb
117
+ - lib/userlist/push/relation.rb
118
+ - lib/userlist/push/relationship.rb
119
+ - lib/userlist/push/resource.rb
120
+ - lib/userlist/push/resource_collection.rb
121
+ - lib/userlist/push/serializer.rb
93
122
  - lib/userlist/push/strategies.rb
94
123
  - lib/userlist/push/strategies/direct.rb
95
124
  - lib/userlist/push/strategies/null.rb
125
+ - lib/userlist/push/strategies/sidekiq.rb
126
+ - lib/userlist/push/strategies/sidekiq/worker.rb
96
127
  - lib/userlist/push/strategies/threaded.rb
97
128
  - lib/userlist/push/strategies/threaded/worker.rb
129
+ - lib/userlist/push/user.rb
130
+ - lib/userlist/token.rb
98
131
  - lib/userlist/version.rb
99
132
  - userlist.gemspec
100
133
  homepage: http://github.com/userlistio/userlist-ruby
101
134
  licenses:
102
135
  - MIT
103
136
  metadata: {}
104
- post_install_message:
137
+ post_install_message:
105
138
  rdoc_options: []
106
139
  require_paths:
107
140
  - lib
@@ -109,16 +142,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
142
  requirements:
110
143
  - - ">="
111
144
  - !ruby/object:Gem::Version
112
- version: '2.2'
145
+ version: '2.4'
113
146
  required_rubygems_version: !ruby/object:Gem::Requirement
114
147
  requirements:
115
148
  - - ">="
116
149
  - !ruby/object:Gem::Version
117
150
  version: '0'
118
151
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.4.5.2
121
- signing_key:
152
+ rubygems_version: 3.1.4
153
+ signing_key:
122
154
  specification_version: 4
123
- summary: Ruby wrapper for the Userlist.io API
155
+ summary: Ruby wrapper for the Userlist API
124
156
  test_files: []
data/.travis.yml DELETED
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.1
5
- before_install: gem install bundler -v 1.15.4