Skip to content

Commit e240f59

Browse files
committed
Update OAuth1 keys to correct defect
1 parent 3375db9 commit e240f59

File tree

4 files changed

+107
-22
lines changed

4 files changed

+107
-22
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
# Changelog
22
All Notable changes to `yelp-php` will be documented in this file
33

4+
## 1.4.2 - 2015-11-23
5+
6+
### Added
7+
- Nothing
8+
9+
### Deprecated
10+
- Nothing
11+
12+
### Fixed
13+
- OAuth1 subscriber configuration issue. (https://github.com/stevenmaguire/yelp-php/issues/9)
14+
15+
### Removed
16+
- Nothing
17+
18+
### Security
19+
- Nothing
20+
421
## 1.4.1 - 2015-11-17
522

623
### Added

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ $ composer require stevenmaguire/yelp-php
2323

2424
```php
2525
$client = new Stevenmaguire\Yelp\Client(array(
26-
'consumer_key' => 'YOUR COSUMER KEY',
27-
'consumer_secret' => 'YOUR CONSUMER SECRET',
26+
'consumerKey' => 'YOUR COSUMER KEY',
27+
'consumerSecret' => 'YOUR CONSUMER SECRET',
2828
'token' => 'YOUR TOKEN',
29-
'token_secret' => 'YOUR TOKEN SECRET',
30-
'api_host' => 'api.yelp.com' // Optional, default 'api.yelp.com'
29+
'tokenSecret' => 'YOUR TOKEN SECRET',
30+
'apiHost' => 'api.yelp.com' // Optional, default 'api.yelp.com'
3131
));
3232
```
3333

src/Client.php

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,8 @@ class Client
9898
*/
9999
public function __construct($configuration = [])
100100
{
101-
$this->parseConfiguration($configuration);
102-
103-
$this->consumerKey = $configuration['consumerKey'];
104-
$this->consumerSecret = $configuration['consumerSecret'];
105-
$this->token = $configuration['token'];
106-
$this->tokenSecret = $configuration['tokenSecret'];
107-
$this->apiHost = $configuration['apiHost'];
108-
$this->createHttpClient();
101+
$this->parseConfiguration($configuration)
102+
->createHttpClient();
109103
}
110104

111105
/**
@@ -150,10 +144,10 @@ protected function createHttpClient()
150144
$stack = HandlerStack::create();
151145

152146
$middleware = new Oauth1([
153-
'consumerKey' => $this->consumerKey,
154-
'consumerSecret' => $this->consumerSecret,
147+
'consumer_key' => $this->consumerKey,
148+
'consumer_secret' => $this->consumerSecret,
155149
'token' => $this->token,
156-
'tokenSecret' => $this->tokenSecret
150+
'token_secret' => $this->tokenSecret
157151
]);
158152

159153
$stack->push($middleware);
@@ -179,14 +173,31 @@ public function getBusiness($businessId)
179173
return $this->request($businessPath);
180174
}
181175

176+
/**
177+
* Maps legacy configuration keys to updated keys.
178+
*
179+
* @param array $configuration
180+
*
181+
* @return array
182+
*/
183+
protected function mapConfiguration(array $configuration)
184+
{
185+
array_walk($configuration, function ($value, $key) use (&$configuration) {
186+
$newKey = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $key))));
187+
$configuration[$newKey] = $value;
188+
});
189+
190+
return $configuration;
191+
}
192+
182193
/**
183194
* Parse configuration using defaults
184195
*
185196
* @param array $configuration
186197
*
187-
* @return array $configuration
198+
* @return client
188199
*/
189-
protected function parseConfiguration(&$configuration = [])
200+
protected function parseConfiguration($configuration = [])
190201
{
191202
$defaults = array(
192203
'consumerKey' => null,
@@ -196,7 +207,11 @@ protected function parseConfiguration(&$configuration = [])
196207
'apiHost' => 'api.yelp.com'
197208
);
198209

199-
$configuration = array_merge($defaults, $configuration);
210+
$configuration = array_merge($defaults, $this->mapConfiguration($configuration));
211+
212+
array_walk($configuration, [$this, 'setConfig']);
213+
214+
return $this;
200215
}
201216

202217
/**
@@ -253,6 +268,23 @@ public function searchByPhone($attributes = [])
253268
return $this->request($searchPath);
254269
}
255270

271+
/**
272+
* Attempts to set a given value.
273+
*
274+
* @param mixed $value
275+
* @param string $key
276+
*
277+
* @return Client
278+
*/
279+
protected function setConfig($value, $key)
280+
{
281+
if (property_exists($this, $key)) {
282+
$this->$key = $value;
283+
}
284+
285+
return $this;
286+
}
287+
256288
/**
257289
* Set default location
258290
*
@@ -307,4 +339,20 @@ public function setSearchLimit($limit)
307339
}
308340
return $this;
309341
}
342+
343+
/**
344+
* Retrives the value of a given property from the client.
345+
*
346+
* @param string $property
347+
*
348+
* @return mixed|null
349+
*/
350+
public function __get($property)
351+
{
352+
if (property_exists($this, $property)) {
353+
return $this->$property;
354+
}
355+
356+
return null;
357+
}
310358
}

tests/YelpTest.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ class YelpTest extends \PHPUnit_Framework_TestCase
1515
public function setUp()
1616
{
1717
$this->client = new Yelp([
18-
'consumer_key' => getenv('YELP_CONSUMER_KEY'),
19-
'consumer_secret' => getenv('YELP_CONSUMER_SECRET'),
18+
'consumerKey' => getenv('YELP_CONSUMER_KEY'),
19+
'consumerSecret' => getenv('YELP_CONSUMER_SECRET'),
2020
'token' => getenv('YELP_ACCESS_TOKEN'),
21-
'token_secret' => getenv('YELP_ACCESS_TOKEN_SECRET'),
22-
'api_host' => 'api.yelp.com'
21+
'tokenSecret' => getenv('YELP_ACCESS_TOKEN_SECRET'),
22+
'apiHost' => 'api.yelp.com'
2323
]);
2424
}
2525

@@ -50,6 +50,26 @@ protected function getHttpClient($path, $status = 200, $payload = null)
5050
return $client;
5151
}
5252

53+
public function testConfigurationMapper()
54+
{
55+
$config = [
56+
'consumer_key' => uniqid(),
57+
'consumer_secret' => uniqid(),
58+
'token' => uniqid(),
59+
'token_secret' => uniqid(),
60+
'api_host' => uniqid()
61+
];
62+
63+
$client = new Yelp($config);
64+
65+
$this->assertEquals($config['consumer_key'], $client->consumerKey);
66+
$this->assertEquals($config['consumer_secret'], $client->consumerSecret);
67+
$this->assertEquals($config['token'], $client->token);
68+
$this->assertEquals($config['token_secret'], $client->tokenSecret);
69+
$this->assertEquals($config['api_host'], $client->apiHost);
70+
$this->assertNull($client->{uniqid()});
71+
}
72+
5373
/**
5474
* @expectedException Stevenmaguire\Yelp\Exception
5575
*/

0 commit comments

Comments
 (0)