Exemplo n.º 1
2
 private function getResponse($stack, $base_uri, $uri, $data, $httpMethod)
 {
     $middleware = new Oauth1(['consumer_key' => self::CONSUMER_KEY, 'consumer_secret' => self::CONSUMER_SECRET, 'token_secret' => self::TOKEN_SECRET]);
     //'auth' => ['user_name', 'pass_name'], // when using username & password
     $options = ['auth' => 'oauth', 'debug' => false, 'headers' => ['Accept' => 'application/hal+json', 'Content-Type' => 'application/hal+json'], 'body' => json_encode($data)];
     $stack->push($middleware);
     $client = new Client(['base_uri' => $base_uri, 'handler' => $stack]);
     $response = false;
     switch ($httpMethod) {
         case self::HTTP_GET:
             $response = $client->get($uri, $options);
             break;
         case self::HTTP_POST:
             $response = $client->post($uri, $options);
             break;
         case self::HTTP_PUT:
             $response = $client->put($uri, $options);
             break;
         case self::HTTP_PATCH:
             $response = $client->patch($uri, $options);
             break;
         case self::HTTP_DELETE:
             $response = $client->delete($uri, $options);
             break;
     }
     return $response;
 }
Exemplo n.º 2
0
 function makeHttpRequest($method, $url, $apiRequest = null, $queryString = null)
 {
     $urlEndPoint = $this->apiConfiguration->getDefaultEndPoint() . '/' . $url;
     $data = ['headers' => ['Authorization' => 'Bearer ' . $this->apiConfiguration->getAccessToken()], 'json' => $apiRequest, 'query' => $queryString];
     try {
         switch ($method) {
             case 'post':
                 $response = $this->guzzle->post($urlEndPoint, $data);
                 break;
             case 'put':
                 $response = $this->guzzle->put($urlEndPoint, $data);
                 break;
             case 'delete':
                 $response = $this->guzzle->delete($urlEndPoint, $data);
                 break;
             case 'get':
                 $response = $this->guzzle->get($urlEndPoint, $data);
                 break;
             default:
                 throw new \Exception('Missing request method!');
         }
         if (in_array(current($response->getHeader('Content-Type')), ['image/png', 'image/jpg'])) {
             $result = $response->getBody()->getContents();
         } else {
             $result = json_decode($response->getBody(), true);
         }
         return $result;
     } catch (ConnectException $c) {
         throw $c;
     } catch (RequestException $e) {
         throw $e;
     }
 }
Exemplo n.º 3
0
 /**
  * Make a post request to shorte.st.
  *
  * @param $url_to_shorten
  *
  * @return \GuzzleHttp\Stream\StreamInterface|null|\Psr\Http\Message\StreamInterface
  */
 private function post($url_to_shorten)
 {
     // Prepare the request.
     $request = $this->client->put(Shortest::BASE_URL, ['headers' => ['public-api-token' => $this->config->get('shortest.api_token')], 'form_params' => ['urlToShorten' => $url_to_shorten]]);
     // Return the body as json.
     return $request->getBody();
 }
Exemplo n.º 4
0
 public function put($resource, $body, $type, $options = [])
 {
     $options['body'] = $this->serializer->serialize($body, 'json');
     $options['headers'] = ['Content-Type' => 'application/json'];
     $content = $this->client->put($resource, $options)->getBody()->getContents();
     return $this->deserialize($content, $type);
 }
 public function updateObject($object, ChangeSet $changeSet)
 {
     $data = $this->prepareUpdateChangeSet($object, $changeSet);
     $identifier = $this->getObjectIdentifier($object);
     $class = $this->objectManager->getClassMetadata(get_class($object));
     $url = sprintf('%s/%s', $this->url, $identifier[$class->identifier[0]]);
     return $this->client->put($url, array('body' => $data))->json();
 }
 public function testUpdateSchedule()
 {
     $response = self::$client->put('/');
     $updatedSchedule = Schedule::create($response->json());
     $this->assertInstanceOf('Ctct\\Components\\EmailMarketing\\Schedule', $updatedSchedule);
     $this->assertEquals(1, $updatedSchedule->id);
     $this->assertEquals("2012-12-16T11:07:43.626Z", $updatedSchedule->scheduled_date);
 }
