adcdownload 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 327595157e8ed7d8f5c1f2e3adf822ce8256010c
4
+ data.tar.gz: 8cf925b291932d79a9d6abfad36a02191e852776
5
+ SHA512:
6
+ metadata.gz: 8452a51de4e08fcad543bac27ddcb5964d093472f07e4e2ece7e4c68db17bff4a8f743cb2484d66b65f5a58cfb5f658667d1a084e5836093997ce4765e992b68
7
+ data.tar.gz: d54767c5a7a681c6ab3fcbf86a095154365ab929ad19246a58f54e9d5b5e717a0f871743d9cc0f31e22c64f404011f73f51e27a6a76dd705da7bdccab5853466
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .adccookies
2
+ *.dmg
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,107 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ adcdownload (0.1.0)
5
+ activesupport (~> 4.2)
6
+ bundler (~> 1.10)
7
+ commander (~> 4.3)
8
+ http-cookie (~> 1.0)
9
+ logging (~> 2.0)
10
+ spaceship (~> 0.7)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activesupport (4.2.4)
16
+ i18n (~> 0.7)
17
+ json (~> 1.7, >= 1.7.7)
18
+ minitest (~> 5.1)
19
+ thread_safe (~> 0.3, >= 0.3.4)
20
+ tzinfo (~> 1.1)
21
+ ast (2.1.0)
22
+ astrolabe (1.3.1)
23
+ parser (~> 2.2)
24
+ coderay (1.1.0)
25
+ colored (1.2)
26
+ commander (4.3.5)
27
+ highline (~> 1.7.2)
28
+ credentials_manager (0.8.2)
29
+ colored
30
+ highline (>= 1.7.1)
31
+ security
32
+ diff-lcs (1.2.5)
33
+ domain_name (0.5.24)
34
+ unf (>= 0.0.5, < 1.0.0)
35
+ faraday (0.9.1)
36
+ multipart-post (>= 1.2, < 3)
37
+ faraday_middleware (0.10.0)
38
+ faraday (>= 0.7.4, < 0.10)
39
+ highline (1.7.7)
40
+ http-cookie (1.0.2)
41
+ domain_name (~> 0.5)
42
+ i18n (0.7.0)
43
+ json (1.8.3)
44
+ little-plugger (1.1.4)
45
+ logging (2.0.0)
46
+ little-plugger (~> 1.1)
47
+ multi_json (~> 1.10)
48
+ method_source (0.8.2)
49
+ minitest (5.8.1)
50
+ multi_json (1.11.2)
51
+ multi_xml (0.5.5)
52
+ multipart-post (2.0.0)
53
+ parser (2.2.2.6)
54
+ ast (>= 1.1, < 3.0)
55
+ plist (3.1.0)
56
+ powerpack (0.1.1)
57
+ pry (0.10.2)
58
+ coderay (~> 1.1.0)
59
+ method_source (~> 0.8.1)
60
+ slop (~> 3.4)
61
+ rainbow (2.0.0)
62
+ rspec (3.3.0)
63
+ rspec-core (~> 3.3.0)
64
+ rspec-expectations (~> 3.3.0)
65
+ rspec-mocks (~> 3.3.0)
66
+ rspec-core (3.3.2)
67
+ rspec-support (~> 3.3.0)
68
+ rspec-expectations (3.3.1)
69
+ diff-lcs (>= 1.2.0, < 2.0)
70
+ rspec-support (~> 3.3.0)
71
+ rspec-mocks (3.3.2)
72
+ diff-lcs (>= 1.2.0, < 2.0)
73
+ rspec-support (~> 3.3.0)
74
+ rspec-support (3.3.0)
75
+ rubocop (0.34.2)
76
+ astrolabe (~> 1.3)
77
+ parser (>= 2.2.2.5, < 3.0)
78
+ powerpack (~> 0.1)
79
+ rainbow (>= 1.99.1, < 3.0)
80
+ ruby-progressbar (~> 1.4)
81
+ ruby-progressbar (1.7.5)
82
+ security (0.1.3)
83
+ slop (3.6.0)
84
+ spaceship (0.7.0)
85
+ credentials_manager (>= 0.8.1)
86
+ faraday (~> 0.9)
87
+ faraday_middleware (~> 0.9)
88
+ multi_xml (~> 0.5)
89
+ plist (~> 3.1)
90
+ thread_safe (0.3.5)
91
+ tzinfo (1.2.2)
92
+ thread_safe (~> 0.1)
93
+ unf (0.1.4)
94
+ unf_ext
95
+ unf_ext (0.0.7.1)
96
+
97
+ PLATFORMS
98
+ ruby
99
+
100
+ DEPENDENCIES
101
+ adcdownload!
102
+ pry (~> 0.10)
103
+ rspec (~> 3.3)
104
+ rubocop (~> 0.32)
105
+
106
+ BUNDLED WITH
107
+ 1.10.6
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # XCode ADCDownload
2
+
3
+ Smart file downloader from Apple Developer downloads area
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'adcdownload/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "adcdownload"
7
+ s.version = ADCDownload::VERSION
8
+ s.licenses = ["BSD-3-Clause"]
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Tobias Strebitzer"]
11
+ s.email = ["tobias.strebitzer@magloft.com"]
12
+ s.homepage = "https://github.com/MagLoft/adcdownload"
13
+ s.summary = "ADCDownload - Apple Developer Center Downloader."
14
+ s.description = "This gem helps you download files from Apple Developer Center."
15
+ s.required_rubygems_version = '>= 2.4.7'
16
+ s.add_runtime_dependency "bundler", "~> 1.10"
17
+ s.add_runtime_dependency "activesupport", "~> 4.2"
18
+ s.add_runtime_dependency "logging", "~> 2.0"
19
+ s.add_runtime_dependency "commander", "~> 4.3"
20
+ s.add_runtime_dependency "spaceship", "~> 0.7"
21
+ s.add_runtime_dependency "http-cookie", "~> 1.0"
22
+ s.add_development_dependency "rspec", "~> 3.3"
23
+ s.add_development_dependency "pry", "~> 0.10"
24
+ s.add_development_dependency "rubocop", "~> 0.32"
25
+ s.files = `git ls-files`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
27
+ s.require_path = 'lib'
28
+ end
data/bin/adcdownload ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push File.expand_path("../../lib", __FILE__)
3
+
4
+ require "adcdownload"
5
+
6
+ ADCDownload::Application.new.run
@@ -0,0 +1,15 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ require "active_support/all"
4
+ require "logging"
5
+ require "commander"
6
+ require "spaceship"
7
+ require "http-cookie"
8
+ require "json"
9
+ require "pry"
10
+
11
+ require "adcdownload/version"
12
+ require "adcdownload/client"
13
+ require "adcdownload/helper/log_helper"
14
+ require "adcdownload/command/get"
15
+ require "adcdownload/application"
@@ -0,0 +1,38 @@
1
+ module ADCDownload
2
+ class Application
3
+ include Commander::Methods
4
+
5
+ def run
6
+ program :version, ADCDownload::VERSION
7
+ program :description, 'Apple Developer Center Downloader'
8
+ program :help, 'Author', 'Tobias Strebitzer <tobias.strebitzer@magloft.com>'
9
+ program :help, 'Website', 'http://www.magloft.com'
10
+ program :help_formatter, Commander::HelpFormatter::TerminalCompact
11
+ global_option '-x', '--verbose' do
12
+ logger.level = :debug
13
+ end
14
+ global_option '--verbosity LEVEL', 'Specify verbosity level (*info*, debug, warn, error)' do |verbosity|
15
+ verbosity = "info" if !["info", "debug", "warn", "error"].include?(verbosity.to_s)
16
+ logger.level = verbosity.to_sym
17
+ end
18
+ global_option '--production'
19
+ default_command :help
20
+
21
+ logger.level = ENV["LOG_LEVEL"].to_sym if ENV["LOG_LEVEL"]
22
+
23
+ ADCDownload::Command::Get.new.run
24
+
25
+ # allow colons
26
+ ARGV[0] = ARGV[0].gsub(":", "-") if ARGV[0]
27
+
28
+ # merge first two commands
29
+ if ARGV.length > 1 and defined_commands.keys.include?("#{ARGV[0]}-#{ARGV[1]}")
30
+ ARGV[0] = "#{ARGV[0]}-#{ARGV[1]}"
31
+ ARGV.slice!(1)
32
+ end
33
+
34
+ run!
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,60 @@
1
+ module ADCDownload
2
+ class Client < Spaceship::Client
3
+ attr_accessor :download_cookie
4
+
5
+ def self.hostname
6
+ "https://developer.apple.com/services-account/#{PROTOCOL_VERSION}/"
7
+ end
8
+
9
+ # Fetches the latest API Key from the Apple Dev Portal
10
+ def api_key
11
+ cache_path = "/tmp/spaceship_api_key.txt"
12
+ begin
13
+ cached = File.read(cache_path)
14
+ rescue Errno::ENOENT
15
+ end
16
+ return cached if cached
17
+
18
+ landing_url = "https://developer.apple.com/membercenter/index.action"
19
+ logger.info("GET: " + landing_url)
20
+ headers = @client.get(landing_url).headers
21
+ results = headers['location'].match(/.*appIdKey=(\h+)/)
22
+ if (results || []).length > 1
23
+ api_key = results[1]
24
+ File.write(cache_path, api_key) if api_key.length == 64
25
+ return api_key
26
+ else
27
+ raise "Could not find latest API Key from the Dev Portal - the server might be slow right now"
28
+ end
29
+ end
30
+
31
+ def get_cookies(user, password)
32
+ jar = HTTP::CookieJar.new(store: :hash, filename: 'cookies.txt')
33
+ response = request(:post, "https://idmsa.apple.com/IDMSWebAuth/authenticate", {
34
+ appleId: user,
35
+ accountPassword: password,
36
+ appIdKey: api_key
37
+ })
38
+ jar.parse(response['Set-Cookie'], "http://idmsa.apple.com")
39
+
40
+ if response['Set-Cookie'] =~ /myacinfo=(\w+);/
41
+ @cookie = "myacinfo=#{$1};"
42
+ else
43
+ raise InvalidUserCredentialsError.new, response
44
+ end
45
+
46
+ response = request(:get, "#{self.class.hostname}/downloadws/listDownloads.action")
47
+ jar.parse(response['Set-Cookie'], "https://developer.apple.com")
48
+
49
+ if response['Set-Cookie'] =~ /ADCDownloadAuth=([^;]+);/
50
+ @download_cookie = "ADCDownloadAuth=#{$1};"
51
+ else
52
+ raise InvalidUserCredentialsError.new, response
53
+ end
54
+
55
+ jar.each {|c| c.httponly = false}
56
+ jar.save(".adccookies", format: :cookiestxt, session: true)
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,68 @@
1
+ module ADCDownload
2
+ module Command
3
+ class Get
4
+ include Commander::Methods
5
+ include Helper::LogHelper
6
+
7
+ def run
8
+ command :get do |c|
9
+ c.syntax = "adbdownload get [filename]"
10
+ c.summary = "Download file from ADC"
11
+ c.option "--user String", String, "[optional]"
12
+ c.option "--pass String", String, "[optional]"
13
+ c.action do |args, options|
14
+
15
+ # arguments and validation
16
+ store_path = File.expand_path("~/.adcdownload")
17
+ download_url = args[0]
18
+ download_file = File.basename(download_url)
19
+ error!("Invalid download URL") if !download_url or download_url[0..28] != "http://adcdownload.apple.com/"
20
+
21
+ # load stored login information
22
+ if !options.user or !options.pass
23
+ if File.exists?(store_path)
24
+ store_contents = JSON.parse(File.open(store_path).read)
25
+ options.user = store_contents["user"]
26
+ options.pass = store_contents["pass"]
27
+ end
28
+ end
29
+
30
+ # collect login information
31
+ if !options.user or !options.pass
32
+ options.user = ask("User: ")
33
+ options.pass = ask("Pass: ") { |q| q.echo = "*" }
34
+ end
35
+
36
+ # create cookie
37
+ while !valid_cookie?
38
+ info "creating download cookie"
39
+ client = Client.new()
40
+ client.get_cookies(options.user, options.pass)
41
+ end
42
+
43
+ # store account information
44
+ File.open(store_path, "w") {|f| f.write(JSON.dump({user: options.user, pass: options.pass})) }
45
+
46
+ # download file
47
+ info "downloading #{download_file}"
48
+ system "wget -c --load-cookies .adccookies -p '#{download_url}' -O #{download_file}"
49
+ end
50
+ end
51
+ end
52
+
53
+ def valid_cookie?
54
+ if File.exists?(".adccookies")
55
+ existing_cookies = File.open(".adccookies").read
56
+ if existing_cookies =~ /([0-9]+)\tADCDownloadAuth/
57
+ expires = $1
58
+ if Time.at(expires.to_i) > Time.now
59
+ return true
60
+ end
61
+ end
62
+ end
63
+ false
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,42 @@
1
+ module ADCDownload
2
+ module Helper
3
+ module LogHelper
4
+ @@logger = nil
5
+
6
+ def info(message)
7
+ logger.send(:info, message)
8
+ end
9
+
10
+ def debug(message)
11
+ logger.send(:debug, message)
12
+ end
13
+
14
+ def error(message)
15
+ logger.send(:error, message)
16
+ end
17
+
18
+ def error!(message)
19
+ logger.send(:fatal, message)
20
+ Kernel.exit
21
+ end
22
+
23
+ def logger
24
+ # reset logger on task change
25
+ if @@logger.nil?
26
+ Logging.color_scheme("bright",
27
+ levels: { debug: :blue, info: :green, warn: :yellow, error: :red, fatal: [:white, :on_red] },
28
+ date: :blue,
29
+ mdc: :cyan,
30
+ logger: :cyan,
31
+ message: :black
32
+ )
33
+ Logging.appenders.stdout("stdout", layout: Logging.layouts.pattern( pattern: '[%d] %-5l %-16X{command} %x %m\n', color_scheme: 'bright' ))
34
+ @@logger = Logging::Logger.new(self.class.name)
35
+ @@logger.level = :info
36
+ @@logger.add_appenders('stdout')
37
+ end
38
+ @@logger
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ module ADCDownload
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adcdownload
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tobias Strebitzer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: logging
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: commander
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '4.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: spaceship
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.7'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: http-cookie
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '3.3'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '3.3'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.10'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '0.10'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: '0.32'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ~>
137
+ - !ruby/object:Gem::Version
138
+ version: '0.32'
139
+ description: This gem helps you download files from Apple Developer Center.
140
+ email:
141
+ - tobias.strebitzer@magloft.com
142
+ executables:
143
+ - adcdownload
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - .gitignore
148
+ - Gemfile
149
+ - Gemfile.lock
150
+ - README.md
151
+ - adcdownload.gemspec
152
+ - bin/adcdownload
153
+ - lib/adcdownload.rb
154
+ - lib/adcdownload/application.rb
155
+ - lib/adcdownload/client.rb
156
+ - lib/adcdownload/command/get.rb
157
+ - lib/adcdownload/helper/log_helper.rb
158
+ - lib/adcdownload/version.rb
159
+ homepage: https://github.com/MagLoft/adcdownload
160
+ licenses:
161
+ - BSD-3-Clause
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - '>='
175
+ - !ruby/object:Gem::Version
176
+ version: 2.4.7
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.4.8
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: ADCDownload - Apple Developer Center Downloader.
183
+ test_files: []
184
+ has_rdoc: