Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
/**
 * Copyright 2014 Facebook, Inc.
 *
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
 * use, copy, modify, and distribute this software in source code or binary
 * form for use in connection with the web services and APIs provided by
 * Facebook.
 *
 * As with any software that integrates with the Facebook platform, your use
 * of this software is subject to the Facebook Developer Principles and
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
 * shall be included in all copies or substantial portions of the software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 */
namespace Facebook;

/**
 * Class FacebookResponse
 * @package Facebook
 * @author Fosco Marotto <fjm@fb.com>
 * @author David Poll <depoll@fb.com>
 */
class FacebookResponse
{

  /**
   * @var FacebookRequest The request which produced this response
   */
  private $request;

  /**
   * @var array The decoded response from the Graph API
   */
  private $responseData;

  /**
   * @var string The raw response from the Graph API
   */
  private $rawResponse;

  /**
   * @var bool Indicates whether sent ETag matched the one on the FB side
   */
  private $etagHit;

  /**
   * @var string ETag received with the response. `null` in case of ETag hit.
   */
  private $etag;

  /**
   * Creates a FacebookResponse object for a given request and response.
   *
   * @param FacebookRequest $request
   * @param array $responseData JSON Decoded response data
   * @param string $rawResponse Raw string response
   * @param bool $etagHit Indicates whether sent ETag matched the one on the FB side
   * @param string|null $etag ETag received with the response. `null` in case of ETag hit.
   */
  public function __construct($request, $responseData, $rawResponse, $etagHit = false, $etag = null)
  {
    $this->request = $request;
    $this->responseData = $responseData;
    $this->rawResponse = $rawResponse;
    $this->etagHit = $etagHit;
    $this->etag = $etag;
  }

  /**
   * Returns the request which produced this response.
   *
   * @return FacebookRequest
   */
  public function getRequest()
  {
    return $this->request;
  }

  /**
   * Returns the decoded response data.
   *
   * @return array
   */
  public function getResponse()
  {
    return $this->responseData;
  }

  /**
   * Returns the raw response
   *
   * @return string
   */
  public function getRawResponse()
  {
    return $this->rawResponse;
  }

  /**
   * Returns true if ETag matched the one sent with a request
   *
   * @return bool
   */
  public function isETagHit()
  {
    return $this->etagHit;
  }

  /**
   * Returns the ETag
   *
   * @return string
   */
  public function getETag()
  {
    return $this->etag;
  }

  /**
   * Gets the result as a GraphObject.  If a type is specified, returns the
   *   strongly-typed subclass of GraphObject for the data.
   *
   * @param string $type
   *
   * @return mixed
   */
  public function getGraphObject($type = 'Facebook\GraphObject') {
    return (new GraphObject($this->responseData))->cast($type);
  }

  /**
   * Returns an array of GraphObject returned by the request.  If a type is
   * specified, returns the strongly-typed subclass of GraphObject for the data.
   *
   * @param string $type
   *
   * @return mixed
   */
  public function getGraphObjectList($type = 'Facebook\GraphObject') {
    $out = array();
    $data = $this->responseData->data;
    $dataLength = count($data);
    for ($i = 0; $i < $dataLength; $i++) {
      $out[] = (new GraphObject($data[$i]))->cast($type);
    }
    return $out;
  }

  /**
   * If this response has paginated data, returns the FacebookRequest for the
   *   next page, or null.
   *
   * @return FacebookRequest|null
   */
  public function getRequestForNextPage()
  {
    return $this->handlePagination('next');
  }

  /**
   * If this response has paginated data, returns the FacebookRequest for the
   *   previous page, or null.
   *
   * @return FacebookRequest|null
   */
  public function getRequestForPreviousPage()
  {
    return $this->handlePagination('previous');
  }

  /**
   * Returns the FacebookRequest for the previous or next page, or null.
   *
   * @param string $direction
   *
   * @return FacebookRequest|null
   */
  private function handlePagination($direction) {
    if (isset($this->responseData->paging->$direction)) {
      $url = parse_url($this->responseData->paging->$direction);
      parse_str($url['query'], $params);

      if (isset($params['type']) && strpos($this->request->getPath(), $params['type']) !== false){
        unset($params['type']);
      }
      return new FacebookRequest(
        $this->request->getSession(),
        $this->request->getMethod(),
        $this->request->getPath(),
        $params
      );
    } else {
      return null;
    }
  }

}

Commits for Nextrek/Android/SmartCharging/endPoints/fb_SDK/src/Facebook/FacebookResponse.php

Diff revisions: vs.
Revision Author Commited Message
507 FSallustio picture FSallustio Thu 20 Aug, 2015 07:51:22 +0000

Merge ramo stable con la nightly.