Skip to content

Commit d87ee8a

Browse files
committed
Removed branch alias from composer, added collection key, injected curl instead of HTTP client, implemented curl on Resource::fetchAll
1 parent 8188b00 commit d87ee8a

File tree

5 files changed

+75
-16
lines changed

5 files changed

+75
-16
lines changed

composer.json

-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@
2828
"squizlabs/php_codesniffer": "~2.0",
2929
"phpunit/PHPUnit": "~4.5.0"
3030
},
31-
"extra": {
32-
"branch-alias": {
33-
"dev-master": "1.0-dev",
34-
"dev-develop": "1.0-dev"
35-
}
36-
},
3731
"autoload": {
3832
"psr-4": {
3933
"Zoho\\Subscriptions\\": "src/"

config/module.config.php

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
'resources' => [
2121
'Zoho\Subscriptions\Resource\Product' => [
2222
'path' => '/products',
23+
'collectionName' => 'products',
2324
'input-filter' => [
2425
0 => [
2526
'name' => 'name',
@@ -126,6 +127,7 @@
126127
],
127128
'Zoho\Subscriptions\Resource\Plan' => [
128129
'path' => '/plans',
130+
'collectionName' => 'plans',
129131
'input-filter' => [
130132
0 => [
131133
'name' => 'name',
@@ -332,6 +334,7 @@
332334
],
333335
'Zoho\Subscriptions\Resource\Addon' => [
334336
'path' => '/addons',
337+
'collectionName' => 'addons',
335338
'input-filter' => [
336339
0 => [
337340
'name' => '',
@@ -347,6 +350,7 @@
347350
],
348351
'Zoho\Subscriptions\Resource\Coupon' => [
349352
'path' => '/coupons',
353+
'collectionName' => 'coupons',
350354
'input-filter' => [
351355
0 => [
352356
'name' => '',
@@ -362,6 +366,7 @@
362366
],
363367
'Zoho\Subscriptions\Resource\Customer' => [
364368
'path' => '/customers',
369+
'collectionName' => 'customers',
365370
'input-filter' => [
366371
0 => [
367372
'name' => 'displayName',
@@ -625,6 +630,7 @@
625630
],
626631
'Zoho\Subscriptions\Resource\ContactPerson' => [
627632
'path' => '/customers/:customer_id/contactpersons',
633+
'collectionName' => 'contactpersons',
628634
'input-filter' => [
629635
0 => [
630636
'name' => 'contactpersonId',
@@ -780,6 +786,7 @@
780786
],
781787
'Zoho\Subscriptions\Resource\Subscription' => [
782788
'path' => '/subscriptions',
789+
'collectionName' => 'subscriptions',
783790
'input-filter' => [
784791
0 => [
785792
'name' => 'name',
@@ -857,6 +864,7 @@
857864
],
858865
'Zoho\Subscriptions\Resource\Invoice' => [
859866
'path' => '/invoices',
867+
'collectionName' => 'invoices',
860868
'input-filter' => [
861869
0 => [
862870
'name' => '',
@@ -872,6 +880,7 @@
872880
],
873881
'Zoho\Subscriptions\Resource\Payment' => [
874882
'path' => '/payments',
883+
'collectionName' => 'payments',
875884
'input-filter' => [
876885
0 => [
877886
'name' => '',
@@ -887,6 +896,7 @@
887896
],
888897
'Zoho\Subscriptions\Resource\HostedPage' => [
889898
'path' => '/hostedpages',
899+
'collectionName' => 'hostedpages',
890900
'input-filter' => [
891901
0 => [
892902
'name' => '',

src/Factory/ResourceAbstractFactory.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $
9696
$zohoConfig = $config['zoho'];
9797
$resourceConfig = $config['zoho']['resources'][$requestedName];
9898

99-
$opensslCapath = ini_get('openssl.capath');
99+
/*$opensslCapath = ini_get('openssl.capath');
100100
101101
if (!empty($opensslCapath)) {
102102
$clientConfig = ['sslcapath' => $opensslCapath];
@@ -111,7 +111,14 @@ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $
111111
'Authorization' => 'Zoho-authtoken ' . $zohoConfig['auth_token'],
112112
));
113113
114-
$resource = new Resource($httpClient);
114+
$resource = new Resource($httpClient);*/
115+
$curl = curl_init();
116+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
117+
curl_setopt($curl, CURLOPT_HTTPHEADER, [
118+
'Authorization: Zoho-authtoken ' . $zohoConfig['auth_token'],
119+
'X-com-zoho-subscriptions-organizationid: ' . $zohoConfig['organization_id'],
120+
]);
121+
$resource = new Resource($curl);
115122
$resource->setPath($resourceConfig['path']);
116123

117124
$entityClass = str_replace('Resource', 'Entity', $requestedName);

src/Service/Resource.php

+41-8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ class Resource implements InputFilterAwareInterface
3434
*/
3535
protected $httpClient;
3636

37+
/**
38+
* @var mixed
39+
*/
40+
protected $curl;
41+
42+
/**
43+
* @var string
44+
*/
45+
protected $collectionName;
46+
3747
/**
3848
* @var string
3949
*/
@@ -54,6 +64,28 @@ public function hasErrors()
5464
return count($this->errors) > 0;
5565
}
5666

67+
/**
68+
* Get the collectionName
69+
*
70+
* @return string
71+
*/
72+
public function getCollectionName()
73+
{
74+
return $this->collectionName;
75+
}
76+
77+
/**
78+
* Set the collectionName
79+
*
80+
* @param string $collectionName
81+
* @return Resource
82+
*/
83+
public function setCollectionName($collectionName)
84+
{
85+
$this->collectionName = $collectionName;
86+
return $this;
87+
}
88+
5789
/**
5890
* @return string
5991
*/
@@ -111,23 +143,24 @@ public function setHydrator(HydratorInterface $hydrator)
111143
/**
112144
* Constructor
113145
*
114-
* @param Http\Client $httpClient
146+
* @param $curl
115147
*/
116-
public function __construct(Http\Client $httpClient)
148+
public function __construct($curl)
117149
{
118-
$this->httpClient = $httpClient;
119-
$this->httpClient->setUri(self::ZOHO_API_ENDPOINT);
150+
$this->curl = $curl;
120151
}
121152

122153
/**
123154
* @return array
124155
*/
125156
public function fetchAll()
126157
{
127-
$this->httpClient->setMethod(Http\Request::METHOD_GET)
128-
->setUri(self::ZOHO_API_ENDPOINT . $this->getPath());
129-
130-
return $this->httpClient->send();
158+
curl_setopt($this->curl, CURLOPT_URL, self::ZOHO_API_ENDPOINT . $this->getPath());
159+
$result = curl_exec($this->curl);
160+
$result = json_decode($result);
161+
curl_close($this->curl);
162+
$collectioNName = $this->getCollectionName();
163+
return $result->$collectioNName;
131164
}
132165

133166
/**

src/Service/ResourceInterface.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: julien
5+
* Date: 26/06/15
6+
* Time: 10:06
7+
*/
8+
9+
namespace Zoho\Subscriptions\Service;
10+
11+
12+
interface ResourceInterface
13+
{
14+
15+
}

0 commit comments

Comments
 (0)