Class: Conveyor::Client
- Inherits:
-
Object
- Object
- Conveyor::Client
- Defined in:
- lib/conveyor/client.rb
Instance Method Summary collapse
- #connect! ⇒ Object
- #create_channel(channel_name) ⇒ Object
- #get(channel_name, id) ⇒ Object
- #get_next(channel_name, group = nil) ⇒ Object
-
#initialize(host, port = 8011) ⇒ Client
constructor
A new instance of Client.
- #post(channel_name, content) ⇒ Object
Constructor Details
#initialize(host, port = 8011) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 |
# File 'lib/conveyor/client.rb', line 5 def initialize host, port = 8011 @host = host @port = port connect! end |
Instance Method Details
#connect! ⇒ Object
11 12 13 |
# File 'lib/conveyor/client.rb', line 11 def connect! @conn = Net::HTTP.start(@host, @port) end |
#create_channel(channel_name) ⇒ Object
15 16 17 |
# File 'lib/conveyor/client.rb', line 15 def create_channel channel_name @conn.put("/channels/#{channel_name}", nil, {'Content-Type' => 'application/octet-stream'}) end |
#get(channel_name, id) ⇒ Object
23 24 25 |
# File 'lib/conveyor/client.rb', line 23 def get channel_name, id @conn.get("/channels/#{channel_name}/#{id}").body end |
#get_next(channel_name, group = nil) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/conveyor/client.rb', line 27 def get_next channel_name, group=nil if group @conn.get("/channels/#{channel_name}?next&group=#{group}").body else @conn.get("/channels/#{channel_name}?next").body end end |
#post(channel_name, content) ⇒ Object
19 20 21 |
# File 'lib/conveyor/client.rb', line 19 def post channel_name, content @conn.post("/channels/#{channel_name}", content, {'Content-Type' => 'application/octet-stream', 'Date' => Time.now.to_s}) end |