httpstate 0.1.0 → 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.
- checksums.yaml +4 -4
- data/Rakefile +4 -0
- data/httpstate-0.1.0.gem +0 -0
- data/httpstate.gemspec +39 -0
- data/lib/httpstate.rb +87 -6
- data/sig/httpstate.rbs +4 -0
- metadata +6 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 38ea401ab24e65e990b89f68e464d63868847f99cf5a7132111fafa1d79765ff
|
|
4
|
+
data.tar.gz: c0d0002bbffd929f4c25cd9a0d6c3c9e47e50a2240e540e9ec84b57133ace69d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: df4c662f2914108f62d84f532e5d0f17aa1e22c0770aa25ebfffde2256c988ac6e716a56787768d9ae7a79e99a816d659c5d22e2610238e3e7e6f6e823fbb1a4
|
|
7
|
+
data.tar.gz: 024fe310ad88acb6e51b239fbe2403de5ebc1c8d0c63e16eb5c001eed4d059f0ff7857ded082aab8a04d4c383a164018721c71549b3d77d039eebdb43149edc2
|
data/Rakefile
ADDED
data/httpstate-0.1.0.gem
ADDED
|
Binary file
|
data/httpstate.gemspec
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/httpstate"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.authors = ["HTTP State"]
|
|
7
|
+
spec.description = "HTTP State, httpstate.com"
|
|
8
|
+
spec.email = ["inbox@httpstate.com"]
|
|
9
|
+
spec.homepage = "https://httpstate.com"
|
|
10
|
+
spec.license = "AGPL-3.0"
|
|
11
|
+
spec.name = "httpstate"
|
|
12
|
+
spec.required_ruby_version = ">= 2.6.0"
|
|
13
|
+
spec.summary = "HTTP State, httpstate.com"
|
|
14
|
+
spec.version = HttpState::VERSION
|
|
15
|
+
|
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
17
|
+
spec.metadata["changelog_uri"] = "https://github.com/httpstate/httpstate"
|
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
19
|
+
spec.metadata["license_uri"] = "https://www.gnu.org/licenses/agpl-3.0.txt"
|
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/httpstate/httpstate"
|
|
21
|
+
|
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
24
|
+
spec.files = Dir.chdir(__dir__) do
|
|
25
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
26
|
+
(File.expand_path(f) == __FILE__) ||
|
|
27
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
spec.bindir = "exe"
|
|
31
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
32
|
+
spec.require_paths = ["lib"]
|
|
33
|
+
|
|
34
|
+
# Uncomment to register a new dependency of your gem
|
|
35
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
|
36
|
+
|
|
37
|
+
# For more information and examples about making a new gem, check out our
|
|
38
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
39
|
+
end
|
data/lib/httpstate.rb
CHANGED
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
# frozen_string_literal: true
|
|
10
10
|
|
|
11
|
-
require_relative "httpstate/version"
|
|
12
|
-
|
|
13
11
|
require 'eventmachine'
|
|
14
12
|
require 'faye/websocket'
|
|
15
13
|
require 'json'
|
|
@@ -18,7 +16,7 @@ require 'socket'
|
|
|
18
16
|
require 'uri'
|
|
19
17
|
|
|
20
18
|
class HttpState
|
|
21
|
-
VERSION = '0.
|
|
19
|
+
VERSION = '0.1.1'
|
|
22
20
|
|
|
23
21
|
attr_reader :data, :uuid, :ws
|
|
24
22
|
|
|
@@ -32,6 +30,34 @@ class HttpState
|
|
|
32
30
|
nil
|
|
33
31
|
end
|
|
34
32
|
|
|
33
|
+
class Message
|
|
34
|
+
class MessageType
|
|
35
|
+
attr_accessor :uuid, :timestamp, :type, :value
|
|
36
|
+
|
|
37
|
+
def initialize(uuid, timestamp, type, value)
|
|
38
|
+
@uuid = uuid
|
|
39
|
+
@timestamp = timestamp
|
|
40
|
+
@type = type
|
|
41
|
+
@value = value
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.unpack(b)
|
|
46
|
+
length = b.getbyte(0)
|
|
47
|
+
|
|
48
|
+
MessageType.new(
|
|
49
|
+
b.byteslice(1, length).force_encoding("UTF-8"),
|
|
50
|
+
b.byteslice(1+length, 8).unpack1("Q>"),
|
|
51
|
+
b.getbyte(1+length+8),
|
|
52
|
+
b.byteslice(1+length+9, b.bytesize-(1+length+9))
|
|
53
|
+
)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.message
|
|
58
|
+
Message
|
|
59
|
+
end
|
|
60
|
+
|
|
35
61
|
def self.set(uuid, data)
|
|
36
62
|
uri = URI.join('https://httpstate.com', uuid)
|
|
37
63
|
|
|
@@ -52,12 +78,16 @@ class HttpState
|
|
|
52
78
|
|
|
53
79
|
class << self
|
|
54
80
|
alias read get
|
|
81
|
+
alias post set
|
|
82
|
+
alias put set
|
|
55
83
|
alias write set
|
|
56
84
|
end
|
|
57
85
|
|
|
58
86
|
def initialize(uuid)
|
|
59
87
|
@data = nil
|
|
88
|
+
@et = nil
|
|
60
89
|
@uuid = uuid
|
|
90
|
+
@ws = nil
|
|
61
91
|
|
|
62
92
|
Thread.new do
|
|
63
93
|
EM.run do
|
|
@@ -72,13 +102,21 @@ class HttpState
|
|
|
72
102
|
end
|
|
73
103
|
|
|
74
104
|
@ws.on :message do |event|
|
|
75
|
-
|
|
105
|
+
data = self.class.message.unpack(event.data)
|
|
106
|
+
|
|
107
|
+
if data &&
|
|
108
|
+
data.uuid == @uuid &&
|
|
109
|
+
data.type == 1
|
|
110
|
+
@data = data.value
|
|
111
|
+
|
|
112
|
+
emit('change', @data)
|
|
113
|
+
end
|
|
76
114
|
end
|
|
77
115
|
|
|
78
116
|
@ws.on :open do |_|
|
|
79
117
|
puts '@ws.open'
|
|
80
118
|
|
|
81
|
-
@ws.send({ open
|
|
119
|
+
@ws.send({ open:@uuid }.to_json)
|
|
82
120
|
end
|
|
83
121
|
end
|
|
84
122
|
|
|
@@ -86,19 +124,62 @@ class HttpState
|
|
|
86
124
|
end
|
|
87
125
|
end
|
|
88
126
|
|
|
127
|
+
def emit(type, data = nil)
|
|
128
|
+
if @et && @et[type]
|
|
129
|
+
for callback in @et[type]
|
|
130
|
+
if data.nil?
|
|
131
|
+
callback.call
|
|
132
|
+
else
|
|
133
|
+
callback.call(data)
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
self
|
|
139
|
+
end
|
|
140
|
+
|
|
89
141
|
def get
|
|
90
142
|
if @uuid
|
|
91
143
|
data = self.class.get(@uuid)
|
|
92
144
|
|
|
93
145
|
if(data != @data)
|
|
94
|
-
|
|
146
|
+
# emit change
|
|
95
147
|
end
|
|
148
|
+
|
|
149
|
+
@data = data
|
|
96
150
|
|
|
97
151
|
return @data
|
|
98
152
|
end
|
|
99
153
|
end
|
|
100
154
|
|
|
155
|
+
def off(type, &callback)
|
|
156
|
+
if @et && @et[type]
|
|
157
|
+
if callback
|
|
158
|
+
@et[type].delete(callback)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
if !callback || @et[type].empty?
|
|
162
|
+
@et.delete(type)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
self
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def on(type, &callback)
|
|
170
|
+
@et ||= {}
|
|
171
|
+
@et[type] ||= []
|
|
172
|
+
@et[type] << callback
|
|
173
|
+
|
|
174
|
+
self
|
|
175
|
+
end
|
|
176
|
+
|
|
101
177
|
def set(data)
|
|
102
178
|
self.class.set(@uuid, data) if @uuid
|
|
103
179
|
end
|
|
180
|
+
|
|
181
|
+
alias read get
|
|
182
|
+
alias post set
|
|
183
|
+
alias put set
|
|
184
|
+
alias write set
|
|
104
185
|
end
|
data/sig/httpstate.rbs
ADDED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: httpstate
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- HTTP State
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-04-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: HTTP State, httpstate.com
|
|
14
14
|
email:
|
|
@@ -18,7 +18,11 @@ extensions: []
|
|
|
18
18
|
extra_rdoc_files: []
|
|
19
19
|
files:
|
|
20
20
|
- LICENSE
|
|
21
|
+
- Rakefile
|
|
22
|
+
- httpstate-0.1.0.gem
|
|
23
|
+
- httpstate.gemspec
|
|
21
24
|
- lib/httpstate.rb
|
|
25
|
+
- sig/httpstate.rbs
|
|
22
26
|
homepage: https://httpstate.com
|
|
23
27
|
licenses:
|
|
24
28
|
- AGPL-3.0
|