Sha256: e6a310ef70e22cfdff7a72e4bd66ecd5517dc548bbd49df9edb89bd9c59a2351

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

# encoding: utf-8
module Nokaya

  # Inspired by Brett Terpstra

  class AppStore < Apple

    attr_accessor :appname

    def initialize args, options = {}
      super(args, options)
      @type = :appstore
      @appname = @workers.sanitize(args.join('_'))
      @image_url = [grab_small(args), grab_big(args)].compact
      find_screenshots(args)
      @path = "#{@path}/appstore-#{@appname}-#{@workers.timed}"
      @file_name = name()
      remove_instance_variable(:@res)
    end

    private

    def name
      @image_url.map.with_index do |url, index|
        "#{@type.to_s}-#{@appname}-#{'%02d' % index}-#{File.basename(url).gsub('ApplicationIcon.', '')}"
      end
    end

    def find_icon terms
      itunes_url = self.create_url(terms)
      @res = open(itunes_url).read
      match = @res.match(/"#{@icon_size}":"(.*?)",/)
      unless match.nil?
        return match[1]
      else
        return false
      end
    end

    def grab_small args
      @icon_size = "artworkUrl60"
      find_icon(args)
    end

    def grab_big args
      @icon_size = "artworkUrl100"
      find_icon(args)
    end

    def find_screenshots terms
      res = JSON.parse(@res)
      res['results'][0]['screenshotUrls'].each {|link| @image_url << link}
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nokaya-0.1.2 lib/nokaya/appstore.rb