lib/protolink/protonet.rb in protolink-0.2.7 vs lib/protolink/protonet.rb in protolink-0.2.8
- old
+ new
@@ -23,15 +23,24 @@
clazz.base_uri(uri)
clazz.basic_auth(username, password) if username && password
if proxy
clazz.http_proxy(proxy[:uri], proxy[:port])
end
- clazz.new
+ clazz.new(username)
end
# CHANNELS
-
+
+ def initialize(username)
+ @current_user_name = username
+ super()
+ end
+
+ def current_user
+ @current_user ||= find_user_by_login(@current_user_name)
+ end
+
# Get an array of all the available channels
def channels
get('/api/v1/channels').map do |channel|
Channel.new(self, channel)
end
@@ -135,11 +144,11 @@
channel_query = channel_id.to_s.match("-") ? {:channel_uuid => channel_id} : {:channel_id => channel_id}
post('/api/v1/listens', :body => {:user_id => user_id}.merge(channel_query) )
end
def destroy_listen(user_id, channel_id)
- channel_query = channel_id.match("-") ? {:channel_uuid => channel_id} : {:channel_id => channel_id}
+ channel_query = channel_id.to_s.match("-") ? {:channel_uuid => channel_id} : {:channel_id => channel_id}
delete('/api/v1/listens', :body => {:user_id => user_id}.merge(channel_query) )
end
def couple(node_data)
response = post("/api/v1/couplings", :body => {:node_data => node_data})
@@ -147,9 +156,15 @@
end
def node
response = get("/api/v1/nodes/1")
Node.new(self, response) if response
+ end
+
+ def socket(&blk)
+ EventMachine.run {
+ EventMachine.connect URI.parse(self.class.base_uri).host, 5000, ProtoSocket, self, blk
+ }
end
[:get, :post, :update, :delete].each do |method|
class_eval <<-EOS
def #{method}(uri, options = {})