Class: Conveyor::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/conveyor/client.rb

Instance Method Summary collapse

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

#channel_status(channel_name) ⇒ Object



35
36
37
# File 'lib/conveyor/client.rb', line 35

def channel_status channel_name
  JSON::parse(@conn.get("/channels/#{channel_name}").body)
end

#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

#get_next_n(channel_name, n = 10, group = nil) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/conveyor/client.rb', line 39

def get_next_n channel_name, n = 10, group = nil
  if group
    JSON.parse(@conn.get("/channels/#{channel_name}?next&n=#{n}&group=#{group}").body)
  else
    JSON.parse(@conn.get("/channels/#{channel_name}?next&n=#{n}").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

#rewind(channel_name, id, group = nil) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/conveyor/client.rb', line 47

def rewind channel_name, id, group=nil
  if group
    @conn.post("/channels/#{channel_name}?rewind_id=#{id}&group=#{group}", nil)
  else
    @conn.post("/channels/#{channel_name}?rewind_id=#{id}", nil)
  end
end