- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
$query = http_build_query([
'access_key' => 'YOUR_ACCESS_KEY',
'ua' => 'Mozilla/5.0 (iPad; CPU OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1',
]);
$ch = curl_init('https://api.userstack.com/detect?' . $query);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$json = curl_exec($ch);
curl_close($ch);
$api_result = json_decode($json, true);
if ($api_result['device']['type'] === 'tablet') {
echo "It's a tablet";
}
import requests
params = {
'access_key': 'YOUR_ACCESS_KEY',
'ua': 'Mozilla/5.0 (iPad; CPU OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1'
}
api_result = requests.get('http://api.userstack.com/detect', params)
if api_result.json()['device']['type'] == 'tablet':
print "It's a tablet";
const http = require('http');
const querystring = require('querystring');
let query = {
access_key: 'YOUR_ACCESS_KEY',
ua: 'Mozilla/5.0 (iPad; CPU OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1'
};
http.get(`http://api.userstack.com/detect?${querystring.stringify(query)}`, response => {
let data = '';
response.on('data', chunk => data += chunk);
response.on('end', () => {
let api_response = JSON.parse(data);
if(api_response.device && api_response.device.type === 'tablet') {
console.log("It's a tablet.");
}
});
});
$.ajax({
url: 'https://api.userstack.com/detect',
data: {
access_key: 'YOUR_ACCESS_KEY',
ua: 'Mozilla/5.0 (iPad; CPU OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1'
},
dataType: 'jsonp',
success: function(json) {
if (json.device && json.device.type == 'tablet') {
console.log("It's a tablet.");
}
}
});
package main
import (
"encoding/json"
"fmt"
"net/http"
)
type Device struct {
Type string
}
type Response struct {
Success bool
Device Device
}
func main() {
httpClient := http.Client{}
req, err := http.NewRequest("GET", "http://api.userstack.com/detect", nil)
if err != nil {
panic(err)
}
q := req.URL.Query()
q.Add("access_key", "YOUR_ACCESS_KEY")
q.Add("ua", "Mozilla/5.0 (iPad; CPU OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1")
req.URL.RawQuery = q.Encode()
res, err := httpClient.Do(req)
if err != nil {
panic(err)
}
defer res.Body.Close()
response := Response{}
json.NewDecoder(res.Body).Decode(&response)
if(response.Device.Type == "tablet") {
fmt.Printf("It's a tablet.")
}
}
require 'net/http'
require 'json'
params = {
:access_key => "YOUR_ACCESS_KEY",
:ua => "Mozilla/5.0 (iPad; CPU OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1"
}
uri = URI('http://api.userstack.com/detect')
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get(uri)
json = JSON.parse(response)
if json['device']['type'] == 'tablet'
print("It's a tablet.")
end