class Rialto::Version

A version of an application

Constants

APPLICATION_CLASSNAME

Parse DB related

APPLICATION_ID_PROPERTYNAME
APPLICATION_TITLE_PROPERTYNAME
APPLICATION_TYPE
APPLICATION_VERSIONCHANGELOG_PROPERTYNAME
APPLICATION_VERSIONCODE_PROPERTYNAME
APPLICATION_VERSIONLEVEL_PROPERTYNAME
APPLICATION_VERSIONNUMBER_PROPERTYNAME
APPLICATION_VERSIONURL_PROPERTYNAME
APPLICATION_VERSION_CLASSNAME

Attributes

appId[R]

Attributes

parseId[R]

Attributes

parseKey[R]

Attributes

versionCode[R]

Attributes

versionLevel[R]

Attributes

versionLog[R]

Attributes

versionNumber[R]

Attributes

versionUrl[R]

Attributes

Public Class Methods

new() click to toggle source

Methods

# File lib/rialto/main.rb, line 39
def initialize()
end

Public Instance Methods

build() click to toggle source
# File lib/rialto/main.rb, line 84
def build
  puts "build: coming soon"
end
deploy() click to toggle source
# File lib/rialto/main.rb, line 88
def deploy
  puts "deploy: coming soon"
end
initParse(id, key) click to toggle source
# File lib/rialto/main.rb, line 79
def initParse(id, key)
    Parse.init         :application_id        => id,
                                  :api_key          => key
end
initVersion(file) click to toggle source
# File lib/rialto/main.rb, line 42
def initVersion(file)
  
  f = File.open(file)
  doc = Nokogiri::XML(f)
  f.close
  
  version = doc.xpath("//version/item").map do |i|
    {"key" => i.xpath("key"), "value" => i.xpath("value")}
  end
  
  version.each { |item|
    
    key = item["key"][0].content
    value = item["value"][0].content
    
    case key
    when "parseId"
      @parseId = value  
    when "apiKey"
      @parseKey = value 
    when "appId"
      @appId = value
    when "versionCode"
      @versionCode = value  
    when "versionLog"
      @versionLog = value  
    when "versionNumber"
      @versionNumber = value  
    when "versionLevel"
      @versionLevel = value 
    when "versionUrl"
      @versionUrl = value 
    end
  }
  
end
parseNotify(file) click to toggle source
# File lib/rialto/main.rb, line 145
def parseNotify(file)
  
  f = File.open(file)
  doc = Nokogiri::XML(f)
  f.close
  
  notification = doc.xpath("//notification/item").map do |i|
    {"key" => i.xpath("key"), "value" => i.xpath("value")}
  end
    
  title = ""
  message = ""
  action = ""
  channel = ""
  
  notification.each { |item|
    
    key = item["key"][0].content
    value = item["value"][0].content
    
    case key
    when "parseId"
      @parseId = value  
    when "apiKey"
      @parseKey = value 
    when "appId"
      @appId = value
    when "versionCode"
      @versionCode = value  
    when "title"
      title = value  
    when "message"
      message = value  
    when "action"
      action = value 
    when "channel"
      channel = value 
    end
  }
  
  initParse(@parseId, @parseKey)
  
  parseApplication = Parse.get APPLICATION_CLASSNAME, @appId
  
  if parseApplication != nil
    puts parseApplication[APPLICATION_TITLE_PROPERTYNAME] + " found in Parse.com"
  else
    puts "No Application with id #{appId} found"
    exit -1
  end
  
  # Default value for title
  if (title.length == 0)
    puts "Title is set to default: Application name & version"
    finTitle = "#{parseApplication[APPLICATION_TITLE_PROPERTYNAME]} - #{versionNumber}"
  else
    puts "Title is set to: #{title}"
    finTitle = title
  end
  
  push = Parse::Push.new(
    {
            "title" => finTitle,
            "alert" => message,
            "action" => action,
            "parseAppID" => @appId,
            "newVersionCode" => @versionCode
    }, channel)
    
  push.type = APPLICATION_TYPE
  push.save
  
  
end
parseUpdate(file) click to toggle source
# File lib/rialto/main.rb, line 92
def parseUpdate(file)

  initVersion(file)
  initParse(@parseId, @parseKey)
  
  parseApplication = Parse.get APPLICATION_CLASSNAME, @appId
  
  if parseApplication != nil
    puts parseApplication[APPLICATION_TITLE_PROPERTYNAME] + " loaded from Parse.com"
  else
    puts "No Application with id #{appId} found"
    exit -1
  end
  
  parseAppVersion = Parse::Query.new(APPLICATION_VERSION_CLASSNAME)
    .eq(APPLICATION_ID_PROPERTYNAME, parseApplication.pointer)
    .eq(APPLICATION_VERSIONNUMBER_PROPERTYNAME, @versionNumber)
    .get
    
  if (parseAppVersion != nil && parseAppVersion.length > 0)
    puts "Versions found: #{parseAppVersion.length}"
    puts "Updating existing ApplicationVersion"

    version = parseAppVersion[0]
    
    version[APPLICATION_VERSIONURL_PROPERTYNAME]             = @versionUrl
    version[APPLICATION_VERSIONCHANGELOG_PROPERTYNAME]               = @versionLog
    version[APPLICATION_VERSIONCODE_PROPERTYNAME]         = @versionCode.to_i
    
    version.save
    
    puts "Application updated"
    
  else
    puts "No version found. Creating it."
    
    newVersion = Parse::Object.new(APPLICATION_VERSION_CLASSNAME)
    
    newVersion[APPLICATION_ID_PROPERTYNAME]                      = parseApplication.pointer
    newVersion[APPLICATION_VERSIONCODE_PROPERTYNAME]           = @versionCode.to_i
    newVersion[APPLICATION_VERSIONNUMBER_PROPERTYNAME]               = @versionNumber
    newVersion[APPLICATION_VERSIONCHANGELOG_PROPERTYNAME]    = @versionLog
    newVersion[APPLICATION_VERSIONURL_PROPERTYNAME]                    = @versionUrl
    newVersion[APPLICATION_VERSIONLEVEL_PROPERTYNAME]                  = @versionLevel
    
    newVersion.save
    
    puts "Application created"
    
  end
  
end