Exemplo n.º 7
0
 /**
  * @param string $testId
  * @return int result_id
  */
 public function run($testId)
 {
     $url = sprintf(static::API_BASE_URL . '/tests/%s/run', $testId);
     $response = $this->client->put($url);
     if (empty($response->getBody())) {
         return null;
     }
     return $response->json(['object' => true])->result_id;
 }
 public function testUpdateList()
 {
     $response = self::$client->put('/');
     $list = ContactList::create($response->json());
     $this->assertInstanceOf('Ctct\\Components\\Contacts\\ContactList', $list);
     $this->assertEquals(6, $list->id);
     $this->assertEquals("Test List 4", $list->name);
     $this->assertEquals("HIDDEN", $list->status);
     $this->assertEquals(19, $list->contact_count);
 }
Exemplo n.º 9
0
 /** @test */
 public function shouldRespondToMultipleRequestsWithTheSameResponse()
 {
     $mockResponse = $this->createResponse(new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['hello' => 'world', 'howareyou' => 'today']))));
     $this->httpMock->shouldReceiveRequest()->once()->withUrl('http://example.com/foo')->withMethod('PUT')->withQueryParams(['faz' => 'baz'])->withJsonBodyParams(['shakeyo' => 'body'])->andRespondWith($mockResponse);
     $this->httpMock->shouldReceiveRequest()->once()->withUrl('http://example.com/foo')->withMethod('PUT')->withQueryParams(['faz' => 'baz'])->withJsonBodyParams(['shakeyo' => 'hands in the air like you just don\'t care'])->andRespondWith($mockResponse);
     $actualResponse = $this->guzzleClient->put('http://example.com/foo', ['query' => ['faz' => 'baz'], 'body' => json_encode(['shakeyo' => 'body']), 'headers' => ['Content-Type' => 'application/json']]);
     $actualResponse2 = $this->guzzleClient->put('http://example.com/foo', ['query' => ['faz' => 'baz'], 'body' => json_encode(['shakeyo' => 'hands in the air like you just don\'t care']), 'headers' => ['Content-Type' => 'application/json']]);
     $this->httpMock->verify();
     $this->assertSame($mockResponse, $actualResponse);
     $this->assertSame($mockResponse, $actualResponse2);
 }
Exemplo n.º 10
0
 public function put($resource, $body, $type, $options = [])
 {
     $options['future'] = true;
     $options['body'] = $this->serializer->serialize($body, 'json');
     $options['headers'] = ['Content-Type' => 'application/json'];
     return $this->client->put($resource, $options)->then(function (Response $reponse) {
         return $reponse->getBody()->getContents();
     })->then(function ($content) use($type) {
         return $this->deserialize($content, $type);
     });
 }
Exemplo n.º 11
0
 public function testNoCacheOtherMethod()
 {
     $this->client->post("anything");
     $response = $this->client->post("anything");
     $this->assertEquals("", $response->getHeaderLine("X-Cache"));
     $this->client->put("anything");
     $response = $this->client->put("anything");
     $this->assertEquals("", $response->getHeaderLine("X-Cache"));
     $this->client->delete("anything");
     $response = $this->client->delete("anything");
     $this->assertEquals("", $response->getHeaderLine("X-Cache"));
     $this->client->patch("anything");
     $response = $this->client->patch("anything");
     $this->assertEquals("", $response->getHeaderLine("X-Cache"));
 }
Exemplo n.º 12
0
 public function testNoCacheOtherMethod()
 {
     $this->client->post('anything');
     $response = $this->client->post('anything');
     $this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
     $this->client->put('anything');
     $response = $this->client->put('anything');
     $this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
     $this->client->delete('anything');
     $response = $this->client->delete('anything');
     $this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
     $this->client->patch('anything');
     $response = $this->client->patch('anything');
     $this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
 }
Exemplo n.º 13
0
 public static function makeRequest($request, $url, $getRawResponse = false)
 {
     $client = new Client();
     switch ($request->getActionType()) {
         case ActionType::GET:
             if ($getRawResponse) {
                 return $client->get($url);
             } else {
                 $response = GuzzleHelper::getAsset($url);
                 //$client->get($url);
             }
             break;
         case ActionType::DELETE:
             $response = $client->delete($url);
             break;
         case ActionType::PUT:
             $response = $client->put($url);
             break;
         case ActionType::POST:
             $response = $client->post($url);
             break;
         default:
             $response = GuzzleHelper::getAsset($url);
             //$client->get($url);
     }
     return $response;
 }
