class Ognivo::Upload

Constants

OPTIONS

Public Class Methods

new(opts = {}) click to toggle source
# File lib/ognivo/upload.rb, line 11
def initialize(opts = {})
  OPTIONS.each { |v| instance_variable_set("@#{v}", opts[v]) }
end

Public Instance Methods

init_appcast() click to toggle source
# File lib/ognivo/upload.rb, line 29
def init_appcast
  ensure_bucket
  create_cast
end
upload() click to toggle source
# File lib/ognivo/upload.rb, line 15
def upload
  ensure_appfile
  ensure_bucket
  ensure_appcast

  item = create_item

  upload_build
  say_ok 'Build has been uploaded to S3'

  add_item_to_app_cast(item)
  say_ok 'Appcast succesfully updated'
end

Private Instance Methods

add_item_to_app_cast(item) click to toggle source
# File lib/ognivo/upload.rb, line 119
def add_item_to_app_cast(item)
  xml = s3_client.read(@appcast_name)

  new_xml = Sparklecast::Appcast.add_item(xml, item)

  s3_client.upload(new_xml, @appcast_name)
end
appcast_exists?() click to toggle source
# File lib/ognivo/upload.rb, line 90
def appcast_exists?
  s3_client.key_exists?(@appcast_name)
end
cast_description() click to toggle source
# File lib/ognivo/upload.rb, line 82
def cast_description
  ask('Appcast Description: ')
end
cast_language() click to toggle source
# File lib/ognivo/upload.rb, line 86
def cast_language
  ask('Appcast Language (e.g. en): ') { |q| q.default = 'en' }
end
cast_title() click to toggle source
# File lib/ognivo/upload.rb, line 74
def cast_title
  ask('Appcast Title: ')
end
create_cast() click to toggle source
# File lib/ognivo/upload.rb, line 51
def create_cast
  cast = Sparklecast::Appcast.new(
    cast_title, cast_link, cast_description, cast_language
  )

  data = cast.generate

  s3_client.upload(data, @appcast_name)

  say_ok "Appcast has been created at #{cast_link}\n" \
         'Use this link as a value for SUFeedURL key in an Info.plist'
end
create_item() click to toggle source
# File lib/ognivo/upload.rb, line 108
def create_item
  say "Let's create an update entry"
  item = Sparklecast::Appcast::Item.new(item_title, item_description, item_version)
  item.url = item_url
  item.type = 'application/octet-stream'

  Utils.update_item_for_file(@app_filename, item, @dsa_filename)

  item
end
ensure_appcast() click to toggle source
# File lib/ognivo/upload.rb, line 41
def ensure_appcast
  return if appcast_exists?

  unless agree('There is no appcast in a bucket. lets create one? [y/n]')
    error_and_abort "can't continue"
  end

  create_cast
end
ensure_appfile() click to toggle source
# File lib/ognivo/upload.rb, line 36
def ensure_appfile
  return if @app_filename && File.exist?(@app_filename)
  error_and_abort "Bad filename: \nfilename is empty or file doesn't exist"
end
ensure_bucket() click to toggle source
# File lib/ognivo/upload.rb, line 64
def ensure_bucket
  return if s3_client.bucket_exists?
  error_and_abort "Bucket \"#{@bucket_name}\" doesn't exist"
end
item_description() click to toggle source
# File lib/ognivo/upload.rb, line 98
def item_description
  text = ask_editor "Write update description. What's new in this update, etc...\n"
  markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
  markdown.render(text)
end
item_title() click to toggle source
# File lib/ognivo/upload.rb, line 94
def item_title
  ask('Update Title: ')
end
item_url() click to toggle source
# File lib/ognivo/upload.rb, line 135
def item_url
  s3_client.public_url(s3_build_path)
end
item_version() click to toggle source
# File lib/ognivo/upload.rb, line 104
def item_version
  @version ||= ask('Update Version: ')
end
s3_build_path() click to toggle source
# File lib/ognivo/upload.rb, line 127
def s3_build_path
  file_name = File.basename(@app_filename, '.*')
  ext = File.extname(@app_filename)
  version = item_version

  "releases/#{file_name}-#{version}#{ext}"
end
s3_client() click to toggle source
# File lib/ognivo/upload.rb, line 69
def s3_client
  @s3_client ||=
    S3Client.new(@access_key_id, @secret_access_key, @bucket_name)
end
upload_build() click to toggle source
# File lib/ognivo/upload.rb, line 139
def upload_build
  s3_client.upload_file(@app_filename, s3_build_path)
end