Skip to content

Commit 9d0abb5

Browse files
committed
Merge pull request #1 from sweetcode/master
Customer
2 parents 1d93797 + bbe8412 commit 9d0abb5

File tree

2 files changed

+97
-1
lines changed

2 files changed

+97
-1
lines changed

lib/Nitrapi/Customer/Customer.php

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
3+
namespace Nitrapi;
4+
5+
use Nitrapi\Nitrapi;
6+
7+
class Customer {
8+
9+
private $api;
10+
private $data;
11+
12+
public function __construct(Nitrapi $api, $token) {
13+
14+
$this->api = $api;
15+
16+
$this->data = $api->dataGet("user?access_token=" . $token, null);
17+
18+
}
19+
20+
/**
21+
* Returns the user id.
22+
* @return string
23+
*/
24+
public function getUserId() {
25+
26+
return $this->get('id');
27+
28+
}
29+
30+
/**
31+
* Returns the username.
32+
* @return string username
33+
*/
34+
public function getUsername() {
35+
36+
return $this->get('username');
37+
38+
}
39+
40+
/**
41+
* Returns credit.
42+
* @return int
43+
*/
44+
public function getCredit() {
45+
46+
return $this->get('credit');
47+
48+
}
49+
50+
/**
51+
* Returns email address of the user.
52+
* @return string
53+
*/
54+
public function getEmail() {
55+
56+
return $this->get('email');
57+
58+
}
59+
60+
/**
61+
* Returns the personal details of the user.
62+
* @return array
63+
*/
64+
public function getPersonalData() {
65+
66+
return $this->get('profile');
67+
68+
}
69+
70+
/**
71+
* This function returns the whole data-set
72+
* @return mixed
73+
*/
74+
public function get($field = null) {
75+
76+
if($field === null) {
77+
return $this->data['user'];
78+
}
79+
80+
return $this->data['user'][$field];
81+
82+
}
83+
84+
85+
}

lib/Nitrapi/Nitrapi.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Nitrapi\Services\Service;
77
use Nitrapi\Services\ServiceCollection;
88
use Nitrapi\Services\ServiceFactory;
9+
use Nitrapi\Customer;
910

1011
define('NITRAPI_LIVE_URL', 'https://api.nitrado.net/');
1112

@@ -48,6 +49,16 @@ public function getServices(array $options = array()) {
4849
return $collection->getServices();
4950
}
5051

52+
/**
53+
* Gets the customer data set
54+
* @return Nitrapi\Customer
55+
*/
56+
public function getCustomer() {
57+
58+
return new Customer($this, $this->getAccessToken());
59+
60+
}
61+
5162
protected function setAccessToken($accessToken) {
5263
$this->accessToken = $accessToken;
5364

@@ -57,4 +68,4 @@ protected function setAccessToken($accessToken) {
5768
protected function getAccessToken() {
5869
return $this->accessToken;
5970
}
60-
}
71+
}

0 commit comments

Comments
 (0)