Exemplo n.º 14
0
 public static function put($url, $data)
 {
     $result = [];
     $client = new Client();
     try {
         $response = $client->put($url, ['body' => json_encode($data)]);
         $result = $response->getBody();
         if ($result->isReadable()) {
             return $result->__toString();
         } else {
             return null;
         }
     } catch (\GuzzleHttp\Exception\ClientErrorResponseException $e) {
         //$resp              = $e->getResponse();
         return null;
     } catch (\GuzzleHttp\Exception\ServerErrorResponseException $e) {
         return null;
     } catch (\GuzzleHttp\Exception\BadResponseException $e) {
         return null;
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         return null;
     } catch (Exception $e) {
         return null;
     }
 }
 public function testStreamAttributeKeepsStreamOpen()
 {
     Server::flush();
     Server::enqueue("HTTP/1.1 200 OK\r\nFoo: Bar\r\nContent-Length: 8\r\n\r\nhi there");
     $client = new Client(['base_url' => Server::$url, 'adapter' => new StreamAdapter(new MessageFactory())]);
     $response = $client->put('/foo', ['headers' => ['Foo' => 'Bar'], 'body' => 'test', 'stream' => true]);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('OK', $response->getReasonPhrase());
     $this->assertEquals('8', $response->getHeader('Content-Length'));
     $body = $response->getBody();
     if (defined('HHVM_VERSION')) {
         $this->markTestIncomplete('HHVM has not implemented this?');
     }
     $this->assertEquals('http', $body->getMetadata()['wrapper_type']);
     $this->assertEquals(8, $body->getMetadata()['unread_bytes']);
     $this->assertEquals(Server::$url . 'foo', $body->getMetadata()['uri']);
     $this->assertEquals('hi', $body->read(2));
     $body->close();
     $sent = Server::received(true)[0];
     $this->assertEquals('PUT', $sent->getMethod());
     $this->assertEquals('/foo', $sent->getResource());
     $this->assertEquals('127.0.0.1:8125', $sent->getHeader('host'));
     $this->assertEquals('Bar', $sent->getHeader('foo'));
     $this->assertTrue($sent->hasHeader('user-agent'));
 }
Exemplo n.º 16
0
 public function put($url = null, array $options = [])
 {
     $options = $this->setVerify($options);
     $options['body'] = $this->ApiParams;
     $this->resetParams();
     return parent::put($url, $options);
 }
Exemplo n.º 17
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Parametros com os dados do recurso especificado $json
  * @param  int  $id
  * @return Retorna status da alteração 200=OK
  */
 public function update($json, $id)
 {
     $client = new GuzzleHttp\Client();
     $request = $client->put($this->_apiBase . $this->_className . '/' . $id . '?access_token=' . $this->_apiKey, ['json' => $json]);
     $response = $request->getStatusCode();
     return $response;
 }
Exemplo n.º 18
0
 public function uploadChunk($chunk, $sessionId)
 {
     try {
         $this->client->put("{$this->baseUri}/sites/{$this->siteId}/fileUploads/{$sessionId}", ['headers' => ['X-Tableau-Auth' => $this->token], 'multipart' => [['name' => 'request_payload', 'contents' => '', 'headers' => ['Content-Type' => 'text/xml']], ['name' => 'tableau_file', 'contents' => $chunk, 'filename' => 'file.tde', 'headers' => ['Content-Type' => 'application/octet-stream']]], 'isMixed' => true]);
     } catch (ClientException $e) {
         throw new Exception('Upload chunk failed with response: ' . $e->getResponse()->getBody());
     }
 }
Exemplo n.º 19
0
 /**
  * @param string $uri
  * @param array $data
  * @param array $options
  * @param bool $api
  * @return $this;
  */
 public function put($uri, array $data = [], array $options = [], $api = true)
 {
     $options = $this->configureOptions($options);
     $uri = $api ? $this->getServiceConfig('api_url') . $uri : $uri;
     $response = $this->client->put($uri, array_merge($options, ['form_params' => $data]));
     $this->setGuzzleResponse($response);
     return $this;
 }
