Class: Urbit::Message
- Inherits:
-
Object
show all
- Defined in:
- lib/urbit/message.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(channel:, app: nil, mark: nil, contents: nil) ⇒ 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
Returns the value of attribute app.
6
7
8
|
# File 'lib/urbit/message.rb', line 6
def app
@app
end
|
#channel ⇒ Object
Returns the value of attribute channel.
6
7
8
|
# File 'lib/urbit/message.rb', line 6
def channel
@channel
end
|
#contents ⇒ Object
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
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.['Cookie'] = self.ship.cookie
req.['Content-Type'] = 'application/json'
req.body = request_body
end
response
end
|