device_aware 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Mint Digital, Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,16 @@
1
+ require 'yaml'
2
+ require 'device_aware/device'
3
+ require 'device_aware/version'
4
+
5
+ module DeviceAware
6
+ def self.config
7
+ YAML.load_file(Rails.root+'config'+'device_aware.yml')[Rails.env]
8
+ end
9
+
10
+ def self.detect(user_agent)
11
+ DeviceAware::Device.new(
12
+ :server => DeviceAware.config['server'],
13
+ :user_agent => user_agent
14
+ )
15
+ end
16
+ end
@@ -0,0 +1,67 @@
1
+ require 'uri'
2
+ require 'cgi'
3
+ require 'net/http'
4
+
5
+ module DeviceAware
6
+ class Device
7
+ include Enumerable
8
+
9
+ def initialize(options={})
10
+ @user_agent = options[:user_agent] || options['user_agent']
11
+ @server = URI.parse(options[:server] || options['server'])
12
+ end
13
+
14
+ # be Enumerable
15
+ def each
16
+ data.each {|k,v| yield(k, coerce(v)) }
17
+ end
18
+
19
+ # allow direct access to data for anything we don't alias
20
+ def [](key)
21
+ data[key]
22
+ end
23
+
24
+ { :mobile? => 'mobileDevice',
25
+ :desktop? => 'isBrowser',
26
+ :touchscreen? => 'touchScreen',
27
+ :supports_cookies? => 'cookieSupport',
28
+ :supports_https? => 'https'
29
+ }.each do |method, key|
30
+ define_method(method) { coerce(data[key]) }
31
+ end
32
+
33
+ { :make => 'vendor',
34
+ :model => 'model',
35
+ :display_height => 'displayHeight',
36
+ :display_width => 'displayWidth',
37
+ :usable_width => 'usableDisplayWidth',
38
+ :usable_height => 'usableDisplayHeight'
39
+ }.each do |method, key|
40
+ define_method(method) { data[key] }
41
+ end
42
+
43
+ def unknown? ; data.empty? || data == {} ; end
44
+
45
+ def is?(phone)
46
+ self.model.downcase == phone.to_s.downcase
47
+ end
48
+
49
+ private
50
+ def coerce(value)
51
+ case value
52
+ when 0 then false
53
+ when 1 then true
54
+ else value
55
+ end
56
+ end
57
+
58
+ def data
59
+ @_data ||= begin
60
+ body = Net::HTTP.start(@server.host, @server.port) {|http|
61
+ http.get("/lookup?u=#{CGI::escape(@user_agent)}")
62
+ }.body
63
+ JSON.parse(body)
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,13 @@
1
+ module DeviceAware
2
+ module Version
3
+ MAJOR = 0
4
+ MINOR = 2
5
+ PATCH = 0
6
+ BUILD = nil
7
+ STRING = [MAJOR,MINOR,PATCH,BUILD].compact.join('.')
8
+ end
9
+
10
+ def self.version
11
+ Version::STRING
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: device_aware
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 0
9
+ version: 0.2.0
10
+ platform: ruby
11
+ authors:
12
+ - Dean Strelau
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-14 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A Rails plugin for accessing device_aware_server API
22
+ email: dean@mintdigital.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/device_aware/device.rb
31
+ - lib/device_aware/version.rb
32
+ - lib/device_aware.rb
33
+ - LICENSE
34
+ has_rdoc: true
35
+ homepage: http://github.com/mintdigital/device_aware
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.6
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Make your Rails device aware
64
+ test_files: []
65
+