rack-smart-app-banner 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +23 -0
- data/LICENSE +19 -0
- data/README.md +65 -0
- data/Rakefile +11 -0
- data/lib/rack/smart-app-banner.rb +54 -0
- data/rack-smart-app-banner.gemspec +25 -0
- metadata +105 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rack-smart-app-banner (0.0.1)
|
5
|
+
rack (>= 1.2.0, <= 2.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
minitest (2.11.4)
|
11
|
+
rack (1.4.1)
|
12
|
+
rack-test (0.6.1)
|
13
|
+
rack (>= 1.0)
|
14
|
+
rake (0.9.2.2)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
minitest (~> 2.11.4)
|
21
|
+
rack-smart-app-banner!
|
22
|
+
rack-test (~> 0.6.1)
|
23
|
+
rake (~> 0.9.2)
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 Mattt Thompson (http://mattt.me)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
rack-smart-app-banner
|
2
|
+
=====================
|
3
|
+
|
4
|
+
**Rack middleware to automatically include code for Smart App Banner, introduced in iOS 6**
|
5
|
+
|
6
|
+
![Smart App Banner Example](http://cl.ly/image/1K0W2F050a0h/smartappbanner.png)
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
According to the ["Promoting Apps with Smart App Banners"](https://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html) section of the [Safari Web Content Guide](https://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/Introduction/Introduction.html#//apple_ref/doc/uid/TP40002051-CH1-SW1):
|
11
|
+
|
12
|
+
> Smart App Banners vastly improve users’ browsing experience compared to other promotional methods. ... [Users] will appreciate that banners are presented unobtrusively at the top of a webpage, instead of as a full-screen ad interrupting the web content. And with a large and prominent close button, a banner is easy for users to dismiss.
|
13
|
+
>
|
14
|
+
> If the app is already installed on a user's device, the banner intelligently changes its action, and tapping the banner will simply open the app. If the user doesn’t have your app on his device, tapping on the banner will take him to the app’s entry in the App Store.
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require "rack/smart-app-banner"
|
22
|
+
|
23
|
+
use Rack::SmartAppBanner, app_id: "123456789",
|
24
|
+
affiliate_partner_id: 42,
|
25
|
+
affiliate_site_id: "abcdef123456",
|
26
|
+
app_argument: lambda {|request| request.path}
|
27
|
+
```
|
28
|
+
|
29
|
+
Including this in the `config.ru` file of your Rack application will automatically inject the corresponding `<meta>` tag into the `<head>` of each HTML document.
|
30
|
+
|
31
|
+
```html
|
32
|
+
<meta name="apple-itunes-app" content="app-id=123456789, affiliate-data=partnerId=42&siteID=abcdef123456 app-argument=http://listings/123" />
|
33
|
+
```
|
34
|
+
|
35
|
+
### Parameters
|
36
|
+
|
37
|
+
- `app_id`: _Required_. Your app's unique identifier. To find your app ID from the [iTunes Link Maker](http://itunes.apple.com/linkmaker/), type the name of your app in the Search field, and select the appropriate country and media type. In the results, find your app and select iPhone App Link in the column on the right. Your app ID is the nine-digit number in between id and ?mt.
|
38
|
+
- `affiliate_partner_id` & `affiliate_site_id`: _Optional_. Your iTunes affiliate details, if you are an iTunes affiliate. If you are not, find out more about becoming an iTunes affiliate at http://www.apple.com/itunes/affiliates/.
|
39
|
+
- `app_argument`: _Optional_. A block that generates a URL that provides context to your native app. If you include this, and the user has your app installed, she can jump from your website to the corresponding position in your iOS app.
|
40
|
+
|
41
|
+
## Installation
|
42
|
+
|
43
|
+
Add `rack-smart-app-banner` to your application's `Gemfile`:
|
44
|
+
|
45
|
+
### Gemfile
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
gem 'rack-smart-app-banner', require: 'rack/smart-app-banner'
|
49
|
+
```
|
50
|
+
|
51
|
+
## Requirements
|
52
|
+
|
53
|
+
- Ruby 1.9
|
54
|
+
|
55
|
+
## Contact
|
56
|
+
|
57
|
+
Mattt Thompson
|
58
|
+
|
59
|
+
- http://github.com/mattt
|
60
|
+
- http://twitter.com/mattt
|
61
|
+
- m@mattt.me
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
rack-smart-app-banner is available under the MIT license. See the LICENSE file for more info.
|
data/Rakefile
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "bundler"
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
gemspec = eval(File.read("rack-smart-app-banner.gemspec"))
|
5
|
+
|
6
|
+
task :build => "#{gemspec.full_name}.gem"
|
7
|
+
|
8
|
+
file "#{gemspec.full_name}.gem" => gemspec.files + ["rack-smart-app-banner.gemspec"] do
|
9
|
+
system "gem build rack-smart-app-banner.gemspec"
|
10
|
+
system "gem install rack-smart-app-banner-#{Rack::SmartAppBanner::VERSION}.gem"
|
11
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Rack #:nodoc:
|
4
|
+
class SmartAppBanner
|
5
|
+
|
6
|
+
VERSION = "0.0.1"
|
7
|
+
|
8
|
+
def initialize(app, options = {})
|
9
|
+
raise ArgumentError, "App ID Required" unless options[:app_id] &&
|
10
|
+
!options[:app_id].empty?
|
11
|
+
raise ArgumentError, "Incomplete Affiliate Information" if (options[:affiliate_partner_id] or options[:affiliate_site_id]) and not (options[:affiliate_partner_id] and options[:affiliate_site_id])
|
12
|
+
raise ArgumentError, "App Argument Must Be Lambda" if options[:app_argument] and not options[:app_argument].lambda?
|
13
|
+
|
14
|
+
@app, @options = app, options
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
@status, @headers, @response = @app.call(env)
|
19
|
+
return [@status, @headers, @response] unless html?
|
20
|
+
|
21
|
+
request = Rack::Request.new(env)
|
22
|
+
response = Rack::Response.new([], @status, @headers)
|
23
|
+
if @response.respond_to?(:to_ary)
|
24
|
+
@response.each do |fragment|
|
25
|
+
response.write inject_smart_app_banner(request, fragment)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
response.finish
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def html?; @headers["Content-Type"] =~ /html/; end
|
35
|
+
|
36
|
+
def inject_smart_app_banner(request, response)
|
37
|
+
parameters = {'app-id' => @options[:app_id]}
|
38
|
+
parameters['affiliate-data'] = "partnerId=#{@options[:affiliate_partner_id]}&siteID=#{@options[:affiliate_site_id]}" if @options[:affiliate_partner_id] and @options[:affiliate_site_id]
|
39
|
+
parameters['app-argument'] = @options[:app_argument].call(request) if @options[:app_argument]
|
40
|
+
|
41
|
+
if argument = parameters['app-argument']
|
42
|
+
parameters['app-argument'] = "http://#{argument}" unless URI(argument).scheme
|
43
|
+
end
|
44
|
+
|
45
|
+
content = parameters.collect{|k, v| "#{k}=#{v}"}.join(", ")
|
46
|
+
|
47
|
+
meta = <<-EOF
|
48
|
+
<meta name="apple-itunes-app" content="#{content}" />
|
49
|
+
EOF
|
50
|
+
|
51
|
+
response.gsub(%r{</head>}, meta + "</head>")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rack/smart-app-banner"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rack-smart-app-banner"
|
7
|
+
s.authors = ["Mattt Thompson"]
|
8
|
+
s.email = "m@mattt.me"
|
9
|
+
s.homepage = "http://github.com/mattt/rack-smart-app-banner"
|
10
|
+
s.version = Rack::SmartAppBanner::VERSION
|
11
|
+
s.platform = Gem::Platform::RUBY
|
12
|
+
s.summary = "rack-smart-app-banner"
|
13
|
+
s.description = "Rack middleware to automatically include code for Smart App Banner, introduced in iOS 6."
|
14
|
+
|
15
|
+
s.add_runtime_dependency "rack", ">= 1.2.0", "<= 2.0.0"
|
16
|
+
|
17
|
+
s.add_development_dependency "minitest", "~> 2.11.4"
|
18
|
+
s.add_development_dependency "rack-test", "~> 0.6.1"
|
19
|
+
s.add_development_dependency "rake", "~> 0.9.2"
|
20
|
+
|
21
|
+
s.files = Dir["./**/*"].reject { |file| file =~ /\.\/(bin|log|pkg|script|spec|test|vendor)/ }
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-smart-app-banner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mattt Thompson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-21 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rack
|
16
|
+
requirement: &70224480205380 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.2.0
|
22
|
+
- - <=
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.0.0
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: *70224480205380
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: minitest
|
30
|
+
requirement: &70224480191040 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2.11.4
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: *70224480191040
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: rack-test
|
41
|
+
requirement: &70224480190300 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.6.1
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *70224480190300
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rake
|
52
|
+
requirement: &70224480189780 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 0.9.2
|
58
|
+
type: :development
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: *70224480189780
|
61
|
+
description: Rack middleware to automatically include code for Smart App Banner, introduced
|
62
|
+
in iOS 6.
|
63
|
+
email: m@mattt.me
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ./Gemfile
|
69
|
+
- ./Gemfile.lock
|
70
|
+
- ./lib/rack/smart-app-banner.rb
|
71
|
+
- ./LICENSE
|
72
|
+
- ./rack-smart-app-banner.gemspec
|
73
|
+
- ./Rakefile
|
74
|
+
- ./README.md
|
75
|
+
homepage: http://github.com/mattt/rack-smart-app-banner
|
76
|
+
licenses: []
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
hash: 2669496524341184505
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
hash: 2669496524341184505
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.8.15
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: rack-smart-app-banner
|
105
|
+
test_files: []
|