Class: Netbout::Message

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

Overview

Message.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(iri, token, json) ⇒ Message

Returns a new instance of Message.



29
30
31
32
33
# File 'lib/netbout/message.rb', line 29

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

Instance Method Details

#attach(flag) ⇒ Object



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

def attach(flag)
  Netbout::Http.new(@iri.append('/m').append(id).append('/attach'), @token)
    .post('name' => flag)
end

#authorObject



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

def author
  @json['author']
end

#detach(flag) ⇒ Object



56
57
58
# File 'lib/netbout/message.rb', line 56

def detach(flag)
  Netbout::Http.new(@iri.append('/m').append(id).append('/detach').add(name: flag), @token).get
end

#flagsObject



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

def flags
  JSON.parse(Netbout::Http.new(@iri.append('/flags').append(id), @token).get.response_body)
end

#idObject



35
36
37
# File 'lib/netbout/message.rb', line 35

def id
  @json['id'].to_i
end

#textObject



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

def text
  @json['text']
end