@@ -15,10 +15,11 @@ class RestClientException extends Exception {
15
15
class RestClient {
16
16
17
17
const COOKIE_JAR = '/tmp/rest-client-cookie ' ;
18
- const AGENT = 'rest-client-php/0.0.1 ' ;
18
+ const AGENT = 'rest-client-php/0.0.2 ' ;
19
19
20
20
public $ response_info ;
21
- public $ resonse_object ;
21
+ public $ response_object ;
22
+ public $ response_raw ;
22
23
23
24
public $ http_options = array ();
24
25
@@ -35,7 +36,7 @@ function get($url, $http_options = array()) {
35
36
$ this ->http_parse_message (
36
37
http_get ($ url , $ http_options , $ this ->response_info )
37
38
);
38
- return $ this ->resonse_object ->body ;
39
+ return $ this ->response_object ->body ;
39
40
}
40
41
41
42
function post ($ url , $ fields = array (), $ http_options = array ()) {
@@ -44,46 +45,46 @@ function post($url, $fields = array(), $http_options = array()) {
44
45
http_post_fields ($ url , $ fields , array (), $ http_options , $ this ->response_info ) :
45
46
http_post_data ($ url , $ fields , $ http_options , $ this ->response_info );
46
47
$ this ->http_parse_message ($ res );
47
- return $ this ->resonse_object ->body ;
48
+ return $ this ->response_object ->body ;
48
49
}
49
50
50
51
function put ($ url , $ data = '' , $ http_options = array ()) {
51
52
$ http_options = array_merge ($ this ->http_options , $ http_options );
52
53
$ this ->http_parse_message (
53
54
http_put_data ($ url , $ data , $ http_options , $ this ->response_info )
54
55
);
55
- return $ this ->resonse_object ->body ;
56
+ return $ this ->response_object ->body ;
56
57
}
57
58
58
59
function delete ($ url , $ http_options = array ()) {
59
60
$ http_options = array_merge ($ this ->http_options , $ http_options );
60
61
$ this ->http_parse_message (
61
62
http_request (HTTP_METH_DELETE , $ url , '' , $ http_options , $ this ->response_info )
62
63
);
63
- return $ this ->resonse_object ->body ;
64
+ return $ this ->response_object ->body ;
64
65
}
65
66
66
67
function http_parse_message ($ res ) {
67
-
68
- $ this ->resonse_object = http_parse_message ($ res );
68
+ $ this -> response_raw = $ res ;
69
+ $ this ->response_object = http_parse_message ($ res );
69
70
70
- if ($ this ->resonse_object ->responseCode == 404 ) {
71
+ if ($ this ->response_object ->responseCode == 404 ) {
71
72
throw new HttpServerException404 (
72
- $ this ->resonse_object ->responseStatus
73
+ $ this ->response_object ->responseStatus
73
74
);
74
75
}
75
76
76
- if ($ this ->resonse_object ->responseCode >= 400 && $ this ->resonse_object ->responseCode <=600 ) {
77
+ if ($ this ->response_object ->responseCode >= 400 && $ this ->response_object ->responseCode <=600 ) {
77
78
throw new HttpServerException (
78
- $ this ->resonse_object ->responseStatus ,
79
- $ this ->resonse_object ->responseCode
79
+ $ this ->response_object ->responseStatus ,
80
+ $ this ->response_object ->responseCode
80
81
);
81
82
}
82
83
83
- if (!in_array ($ this ->resonse_object ->responseCode , range (200 ,207 ))) {
84
+ if (!in_array ($ this ->response_object ->responseCode , range (200 ,207 ))) {
84
85
throw new RestClientException (
85
- $ this ->resonse_object ->responseStatus ,
86
- $ this ->resonse_object ->responseCode
86
+ $ this ->response_object ->responseStatus ,
87
+ $ this ->response_object ->responseCode
87
88
);
88
89
}
89
90
}
0 commit comments