handset_detection 4.1.5 → 4.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.
- checksums.yaml +4 -4
- data/lib/handset_detection/cache.rb +3 -0
- data/lib/handset_detection/cache/memory.rb +81 -0
- data/lib/handset_detection/hd4.rb +35 -10
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 18473df45643ba28520b8290e44302de24a98206
         | 
| 4 | 
            +
              data.tar.gz: 1f30d683bd3f207f2cc71d4b6e4666cb8b904491
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e7f8da9077e3e11fd3d19906ee1b6c0764704723c67c70b6654d5da4899a7c133017e614970d7ef83798e42642bd7938aa19214ce8e2ba46d8d1a8d9610aae13
         | 
| 7 | 
            +
              data.tar.gz: e9d8faf7dff0ace05b716cce2a653cd707cd1778a70423850647eda35ae41f500428d383719b0167836495900097105f23faf779b35368f5426d3fe1a3428582
         | 
| @@ -29,6 +29,7 @@ require 'handset_detection/cache/filesystem' | |
| 29 29 | 
             
            require 'handset_detection/cache/memcached'
         | 
| 30 30 | 
             
            require 'handset_detection/cache/rails'
         | 
| 31 31 | 
             
            require 'handset_detection/cache/none'
         | 
| 32 | 
            +
            require 'handset_detection/cache/memory'
         | 
| 32 33 |  | 
| 33 34 | 
             
            # Cache class for HandsetDetection
         | 
| 34 35 | 
             
            #
         | 
| @@ -58,6 +59,8 @@ class Cache | |
| 58 59 | 
             
                  @cache = RailsCache.new(@config)
         | 
| 59 60 | 
             
                elsif config.include?('cache') and config['cache'].include?('none')
         | 
| 60 61 | 
             
                  @cache = None.new(@config)
         | 
| 62 | 
            +
                elsif config.include?('cache') and config['cache'].include?('memory')
         | 
| 63 | 
            +
                  @cache = Memory.new(@config)
         | 
| 61 64 | 
             
                elsif defined? Rails
         | 
| 62 65 | 
             
                  @cache = RailsCache.new(@config)
         | 
| 63 66 | 
             
                else
         | 
| @@ -0,0 +1,81 @@ | |
| 1 | 
            +
            #--
         | 
| 2 | 
            +
            # Copyright (c) Richard Uren 2016 <richard@teleport.com.au>
         | 
| 3 | 
            +
            # All Rights Reserved
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # LICENSE: Redistribution and use in source and binary forms, with or
         | 
| 6 | 
            +
            # without modification, are permitted provided that the following
         | 
| 7 | 
            +
            # conditions are met: Redistributions of source code must retain the
         | 
| 8 | 
            +
            # above copyright notice, this list of conditions and the following
         | 
| 9 | 
            +
            # disclaimer. Redistributions in binary form must reproduce the above
         | 
| 10 | 
            +
            # copyright notice, this list of conditions and the following disclaimer
         | 
| 11 | 
            +
            # in the documentation and/or other materials provided with the
         | 
| 12 | 
            +
            # distribution.
         | 
| 13 | 
            +
            #
         | 
| 14 | 
            +
            # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
         | 
| 15 | 
            +
            # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
         | 
| 16 | 
            +
            # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
         | 
| 17 | 
            +
            # NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
         | 
| 18 | 
            +
            # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
         | 
| 19 | 
            +
            # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
         | 
| 20 | 
            +
            # OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
         | 
| 21 | 
            +
            # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
         | 
| 22 | 
            +
            # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
         | 
| 23 | 
            +
            # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
         | 
| 24 | 
            +
            # DAMAGE.
         | 
| 25 | 
            +
            #++
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            begin
         | 
| 28 | 
            +
              require 'thread_safe'
         | 
| 29 | 
            +
            rescue LoadError
         | 
| 30 | 
            +
            end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
            class Memory
         | 
| 33 | 
            +
              # Construct a new Memory cache object.
         | 
| 34 | 
            +
              #
         | 
| 35 | 
            +
              # +param+  string dir
         | 
| 36 | 
            +
              #
         | 
| 37 | 
            +
              def initialize(config={})
         | 
| 38 | 
            +
                @thread_safe = (config.include?('cache') and config['cache'].include?('memory') and config['cache']['memory']['thread_safe']) ? true : false
         | 
