public static function get() { $res = RestLayer::get('v1/token', array(), array('Authentication' => "Key " . Settings::$appSecret)); if ($res[0] == 200) { $body = json_decode($res[2], true); $expiration = date("U", strtotime($body['expired_at'])); self::$access_token = $body['token']; self::$expiration = $expiration; self::$retailer_id = $body['retailer_id']; } return self::$access_token; }
public function get($id) { $res = RestLayer::get("v1/stores/{$id}", array(), array('Authorization' => "Bearer " . self::token())); if ($res[0] == 200) { self::from_json(json_decode($res[2], true)); } else { if ($res[0] == 404) { return null; } else { throw new \Exception("Unexpected HTTP status code {$res[0]}, {$res[1]}"); } } }
public function find($name) { $res = RestLayer::get('v1/brands/search', array("q" => $name), array('Authorization' => 'Bearer ' . self::token())); if ($res[0] == 200) { return self::from_json($res[1]); } else { if ($res[0] == 404) { return null; } else { throw new \Exception("Unexpected HTTP status code {$res[0]}, {$res[1]}"); } } }
public function show() { $method = "get"; $endpoint = "v1/leaflet"; $expected_status = 201; $fields = []; $fields['id'] = is_int($this->id) && $this->id != null ? $this->id : null; $res = RestLayer::get($method, $endpoint, $fields, array('Authorization' => "Bearer " . self::token())); if ($res[0] != $expected_status) { throw new \Exception("Unexpected HTTP status code {$res[0]}, {$res[1]}"); } else { return self::from_json(json_decode($res[2], true)); } }
public function all() { $res = RestLayer::get('v1/cities', array(), array("Authorization" => "Bearer " . self::token())); if ($res[0] == 200) { $cities = array(); foreach ($res[1] as $city) { $cities[] = self::from_json($city); } return $cities; } else { if ($res[0] == 404) { return null; } else { throw new \Exception("Unexpected HTTP status code {$res[0]}, {$res[1]}"); } } }