Class: Leecher::Client
- Inherits:
-
Object
- Object
- Leecher::Client
- Defined in:
- lib/leecher/client.rb
Instance Attribute Summary collapse
-
#aria2_client ⇒ Object
readonly
Returns the value of attribute aria2_client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#gheed_client ⇒ Object
readonly
Returns the value of attribute gheed_client.
Instance Method Summary collapse
- #filename(relative) ⇒ Object
-
#initialize(config, aria2_client, gheed_client) ⇒ Client
constructor
A new instance of Client.
- #notify_gheed(uri, state) ⇒ Object
- #process_message_on_metalink_queue(msg) ⇒ Object
- #queue ⇒ Object
- #state_change(gid) ⇒ Object
- #status_update ⇒ Object
Constructor Details
#initialize(config, aria2_client, gheed_client) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 |
# File 'lib/leecher/client.rb', line 12 def initialize(config, aria2_client, gheed_client) @config = config @aria2_client = aria2_client @gheed_client = gheed_client end |
Instance Attribute Details
#aria2_client ⇒ Object (readonly)
Returns the value of attribute aria2_client.
10 11 12 |
# File 'lib/leecher/client.rb', line 10 def aria2_client @aria2_client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/leecher/client.rb', line 10 def config @config end |
#gheed_client ⇒ Object (readonly)
Returns the value of attribute gheed_client.
10 11 12 |
# File 'lib/leecher/client.rb', line 10 def gheed_client @gheed_client end |
Instance Method Details
#filename(relative) ⇒ Object
23 24 25 |
# File 'lib/leecher/client.rb', line 23 def filename(relative) File.join(@config.work_dir, relative) end |
#notify_gheed(uri, state) ⇒ Object
51 52 53 54 |
# File 'lib/leecher/client.rb', line 51 def notify_gheed(uri, state) , deliveries = gheed_client.state_change(uri, state) queue.set_store_entry(["metalink_url"], :state => :complete) end |
#process_message_on_metalink_queue(msg) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/leecher/client.rb', line 27 def (msg) # URIs will only ever be one (contract with gheed) uris, = MultiJson.decode(msg) queue.add_uris(uris) gid = aria2_client.add_uri(uris, ) queue.set_store_entry(uris.first, :gid => gid.to_i, :state => :added_to_aria2) end |
#queue ⇒ Object
19 20 21 |
# File 'lib/leecher/client.rb', line 19 def queue @queue ||= MetalinkQueue.new(filename("queue.yml")) end |
#state_change(gid) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/leecher/client.rb', line 35 def state_change(gid) response = aria2_client.tell_status(gid) uri = response["files"].first["uris"].first["uri"] state = response["status"].to_sym queue.set_store_entry(uri, :gid => gid, :state => state) # Don't tell Gheed about completing metalink downloads - we only # need to say when the file the metalink speaks about changes state unless File.extname(uri) == ".metalink" # .. and to a state we care about if [:complete, :error].include?(state) notify_gheed(uri, state) end end end |