| 39 | 
            +
                make_cache unless defined?(@@c)
         | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              # Get key
         | 
| 43 | 
            +
              #
         | 
| 44 | 
            +
              def get(key)
         | 
| 45 | 
            +
                data, exp = @@c[key]
         | 
| 46 | 
            +
                return nil if exp.nil? or Time.now.to_i > exp
         | 
| 47 | 
            +
                data 
         | 
| 48 | 
            +
              end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
              # Set key
         | 
| 51 | 
            +
              #
         | 
| 52 | 
            +
              def set(key, data, ttl)
         | 
| 53 | 
            +
                @@c[key] = [data, Time.now.to_i + ttl]
         | 
| 54 | 
            +
                true
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
              # Delete key
         | 
| 58 | 
            +
              #
         | 
| 59 | 
            +
              def del(key)
         | 
| 60 | 
            +
                @@c.delete key
         | 
| 61 | 
            +
                true
         | 
| 62 | 
            +
              end
         | 
| 63 | 
            +
              
         | 
| 64 | 
            +
              # Flush cache
         | 
| 65 | 
            +
              def flush
         | 
| 66 | 
            +
                make_cache
         | 
| 67 | 
            +
                true
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
              # Initialize the cache data structure
         | 
| 71 | 
            +
              #
         | 
| 72 | 
            +
              def make_cache
         | 
| 73 | 
            +
                if !@thread_safe 
         | 
| 74 | 
            +
                  @@c = {}
         | 
| 75 | 
            +
                elsif defined?(ThreadSafe)
         | 
| 76 | 
            +
                  @@c = ThreadSafe::Hash.new
         | 
| 77 | 
            +
                else
         | 
| 78 | 
            +
                  raise 'ThreadSafe is required to use the Memory cache.'
         | 
| 79 | 
            +
                end    
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
            end
         | 
| @@ -333,8 +333,9 @@ class HD4 < Base | |
| 333 333 |  | 
| 334 334 | 
             
                # If caching enabled then check cache
         | 
| 335 335 | 
             
                unless @config['cache_requests'].blank?
         | 
| 336 | 
            +
                  headers = {}
         | 
| 336 337 | 
             
                  request_body.each { |k, v| headers[k.downcase] = v }
         | 
| 337 | 
            -
                  headers = headers.sort | 
| 338 | 
            +
                  headers = Hash[headers.sort]
         | 
| 338 339 | 
             
                  fast_key = JSON.generate(headers).gsub(/ /, '')
         | 
| 339 340 | 
             
                  if reply = @cache.read(fast_key)
         | 
| 340 341 | 
             
                    @reply = reply
         | 
| @@ -366,13 +367,29 @@ class HD4 < Base | |
| 366 367 | 
             
                result
         | 
| 367 368 | 
             
              end
         | 
| 368 369 |  | 
| 370 | 
            +
              # Get the local file path of the Ultimate database ZIP file.
         | 
| 371 | 
            +
              #
         | 
| 372 | 
            +
              # +return+ string path
         | 
| 373 | 
            +
              #
         | 
| 374 | 
            +
              def device_get_zip_path
         | 
| 375 | 
            +
                File.join(@config['filesdir'], "ultimate.zip")
         | 
| 376 | 
            +
              end
         | 
| 377 | 
            +
             | 
| 378 | 
            +
              # Get the local file path of the Ultimate database ZIP file.
         | 
| 379 | 
            +
              #
         | 
| 380 | 
            +
              # +return+ string path
         | 
| 381 | 
            +
              #
         | 
| 382 | 
            +
              def community_get_zip_path
         | 
| 383 | 
            +
                File.join(@config['filesdir'], "communityultimate.zip")
         | 
| 384 | 
            +
              end
         | 
| 385 | 
            +
             | 
| 369 386 | 
             
              # Fetch an archive from handset detection which contains all the device specs and matching trees as individual json files.
         | 
| 370 387 | 
             
              #
         | 
| 371 388 | 
             
              # +param+ void
         | 
| 372 389 | 
             
              # +return+ hd_specs data on success, false otherwise
         | 
| 373 390 | 
             
              #
         | 
| 374 391 | 
             
              def device_fetch_archive
         | 
| 375 | 
            -
                path =  | 
| 392 | 
            +
                path = device_get_zip_path
         | 
| 376 393 | 
             
                unless @config['local_archive_source'].blank?
         | 
