Sha256: 0e49cda8c92258bd64ca322bbf555b10b8c5b5f59aa738bac14d9d852cd4e71e

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

require "deviceatlasapi/version"
require "uri"
require 'httparty'

module DeviceAtlasApi
  autoload :ControllerHelpers, 'deviceatlasapi/controller'

  def self.setup
    yield self
  end

  class Client

    def initialize request
      @user_agent = request.env['HTTP_USER_AGENT']
      @headers = prepare_headers request
      @cloud_host = 'api.deviceatlascloud.com'
    end

    def get_device_data
      url = prepare_url
      HTTParty.get(url, @headers)["properties"]
    end

    private

    def prepare_headers request
      {
          'HTTP_X_PROFILE' => request.env['HTTP_X_PROFILE'],
          'HTTP_X_WAP_PROFILE' => request.env['HTTP_X_WAP_PROFILE'],
          'HTTP_X_ATT_DEVICEID' => request.env['HTTP_X_ATT_DEVICEID'],
          'HTTP_ACCEPT' => request.env['HTTP_ACCEPT'],
          'HTTP_ACCEPT_LANGUAGE' => request.env['HTTP_ACCEPT_LANGUAGE'],
          'HTTP_X_DEVICE_USER_AGENT' => request.env['HTTP_X_DEVICE_USER_AGENT'],
          'HTTP_X_ORIGINAL_USER_AGENT' => request.env['HTTP_X_ORIGINAL_USER_AGENT'],
          'HTTP_X_OPERAMINI_PHONE_UA' => request.env['HTTP_X_OPERAMINI_PHONE_UA'],
          'HTTP_X_SKYFIRE_PHONE' => request.env['HTTP_X_SKYFIRE_PHONE'],
          'HTTP_X_BOLT_PHONE_UA' => request.env['HTTP_X_BOLT_PHONE_UA'],
          'HTTP_DEVICE_STOCK_UA' => request.env['HTTP_DEVICE_STOCK_UA'],
          'HTTP_X_UCBROWSER_DEVICE_UA' => request.env['HTTP_X_UCBROWSER_DEVICE_UA'],
      }
    end

    def prepare_url
      "http://#{@cloud_host}/v1/detect/properties?licencekey=#{ENV['DEVICE_ATLAS_LICENCE_KEY']}&useragent=#{URI.escape(@user_agent)}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
deviceatlasapi-0.0.4 lib/deviceatlasapi.rb
deviceatlasapi-0.0.3 lib/deviceatlasapi.rb