netbout 0.0.1 → 0.0.2
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/README.md +8 -8
- data/lib/netbout/bout.rb +1 -1
- data/lib/netbout/http.rb +1 -1
- data/lib/netbout/inbox.rb +6 -0
- data/lib/netbout/message.rb +8 -3
- data/lib/netbout/search.rb +20 -4
- data/lib/netbout/tags.rb +10 -5
- data/lib/netbout/version.rb +1 -1
- data/test/netbout/test_bout.rb +7 -3
- data/test/netbout/test_inbox.rb +37 -0
- data/test/netbout/test_message.rb +42 -0
- data/test/netbout/test_search.rb +41 -0
- data/test/netbout/test_tags.rb +43 -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: f3f13654d9729f3b811d0e268057575967176d2d9315005cfb7940ae73a956d1
|
4
|
+
data.tar.gz: 39c4faefd925dd30c7b99bdc1fb75beaf5bc6e4033c94dee97fa604ee682deea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b056975482ddc06d936d83d20939c5468e6ecee40239ca15ef4d481703a79f79bb92ed343a1b717ad62f64a336d80e5319b0c5cd3fce80a560ac2fc050a3c33
|
7
|
+
data.tar.gz: 6c48049de759369301d8053a504de64a6621e2d5850c211cc44368eb84765a00e04fe12f7938c98abb76b0d060418beb9b3f96caa040fa5c437c7b9b9e95be41
|
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
<img src="https://github.com/yegor256/netbout/raw/master/public/logo.svg" width="132px"/>
|
2
2
|
|
3
|
-
[](http://www.rultor.com/p/yegor256/netbout)
|
3
|
+
[](http://www.rultor.com/p/yegor256/netbout.rb)
|
4
4
|
[](https://www.jetbrains.com/ruby/)
|
5
5
|
|
6
|
-
[](https://github.com/yegor256/netbout/actions/workflows/rake.yml)
|
7
|
-
[](http://www.0pdd.com/p?name=yegor256/netbout)
|
8
|
-
[](http://badge.fury.io/rb/netbout)
|
9
|
-
[](https://codecov.io/github/yegor256/netbout?branch=master)
|
10
|
-
[](http://rubydoc.info/github/yegor256/netbout/master/frames)
|
11
|
-
[](https://hitsofcode.com/view/github/yegor256/netbout)
|
12
|
-
[](https://github.com/yegor256/netbout/blob/master/LICENSE.txt)
|
6
|
+
[](https://github.com/yegor256/netbout.rb/actions/workflows/rake.yml)
|
7
|
+
[](http://www.0pdd.com/p?name=yegor256/netbout.rb)
|
8
|
+
[](http://badge.fury.io/rb/netbout.rb)
|
9
|
+
[](https://codecov.io/github/yegor256/netbout.rb?branch=master)
|
10
|
+
[](http://rubydoc.info/github/yegor256/netbout.rb/master/frames)
|
11
|
+
[](https://hitsofcode.com/view/github/yegor256/netbout.rb)
|
12
|
+
[](https://github.com/yegor256/netbout.rb/blob/master/LICENSE.txt)
|
13
13
|
|
14
14
|
This Ruby gem connects you to [Netbout](https://netbout.com).
|
15
15
|
|
data/lib/netbout/bout.rb
CHANGED
data/lib/netbout/http.rb
CHANGED
@@ -73,7 +73,7 @@ module Netbout
|
|
73
73
|
|
74
74
|
def checked(rsp)
|
75
75
|
code = rsp.response_code.to_i
|
76
|
-
raise "Invalid response #{code}: '#{rsp.headers['x-netbout-flash']}'" if code != 200 && code != 303
|
76
|
+
raise "Invalid response #{code}: '#{rsp.headers['x-netbout-flash']}'" if code != 200 && code != 303 && code != 302
|
77
77
|
rsp
|
78
78
|
end
|
79
79
|
|
data/lib/netbout/inbox.rb
CHANGED
@@ -38,6 +38,12 @@ class Netbout::Inbox
|
|
38
38
|
@iri = Iri.new('https://netbout.com')
|
39
39
|
end
|
40
40
|
|
41
|
+
def identity
|
42
|
+
rsp = Netbout::Http.new(@iri.append('/self'), @token).get
|
43
|
+
json = JSON.parse(rsp.response_body)
|
44
|
+
json['identity']
|
45
|
+
end
|
46
|
+
|
41
47
|
def search(query = '')
|
42
48
|
Netbout::Search.new(@iri, @token, query)
|
43
49
|
end
|
data/lib/netbout/message.rb
CHANGED
@@ -45,10 +45,15 @@ class Netbout::Message
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def flags
|
48
|
-
|
48
|
+
JSON.parse(Netbout::Http.new(@iri.append('/flags').append(id), @token).get.response_body)
|
49
49
|
end
|
50
50
|
|
51
|
-
def attach(flag)
|
51
|
+
def attach(flag)
|
52
|
+
Netbout::Http.new(@iri.append('/m').append(id).append('/attach'), @token)
|
53
|
+
.post('name' => flag)
|
54
|
+
end
|
52
55
|
|
53
|
-
def detach(flag)
|
56
|
+
def detach(flag)
|
57
|
+
Netbout::Http.new(@iri.append('/m').append(id).append('/detach').add(name: flag), @token).get
|
58
|
+
end
|
54
59
|
end
|
data/lib/netbout/search.rb
CHANGED
@@ -35,11 +35,27 @@ class Netbout::Search
|
|
35
35
|
@query = query
|
36
36
|
end
|
37
37
|
|
38
|
+
def to_a
|
39
|
+
array = []
|
40
|
+
each do |m|
|
41
|
+
array << m
|
42
|
+
end
|
43
|
+
array
|
44
|
+
end
|
45
|
+
|
38
46
|
def each
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
entry = @iri.append('/search').add(q: @query).add(limit: '10')
|
48
|
+
offset = 0
|
49
|
+
loop do
|
50
|
+
rsp = Netbout::Http.new(entry.over(offset: offset), @token).get
|
51
|
+
json = JSON.parse(rsp.response_body)
|
52
|
+
seen = 0
|
53
|
+
json.each do |h|
|
54
|
+
yield Netbout::Message.new(@iri, @token, h['id'])
|
55
|
+
seen += 1
|
56
|
+
end
|
57
|
+
offset += seen
|
58
|
+
break if seen.zero?
|
43
59
|
end
|
44
60
|
end
|
45
61
|
end
|
data/lib/netbout/tags.rb
CHANGED
@@ -21,20 +21,25 @@
|
|
21
21
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
22
|
# SOFTWARE.
|
23
23
|
|
24
|
+
require_relative 'http'
|
25
|
+
|
24
26
|
# Tags.
|
25
27
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
26
28
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
27
29
|
# License:: MIT
|
28
30
|
class Netbout::Tags
|
29
|
-
def initialize(iri, token,
|
31
|
+
def initialize(iri, token, id)
|
30
32
|
@iri = iri
|
31
33
|
@token = token
|
32
|
-
@
|
34
|
+
@id = id
|
33
35
|
end
|
34
36
|
|
35
|
-
def
|
36
|
-
|
37
|
+
def to_a
|
38
|
+
JSON.parse(Netbout::Http.new(@iri.append('/tags').append(@id), @token).get.response_body)
|
37
39
|
end
|
38
40
|
|
39
|
-
def put(key, value)
|
41
|
+
def put(key, value)
|
42
|
+
Netbout::Http.new(@iri.append('/b').append(@id).append('/tag'), @token)
|
43
|
+
.post('name' => key, 'value' => value)
|
44
|
+
end
|
40
45
|
end
|
data/lib/netbout/version.rb
CHANGED
data/test/netbout/test_bout.rb
CHANGED
@@ -24,16 +24,20 @@
|
|
24
24
|
require 'minitest/autorun'
|
25
25
|
require_relative '../../lib/netbout'
|
26
26
|
|
27
|
-
#
|
27
|
+
# Test of Bout.
|
28
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
29
|
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
30
30
|
# License:: MIT
|
31
31
|
class TestBout < Minitest::Test
|
32
32
|
def test_start_and_post
|
33
33
|
inbox = Netbout::Inbox.new('test')
|
34
|
-
bout = inbox.start('Hello
|
34
|
+
bout = inbox.start('Hello, друг!')
|
35
35
|
assert(bout.id.positive?)
|
36
|
-
|
36
|
+
assert(bout.title.include?('друг'))
|
37
|
+
assert_equal('?test', bout.owner)
|
38
|
+
msg = bout.post('How are you, друг?')
|
37
39
|
assert(msg.id.positive?)
|
40
|
+
assert(msg.text.include?('друг'))
|
41
|
+
assert_equal('?test', msg.author)
|
38
42
|
end
|
39
43
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2024 Yegor Bugayenko
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
require 'minitest/autorun'
|
25
|
+
require_relative '../../lib/netbout'
|
26
|
+
|
27
|
+
# Test of Inbox.
|
28
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
+
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
30
|
+
# License:: MIT
|
31
|
+
class TestInbox < Minitest::Test
|
32
|
+
def test_self_identity
|
33
|
+
inbox = Netbout::Inbox.new('test')
|
34
|
+
i = inbox.identity
|
35
|
+
assert_equal('?test', i)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2024 Yegor Bugayenko
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
require 'minitest/autorun'
|
25
|
+
require_relative '../../lib/netbout'
|
26
|
+
|
27
|
+
# Test of Message.
|
28
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
+
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
30
|
+
# License:: MIT
|
31
|
+
class TestMessage < Minitest::Test
|
32
|
+
def test_attach_flag
|
33
|
+
inbox = Netbout::Inbox.new('test')
|
34
|
+
bout = inbox.start('Hello, друг!')
|
35
|
+
msg = bout.post('oops')
|
36
|
+
tag = 'hey-you'
|
37
|
+
msg.attach(tag)
|
38
|
+
assert_equal(tag, msg.flags.first['name'])
|
39
|
+
msg.detach(tag)
|
40
|
+
assert(msg.flags.empty?)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2024 Yegor Bugayenko
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
require 'minitest/autorun'
|
25
|
+
require_relative '../../lib/netbout'
|
26
|
+
|
27
|
+
# Test of Search.
|
28
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
+
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
30
|
+
# License:: MIT
|
31
|
+
class TestSearch < Minitest::Test
|
32
|
+
def test_post_and_search
|
33
|
+
inbox = Netbout::Inbox.new('test')
|
34
|
+
found = []
|
35
|
+
inbox.search.each do |m|
|
36
|
+
found << m
|
37
|
+
break if found.size > 42
|
38
|
+
end
|
39
|
+
assert(found.size > 20)
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#
|
4
|
+
# Copyright (c) 2024 Yegor Bugayenko
|
5
|
+
#
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the 'Software'), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
|
24
|
+
require 'minitest/autorun'
|
25
|
+
require_relative '../../lib/netbout'
|
26
|
+
|
27
|
+
# Test of Tags.
|
28
|
+
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
+
# Copyright:: Copyright (c) 2024 Yegor Bugayenko
|
30
|
+
# License:: MIT
|
31
|
+
class TestTags < Minitest::Test
|
32
|
+
def test_put_and_list
|
33
|
+
inbox = Netbout::Inbox.new('test')
|
34
|
+
bout = inbox.start('Hello, друг!')
|
35
|
+
assert(bout.id.positive?)
|
36
|
+
key = 'tag1'
|
37
|
+
value = 'привет!'
|
38
|
+
bout.tags.put(key, value)
|
39
|
+
t = inbox.take(bout.id).tags.to_a.first
|
40
|
+
assert_equal(key, t['name'])
|
41
|
+
assert_equal(value, t['value'])
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netbout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: backtrace
|
@@ -128,6 +128,10 @@ files:
|
|
128
128
|
- netbout.gemspec
|
129
129
|
- renovate.json
|
130
130
|
- test/netbout/test_bout.rb
|
131
|
+
- test/netbout/test_inbox.rb
|
132
|
+
- test/netbout/test_message.rb
|
133
|
+
- test/netbout/test_search.rb
|
134
|
+
- test/netbout/test_tags.rb
|
131
135
|
- test/test__helper.rb
|
132
136
|
- test/test_netbout.rb
|
133
137
|
homepage: http://github.com/yegor256/netbout.rb
|