Module: TransmissionServer

Defined in:
lib/transmission-connect/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connectorsObject

Returns the value of attribute connectors.



2
3
4
# File 'lib/transmission-connect/server.rb', line 2

def connectors
  @connectors
end

Instance Method Details

#receive_data(data) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/transmission-connect/server.rb', line 4

def receive_data data
  query = JSON.parse(data)
  case query['command']
    when 'add'
      respond = 'Add: '  + query['uri']
      target = query['client']
      ## Add magnet link to download client
      session = @connectors.find{|client| client.host == target['host'] and client.peer_port == target['port']}
      if session
        session.transmission.add_torrent_by_file(query['uri'])
        session.transmission.add_tracker(query['hash'], 'http://retracker.local/announce') if query['hash']
      end
    when 'move'
      respond = 'move'
      ## Move torrent from download to upload client
    else
      respond = 'Illegal operation'
  end
  puts respond
  send_data respond
  close_connection_after_writing
end