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['username'] = $argv[1];
|
||||
$opts['password'] = $argv[2];
|
||||
$opts['debug'] = 1; // CHANGE THIS; major spewage
|
||||
|
||||
$s = new Snaphax($opts);
|
||||
$result = $s->login();
|
||||
|
@ -27,7 +26,7 @@
|
|||
foreach ($result['snaps'] as $snap) {
|
||||
var_dump($snap['st']);
|
||||
if ($snap['st'] == SnapHax::STATUS_NEW) {
|
||||
echo "fetching $snap[id]";
|
||||
echo "fetching $snap[id]\n";
|
||||
$blob_data = $s->fetch($snap['id']);
|
||||
if ($blob_data)
|
||||
file_put_contents($snap['id'].'.jpg', $blob_data);
|
||||
|
|
37
snaphax.php
37
snaphax.php
|
@ -30,7 +30,8 @@
|
|||
'pattern' => '0001110111101110001111010101111011010001001110011000110001000110',
|
||||
'secret' => 'iEk21fuwZApXlz93750dmW22pw389dPwOk',
|
||||
'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')) {
|
||||
|
@ -53,8 +54,6 @@
|
|||
public function blob($snap_id, $username, $auth_token) {
|
||||
$un = urlencode($username);
|
||||
$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";
|
||||
$result = $this->postToEndpoint($url, array(
|
||||
'id' => $snap_id,
|
||||
|
@ -71,40 +70,18 @@
|
|||
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) {
|
||||
$ch = curl_init();
|
||||
|
||||
// set the url, number of POST vars, POST data
|
||||
curl_setopt($ch,CURLOPT_URL, $this->options['url'].$endpoint);
|
||||
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);
|
||||
curl_setopt($ch,CURLOPT_POST, count($post_data));
|
||||
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($post_data));
|
||||
|
||||
$this->debug(json_encode($post_data));
|
||||
|
||||
// execute post
|
||||
$this->debug('POST params: ' . json_encode($post_data));
|
||||
$result = curl_exec($ch);
|
||||
$this->debug($result);
|
||||
|
||||
|
@ -159,10 +136,6 @@
|
|||
$this->api = new SnaphaxApi($this->options);
|
||||
$this->auth_token = false;
|
||||
}
|
||||
private function error($text) {
|
||||
error_report($text);
|
||||
return false;
|
||||
}
|
||||
function login() {
|
||||
$ts = time();
|
||||
$out = $this->api->postToEndpoint(
|
||||
|
@ -183,7 +156,7 @@
|
|||
}
|
||||
function fetch($id) {
|
||||
if (!$this->auth_token) {
|
||||
return $this->error('no auth token');
|
||||
throw new Exception('no auth token');
|
||||
}
|
||||
$blob = $this->api->blob($id,
|
||||
$this->options['username'],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue