Skip to content

Commit

Permalink
#5 search fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jan 31, 2024
1 parent 575025f commit cece206
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 8 additions & 3 deletions lib/netbout/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,26 @@ def initialize(iri, token, query)
@query = query
end

def to_a
array = []
each do |m|
array << m
end
array
end

def each
entry = @iri.append('/search').add(q: @query).add(limit: '10')
offset = 0
loop do
rsp = Netbout::Http.new(entry.over(offset: offset), @token).get
p entry.over(offset: offset).to_s
json = JSON.parse(rsp.response_body)
seen = 0
json.each do |h|
yield Netbout::Message.new(@iri, @token, h['id'])
p h
seen += 1
end
offset += seen
p offset
break if seen.zero?
end
end
Expand Down
5 changes: 2 additions & 3 deletions test/netbout/test_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@
class TestSearch < Minitest::Test
def test_post_and_search
inbox = Netbout::Inbox.new('test')
bout = inbox.start('Hello, друг!')
msg = bout.post('How are you, друг?')
found = []
inbox.search.each do |m|
found << m
break if found.size > 42
end
assert_equal(1, found.size)
assert(found.size > 20)
end
end

0 comments on commit cece206

Please sign in to comment.