Class: Yolo::Deployment::OTA

Inherits:
BaseDeployer show all
Defined in:
lib/yolo/deployment/ota.rb

Overview

Deploys IPA’s using ustwo’s OTA

Author:

  • Alex Fish

Instance Attribute Summary

Attributes inherited from BaseDeployer

#package_path, #url

Instance Method Summary collapse

Constructor Details

#initializeOTA

Creates a new OTA instance



17
18
19
20
21
# File 'lib/yolo/deployment/ota.rb', line 17

def initialize
  @error_formatter = Yolo::Formatters::ErrorFormatter.new
  @progress_formatter = Yolo::Formatters::ProgressFormatter.new
  super
end

Instance Method Details

#deploy(package_path, opts = {}, &block) ⇒ Object

Overides the super deploy method

Parameters:

  • package_path (String)

    A full path to the package to deploy

  • opts (Hash) (defaults to: {})

    A hash of deployment options

  • block (Block)

    Block fired on completing



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/yolo/deployment/ota.rb', line 30

def deploy(package_path, opts={}, &block)
  self.package_path = package_path
  @complete_block = block

  unless self.url
    @error_formatter.no_deploy_url
    return
  end

  @progress_formatter.deploying_ipa(self.package_path)

  upload
end

#packageString

Creates a json package for the OTA uploader params

Returns:

  • (String)

    A JSON string package



48
49
50
51
# File 'lib/yolo/deployment/ota.rb', line 48

def package
  filename = self.package_path.split("/").last
  "{\"fileName\": \"#{filename}\", \"password\": \"\", \"validUntil\": \"2000000000\"}"
end

#uploadObject

Uploades the package using CURL



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/yolo/deployment/ota.rb', line 56

def upload
  response = ""
  IO.popen("curl #{self.url} -X POST -# -F fileContent=@\"#{self.package_path}\" -F params='#{package}'") do |io|
    begin
      while line = io.readline
        response << line
      end
      if response.length == 0
        @error_formatter.deploy_failed("Upload error")
      end
    rescue EOFError
    end
  end
  upload_complete(response) if response.length > 0
end

#upload_complete(response) ⇒ Object

Method called when the upload is complete, parses the json response form OTA which contains the package url and password

Parameters:

  • response (String)

    The OTA servers response



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/yolo/deployment/ota.rb', line 76

def upload_complete(response)
  json = nil
  begin
    json = JSON.parse(response)
  rescue JSON::ParserError
    @error_formatter.deploy_failed("\n  ParserError: Deployment server response is not JSON")
    return
  end

  unless json
    @error_formatter.deploy_failed("\n  ParserError: Deployment server response is not JSON")
    return
  end

  url = json["link"]
  password = json["password"]

  @complete_block.call(url,password)
  @progress_formatter.deploy_complete(url,password)
end