Class: ADCDownload::Command::Get
- Inherits:
-
Object
- Object
- ADCDownload::Command::Get
show all
- Includes:
- Helper::LogHelper, Commander::Methods
- Defined in:
- lib/adcdownload/command/get.rb
Instance Method Summary
collapse
#debug, #error, #error!, #info, #logger
Instance Method Details
#run ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/adcdownload/command/get.rb', line 7
def run
command :get do |c|
c.syntax = "adbdownload get [filename]"
c.summary = "Download file from ADC"
c.option "--user String", String, "[optional]"
c.option "--pass String", String, "[optional]"
c.action do |args, options|
store_path = File.expand_path("~/.adcdownload")
download_url = args[0]
download_file = File.basename(download_url)
error!("Invalid download URL") if !download_url or download_url[0..28] != "http://adcdownload.apple.com/"
if !options.user or !options.pass
if File.exists?(store_path)
store_contents = JSON.parse(File.open(store_path).read)
options.user = store_contents["user"]
options.pass = store_contents["pass"]
end
end
if !options.user or !options.pass
options.user = ask("User: ")
options.pass = ask("Pass: ") { |q| q.echo = "*" }
end
while !valid_cookie?
info "creating download cookie"
client = Client.new()
client.get_cookies(options.user, options.pass)
end
File.open(store_path, "w") {|f| f.write(JSON.dump({user: options.user, pass: options.pass})) }
info "downloading #{download_file}"
system "wget -c --load-cookies .adccookies -p '#{download_url}' -O #{download_file}"
end
end
end
|
#valid_cookie? ⇒ Boolean
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/adcdownload/command/get.rb', line 53
def valid_cookie?
if File.exists?(".adccookies")
existing_cookies = File.open(".adccookies").read
if existing_cookies =~ /([0-9]+)\tADCDownloadAuth/
expires = $1
if Time.at(expires.to_i) > Time.now
return true
end
end
end
false
end
|