Class: WaseEndpoint::Message
- Inherits:
-
Object
- Object
- WaseEndpoint::Message
- Defined in:
- lib/wase_endpoint/message.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#input_uri ⇒ Object
readonly
Returns the value of attribute input_uri.
-
#input_uri_1 ⇒ Object
readonly
Returns the value of attribute input_uri_1.
-
#output_uri ⇒ Object
readonly
Returns the value of attribute output_uri.
-
#program_counter ⇒ Object
readonly
Returns the value of attribute program_counter.
-
#program_listing_uri ⇒ Object
readonly
Returns the value of attribute program_listing_uri.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #fetch_output ⇒ Object
- #fetch_program_listing ⇒ Object
-
#initialize(id, raw_message) ⇒ Message
constructor
A new instance of Message.
- #new_program_counter ⇒ Object
-
#send_input(input) ⇒ Object
Accepts either a String of raw data, or a Hash of data and a program counter increment.
Constructor Details
#initialize(id, raw_message) ⇒ Message
Returns a new instance of Message.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/wase_endpoint/message.rb', line 7 def initialize(id, ) myname_and_hashtag, program_counter, program_listing_uri, , output_uri, input_uri, input_uri_1 = .split(/,/) @id = id @program_counter = program_counter.to_i @program_listing_uri = program_listing_uri.strip @timestamp = .to_i @output_uri = output_uri.strip @input_uri = input_uri.strip if input_uri @input_uri_1 = input_uri_1.strip if input_uri_1 @increment = 1 end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/wase_endpoint/message.rb', line 5 def id @id end |
#input_uri ⇒ Object (readonly)
Returns the value of attribute input_uri.
5 6 7 |
# File 'lib/wase_endpoint/message.rb', line 5 def input_uri @input_uri end |
#input_uri_1 ⇒ Object (readonly)
Returns the value of attribute input_uri_1.
5 6 7 |
# File 'lib/wase_endpoint/message.rb', line 5 def input_uri_1 @input_uri_1 end |
#output_uri ⇒ Object (readonly)
Returns the value of attribute output_uri.
5 6 7 |
# File 'lib/wase_endpoint/message.rb', line 5 def output_uri @output_uri end |
#program_counter ⇒ Object (readonly)
Returns the value of attribute program_counter.
5 6 7 |
# File 'lib/wase_endpoint/message.rb', line 5 def program_counter @program_counter end |
#program_listing_uri ⇒ Object (readonly)
Returns the value of attribute program_listing_uri.
5 6 7 |
# File 'lib/wase_endpoint/message.rb', line 5 def program_listing_uri @program_listing_uri end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
5 6 7 |
# File 'lib/wase_endpoint/message.rb', line 5 def @timestamp end |
Instance Method Details
#==(other) ⇒ Object
20 21 22 |
# File 'lib/wase_endpoint/message.rb', line 20 def ==(other) @id == other.id end |
#fetch_output ⇒ Object
28 29 30 |
# File 'lib/wase_endpoint/message.rb', line 28 def fetch_output RestClient.get('http://' + @output_uri) end |
#fetch_program_listing ⇒ Object
24 25 26 |
# File 'lib/wase_endpoint/message.rb', line 24 def fetch_program_listing JSON.parse(RestClient.get('http://' + @program_listing_uri)) end |
#new_program_counter ⇒ Object
52 53 54 |
# File 'lib/wase_endpoint/message.rb', line 52 def new_program_counter @program_counter + @increment end |
#send_input(input) ⇒ Object
Accepts either a String of raw data, or a Hash of data and a program counter increment. An Exception will be thrown if this increment is negative.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wase_endpoint/message.rb', line 35 def send_input(input) if input.is_a?(Hash) @increment = input[:increment] raise ArgumentError, 'You cannot have negative program counter increments' if @increment < 0 input = input[:data] end input_uri = 'http://' + (@input_uri || @output_uri) # RestClient can't follow a redirect for put, so we'll expand it. input_uri[/bit\.ly(\/\w+)/] = Net::HTTP.new('bit.ly').head($1)['Location'] RestClient.put(, input) end |