Class: Netbout::Inbox

Inherits:
Object
  • Object
show all
Defined in:
lib/netbout/inbox.rb

Overview

Inbox.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Inbox

Returns a new instance of Inbox.



35
36
37
38
39
# File 'lib/netbout/inbox.rb', line 35

def initialize(token)
  require_relative 'http'
  @token = token
  @iri = Iri.new('https://netbout.com')
end

Instance Method Details

#identityObject



41
42
43
44
45
# File 'lib/netbout/inbox.rb', line 41

def identity
  rsp = Netbout::Http.new(@iri.append('/self'), @token).get
  json = JSON.parse(rsp.response_body)
  json['identity']
end

#search(query = '') ⇒ Object



47
48
49
# File 'lib/netbout/inbox.rb', line 47

def search(query = '')
  Netbout::Search.new(@iri, @token, query)
end

#start(title) ⇒ Object



51
52
53
54
55
# File 'lib/netbout/inbox.rb', line 51

def start(title)
  rsp = Netbout::Http.new(@iri.append('/start'), @token).post('title' => title)
  id = rsp.headers['X-Netbout-Bout'].to_i
  take(id)
end

#take(id) ⇒ Object



57
58
59
60
# File 'lib/netbout/inbox.rb', line 57

def take(id)
  rsp = Netbout::Http.new(@iri.append('/bout').append(id), @token).get
  Netbout::Bout.new(@iri, @token, JSON.parse(rsp.response_body))
end