Class: Urbit::Message
- Inherits:
-
Object
- Object
- Urbit::Message
- Defined in:
- lib/urbit/message.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#id ⇒ Object
Returns the value of attribute id.
-
#mark ⇒ Object
readonly
Returns the value of attribute mark.
Instance Method Summary collapse
-
#action ⇒ Object
The value for “action” that the inbound API expects for this message type.
- #channel_url ⇒ Object
-
#initialize(channel:, app: nil, mark: nil, contents: nil) ⇒ Message
constructor
A new instance of Message.
- #request_body ⇒ Object
- #ship ⇒ Object
- #to_a ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #transmit ⇒ Object
Constructor Details
#initialize(channel:, app: nil, mark: nil, contents: nil) ⇒ Message
Returns a new instance of Message.
8 9 10 11 12 13 14 |
# File 'lib/urbit/message.rb', line 8 def initialize(channel:, app: nil, mark: nil, contents: nil) @app = app @channel = channel @contents = contents @id = 0 @mark = mark end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
6 7 8 |
# File 'lib/urbit/message.rb', line 6 def app @app end |
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
6 7 8 |
# File 'lib/urbit/message.rb', line 6 def channel @channel end |
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
6 7 8 |
# File 'lib/urbit/message.rb', line 6 def contents @contents end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/urbit/message.rb', line 5 def id @id end |
#mark ⇒ Object (readonly)
Returns the value of attribute mark.
6 7 8 |
# File 'lib/urbit/message.rb', line 6 def mark @mark end |
Instance Method Details
#action ⇒ Object
The value for “action” that the inbound API expects for this message type. defaults to “poke” for historical reasons, but each subclass should override appropriately.
20 21 22 |
# File 'lib/urbit/message.rb', line 20 def action "poke" end |
#channel_url ⇒ Object
24 25 26 |
# File 'lib/urbit/message.rb', line 24 def channel_url "#{self.ship.url}/~/channel/#{self.channel.key}" end |
#request_body ⇒ Object
28 29 30 |
# File 'lib/urbit/message.rb', line 28 def request_body JSON.generate(self.to_a) end |
#ship ⇒ Object
32 33 34 |
# File 'lib/urbit/message.rb', line 32 def ship self.channel.ship end |
#to_a ⇒ Object
36 37 38 |
# File 'lib/urbit/message.rb', line 36 def to_a [self.to_h] end |
#to_h ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/urbit/message.rb', line 40 def to_h { action: self.action, app: app, id: id, json: contents, mark: mark, ship: ship.untilded_name } end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/urbit/message.rb', line 51 def to_s "a Message(#{self.to_h})" end |
#transmit ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/urbit/message.rb', line 55 def transmit response = Faraday.put(channel_url) do |req| req.headers['Cookie'] = self.ship. req.headers['Content-Type'] = 'application/json' req.body = request_body end # TODO: handle_error if response.status != 204 response end |