Skip to content

Commit cf65562

Browse files
committed
Initial library classes added
1 parent 92cd295 commit cf65562

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1177
-0
lines changed

lib/AbandonedCheckout.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tareq
5+
* Date: 8/18/16
6+
* Time: 9:50 AM
7+
*/
8+
9+
namespace PHPShopify;
10+
11+
12+
13+
class AbandonedCheckout extends ShopifyAPI
14+
{
15+
protected $resourceKey = 'checkout';
16+
}

lib/ApplicationCharge.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tareq
5+
* Date: 8/18/16
6+
* Time: 9:50 AM
7+
*/
8+
9+
namespace PHPShopify;
10+
11+
12+
13+
class ApplicationCharge extends ShopifyAPI
14+
{
15+
protected $resourceKey = 'application_charge';
16+
}

lib/Article.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tareq
5+
* Date: 8/18/16
6+
* Time: 3:18 PM
7+
*/
8+
9+
namespace PHPShopify;
10+
11+
12+
class Article extends ShopifyAPI
13+
{
14+
protected $resourceKey = 'article';
15+
}

lib/Asset.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tareq
5+
* Date: 8/18/16
6+
* Time: 3:39 PM
7+
*/
8+
9+
namespace PHPShopify;
10+
11+
12+
class Asset extends ShopifyAPI
13+
{
14+
protected $resourceKey = 'asset';
15+
}

lib/Blog.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tareq
5+
* Date: 8/18/16
6+
* Time: 10:46 AM
7+
*/
8+
9+
namespace PHPShopify;
10+
11+
12+
class Blog extends ShopifyAPI
13+
{
14+
public $resourceKey = 'blog';
15+
public $childResource = array(
16+
'Article',
17+
);
18+
}

lib/CarrierService.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tareq
5+
* Date: 8/19/16
6+
* Time: 10:49 AM
7+
*/
8+
9+
namespace PHPShopify;
10+
11+
12+
class CarrierService extends ShopifyAPI
13+
{
14+
protected $resourceKey = 'carrier_service';
15+
}

lib/Collect.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tareq
5+
* Date: 8/19/16
6+
* Time: 10:54 AM
7+
*/
8+
9+
namespace PHPShopify;
10+
11+
12+
class Collect extends ShopifyAPI
13+
{
14+
protected $resourceKey = 'collect';
15+
}

lib/Comment.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tareq
5+
* Date: 8/19/16
6+
* Time: 10:58 AM
7+
*/
8+
9+
namespace PHPShopify;
10+
11+
12+
class Comment extends ShopifyAPI
13+
{
14+
protected $resourceKey = 'comment';
15+
protected $customPostActions = array(
16+
'spam',
17+
'not_spam' => 'notSpam',
18+
'approve',
19+
'remove',
20+
'restore',
21+
);
22+
}

lib/Country.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tareq
5+
* Date: 8/19/16
6+
* Time: 11:44 AM
7+
*/
8+
9+
namespace PHPShopify;
10+
11+
12+
class Country extends ShopifyAPI
13+
{
14+
protected $resourceKey = 'country';
15+
protected $childResource = array(
16+
'Province',
17+
);
18+
19+
protected function pluralizeKey()
20+
{
21+
return 'countries';
22+
}
23+
}

lib/CurlRequest.php

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: tareq
5+
* Date: 8/17/16
6+
* Time: 2:50 PM
7+
*/
8+
9+
namespace PHPShopify;
10+
11+
12+
use PHPShopify\Exception\CurlException;
13+
14+
class CurlRequest
15+
{
16+
public static function init($url, $httpHeaders = array())
17+
{
18+
// Create Curl resource
19+
$ch = curl_init();
20+
21+
// Set URL
22+
curl_setopt($ch, CURLOPT_URL, $url);
23+
24+
//Return the transfer as a string
25+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
26+
27+
$headers = array();
28+
foreach($httpHeaders as $key => $value) {
29+
$headers[] = "$key: $value";
30+
}
31+
//Set HTTP Headers
32+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
33+
34+
return $ch;
35+
36+
}
37+
38+
public static function get($url, $httpHeaders = array())
39+
{
40+
//Initialize the Curl resource
41+
$ch = self::init($url, $httpHeaders);
42+
43+
return self::processRequest($ch);
44+
}
45+
46+
public static function post($url, $data, $httpHeaders = array())
47+
{
48+
$ch = self::init($url, $httpHeaders);
49+
//Set the request type
50+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
51+
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
52+
53+
return self::processRequest($ch);
54+
}
55+
56+
public static function put($url, $data, $httpHeaders = array())
57+
{
58+
$ch = self::init($url, $httpHeaders);
59+
//set the request type
60+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
61+
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
62+
63+
return self::processRequest($ch);
64+
}
65+
66+
public static function delete($url, $httpHeaders = array())
67+
{
68+
$ch = self::init($url, $httpHeaders);
69+
//set the request type
70+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
71+
72+
return self::processRequest($ch);
73+
}
74+
75+
public static function processRequest($ch)
76+
{
77+
// $output contains the output string
78+
$output = curl_exec($ch);
79+
80+
if(curl_errno($ch)) {
81+
throw new Exception\CurlException(curl_errno($ch) . ' : ' . curl_error($ch));
82+
}
83+
84+
// close curl resource to free up system resources
85+
curl_close($ch);
86+
87+
return $output;
88+
}
89+
}

0 commit comments

Comments
 (0)