rails-open-in-app 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c2194f30ee44171c7149689ceb153db3a049a12c
4
+ data.tar.gz: f5dc592dd479582d6e0993d23f7d7009c2489704
5
+ SHA512:
6
+ metadata.gz: 3cd0f426d4db6813d2b2c6c255fed405caf122d1e3101396d5e40d7274c585fd6eca248bcd21320536bad70ac7b77436067556d5ef1f7a83b12810a3589fa2ed
7
+ data.tar.gz: 670baaeb0bdbc2832b102df809f274910bf95a4abd76abba61019f83e69de75ecb8f7d90fe47da165c0fb7c0998bcb8d5a6ed64720af7804e332fe03800a02c8
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails-open-in-app.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Calvin Yu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # OpenInApp Rails Plugin
2
+
3
+ Adds support to redirect specific URLs to their mobile app equivalents
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rails-open-in-app', require: 'open_in_app'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Usage
16
+
17
+ In the controllers you want to redirect to your mobile app, call ```open_in_app```:
18
+
19
+ open_in_app :only => :show
20
+
21
+ Then implement ```open_in_app_url``` to return the correct URL to open the app:
22
+
23
+ def open_in_app_url
24
+ "scoutmobshoppe://products/#{params[:id]}
25
+ end
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/Scoutmob/rails-open-in-app/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,31 @@
1
+ <!doctype html>
2
+ <html>
3
+ <body>
4
+ <a id="loadApp" href="<%= @open_in_app_url %>" alt="Open in App" style="font-size: 1px;color: transparent" onblur="var APP_OPENED=true;">&nbsp;</a>
5
+ <script>
6
+ (function() {
7
+ var APP_OPENED = false;
8
+ function fireEvent(element,event) {
9
+ if (document.createEvent) { //modern stuff
10
+ var evt = document.createEvent("HTMLEvents");
11
+ evt.initEvent(event, true, true);
12
+ return !element.dispatchEvent(evt);
13
+ } else { //old school IE
14
+ var evt = document.createEventObject();
15
+ return element.fireEvent('on' + event, evt);
16
+ }
17
+ }
18
+ window.onload = function(){
19
+ var loadApp = document.getElementById("loadApp");
20
+ if (loadApp) fireEvent(loadApp,'click');
21
+ };
22
+ var clickedAt = +new Date;
23
+ setTimeout(function() {
24
+ var installed = APP_OPENED || ((+new Date - clickedAt) > 2000);
25
+ var oia = '_oia=' + (installed ? '1' : '0');
26
+ var u = window.document.location.href;
27
+ window.location.href = u + ((u.indexOf('?') > 0) ? "&" : "?") + oia;
28
+ }, 1500);
29
+ })();
30
+ </script>
31
+ </body>
@@ -0,0 +1,2 @@
1
+ require 'open_in_app/version'
2
+ require 'open_in_app/engine' if defined?(Rails)
@@ -0,0 +1,66 @@
1
+ require 'active_support/concern'
2
+
3
+ module OpenInApp
4
+
5
+ module ControllerHelper
6
+ extend ActiveSupport::Concern
7
+
8
+ protected
9
+ def open_in_app_device?
10
+ mobile_device = request.env[Rack::MobileDetect::X_HEADER]
11
+ !!(mobile_device && %w(iphone ipod).include?(mobile_device.downcase))
12
+ end
13
+
14
+ def open_in_app_supported_request?
15
+ request.get? &&
16
+ !request.xhr? &&
17
+ request.format.html? &&
18
+ params[:_oia].blank?
19
+ end
20
+
21
+ def open_in_app_url_present?
22
+ (@open_in_app_url = open_in_app_url).present?
23
+ end
24
+
25
+ def open_in_app?
26
+ open_in_app_device? &&
27
+ open_in_app_supported_request? &&
28
+ open_in_app_url_present? &&
29
+ (
30
+ self.class.open_in_app_options[:if].nil? ||
31
+ send(self.class.open_in_app_options[:if])
32
+ ) &&
33
+ (
34
+ self.class.open_in_app_options[:unless].nil? ||
35
+ !send(self.class.open_in_app_options[:unless])
36
+ )
37
+ end
38
+
39
+ def open_in_app_url
40
+ nil
41
+ end
42
+
43
+ def open_in_app
44
+ if open_in_app?
45
+ render(template: 'open_in_app', layout: false) and return false
46
+ end
47
+ true
48
+ end
49
+
50
+ module ClassMethods
51
+ def open_in_app(options={})
52
+ open_in_app_options.merge!(options.reject { |key,| not [:if, :unless].include?(key.to_sym) })
53
+ filter_options = options.reject { |key,| [:if, :unless, :prepend].include?(key.to_sym) }
54
+ if prepend_filter = options.delete(:prepend)
55
+ prepend_before_filter prepend_filter, :open_in_app, filter_options
56
+ else
57
+ before_filter :open_in_app, filter_options
58
+ end
59
+ end
60
+
61
+ def open_in_app_options
62
+ @open_in_app_options ||= {}
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails'
2
+ require 'rack/mobile-detect'
3
+ require 'open_in_app/controller_helper'
4
+
5
+ module OpenInApp
6
+ class Engine < ::Rails::Engine
7
+ config.app_middleware.use Rack::MobileDetect
8
+
9
+ config.to_prepare do
10
+ ApplicationController.send(:include, OpenInApp::ControllerHelper)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module OpenInApp
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'open_in_app/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails-open-in-app"
8
+ spec.version = OpenInApp::VERSION
9
+ spec.authors = ["Calvin Yu"]
10
+ spec.email = ["calvin@scoutmob.com"]
11
+ spec.summary = %q{Adds support to redirect specific URLs to their mobile app equivalents}
12
+ spec.description = %q{Rails plugin that add supports to redirect specific URLs to their mobile app equivalents.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "rails", "~> 3.2.0"
25
+ spec.add_dependency "rack-mobile-detect", "~> 0.4.0"
26
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-open-in-app
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Calvin Yu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-mobile-detect
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.4.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.4.0
69
+ description: Rails plugin that add supports to redirect specific URLs to their mobile
70
+ app equivalents.
71
+ email:
72
+ - calvin@scoutmob.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - app/views/open_in_app.html.erb
83
+ - lib/open_in_app.rb
84
+ - lib/open_in_app/controller_helper.rb
85
+ - lib/open_in_app/engine.rb
86
+ - lib/open_in_app/version.rb
87
+ - rails-open-in-app.gemspec
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Adds support to redirect specific URLs to their mobile app equivalents
112
+ test_files: []