Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ public function getAttribute($key)

// First we will check for the presence of a mutator for the set operation
// which simply lets the developers tweak the attribute as it is set.
if (method_exists($this, 'get' . Str::studly($key) . 'Attribute')) {
$method = 'get' . Str::studly($key) . 'Attribute';

$method = 'get' . Str::studly($key) . 'Attribute';
if (method_exists($this, $method)) {
return $this->{$method}($value);
}

Expand Down
14 changes: 10 additions & 4 deletions src/Services/IPApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,29 @@ public function boot()
}
}

/** {@inheritDoc} */
/**
* {@inheritDoc}
* @throws \RuntimeException
*/
public function locate($ip)
{
// Get data from client
// Get data from the client
$data = $this->client->get('json/' . $ip);

// Verify server response
if ($this->client->getErrors() !== null) {
throw new Exception('Request failed (' . $this->client->getErrors() . ')');
throw new \RuntimeException("Unexpected ip-api.com response: {$this->client->getErrors()}");
}

// Parse body content
$json = json_decode($data[0]);
if (! is_object($json) || ! property_exists($json, 'status')) {
throw new \RuntimeException("Unexpected ip-api.com response: {$json->message}");
}

// Verify response status
if ($json->status !== 'success') {
throw new Exception('Request failed (' . $json->message . ')');
throw new \RuntimeException("Failed ip-api.com response: {$json->message}");
}

return $this->hydrate([
Expand Down