forked from sriharrsha/flipside.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sriharrsha.flipsidexmlclient.php
57 lines (46 loc) · 1.95 KB
/
sriharrsha.flipsidexmlclient.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
<?php
/**
* PHP Client for Flipkart Affilate API-[FLIPSIDE.IO]
* GitHub: https://github.com/sriharrsha/flipside.io
* License: MIT License
*
* @author Sri Harrsha <[email protected]>
* @version 0.1
*/
namespace sriharrsha;
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
class FlipsideXMLClient extends FlipsideIO
{
use GuzzleHttp\Client;
private $fkAffiliateId;
private $fkAffiliateToken;
private $responseType;
private $apiBaseUrl = 'https://affiliate-api.flipkart.net/affiliate/api/';
private $apiRequestUrl;
private $verifySsl = false;
//XML Client Constructor
function __construct($fkAffiliateId, $fkAffiliateToken, $responseType="xml")
{
$this->fkAffiliateToken = $fkAffiliateId;
$this->fkAffiliateToken = $fkAffiliateToken;
//Add the affiliateId and response_type to the base URL to complete it.
$this->apiRequestUrl.=$this->apiBaseUrl.'.'.$this->affiliateId.'.'.$this->responseType;
$client = new Client();
}
//Make Request to API
function makeRequest(){
$request = $client->createRequest('GET', $this->apiRequestUrl);
$request->setHeader('Content-Type', 'application/xml');
$request->setHeader('Cache-Control: no-cache');
$request->setHeader('Fk-Affiliate-Id',$this->fkAffiliateToken);
$request->setHeader('Fk-Affiliate-Token',$this->fkAffiliateToken);
$response = $client->send($request);
$responseCode = $response->getStatusCode();
if(($responseCode==410)||($responseCode==403)||($responseCode==401)){
returnApiError($responseCode);
}
return $response->xml();
}
}//End Of Class
?>