Class: Netbout::Bout

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

Overview

Bout.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(iri, token, json) ⇒ Bout

Returns a new instance of Bout.



33
34
35
36
37
# File 'lib/netbout/bout.rb', line 33

def initialize(iri, token, json)
  @iri = iri
  @token = token
  @json = json
end

Instance Method Details

#idObject



39
40
41
# File 'lib/netbout/bout.rb', line 39

def id
  @json['id']
end

#ownerObject



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

def owner
  @json['owner']
end

#post(text) ⇒ Object



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

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

#tagsObject



62
63
64
# File 'lib/netbout/bout.rb', line 62

def tags
  Netbout::Tags.new(@iri, @token, id)
end

#take(id) ⇒ Object



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

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

#titleObject



43
44
45
# File 'lib/netbout/bout.rb', line 43

def title
  @json['title']
end