Exemplo n.º 20
0
 /**
  * @param $url
  * @param $version
  * @param array  $data
  * @param string $bodyEncoding
  *
  * @return \GuzzleHttp\Message\FutureResponse|\GuzzleHttp\Message\ResponseInterface|\GuzzleHttp\Ring\Future\FutureInterface|null
  */
 private function put($url, $version, array $data = [], $bodyEncoding = 'json')
 {
     $requestOptions = $this->getPostRequestOptions($version, $data, $bodyEncoding);
     $response = $this->client->put($url, $requestOptions);
     if (200 !== $response->getStatusCode()) {
         throw new \LogicException('An error occurred when trying to POST data to MR API');
     }
     return $response;
 }
Exemplo n.º 21
0
 public function testReadsBodiesFromMockedRequests()
 {
     $m = new Mock([new Response(200)]);
     $client = new Client(['base_url' => 'http://test.com']);
     $client->getEmitter()->attach($m);
     $body = Stream::factory('foo');
     $client->put('/', ['body' => $body]);
     $this->assertEquals(3, $body->tell());
 }
Exemplo n.º 22
0
 /**
  * Executa uma requisição do tipo PUT.
  *
  * @param null  $url
  * @param array $options
  *
  * @throws ClientException
  *
  * @return string
  */
 public function put($url = null, $options = [])
 {
     $response = $this->client->put($url, $this->getOptions($options));
     if ($response and $response->getBody()) {
         return $response->getBody()->getContents();
     } else {
         return json_encode('Nada retornado');
     }
 }
Exemplo n.º 23
0
 public function sendStats()
 {
     $http = new Guzzle(['base_uri' => $this->base_uri]);
     $body = "";
     foreach ($this->registry->getMetrics() as $metric) {
         $body .= $metric->serialize() . "\n";
     }
     $http->put('/metrics/job/j' . uniqid(), ['body' => $body]);
 }
Exemplo n.º 24
0
 /**
  * Sends data via PUT to perforn an update
  *
  * @param string $updateEndpoint
  * @param array $data
  */
 protected function update($updateEndpoint, $data = [])
 {
     if (empty($data)) {
         $apiCallResult = $this->client->put($updateEndpoint);
     } else {
         $apiCallResult = $this->client->put($updateEndpoint, ['json' => $data]);
     }
     return json_decode($apiCallResult->getBody(), true);
 }
Exemplo n.º 25
0
 /**
  * https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record
  * @param  string $dnsCfId
  * @param  array  $datas
  * @return JSONObject
  */
 private function updateDnsRecord($dnsCfId, array $datas)
 {
     try {
         $response = $this->client->put('zones/' . $this->zoneId . '/dns_records/' . $dnsCfId, ['json' => $datas]);
         return $response->json(['object' => true])->result;
     } catch (Exception $e) {
         throw $this->createCloudflareException($e);
     }
 }
 public function testUpdateCampaign()
 {
     $response = self::$client->put('/');
     $campaign = Campaign::create($response->json());
     $this->assertInstanceOf('Ctct\\Components\\EmailMarketing\\Campaign', $campaign);
     $this->assertEquals("1100394165290", $campaign->id);
     $this->assertEquals("CampaignName-05965ddb-12d2-43e5-b8f3-0c22ca487c3a", $campaign->name);
     $this->assertEquals("CampaignSubject", $campaign->subject);
     $this->assertEquals("SENT", $campaign->status);
     $this->assertEquals("From WSPI", $campaign->from_name);
     $this->assertEquals("*****@*****.**", $campaign->from_email);
     $this->assertEquals("*****@*****.**", $campaign->reply_to_email);
     $this->assertEquals("CUSTOM", $campaign->template_type);
     $this->assertEquals("2012-12-06T18:06:05.255Z", $campaign->created_date);
     $this->assertEquals("2012-12-06T18:06:40.342Z", $campaign->last_run_date);
     $this->assertEquals(false, $campaign->is_permission_reminder_enabled);
     $this->assertEquals("", $campaign->permission_reminder_text);
     $this->assertEquals(false, $campaign->is_view_as_webpage_enabled);
     $this->assertEquals("Having trouble viewing this email?", $campaign->view_as_web_page_text);
     $this->assertEquals("Click Here", $campaign->view_as_web_page_link_text);
     $this->assertEquals("Hi", $campaign->greeting_salutations);
     $this->assertEquals("FIRST_NAME", $campaign->greeting_name);
     $this->assertEquals("", $campaign->greeting_string);
     $this->assertEquals("<html><body>Hi <a href=\"http://www.constantcontact.com\">Visit ConstantContact.com!</a> </body></html>", $campaign->email_content);
     $this->assertEquals("HTML", $campaign->email_content_format);
     $this->assertEquals("", $campaign->style_sheet);
     $this->assertEquals("<text>Something to test</text>", $campaign->text_content);
     // message footer
     $this->assertEquals("Waltham", $campaign->message_footer->city);
     $this->assertEquals("MA", $campaign->message_footer->state);
     $this->assertEquals("US", $campaign->message_footer->country);
     $this->assertEquals("WSPIOrgName", $campaign->message_footer->organization_name);
     $this->assertEquals("1601 Trapelo RD", $campaign->message_footer->address_line_1);
     $this->assertEquals("suite 2", $campaign->message_footer->address_line_2);
     $this->assertEquals("box 4", $campaign->message_footer->address_line_3);
     $this->assertEquals("", $campaign->message_footer->international_state);
     $this->assertEquals("02451", $campaign->message_footer->postal_code);
     $this->assertEquals(true, $campaign->message_footer->include_forward_email);
     $this->assertEquals("WSPIForwardThisEmail", $campaign->message_footer->forward_email_link_text);
     $this->assertEquals(true, $campaign->message_footer->include_subscribe_link);
     $this->assertEquals("WSPISubscribeLinkText", $campaign->message_footer->subscribe_link_text);
     // tracking summary
     $this->assertEquals(15, $campaign->tracking_summary->sends);
     $this->assertEquals(10, $campaign->tracking_summary->opens);
     $this->assertEquals(10, $campaign->tracking_summary->clicks);
     $this->assertEquals(3, $campaign->tracking_summary->forwards);
     $this->assertEquals(2, $campaign->tracking_summary->unsubscribes);
     $this->assertEquals(18, $campaign->tracking_summary->bounces);
     // sent to contact lists
     $this->assertEquals(1, count($campaign->sent_to_contact_lists));
     $this->assertEquals(3, $campaign->sent_to_contact_lists[0]->id);
     //click through details
     $this->assertEquals("http://www.constantcontact.com", $campaign->click_through_details[0]->url);
     $this->assertEquals("1100394163874", $campaign->click_through_details[0]->url_uid);
     $this->assertEquals(10, $campaign->click_through_details[0]->click_count);
 }
