| @@ 39-61 (lines=23) @@ | ||
| 36 | * |
|
| 37 | * @return boolean|mixed |
|
| 38 | */ |
|
| 39 | public function getList($org) |
|
| 40 | { |
|
| 41 | // Build the request path. |
|
| 42 | $path = '/orgs/' . $org . '/members'; |
|
| 43 | ||
| 44 | $response = $this->client->get($this->fetchUrl($path)); |
|
| 45 | ||
| 46 | switch ($response->code) |
|
| 47 | { |
|
| 48 | case 302 : |
|
| 49 | // Requester is not an organization member. |
|
| 50 | return false; |
|
| 51 | break; |
|
| 52 | ||
| 53 | case 200 : |
|
| 54 | return json_decode($response->body); |
|
| 55 | break; |
|
| 56 | ||
| 57 | default : |
|
| 58 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); |
|
| 59 | break; |
|
| 60 | } |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * Check membership. |
|
| @@ 74-97 (lines=24) @@ | ||
| 71 | * @since 1.0 |
|
| 72 | * @throws \UnexpectedValueException |
|
| 73 | */ |
|
| 74 | public function check($user) |
|
| 75 | { |
|
| 76 | // Build the request path. |
|
| 77 | $path = '/user/following/' . $user; |
|
| 78 | ||
| 79 | $response = $this->client->get($this->fetchUrl($path)); |
|
| 80 | ||
| 81 | switch ($response->code) |
|
| 82 | { |
|
| 83 | case '204' : |
|
| 84 | // You are following this user |
|
| 85 | return true; |
|
| 86 | break; |
|
| 87 | ||
| 88 | case '404' : |
|
| 89 | // You are not following this user |
|
| 90 | return false; |
|
| 91 | break; |
|
| 92 | ||
| 93 | default : |
|
| 94 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); |
|
| 95 | break; |
|
| 96 | } |
|
| 97 | } |
|
| 98 | ||
| 99 | /** |
|
| 100 | * Check if one user follows another. |
|
| @@ 110-133 (lines=24) @@ | ||
| 107 | * @since 1.4.0 |
|
| 108 | * @throws \UnexpectedValueException |
|
| 109 | */ |
|
| 110 | public function checkUserFollowing($user, $target) |
|
| 111 | { |
|
| 112 | // Build the request path. |
|
| 113 | $path = "/user/$user/following/$target"; |
|
| 114 | ||
| 115 | $response = $this->client->get($this->fetchUrl($path)); |
|
| 116 | ||
| 117 | switch ($response->code) |
|
| 118 | { |
|
| 119 | case '204' : |
|
| 120 | // User is following the target |
|
| 121 | return true; |
|
| 122 | break; |
|
| 123 | ||
| 124 | case '404' : |
|
| 125 | // User is not following the target |
|
| 126 | return false; |
|
| 127 | break; |
|
| 128 | ||
| 129 | default : |
|
| 130 | throw new \UnexpectedValueException('Unexpected response code: ' . $response->code); |
|
| 131 | break; |
|
| 132 | } |
|
| 133 | } |
|
| 134 | ||
| 135 | /** |
|
| 136 | * Follow a user. |
|