-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwoot.php
107 lines (73 loc) · 2.32 KB
/
woot.php
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
require('workflow.php');
/**
* Name: Woot
* Description: This PHP class object provides a simple function that makes a call to woots api for daily deals.
* Author: Robert Ventrone
* Revised: 01/25/2015
* Version: 0.0.1
*
*
* things to do:
* - pass in a site you want the deals for
* - make it so you can add in your own api key
*/
class Woot {
public $alfred;
public $wootKey;
public $baseURL;
public $apiVersion;
function __construct() {
$this->alfred = new Workflows();
}
public function urlBuilder($type) {
$this->baseURL = 'http://api.woot.com/';
$this->wootKey = 'key='.$this->alfred->read('wootkey.json')[0];
$this->apiVersion = '2/events.json?';
$this->eventType = 'eventType='.$type.'&';
return $this->baseURL.$this->apiVersion.$this->eventType.$this->wootKey;
}
public function setKey($key = null) {
if(!file_exists('wootkey.json')){
fopen("wootkey.json", "w");
}
$this->alfred->write([$key],'wootkey.json');
}
public function getAllDeals() {
$url = $this->urlBuilder('Daily');
$ch = curl_init();
// Set url
curl_setopt($ch, CURLOPT_URL, $url);
// Set method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
// Set options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Send the request & save response to $resp
$resp = curl_exec($ch);
if(!$resp) {
echo "Error";
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
} else {
$resp = json_decode($resp);
foreach($resp as $site){
date_default_timezone_set('UTC');
$date = new DateTime($site->EndDate);
$formatedDate = $date->format('m-d-Y');
foreach($site->Offers as $offer){
$price = $offer->Items[0]->SalePrice;
if($offer->SoldOut){
$soldOut = 'Item sold out';
} else {
$soldOut = 'Get it while its hot';
}
}
$subtitle = $site->Site.' - $'.$price.' - '.$soldOut;
$this->alfred->result($site->Id,$site->Site,$site->Title,$subtitle,'/icons/wooteicon.png');
}
echo $this->alfred->toxml();
}
// Close request to clear up some resources
curl_close($ch);
}
}
?>