Sha256: 232cb535ad264963028d4848764f1a2ee0d80cec6ddc31bfd1654d26b09eddd2

Contents?: true

Size: 909 Bytes

Versions: 1

Compression:

Stored size: 909 Bytes

Contents

module MobileIntent
  class Application
    attr_reader :name

    def initialize(name, urls = {})
      @name = name
      @ios = urls[:ios]
      @android = urls[:android]
    end

    def ios? ; !!@ios ; end
    def android? ; !!@android ; end

    def android_intent_url(url)
      raise unless android?
      "intent://#{url}#Intent;scheme=#{name};package=#{@android};end"
    end

    def android_market_url
      raise unless android?
      "market://details?id=#{@android}"
    end

    def ios_market_url
      raise unless ios?
      "itms://itunes.com/apps/#{@ios}"
    end

    def market_url(platform)
      send("#{platform}_market_url")
    end

    def intent_url(url)
      "#{name}://#{url}"
    end

    def launch_url(url, user_agent)
      if user_agent =~ /Chrome/ && user_agent =~ /Android/
        android_intent_url(url)
      else
        intent_url(url)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mobile_intent-0.0.1 lib/mobile_intent/application.rb