customizable user agent and dead code removal
This commit is contained in:
parent
abc2a21abc
commit
6d2c957017
2 changed files with 6 additions and 34 deletions
|
@ -19,7 +19,6 @@
|
||||||
$opts = array();
|
$opts = array();
|
||||||
$opts['username'] = $argv[1];
|
$opts['username'] = $argv[1];
|
||||||
$opts['password'] = $argv[2];
|
$opts['password'] = $argv[2];
|
||||||
$opts['debug'] = 1; // CHANGE THIS; major spewage
|
|
||||||
|
|
||||||
$s = new Snaphax($opts);
|
$s = new Snaphax($opts);
|
||||||
$result = $s->login();
|
$result = $s->login();
|
||||||
|
@ -27,7 +26,7 @@
|
||||||
foreach ($result['snaps'] as $snap) {
|
foreach ($result['snaps'] as $snap) {
|
||||||
var_dump($snap['st']);
|
var_dump($snap['st']);
|
||||||
if ($snap['st'] == SnapHax::STATUS_NEW) {
|
if ($snap['st'] == SnapHax::STATUS_NEW) {
|
||||||
echo "fetching $snap[id]";
|
echo "fetching $snap[id]\n";
|
||||||
$blob_data = $s->fetch($snap['id']);
|
$blob_data = $s->fetch($snap['id']);
|
||||||
if ($blob_data)
|
if ($blob_data)
|
||||||
file_put_contents($snap['id'].'.jpg', $blob_data);
|
file_put_contents($snap['id'].'.jpg', $blob_data);
|
||||||
|
|
37
snaphax.php
37
snaphax.php
|
@ -30,7 +30,8 @@
|
||||||
'pattern' => '0001110111101110001111010101111011010001001110011000110001000110',
|
'pattern' => '0001110111101110001111010101111011010001001110011000110001000110',
|
||||||
'secret' => 'iEk21fuwZApXlz93750dmW22pw389dPwOk',
|
'secret' => 'iEk21fuwZApXlz93750dmW22pw389dPwOk',
|
||||||
'static_token' => 'm198sOkJEn37DjqZ32lpRu76xmw288xSQ9',
|
'static_token' => 'm198sOkJEn37DjqZ32lpRu76xmw288xSQ9',
|
||||||
'url' => 'https://feelinsonice.appspot.com'
|
'url' => 'https://feelinsonice.appspot.com',
|
||||||
|
'user_agent' => 'Snaphax 4.0.1 (iPad; iPhone OS 6.0; en_US)'
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!function_exists('curl_init')) {
|
if (!function_exists('curl_init')) {
|
||||||
|
@ -53,8 +54,6 @@
|
||||||
public function blob($snap_id, $username, $auth_token) {
|
public function blob($snap_id, $username, $auth_token) {
|
||||||
$un = urlencode($username);
|
$un = urlencode($username);
|
||||||
$ts = time();
|
$ts = time();
|
||||||
// $token = $this->hash($ts, $auth_token);
|
|
||||||
// $url = "https://feelinsonice.appspot.com/ph/blob?id=$snap_id&username=$un×tamp=$ts&req_token=$token";
|
|
||||||
$url = "/ph/blob";
|
$url = "/ph/blob";
|
||||||
$result = $this->postToEndpoint($url, array(
|
$result = $this->postToEndpoint($url, array(
|
||||||
'id' => $snap_id,
|
'id' => $snap_id,
|
||||||
|
@ -71,40 +70,18 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function httpGet($url) {
|
|
||||||
$ch = curl_init();
|
|
||||||
|
|
||||||
curl_setopt($ch,CURLOPT_URL, $this->options['url'].$url);
|
|
||||||
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
|
|
||||||
curl_setopt($ch,CURLOPT_USERAGENT,'Snaphax 4.0.1 (iPad; iPhone OS 6.0; en_US)');
|
|
||||||
|
|
||||||
$this->debug($url);
|
|
||||||
|
|
||||||
// execute post
|
|
||||||
$result = curl_exec($ch);
|
|
||||||
$this->debug($result);
|
|
||||||
|
|
||||||
// close connection
|
|
||||||
curl_close($ch);
|
|
||||||
|
|
||||||
return json_decode($result, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function postToEndpoint($endpoint, $post_data, $param1, $param2, $json=1) {
|
public function postToEndpoint($endpoint, $post_data, $param1, $param2, $json=1) {
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
// set the url, number of POST vars, POST data
|
// set the url, number of POST vars, POST data
|
||||||
curl_setopt($ch,CURLOPT_URL, $this->options['url'].$endpoint);
|
curl_setopt($ch,CURLOPT_URL, $this->options['url'].$endpoint);
|
||||||
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($ch,CURLOPT_USERAGENT,'Snaphax 4.0.1 (iPad; iPhone OS 6.0; en_US)');
|
curl_setopt($ch,CURLOPT_USERAGENT, $this->options['user_agent']);
|
||||||
|
|
||||||
$post_data['req_token'] = $this->hash($param1, $param2);
|
$post_data['req_token'] = $this->hash($param1, $param2);
|
||||||
curl_setopt($ch,CURLOPT_POST, count($post_data));
|
curl_setopt($ch,CURLOPT_POST, count($post_data));
|
||||||
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($post_data));
|
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($post_data));
|
||||||
|
$this->debug('POST params: ' . json_encode($post_data));
|
||||||
$this->debug(json_encode($post_data));
|
|
||||||
|
|
||||||
// execute post
|
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec($ch);
|
||||||
$this->debug($result);
|
$this->debug($result);
|
||||||
|
|
||||||
|
@ -159,10 +136,6 @@
|
||||||
$this->api = new SnaphaxApi($this->options);
|
$this->api = new SnaphaxApi($this->options);
|
||||||
$this->auth_token = false;
|
$this->auth_token = false;
|
||||||
}
|
}
|
||||||
private function error($text) {
|
|
||||||
error_report($text);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
function login() {
|
function login() {
|
||||||
$ts = time();
|
$ts = time();
|
||||||
$out = $this->api->postToEndpoint(
|
$out = $this->api->postToEndpoint(
|
||||||
|
@ -183,7 +156,7 @@
|
||||||
}
|
}
|
||||||
function fetch($id) {
|
function fetch($id) {
|
||||||
if (!$this->auth_token) {
|
if (!$this->auth_token) {
|
||||||
return $this->error('no auth token');
|
throw new Exception('no auth token');
|
||||||
}
|
}
|
||||||
$blob = $this->api->blob($id,
|
$blob = $this->api->blob($id,
|
||||||
$this->options['username'],
|
$this->options['username'],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue