wurfl_device 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +2 -2
- data/README.md +31 -7
- data/config/unicorn.conf.rb +13 -7
- data/lib/wurfl_device/cache.rb +215 -0
- data/lib/wurfl_device/capability.rb +5 -1
- data/lib/wurfl_device/cli.rb +59 -67
- data/lib/wurfl_device/settings.rb +595 -0
- data/lib/wurfl_device/ui.rb +1 -0
- data/lib/wurfl_device/user_agent.rb +75 -8
- data/lib/wurfl_device/user_agent_matcher.rb +153 -191
- data/lib/wurfl_device/version.rb +1 -1
- data/lib/wurfl_device/web_service.rb +10 -44
- data/lib/wurfl_device/xml_loader.rb +44 -37
- data/lib/wurfl_device.rb +41 -236
- data/spec/cache/device_spec.rb +7 -31
- data/spec/cache/user_agents_spec.rb +27 -0
- data/spec/spec_helper.rb +6 -1
- data/wurfl_device.gemspec +6 -3
- metadata +52 -38
- data/lib/wurfl_device/constants.rb +0 -43
- data/lib/wurfl_device/device.rb +0 -83
data/lib/wurfl_device/version.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'yaml'
|
2
3
|
require 'wurfl_device'
|
3
4
|
require 'sinatra/base'
|
@@ -5,57 +6,22 @@ require 'sinatra/base'
|
|
5
6
|
module WurflDevice
|
6
7
|
class WebService < Sinatra::Base
|
7
8
|
get '/' do
|
8
|
-
user_agent = request.env['HTTP_USER_AGENT']
|
9
|
-
|
10
|
-
|
11
|
-
{}.to_yaml
|
12
|
-
end
|
13
|
-
|
14
|
-
get '/:capa' do
|
15
|
-
user_agent = request.env['HTTP_USER_AGENT'] || '-'
|
16
|
-
device = WurflDevice.get_device_from_ua(user_agent)
|
17
|
-
return device.send(params[:capa]).to_yaml unless device.nil?
|
18
|
-
{}.to_yaml
|
19
|
-
end
|
20
|
-
|
21
|
-
get '/device/:id' do
|
22
|
-
device = WurflDevice.get_device_from_id(params[:id])
|
23
|
-
capabilities = {}
|
24
|
-
capabilities = device.capabilities unless device.nil?
|
9
|
+
user_agent = request.env['HTTP_USER_AGENT']
|
10
|
+
user_agent = WurflDevice::Settings::GENERIC if user_agent.nil? || user_agent.empty?
|
11
|
+
capabilities = WurflDevice.capabilities_from_user_agent(user_agent)
|
25
12
|
capabilities.to_yaml
|
26
13
|
end
|
27
14
|
|
28
|
-
get '/
|
29
|
-
|
30
|
-
|
31
|
-
capability =
|
15
|
+
get '/capability/:id' do
|
16
|
+
user_agent = request.env['HTTP_USER_AGENT']
|
17
|
+
user_agent = WurflDevice::Settings::GENERIC if user_agent.nil? || user_agent.empty?
|
18
|
+
capability = WurflDevice.capability_from_user_agent(params[:id], user_agent)
|
32
19
|
capability.to_yaml
|
33
20
|
end
|
34
21
|
|
35
|
-
get '/
|
36
|
-
capabilities = WurflDevice.
|
22
|
+
get '/device/:id' do
|
23
|
+
capabilities = WurflDevice.capabilities_from_id(params[:id])
|
37
24
|
capabilities.to_yaml
|
38
25
|
end
|
39
|
-
|
40
|
-
get '/actual_device/:id/:capa' do
|
41
|
-
capabilities = WurflDevice.get_actual_device(params[:id])
|
42
|
-
get_capa(params[:capa], capabilities).to_yaml
|
43
|
-
end
|
44
|
-
|
45
|
-
protected
|
46
|
-
def get_capa(capa, capabilities)
|
47
|
-
capability = nil
|
48
|
-
if capabilities.has_key?(capa)
|
49
|
-
capability = capabilities.send(capa)
|
50
|
-
else
|
51
|
-
capabilities.each_pair do |key, value|
|
52
|
-
if value.is_a?(Hash)
|
53
|
-
capability = value.send(capa)
|
54
|
-
break
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
return capability
|
59
|
-
end
|
60
26
|
end
|
61
27
|
end
|
@@ -1,49 +1,56 @@
|
|
1
|
-
|
2
|
-
require '
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'ox'
|
3
3
|
|
4
4
|
module WurflDevice
|
5
5
|
class XmlLoader
|
6
6
|
def self.load_xml_file(wurfl_file, &blk)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
last_updated = DateTime.parse(xml.xpath('//version/last_updated')[0].children.to_s) rescue nil
|
13
|
-
|
14
|
-
xml.xpath('//devices/*').each do |element|
|
15
|
-
wurfl_id = 'generic'
|
16
|
-
user_agent = 'generic'
|
17
|
-
fall_back = nil
|
18
|
-
if element.attributes["id"].to_s != "generic"
|
19
|
-
wurfl_id = element.attributes["id"].to_s
|
20
|
-
user_agent = element.attributes["user_agent"].to_s
|
21
|
-
user_agent = 'generic' if user_agent.empty?
|
22
|
-
fall_back = element.attributes["fall_back"].to_s
|
23
|
-
end
|
7
|
+
begin
|
8
|
+
file_contents = File.open(wurfl_file).read.force_encoding('UTF-8')
|
9
|
+
rescue => e
|
10
|
+
raise XMLFileError, e.message
|
11
|
+
end
|
24
12
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
13
|
+
# TODO apparently Ox doesn't support UCS/Unicode chars???
|
14
|
+
file_contents.gsub!(/\&\#x.+\;/, '')
|
15
|
+
|
16
|
+
# parse xml using Ox
|
17
|
+
doc = Ox.parse(file_contents)
|
18
|
+
doc.nodes.map do |elem1|
|
19
|
+
next unless elem1.value =~ /wurfl/i
|
20
|
+
elem1.nodes.map do |elem2|
|
21
|
+
# version info
|
22
|
+
version_info = Hash.new
|
23
|
+
if elem2.value == 'version'
|
24
|
+
elem2.nodes.map do |e|
|
25
|
+
if e.value == 'ver'
|
26
|
+
version_info[:version] = e.nodes[0].to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
yield version_info if block_given?
|
30
|
+
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
# devices list
|
33
|
+
if elem2.value == 'devices'
|
34
|
+
elem2.nodes.map do |device|
|
35
|
+
next unless device.value =~ /device/i
|
36
|
+
capabilities = Hash.new
|
37
|
+
capabilities['id'] = device.attributes[:id] || ''
|
38
|
+
capabilities['user_agent'] = device.attributes[:user_agent] || ''
|
39
|
+
capabilities['fall_back'] = device.attributes[:fall_back] || ''
|
40
|
+
|
41
|
+
device.nodes.map do |group|
|
42
|
+
next unless group.value =~ /group/i
|
43
|
+
group.nodes.map do |capability|
|
44
|
+
capabilities[group.attributes[:id]] ||= Hash.new
|
45
|
+
next unless capability.value =~ /capability/i
|
46
|
+
capabilities[group.attributes[:id]][capability.attributes[:name]] = capability.attributes[:value]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
yield capabilities if block_given?
|
50
|
+
end
|
38
51
|
end
|
39
|
-
device[group_id] = group_capa
|
40
52
|
end
|
41
|
-
|
42
|
-
devices[wurfl_id] = device
|
43
|
-
yield device if block_given?
|
44
53
|
end
|
45
|
-
|
46
|
-
[devices, version, last_updated]
|
47
54
|
end
|
48
55
|
end
|
49
56
|
end
|
data/lib/wurfl_device.rb
CHANGED
@@ -1,15 +1,24 @@
|
|
1
|
-
|
2
|
-
require 'redis'
|
3
|
-
|
1
|
+
# encoding: utf-8
|
4
2
|
require 'wurfl_device/version'
|
5
3
|
|
4
|
+
class Object
|
5
|
+
def to_actual_value
|
6
|
+
return self unless self.kind_of?(String)
|
7
|
+
return false if self =~ /^false/i
|
8
|
+
return true if self =~ /^true/i
|
9
|
+
return self.to_i if (self == self.to_i.to_s)
|
10
|
+
return self.to_f if (self == self.to_f.to_s)
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
6
15
|
module WurflDevice
|
7
|
-
autoload :Capability, 'wurfl_device/capability'
|
8
|
-
autoload :Constants, 'wurfl_device/constants'
|
9
|
-
autoload :Device, 'wurfl_device/device'
|
10
|
-
autoload :Handset, 'wurfl_device/handset'
|
11
16
|
autoload :UI, 'wurfl_device/ui'
|
12
17
|
autoload :CLI, 'wurfl_device/cli'
|
18
|
+
autoload :Capability, 'wurfl_device/capability'
|
19
|
+
autoload :Cache, 'wurfl_device/cache'
|
20
|
+
autoload :Handset, 'wurfl_device/handset'
|
21
|
+
autoload :Settings, 'wurfl_device/settings'
|
13
22
|
autoload :UserAgent, 'wurfl_device/user_agent'
|
14
23
|
autoload :UserAgentMatcher, 'wurfl_device/user_agent_matcher'
|
15
24
|
autoload :XmlLoader, 'wurfl_device/xml_loader'
|
@@ -21,249 +30,45 @@ module WurflDevice
|
|
21
30
|
end
|
22
31
|
|
23
32
|
class CacheError < WurflDeviceError; status_code(10); end
|
33
|
+
class XMLFileError < WurflDeviceError; status_code(11); end
|
24
34
|
|
25
35
|
class << self
|
26
|
-
attr_writer :ui
|
36
|
+
attr_writer :ui
|
27
37
|
|
28
38
|
def ui
|
29
39
|
@ui ||= UI.new
|
30
40
|
end
|
31
41
|
|
32
|
-
def
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
def tmp_dir
|
37
|
-
tmp_loc = File.join(Etc.systmpdir, 'wurfl_device')
|
38
|
-
FileUtils.mkdir_p(tmp_loc)
|
39
|
-
return tmp_loc
|
40
|
-
end
|
41
|
-
|
42
|
-
def get_actual_device(device_id)
|
43
|
-
capabilities = Capability.new
|
44
|
-
actual_device = get_actual_device_raw(device_id)
|
45
|
-
return nil if actual_device.nil?
|
46
|
-
actual_device.each_pair do |key, value|
|
47
|
-
if key =~ /^(.+)\:(.+)$/i
|
48
|
-
capabilities[$1] ||= Capability.new
|
49
|
-
capabilities[$1][$2] = parse_string_value(value)
|
50
|
-
else
|
51
|
-
capabilities[key] = parse_string_value(value)
|
52
|
-
end
|
53
|
-
end
|
42
|
+
def capabilities_from_id(device_id)
|
43
|
+
capabilities = Cache.build_capabilities(device_id)
|
54
44
|
capabilities
|
55
45
|
end
|
56
46
|
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
return Marshal::load(cached_device) unless cached_device.nil?
|
72
|
-
end
|
73
|
-
cached_device = db.hget(Constants::WURFL_USER_AGENTS, user_agent)
|
74
|
-
return Marshal::load(cached_device) unless cached_device.nil?
|
75
|
-
return nil
|
76
|
-
end
|
77
|
-
|
78
|
-
def save_device_in_ua_cache(user_agent, device)
|
79
|
-
db.hset(Constants::WURFL_USER_AGENTS_CACHED, user_agent, Marshal::dump(device))
|
80
|
-
end
|
81
|
-
|
82
|
-
def get_info
|
83
|
-
db.hgetall(Constants::WURFL_INFO)
|
84
|
-
end
|
85
|
-
|
86
|
-
# cache related
|
87
|
-
def clear_user_agent_cache
|
88
|
-
db.del(Constants::WURFL_USER_AGENTS_CACHED)
|
89
|
-
end
|
90
|
-
|
91
|
-
def clear_cache
|
92
|
-
db.keys("#{Constants::WURFL}*").each { |k| db.del k }
|
93
|
-
end
|
94
|
-
|
95
|
-
def clear_devices
|
96
|
-
db.keys("#{Constants::WURFL_DEVICES}*").each { |k| db.del k }
|
97
|
-
db.del(Constants::WURFL_INITIALIZED)
|
98
|
-
db.del(Constants::WURFL_INFO)
|
99
|
-
end
|
100
|
-
|
101
|
-
def get_user_agents
|
102
|
-
db.hkeys(Constants::WURFL_USER_AGENTS)
|
103
|
-
end
|
104
|
-
|
105
|
-
def get_user_agents_in_cache
|
106
|
-
db.hkeys(Constants::WURFL_USER_AGENTS_CACHED)
|
107
|
-
end
|
108
|
-
|
109
|
-
def get_user_agents_in_index(matcher)
|
110
|
-
db.hkeys("#{Constants::WURFL_DEVICES_INDEX}#{matcher}")
|
111
|
-
end
|
112
|
-
|
113
|
-
def get_actual_device_raw(device_id)
|
114
|
-
db.hgetall("#{Constants::WURFL_DEVICES}#{device_id}")
|
115
|
-
end
|
116
|
-
|
117
|
-
def get_devices
|
118
|
-
db.keys("#{Constants::WURFL_DEVICES}*")
|
119
|
-
end
|
120
|
-
|
121
|
-
def get_indexes
|
122
|
-
db.keys("#{Constants::WURFL_DEVICES_INDEX}*")
|
123
|
-
end
|
124
|
-
|
125
|
-
def rebuild_user_agent_cache
|
126
|
-
# update the cache's
|
127
|
-
db.del(Constants::WURFL_USER_AGENTS)
|
128
|
-
get_indexes.each { |k| db.del(k) }
|
129
|
-
|
130
|
-
get_devices.each do |device_id|
|
131
|
-
device_id.gsub!(Constants::WURFL_DEVICES, '')
|
132
|
-
actual_device = get_actual_device(device_id)
|
133
|
-
next if actual_device.nil?
|
134
|
-
user_agent = actual_device.user_agent
|
135
|
-
next if user_agent.nil? || user_agent.empty?
|
136
|
-
device = Device.new(device_id)
|
137
|
-
next unless device.is_valid?
|
138
|
-
db.hset(Constants::WURFL_USER_AGENTS, user_agent, Marshal::dump(device))
|
139
|
-
|
140
|
-
next if user_agent =~ /^DO_NOT_MATCH/i
|
141
|
-
matcher = UserAgentMatcher.new.get_index(user_agent)
|
142
|
-
db.hset("#{Constants::WURFL_DEVICES_INDEX}#{matcher}", user_agent, device_id)
|
143
|
-
end
|
144
|
-
|
145
|
-
get_user_agents_in_cache.each do |user_agent|
|
146
|
-
db.hdel(Constants::WURFL_USER_AGENTS_CACHED, user_agent)
|
147
|
-
UserAgentMatcher.new.match(user_agent)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def is_initialized?
|
152
|
-
status = parse_string_value(db.get(Constants::WURFL_INITIALIZED))
|
153
|
-
return false if status.nil?
|
154
|
-
return false unless status.is_a?(TrueClass)
|
155
|
-
true
|
156
|
-
end
|
157
|
-
|
158
|
-
def initialize_cache
|
159
|
-
# make sure only process can initialize at a time
|
160
|
-
# don't initialize if there is another initializing
|
161
|
-
lock_the_cache_for_initializing do
|
162
|
-
db.set(Constants::WURFL_INITIALIZED, false)
|
163
|
-
|
164
|
-
# download & parse the wurfl xml
|
165
|
-
xml_list = Array.new
|
166
|
-
xml_list << download_wurfl_xml_file
|
167
|
-
xml_list << download_wurfl_web_patch_xml_file
|
168
|
-
|
169
|
-
xml_list.each do |xml_file|
|
170
|
-
(devices, version, last_updated) = XmlLoader.load_xml_file(xml_file) do |capabilities|
|
171
|
-
device_id = capabilities.delete('id')
|
172
|
-
next if device_id.nil? || device_id.empty?
|
173
|
-
db.del("#{Constants::WURFL_DEVICES}#{device_id}")
|
174
|
-
user_agent = capabilities.delete('user_agent')
|
175
|
-
fall_back = capabilities.delete('fall_back')
|
176
|
-
|
177
|
-
device_id.strip! unless device_id.nil?
|
178
|
-
user_agent.strip! unless user_agent.nil?
|
179
|
-
fall_back.strip! unless fall_back.nil?
|
180
|
-
|
181
|
-
db.hset("#{Constants::WURFL_DEVICES}#{device_id}", "id", device_id)
|
182
|
-
db.hset("#{Constants::WURFL_DEVICES}#{device_id}", "user_agent", user_agent)
|
183
|
-
db.hset("#{Constants::WURFL_DEVICES}#{device_id}", "fall_back", fall_back)
|
184
|
-
|
185
|
-
capabilities.each_pair do |key, value|
|
186
|
-
if value.is_a?(Hash)
|
187
|
-
value.each_pair do |k, v|
|
188
|
-
db.hset("#{Constants::WURFL_DEVICES}#{device_id}", "#{key.to_s}:#{k.to_s}", v)
|
189
|
-
end
|
190
|
-
else
|
191
|
-
db.hset("#{Constants::WURFL_DEVICES}#{device_id}", "#{key.to_s}", value)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
next if version.nil?
|
197
|
-
db.set(Constants::WURFL_INITIALIZED, true)
|
198
|
-
db.hset(Constants::WURFL_INFO, "version", version)
|
199
|
-
db.hset(Constants::WURFL_INFO, "last_updated", Time.now)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
def parse_string_value(value)
|
205
|
-
return value unless value.is_a?(String)
|
206
|
-
# convert to utf-8 (wurfl.xml encoding format)
|
207
|
-
value.force_encoding('UTF-8')
|
208
|
-
return false if value =~ /^false/i
|
209
|
-
return true if value =~ /^true/i
|
210
|
-
return value.to_i if (value == value.to_i.to_s)
|
211
|
-
return value.to_f if (value == value.to_f.to_s)
|
212
|
-
value
|
213
|
-
end
|
214
|
-
protected
|
215
|
-
def download_wurfl_xml_file
|
216
|
-
wurfl_xml_source = "http://sourceforge.net/projects/wurfl/files/WURFL/2.2/wurfl-2.2.xml.gz"
|
217
|
-
FileUtils.mkdir_p(WurflDevice.tmp_dir)
|
218
|
-
FileUtils.cd(WurflDevice.tmp_dir)
|
219
|
-
`wget --timeout=60 -qN -- #{wurfl_xml_source} > /dev/null`
|
220
|
-
raise "Failed to download wurfl-latest.xml.gz" unless $? == 0
|
221
|
-
|
222
|
-
wurfl_xml_filename = File.basename(wurfl_xml_source)
|
223
|
-
`gunzip -qc #{wurfl_xml_filename} > wurfl.xml`
|
224
|
-
raise 'Failed to unzip wurfl-latest.xml.gz' unless $? == 0
|
225
|
-
|
226
|
-
wurfl_xml_file_extracted = File.join(WurflDevice.tmp_dir, 'wurfl.xml')
|
227
|
-
raise "wurfl.xml does not exists!" unless File.exists?(wurfl_xml_file_extracted)
|
228
|
-
|
229
|
-
wurfl_xml_file_extracted
|
230
|
-
end
|
231
|
-
|
232
|
-
def download_wurfl_web_patch_xml_file
|
233
|
-
wurfl_web_patch_xml_source = 'http://sourceforge.net/projects/wurfl/files/WURFL/2.2/web_browsers_patch.xml'
|
234
|
-
`wget --timeout=60 -qN -- #{wurfl_web_patch_xml_source} > /dev/null`
|
235
|
-
raise "Failed to download wurfl-latest.xml.gz" unless $? == 0
|
236
|
-
|
237
|
-
wurfl_web_patch_xml = File.join(WurflDevice.tmp_dir, 'web_browsers_patch.xml')
|
238
|
-
raise "web_browsers_patch.xml does not exists!" unless File.exists?(wurfl_web_patch_xml)
|
239
|
-
|
240
|
-
wurfl_web_patch_xml
|
241
|
-
end
|
242
|
-
|
243
|
-
def lock_the_cache_for_initializing
|
244
|
-
start_at = Time.now
|
245
|
-
success = false
|
246
|
-
while Time.now - start_at < Constants::LOCK_TIMEOUT
|
247
|
-
success = true and break if try_lock
|
248
|
-
sleep Constants::LOCK_SLEEP
|
47
|
+
def capability_from_user_agent(capability, user_agent)
|
48
|
+
capability_group = nil
|
49
|
+
|
50
|
+
if Settings::CAPABILITY_GROUPS.include?(capability)
|
51
|
+
group_keys = Array.new
|
52
|
+
Settings::CAPABILITY_TO_GROUP.select { |k, v| v == capability }.each_pair { |k, v| group_keys << "#{v}:#{k}" }
|
53
|
+
group_vals = Cache.storage.hmget(Cache::UserAgents.build_cache_id(user_agent), *group_keys)
|
54
|
+
return Cache.parse_actual_capabilities(Hash[*group_keys.zip(group_vals).flatten])[capability] if (group_vals.select { |v| v.nil? }.empty?)
|
55
|
+
else
|
56
|
+
capability_mapped = capability
|
57
|
+
capability_group = Settings::CAPABILITY_TO_GROUP[capability]
|
58
|
+
capability_mapped = "#{capability_group}:#{capability}" unless capability_group.nil?
|
59
|
+
actual_capability = WurflDevice::Cache::UserAgents.get(user_agent, capability_mapped)
|
60
|
+
return actual_capability.to_actual_value unless actual_capability.nil?
|
249
61
|
end
|
250
|
-
if block_given? and success
|
251
|
-
yield
|
252
|
-
unlock
|
253
|
-
end
|
254
|
-
end
|
255
62
|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
return true if db.setnx(Constants::WURFL_INITIALIZING, @expires_at)
|
260
|
-
return false if db.get(Constants::WURFL_INITIALIZING).to_f > now
|
261
|
-
return true if db.getset(Constants::WURFL_INITIALIZING, @expires_at).to_f <= now
|
262
|
-
return false
|
63
|
+
capabilities = capabilities_from_user_agent(user_agent)
|
64
|
+
return capabilities[capability] if capability_group.nil?
|
65
|
+
return capabilities[capability_group][capability]
|
263
66
|
end
|
264
67
|
|
265
|
-
def
|
266
|
-
|
68
|
+
def capabilities_from_user_agent(user_agent)
|
69
|
+
matcher = UserAgentMatcher.new
|
70
|
+
matcher.match(user_agent)
|
71
|
+
matcher.capabilities
|
267
72
|
end
|
268
73
|
end
|
269
74
|
end
|
data/spec/cache/device_spec.rb
CHANGED
@@ -1,37 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'yaml'
|
3
2
|
|
4
3
|
describe WurflDevice do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
it "generic device should exists" do
|
11
|
-
device = WurflDevice.get_actual_device(WurflDevice::Constants::GENERIC)
|
12
|
-
device.id.should == WurflDevice::Constants::GENERIC
|
13
|
-
end
|
14
|
-
|
15
|
-
it "check for user agent matcher" do
|
16
|
-
{
|
17
|
-
'nokia_x3_02_ver1' => 'NokiaX3-02/5.0 (05.60) Profile/MIDP-2.1 Configuration/CLDC-1.1',
|
18
|
-
'nokia_n90_ver1_sub2052414' => 'NokiaN90-1/3.0541.5.2 Series60/2.8 Profile/MIDP-2.0 Configuration/CLDC-1.1',
|
19
|
-
|
20
|
-
#'opwv_v6_generic' => 'SAMSUNG-B5712C/1.0 RTK-E/1.0 DF/1.0 Release/08.17.2007 Browser/Openwave6.2.3.3.c.1.101 Profile/MIDP-2.0 Configuration/CLDC-1.1/*MzU3ODEwMDIwNzc5ODgx UP.Browser/6.',
|
21
|
-
'samsung_a707_ver1_subshpvppr5' => 'SAMSUNG-SGH-A707/1.0 SHP/VPP/R5 NetFront/3.3 SMM-MMS/1.2.0 profile/MIDP-2.0 configuration/CLDC-1.1',
|
22
|
-
'samsung_u700_ver1_subua' => 'SAMSUNG-SGH-U700/1.0 SHP/VPP/R5 NetFront/3.4 SMM-MMS/1.2.0 profile/MIDP-2.0 configuration/CLDC-1.1',
|
23
|
-
#'generic' => 'SAMSUNG-SCH-M710/(null)ID4 (compatible; MSIE 6.0; Windows CE; PPC) Opera 9.5',
|
24
|
-
|
25
|
-
'sonyericsson_k700i_ver1subr2ay' => 'SonyEricssonK700i/R2AC SEMC-Browser/4.0.2 Profile/MIDP-2.0 Configuration/CLDC-1.1',
|
26
|
-
'sonyericsson_k550i_ver1_subr1jd' => 'SonyEricssonK550i/R1JD Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1',
|
27
|
-
|
28
|
-
'blackberry8520_ver1_subos5' => 'BlackBerry8520/5.0.0.592 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/603',
|
4
|
+
it "devices should be many" do
|
5
|
+
WurflDevice::Cache::Devices.entries.count.should > 0
|
6
|
+
end
|
29
7
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
end
|
8
|
+
it "generic device should exists" do
|
9
|
+
capabilities = WurflDevice.capabilities_from_id(WurflDevice::Settings::GENERIC)
|
10
|
+
capabilities.id.nil?.should == false
|
11
|
+
capabilities.id.should == WurflDevice::Settings::GENERIC
|
36
12
|
end
|
37
13
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
describe WurflDevice do
|
5
|
+
it "check for user agent matcher" do
|
6
|
+
{
|
7
|
+
'nokia_x3_02_ver1' => 'NokiaX3-02/5.0 (05.60) Profile/MIDP-2.1 Configuration/CLDC-1.1',
|
8
|
+
'nokia_n90_ver1_sub2052314' => 'NokiaN90-1/3.0541.5.2 Series60/2.8 Profile/MIDP-2.0 Configuration/CLDC-1.1',
|
9
|
+
|
10
|
+
'opwv_v6_generic' => 'SAMSUNG-B5712C/1.0 RTK-E/1.0 DF/1.0 Release/08.17.2007 Browser/Openwave6.2.3.3.c.1.101 Profile/MIDP-2.0 Configuration/CLDC-1.1/*MzU3ODEwMDIwNzc5ODgx UP.Browser/6.',
|
11
|
+
'samsung_a707_ver1_subshpvppr5' => 'SAMSUNG-SGH-A707/1.0 SHP/VPP/R5 NetFront/3.3 SMM-MMS/1.2.0 profile/MIDP-2.0 configuration/CLDC-1.1',
|
12
|
+
'samsung_u700_ver1_subua' => 'SAMSUNG-SGH-U700/1.0 SHP/VPP/R5 NetFront/3.4 SMM-MMS/1.2.0 profile/MIDP-2.0 configuration/CLDC-1.1',
|
13
|
+
'generic' => 'SAMSUNG-SCH-M710/(null)ID4 (compatible; MSIE 6.0; Windows CE; PPC) Opera 9.5',
|
14
|
+
|
15
|
+
'sonyericsson_k700i_ver1subr2ay' => 'SonyEricssonK700i/R2AC SEMC-Browser/4.0.2 Profile/MIDP-2.0 Configuration/CLDC-1.1',
|
16
|
+
'sonyericsson_k550i_ver1_subr1jd' => 'SonyEricssonK550i/R1JD Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1',
|
17
|
+
|
18
|
+
'blackberry8520_ver1_subos5' => 'BlackBerry8520/5.0.0.592 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/603',
|
19
|
+
|
20
|
+
'generic' => "'M', 'Y' 'P', 'H', 'O', 'N', 'E' Browser/WAP2.0 Profile/MIDP-2.0 Configuration/CLDC-1.1",
|
21
|
+
}.each_pair do |device_id, user_agent|
|
22
|
+
device = WurflDevice.capabilities_from_user_agent(user_agent)
|
23
|
+
device.id.nil?.should == false
|
24
|
+
device.id.should == device_id
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,7 +7,6 @@ else
|
|
7
7
|
require 'rubygems'
|
8
8
|
end
|
9
9
|
|
10
|
-
require 'faker'
|
11
10
|
require 'rspec/core'
|
12
11
|
|
13
12
|
$LOAD_PATH.unshift(File.expand_path('../lib', File.dirname(__FILE__)))
|
@@ -17,4 +16,10 @@ RSpec.configure do |config|
|
|
17
16
|
config.color_enabled = true
|
18
17
|
end
|
19
18
|
|
19
|
+
use_fake_redis = ENV['NO_FAKE_REDIS'].nil? ? true : false
|
20
|
+
|
21
|
+
require 'fakeredis' if use_fake_redis
|
20
22
|
require 'wurfl_device'
|
23
|
+
|
24
|
+
xml_file ||= WurflDevice::Settings.default_wurfl_xml_file
|
25
|
+
WurflDevice::Cache::initialize_cache(xml_file) unless WurflDevice::Cache.initialized?
|
data/wurfl_device.gemspec
CHANGED
@@ -16,9 +16,10 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.rubyforge_project = 'wurfl_device'
|
18
18
|
|
19
|
-
s.add_dependency '
|
20
|
-
s.add_dependency 'nokogiri'
|
19
|
+
s.add_dependency 'hiredis'
|
21
20
|
s.add_dependency 'redis'
|
21
|
+
s.add_dependency 'thor'
|
22
|
+
s.add_dependency 'ox'
|
22
23
|
s.add_dependency 'text'
|
23
24
|
s.add_dependency 'sinatra'
|
24
25
|
s.add_dependency 'unicorn'
|
@@ -28,8 +29,10 @@ Gem::Specification.new do |s|
|
|
28
29
|
s.add_development_dependency 'rspec-core', '~> 2.0'
|
29
30
|
s.add_development_dependency 'rspec-expectations', '~> 2.0'
|
30
31
|
s.add_development_dependency 'rr', '~> 1.0'
|
31
|
-
s.add_development_dependency 'faker', '~> 0.9'
|
32
32
|
s.add_development_dependency 'simplecov', '~> 0.5.3'
|
33
|
+
s.add_development_dependency 'fakeredis', '~> 0.2.2'
|
34
|
+
|
35
|
+
s.requirements << 'redis server'
|
33
36
|
|
34
37
|
s.files = `git ls-files`.split("\n")
|
35
38
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|