netbout 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0609a1212f6f2413d82f2883a236429d21b9d293b8959a8662323ec3fc8f03dd'
4
- data.tar.gz: 2a714d3a6e2bb2b09adf7c2e341e882330a03314bdb9db96d772082aa0eb5517
3
+ metadata.gz: f3f13654d9729f3b811d0e268057575967176d2d9315005cfb7940ae73a956d1
4
+ data.tar.gz: 39c4faefd925dd30c7b99bdc1fb75beaf5bc6e4033c94dee97fa604ee682deea
5
5
  SHA512:
6
- metadata.gz: 0e8d57eba1b82394e14bae90fd932b8c9880a8cbf75babeae84b114436c425e645d4ba1d751360269f1a6be2a7756458ac15020217acd02dc5324e4fca5404d8
7
- data.tar.gz: e938723b00fe40245d66f647854c94d1bea9148c5d7843de09508bcd0e5f1e1d43ec2141c08c65f44b7c14349f030db90bccab76d62111d0af9bab73650b392d
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
- [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/netbout)](http://www.rultor.com/p/yegor256/netbout)
3
+ [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/netbout.rb)](http://www.rultor.com/p/yegor256/netbout.rb)
4
4
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
5
5
 
6
- [![rake](https://github.com/yegor256/netbout/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/netbout/actions/workflows/rake.yml)
7
- [![PDD status](http://www.0pdd.com/svg?name=yegor256/netbout)](http://www.0pdd.com/p?name=yegor256/netbout)
8
- [![Gem Version](https://badge.fury.io/rb/netbout.svg)](http://badge.fury.io/rb/netbout)
9
- [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/netbout.svg)](https://codecov.io/github/yegor256/netbout?branch=master)
10
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/netbout/master/frames)
11
- [![Hits-of-Code](https://hitsofcode.com/github/yegor256/netbout)](https://hitsofcode.com/view/github/yegor256/netbout)
12
- [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/netbout/blob/master/LICENSE.txt)
6
+ [![rake](https://github.com/yegor256/netbout.rb/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/netbout.rb/actions/workflows/rake.yml)
7
+ [![PDD status](http://www.0pdd.com/svg?name=yegor256/netbout.rb)](http://www.0pdd.com/p?name=yegor256/netbout.rb)
8
+ [![Gem Version](https://badge.fury.io/rb/netbout.rb.svg)](http://badge.fury.io/rb/netbout.rb)
9
+ [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/netbout.rb.svg)](https://codecov.io/github/yegor256/netbout.rb?branch=master)
10
+ [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/netbout.rb/master/frames)
11
+ [![Hits-of-Code](https://hitsofcode.com/github/yegor256/netbout.rb)](https://hitsofcode.com/view/github/yegor256/netbout.rb)
12
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](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
@@ -60,6 +60,6 @@ class Netbout::Bout
60
60
  end
61
61
 
62
62
  def tags
63
- Netbout::Tags.new(@token, self)
63
+ Netbout::Tags.new(@iri, @token, id)
64
64
  end
65
65
  end
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
@@ -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); end
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); end
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
@@ -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
- rsp = Netbout::Http.new(@iri.append('/search').add(q: @query), @token).get
40
- json = JSON.parse(rsp.response_body)
41
- json.each do |h|
42
- yield Netbout::Message.new(@iri, token, h['id'])
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, bout)
31
+ def initialize(iri, token, id)
30
32
  @iri = iri
31
33
  @token = token
32
- @bout = bout
34
+ @id = id
33
35
  end
34
36
 
35
- def each
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); end
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
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2024 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module Netbout
29
- VERSION = '0.0.1'
29
+ VERSION = '0.0.2'
30
30
  end
@@ -24,16 +24,20 @@
24
24
  require 'minitest/autorun'
25
25
  require_relative '../../lib/netbout'
26
26
 
27
- # Netbout main module test.
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
- msg = bout.post('How are you?')
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.1
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-30 00:00:00.000000000 Z
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