9namespace TANIOS\Airtable;
11class Request implements \ArrayAccess
15 * @var Airtable Instance of Airtable
19 * @var resource Instance of CURL
23 * @var string Content type
25 private $content_type;
27 * @var array Request data
31 * @var bool Is it a POST request?
33 private $is_post = false;
36 * @var array|boolean Relations to lazy load
41 * Create a Request to AirTable API
42 * @param Airtable $airtable Instance of Airtable
43 * @param string $content_type Content type
44 * @param array $data Request data
45 * @param bool|string $is_post Is it a POST request?
47 public function __construct( $airtable, $content_type, $data = [], $is_post = false, $relations = false )
50 $this->airtable = $airtable;
51 $this->content_type = $content_type;
53 $this->is_post = $is_post;
54 $this->relations = $relations;
58 private function init()
62 'Content-Type: application/json',
63 sprintf('Authorization: Bearer %s', $this->airtable->getKey())
66 $request = $this->content_type;
68 if( ! $this->is_post )
70 if (!empty($this->data)){
71 $data = http_build_query($this->data);
72 $request .= "?" . $data;
76 $curl = curl_init($this->airtable->getApiUrl($request));
78 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
79 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
83 if( strtolower( $this->is_post ) == 'patch' )
85 curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PATCH');
87 else if( strtolower( $this->is_post ) == 'delete' )
89 curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
91 curl_setopt($curl,CURLOPT_POST, count($this->data));
92 curl_setopt($curl,CURLOPT_POSTFIELDS, json_encode($this->data));
100 * @return Response Get response from API
102 public function getResponse()
107 $response_string = curl_exec( $this->curl );
109 $response = new Response( $this->airtable, $this, $response_string, $this->relations );
115 public function __set( $key, $value )
117 if( ! is_array( $this->data ) )
122 $this->data[ $key ] = $value;
125 public function offsetExists($offset)
127 return is_array( $this->data) && isset( $this->data[ $offset ] );
130 public function offsetGet($offset)
132 return is_array( $this->data ) && isset( $this->data[ $offset ] )
133 ? $this->data[ $offset ]
137 public function offsetSet($offset, $value)
139 if( ! is_array( $this->data ) )
144 $this->data[ $offset ] = $value;
147 public function offsetUnset($offset)
149 if( is_array( $this->data ) && isset( $this->data[ $offset ] ) )
151 unset( $this->data[ $offset ] );
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list