| 377 394 | 
             
                  FileUtils.cp File.join(@config['local_archive_source'], "ultimate.zip"), path
         | 
| 378 395 | 
             
                  return install_archive path 
         | 
| @@ -383,11 +400,15 @@ class HD4 < Base | |
| 383 400 | 
             
                if data.blank? 
         | 
| 384 401 | 
             
                  return set_error 299, 'Error : FetchArchive failed. Bad Download. File is zero length'
         | 
| 385 402 | 
             
                elsif data.length < 9000000
         | 
| 386 | 
            -
                   | 
| 387 | 
            -
             | 
| 388 | 
            -
                     | 
| 403 | 
            +
                  begin
         | 
| 404 | 
            +
                    trythis = JSON.parse data
         | 
| 405 | 
            +
                    if trythis and trythis.include?('status') and trythis.include('message')
         | 
| 406 | 
            +
                      return set_error trythis['status'].to_i, trythis['message']
         | 
| 407 | 
            +
                    end
         | 
| 408 | 
            +
                  rescue Exception
         | 
| 409 | 
            +
                    return set_error 299, "Error : FetchArchive failed. Cannot parse the file."
         | 
| 389 410 | 
             
                  end
         | 
| 390 | 
            -
                  set_error 299, "Error : FetchArchive failed. Bad Download. File too short at #{data.length} bytes."
         | 
| 411 | 
            +
                  return set_error 299, "Error : FetchArchive failed. Bad Download. File too short at #{data.length} bytes."
         | 
| 391 412 | 
             
                end
         | 
| 392 413 |  | 
| 393 414 | 
             
                begin
         | 
| @@ -404,7 +425,7 @@ class HD4 < Base | |
| 404 425 | 
             
              # +return+ hd_specs data on success, false otherwise
         | 
| 405 426 | 
             
              #
         | 
| 406 427 | 
             
              def community_fetch_archive
         | 
| 407 | 
            -
                path =  | 
| 428 | 
            +
                path = community_get_zip_path
         | 
| 408 429 | 
             
                unless @config['local_archive_source'].blank?
         | 
| 409 430 | 
             
                  FileUtils.cp File.join(@config['local_archive_source'], "communityultimate.zip"), path
         | 
| 410 431 | 
             
                  return install_archive path 
         | 
| @@ -415,9 +436,13 @@ class HD4 < Base | |
| 415 436 | 
             
                if data.blank?
         | 
| 416 437 | 
             
                  return set_error 299, 'Error : FetchArchive failed. Bad Download. File is zero length'
         | 
| 417 438 | 
             
                elsif data.length < 900000
         | 
| 418 | 
            -
                   | 
| 419 | 
            -
             | 
| 420 | 
            -
                     | 
| 439 | 
            +
                  begin
         | 
| 440 | 
            +
                    trythis = JSON.parse data
         | 
| 441 | 
            +
                    if not trythis.blank? and trythis.include?('status') and trythis.include?('message')
         | 
| 442 | 
            +
                      return set_error trythis['status'].to_int, trythis['message']
         | 
| 443 | 
            +
                    end
         | 
| 444 | 
            +
                  rescue Exception
         | 
| 445 | 
            +
                    return set_error 299, "Error : FetchArchive failed. Cannot parse the file."
         | 
| 421 446 | 
             
                  end
         | 
| 422 447 | 
             
                  return set_error 299, "Error : FetchArchive failed. Bad Download. File too short at #{data.length} bytes."
         | 
| 423 448 | 
             
                end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: handset_detection
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 4.1. | 
| 4 | 
            +
              version: 4.1.6
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Handset Detection
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2016- | 
| 11 | 
            +
            date: 2016-12-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: dalli
         | 
| @@ -49,6 +49,7 @@ files: | |
| 49 49 | 
             
            - lib/handset_detection/cache.rb
         | 
| 50 50 | 
             
            - lib/handset_detection/cache/filesystem.rb
         | 
| 51 51 | 
             
            - lib/handset_detection/cache/memcached.rb
         | 
| 52 | 
            +
            - lib/handset_detection/cache/memory.rb
         | 
| 52 53 | 
             
            - lib/handset_detection/cache/none.rb
         | 
| 53 54 | 
             
            - lib/handset_detection/cache/rails.rb
         | 
| 54 55 | 
             
            - lib/handset_detection/device.rb
         |