Class: Establish::ItunesTransporter
- Inherits:
-
Object
- Object
- Establish::ItunesTransporter
- Defined in:
- lib/establish/itunes_transporter.rb
Constant Summary collapse
- ERROR_REGEX =
/>\s*ERROR:\s+(.+)/
- WARNING_REGEX =
/>\s*WARN:\s+(.+)/
- OUTPUT_REGEX =
/>\s+(.+)/
Instance Method Summary collapse
- #download(app, dir = nil) ⇒ Object
- #execute_transporter(command) ⇒ Object
-
#initialize(user = nil, password = nil) ⇒ ItunesTransporter
constructor
A new instance of ItunesTransporter.
- #upload(app, dir) ⇒ Object
Constructor Details
#initialize(user = nil, password = nil) ⇒ ItunesTransporter
Returns a new instance of ItunesTransporter.
12 13 14 15 |
# File 'lib/establish/itunes_transporter.rb', line 12 def initialize(user = nil, password = nil) @user = (user || PasswordManager.new.username) @password = (password || PasswordManager.new.password) end |
Instance Method Details
#download(app, dir = nil) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/establish/itunes_transporter.rb', line 17 def download(app, dir = nil) raise "No valid Establish::App given" unless app.kind_of?Establish::App dir ||= app. command = build_download_command(@user, @password, app.apple_id, dir) self.execute_transporter(command) end |
#execute_transporter(command) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/establish/itunes_transporter.rb', line 37 def execute_transporter(command) # Taken from https://github.sshaw/itunes_store_transporter/blob/master/lib/itunes/store/transporter/output_parser.rb errors = [] warnings = [] begin PTY.spawn(command) do |stdin, stdout, pid| stdin.each do |line| if line =~ ERROR_REGEX errors << $1 elsif line =~ WARNING_REGEX warnings << $1 end if line =~ OUTPUT_REGEX # General logging for debug purposes Helper.log.debug "[Transporter Output]: #{$1}" end end end rescue Exception => ex Helper.log.fatal(ex.to_s) errors << ex.to_s end if errors.count > 0 Helper.log.debug(caller) raise errors.join("\n") end true end |
#upload(app, dir) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/establish/itunes_transporter.rb', line 26 def upload(app, dir) raise "No valid Establish::App given" unless app.kind_of?Establish::App dir ||= app. dir += "/#{app.apple_id}.itmsp" command = build_upload_command(@user, @password, app.apple_id, dir) self.execute_transporter(command) end |