File tree Expand file tree Collapse file tree 2 files changed +97
-1
lines changed Expand file tree Collapse file tree 2 files changed +97
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 6
6
use Nitrapi \Services \Service ;
7
7
use Nitrapi \Services \ServiceCollection ;
8
8
use Nitrapi \Services \ServiceFactory ;
9
+ use Nitrapi \Customer ;
9
10
10
11
define ('NITRAPI_LIVE_URL ' , 'https://api.nitrado.net/ ' );
11
12
@@ -48,6 +49,16 @@ public function getServices(array $options = array()) {
48
49
return $ collection ->getServices ();
49
50
}
50
51
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
+
51
62
protected function setAccessToken ($ accessToken ) {
52
63
$ this ->accessToken = $ accessToken ;
53
64
@@ -57,4 +68,4 @@ protected function setAccessToken($accessToken) {
57
68
protected function getAccessToken () {
58
69
return $ this ->accessToken ;
59
70
}
60
- }
71
+ }
You can’t perform that action at this time.
0 commit comments