blackevin 0.1.1

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.
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blackevin
4
+ # A stored message, as +channel.history+ returns it.
5
+ Message = Struct.new(:channel, :name, :data, :connection_id, :timestamp, keyword_init: true) do
6
+ def self.from_h(hash)
7
+ new(
8
+ channel: hash['channel'],
9
+ name: hash['name'],
10
+ data: hash['data'],
11
+ connection_id: hash['connectionId'],
12
+ timestamp: hash['timestamp']
13
+ )
14
+ end
15
+
16
+ # @return [Time, nil]
17
+ def time = timestamp&.then { Time.at(_1 / 1000.0) }
18
+ end
19
+
20
+ # Someone present on a channel right now.
21
+ PresenceMember = Struct.new(:client_id, :connection_id, :data, :updated_at, keyword_init: true) do
22
+ def self.from_h(hash)
23
+ new(
24
+ client_id: hash['clientId'],
25
+ connection_id: hash['connectionId'],
26
+ data: hash['data'],
27
+ updated_at: hash['updatedAt']
28
+ )
29
+ end
30
+ end
31
+
32
+ # A past enter, leave or update.
33
+ PresenceEvent = Struct.new(:channel, :action, :client_id, :connection_id, :data, :timestamp, keyword_init: true) do
34
+ def self.from_h(hash)
35
+ new(
36
+ channel: hash['channel'],
37
+ action: hash['action'],
38
+ client_id: hash['clientId'],
39
+ connection_id: hash['connectionId'],
40
+ data: hash['data'],
41
+ timestamp: hash['timestamp']
42
+ )
43
+ end
44
+
45
+ # @return [Time, nil]
46
+ def time = timestamp&.then { Time.at(_1 / 1000.0) }
47
+ end
48
+
49
+ # An account queue. Addressed by {#id} everywhere; {#name} is immutable and
50
+ # is what a worker consumes from on the broker.
51
+ Queue = Struct.new(:id, :account_id, :name, :max_length, :enabled, keyword_init: true) do
52
+ def self.from_h(hash)
53
+ new(
54
+ id: hash['id'],
55
+ account_id: hash['accountId'],
56
+ name: hash['name'],
57
+ max_length: hash['maxLength'],
58
+ enabled: hash['enabled']
59
+ )
60
+ end
61
+
62
+ def enabled? = enabled == true
63
+ end
64
+
65
+ # Copies messages from channels matching {#source_pattern} into a queue.
66
+ QueueRule = Struct.new(:id, :account_id, :queue_name, :source_pattern, :filter, :enabled, keyword_init: true) do
67
+ def self.from_h(hash)
68
+ new(
69
+ id: hash['id'],
70
+ account_id: hash['accountId'],
71
+ queue_name: hash['queueName'],
72
+ source_pattern: hash['sourcePattern'],
73
+ filter: hash['filter'],
74
+ enabled: hash['enabled']
75
+ )
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Blackevin
4
+ VERSION = '0.1.1'
5
+ end
data/lib/blackevin.rb ADDED
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'blackevin/version'
4
+ require_relative 'blackevin/errors'
5
+ require_relative 'blackevin/api_key'
6
+ require_relative 'blackevin/endpoints'
7
+ require_relative 'blackevin/token_request'
8
+ require_relative 'blackevin/token_details'
9
+ require_relative 'blackevin/types'
10
+ require_relative 'blackevin/transport'
11
+ require_relative 'blackevin/configuration'
12
+ require_relative 'blackevin/rest'
13
+ require_relative 'blackevin/rest/auth'
14
+ require_relative 'blackevin/rest/channels'
15
+ require_relative 'blackevin/rest/clients'
16
+ require_relative 'blackevin/rest/queues'
17
+ require_relative 'blackevin/token_endpoint'
18
+
19
+ # Server-side SDK for Blackevin: sign token requests, publish, read history and
20
+ # presence, manage queues. Standard library only.
21
+ #
22
+ # Blackevin.configure { |config| config.key = ENV.fetch("BLACKEVIN_KEY") }
23
+ #
24
+ # Blackevin.rest.channels.get("room:42").publish("greeting", {text: "hi"})
25
+ module Blackevin
26
+ @mutex = Mutex.new
27
+
28
+ class << self
29
+ # @return [Blackevin::Configuration]
30
+ def configuration
31
+ @mutex.synchronize { @configuration ||= Configuration.new }
32
+ end
33
+
34
+ # @yieldparam config [Blackevin::Configuration]
35
+ # @return [Blackevin::Configuration]
36
+ def configure
37
+ yield configuration
38
+
39
+ @mutex.synchronize { @rest = nil }
40
+
41
+ configuration
42
+ end
43
+
44
+ # The process-wide client, built from {configuration} on first use.
45
+ #
46
+ # @return [Blackevin::Rest]
47
+ def rest
48
+ options = configuration.to_rest_options
49
+
50
+ @mutex.synchronize { @rest ||= Rest.new(**options) }
51
+ end
52
+
53
+ # Forgets the configuration and the client. For test suites.
54
+ def reset!
55
+ @mutex.synchronize do
56
+ @configuration = nil
57
+ @rest = nil
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ require_relative 'blackevin/railtie' if defined?(Rails::Railtie)
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blackevin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Blackevin
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rake
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '13.0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '13.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '3.13'
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '4.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '3.13'
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: '4.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: standard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '1.0'
53
+ type: :development
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '1.0'
60
+ - !ruby/object:Gem::Dependency
61
+ name: railties
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '7.0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '7.0'
74
+ description: 'Sign token requests, publish, read history and presence, and manage
75
+ queues on Blackevin. Standard library only: no runtime dependencies. Ruby 3.0 and
76
+ up. Works in Rails, Sinatra, Hanami or plain Ruby.'
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - CHANGELOG.md
82
+ - LICENSE
83
+ - README.md
84
+ - blackevin.gemspec
85
+ - lib/blackevin.rb
86
+ - lib/blackevin/api_key.rb
87
+ - lib/blackevin/configuration.rb
88
+ - lib/blackevin/endpoints.rb
89
+ - lib/blackevin/errors.rb
90
+ - lib/blackevin/railtie.rb
91
+ - lib/blackevin/rest.rb
92
+ - lib/blackevin/rest/auth.rb
93
+ - lib/blackevin/rest/channels.rb
94
+ - lib/blackevin/rest/clients.rb
95
+ - lib/blackevin/rest/queues.rb
96
+ - lib/blackevin/token_details.rb
97
+ - lib/blackevin/token_endpoint.rb
98
+ - lib/blackevin/token_request.rb
99
+ - lib/blackevin/transport.rb
100
+ - lib/blackevin/types.rb
101
+ - lib/blackevin/version.rb
102
+ homepage: https://blackevin.com
103
+ licenses:
104
+ - MIT
105
+ metadata:
106
+ rubygems_mfa_required: 'true'
107
+ documentation_uri: https://docs.blackevin.com
108
+ source_code_uri: https://github.com/thadeu/blackevin-ruby
109
+ changelog_uri: https://github.com/thadeu/blackevin-ruby/blob/main/CHANGELOG.md
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.6.9
125
+ specification_version: 4
126
+ summary: Blackevin Ruby SDK
127
+ test_files: []