Exemplo n.º 27
0
 /**
  * @param string $username
  * @param string $password
  * @return mixed
  */
 public function setPasswordForUser($username, $password)
 {
     try {
         $response = $this->httpClient->put(rtrim($this->crowdBaseUri, '/') . '/rest/usermanagement/1/user/password?username='******'body' => json_encode(array('value' => $password))));
         $responseData = json_decode($response->getBody()->getContents(), TRUE);
         return $responseData;
     } catch (ClientException $e) {
         return FALSE;
     }
 }
Exemplo n.º 28
0
 /**
  * @When :taggingUser adds the tag :tagName to :fileName shared by :sharingUser
  * @param string $taggingUser
  * @param string $tagName
  * @param string $fileName
  * @param string $sharingUser
  */
 public function addsTheTagToSharedBy($taggingUser, $tagName, $fileName, $sharingUser)
 {
     $fileId = $this->getFileIdForPath($fileName, $sharingUser);
     $tagId = $this->findTagIdByName($tagName);
     try {
         $this->response = $this->client->put($this->baseUrl . '/remote.php/dav/systemtags-relations/files/' . $fileId . '/' . $tagId, ['auth' => [$taggingUser, $this->getPasswordForUser($taggingUser)]]);
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         $this->response = $e->getResponse();
     }
 }
Exemplo n.º 29
0
 /**
  * @param $endPoint
  * @param array $params
  * @return string
  * @throws \Exception
  */
 public function put($endPoint, array $params = [], array $options = [])
 {
     $response = $this->client->put($endPoint, $this->prepareData($params, $options));
     switch ($response->getHeader('content-type')) {
         case "application/json":
             return $response->json();
             break;
         default:
             return $response->getBody()->getContents();
     }
 }
Exemplo n.º 30
0
 /**
  * @param string $uri
  * @param array  $body
  */
 public function put($uri, array $body)
 {
     $this->lastRequestBody = $body;
     try {
         $this->lastResponse = $this->client->put($uri, ['json' => $body, 'headers' => $this->headers]);
     } catch (RequestException $e) {
         $this->lastResponse = $e->getResponse();
     } finally {
         $this->lastResponseBody = $this->lastResponse->getBody()->getContents();
     }
 }