Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

yandex_detector gem (http://api.yandex.ru/detector/)

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

Introduction

yandex_detector is a Ruby 1.9.2 wrapper for Yandex.Detector API (http://api.yandex.ru/detector/) wich allows to detect mobile device's properties by it's request headers.

This document describes installation and usage of yandex_detector.

Please report issues on Github.

For feedback, suggestions, etc. write to aishek@gmail.com.

Build Status

Installation

To install:

gem install yandex_detector

or with a Gemfile:

gem 'yandex_detector'
bundle install

Usage

Usage in Rails:

require 'yandex_detector'

# API call timeout in seconds (default is 2 seconds)
timeout = 2

result = YandexDetector.detect request.headers, timeout

Usage in Ruby program:

require 'yandex_detector'

# HTTP headers, you need at least one to perform detect
headers = Hash.new[
  'user-agent',           'value1'
  'profile',              'value2',
  'wap-profile',          'value3',
  'x-wap-profile',        'value4',
  'x-operamini-phone-ua', 'value1'
]
# API call timeout in seconds (default is 2 seconds)
timeout = 2

result = YandexDetector.detect headers, timeout

Result object have following helpers:

result.error?
result.error_message

result.success?
result.iphone?
result.android?
result.blackberry?

Please, see complete list of available helpers.

Documentation

The RubyDoc documentation is available online.

How it works

yandex_detector perform Yandex's API service call via network if there are at least one of needed headers provided. Please, consider right timeout value and fallback on timeout for your application to prevent slow execution.

Author

Idea & implementation — Alexandr Borisov (aishek@gmail.com)

Licence

yandex_detector is licensed under MIT

Something went wrong with that request. Please try again.