1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Audiens\AppnexusClient\repository; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Psr7\Response; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class RepositoryResponse |
9
|
|
|
*/ |
10
|
|
|
class RepositoryResponse |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
// OK RESPONSE {"response":{"status":"OK","count":1,"start_element":0,"num_elements":100,"id":4959394,"segment":{"id":4959394,"active":true,"description":null,"member_id":3847,"code":null,"provider":"","price":0,"short_name":"Test segment4996","expire_minutes":null,"category":null,"enable_rm_piggyback":false,"last_activity":"2016-03-23 11:21:48","max_usersync_pixels":null,"parent_segment_id":null,"querystring_mapping":null,"querystring_mapping_key_value":null},"dbg":{"instance":"41.api.prod.ams1","slave_hit":false,"db":"master","user::reads":0,"user::read_limit":100,"user::read_limit_seconds":60,"user::writes":2,"user::write_limit":60,"user::write_limit_seconds":60,"reads":0,"read_limit":1073741824,"read_limit_seconds":60,"writes":2,"write_limit":1073741824,"write_limit_seconds":60,"parent_dbg_info":{"instance":"44.bm-api.prod.nym2","slave_hit":false,"db":"master","user::reads":0,"user::read_limit":100,"user::read_limit_seconds":60,"user::writes":2,"user::write_limit":60,"user::write_limit_seconds":60,"reads":0,"read_limit":1073741824,"read_limit_seconds":60,"writes":2,"write_limit":1073741824,"write_limit_seconds":60,"time":88.721990585327,"version":"1.16.497","warnings":["Field `member_id` is not available"],"slave_lag":0,"start_microtime":1458732108.3462},"time":347.10383415222,"version":"1.16.497","warnings":[],"slave_lag":0,"start_microtime":1458732108.1427}}} |
|
|
|
|
14
|
|
|
// OK DELETE "{"response":{"status":"OK","count":1,"start_element":0,"num_elements":100,"id":"4967144","dbg":{"instance":"41.api.prod.ams1","slave_hit":true,"db":"10.2.78.139","user::reads":1,"user::read_limit":100,"user::read_limit_seconds":60,"user::writes":5,"user::write_limit":60,"user::write_limit_seconds":60,"reads":1,"read_limit":1073741824,"read_limit_seconds":60,"writes":5,"write_limit":1073741824,"write_limit_seconds":60,"parent_dbg_info":{"instance":"45.bm-api.prod.nym2","slave_hit":true,"db":"10.3.81.15", |
15
|
|
|
// KO RESPONSE {"response":{"error_id":"SYNTAX","error":"Invalid path \/segment - member is required","error_description":null,"error_code":null,"service":"segment","method":"POST","dbg":{"instance":"40.api.prod.ams1","slave_hit":false,"db":"master","user::reads":0,"user::read_limit":100,"user::read_limit_seconds":60,"user::writes":1,"user::write_limit":60,"user::write_limit_seconds":60,"reads":0,"read_limit":1073741824,"read_limit_seconds":60,"writes":1,"write_limit":1073741824,"write_limit_seconds":60,"parent_dbg_info":{"instance":"44.bm-api.prod.nym2","slave_hit":false,"db":"master","user::reads":0,"user::read_limit":100,"user::read_limit_seconds":60,"user::writes":1,"user::write_limit":60,"user::write_limit_seconds":60,"reads":0,"read_limit":1073741824,"read_limit_seconds":60,"writes":1,"write_limit":1073741824,"write_limit_seconds":60,"time":48.772096633911,"version":"1.16.497","warnings":[],"slave_lag":0,"start_microtime":1458732144.0725},"time":278.25713157654,"version":"1.16.497","warnings":[],"slave_lag":0,"start_microtime":1458732143.8902}}} |
|
|
|
|
16
|
|
|
|
17
|
|
|
const STATUS_SUCCESS = 'OK'; |
18
|
|
|
|
19
|
|
|
/** @var bool */ |
20
|
|
|
protected $successful = true; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $response; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return mixed |
27
|
|
|
*/ |
28
|
|
|
public function getResponse() |
29
|
|
|
{ |
30
|
|
|
return $this->response; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param mixed $response |
35
|
|
|
*/ |
36
|
|
|
public function setResponse($response) |
37
|
|
|
{ |
38
|
|
|
$this->response = $response; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return boolean |
43
|
|
|
*/ |
44
|
|
|
public function isSuccessful() |
45
|
|
|
{ |
46
|
|
|
return $this->successful; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param boolean $successful |
51
|
|
|
*/ |
52
|
|
|
public function setSuccessful($successful) |
53
|
|
|
{ |
54
|
|
|
$this->successful = $successful; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param Response $response |
59
|
|
|
* |
60
|
|
|
* @return RepositoryResponse |
61
|
|
|
*/ |
62
|
|
|
public static function fromResponse(Response $response) |
63
|
|
|
{ |
64
|
|
|
$self = new self(); |
65
|
|
|
|
66
|
|
|
$responseBody = $response->getBody()->getContents(); |
67
|
|
|
$response->getBody()->rewind(); |
68
|
|
|
|
69
|
|
|
$self->setResponse($responseBody); |
70
|
|
|
|
71
|
|
|
$responseArray = json_decode($responseBody, true); |
72
|
|
|
|
73
|
|
|
if (isset ($responseArray['response']['status'])) { |
74
|
|
|
$self->setSuccessful($responseArray['response']['status'] == self::STATUS_SUCCESS); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $self; |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.