Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function put($url, $content = '')
 {
     $response = Request::put($url)->addHeader("Accept", "application,json")->addHeader("X-TOKEN", $this->api)->body($content)->send();
     if ($this->isResponseOk($response->code)) {
         return $response->body;
     }
 }
Beispiel #2
0
 public function put($endpoint, $data, $options = [])
 {
     $uri = Client::endpoint() . $endpoint . Client::getUriOptions($options);
     $data = json_encode($data);
     $response = \Httpful\Request::put($uri)->sendsJson()->authenticateWith(Client::key(), Client::secret())->addHeaders(Client::headers())->body($data)->send();
     return $response;
 }
 private function makeRequest($url, $method, $parameters)
 {
     //http://phphttpclient.com/docs/class-Httpful.Request.html
     $query = http_build_query($parameters);
     $response = Httpful\Request::put($this->platform . $url . "?" . $query)->method($method)->authenticateWith($this->username, $this->password)->expects("plain")->send();
     // and finally, fire that thing off!
     $message = $response->body;
     //$message = ($response->code != 200) ? json_decode($response->body)[0] : $response->body;
     return array("url" => $response->request->uri, "code" => $response->code, "response" => $message);
 }
Beispiel #4
0
 /**
  * PUT command
  * @return bool true if ok
  */
 public function PUT($url, $data)
 {
     try {
         $this->response = Request::put($url, $data, 'xml')->authenticateWith($this->username, $this->password)->expectsType('xml')->send();
     } catch (Exception $exc) {
         \Yii::error($exc->getMessage() . "\n" . $exc->getTraceAsString());
         return false;
     }
     if ($this->isOk()) {
         return true;
     }
     return false;
 }
 public static function _PUT($url, $body = '{}')
 {
     $real_url = \Marketcloud\Marketcloud::$apiBaseUrl . $url;
     $response = \Httpful\Request::put($real_url)->sendsJson()->body($body)->addHeader('Authorization', \Marketcloud\Marketcloud::getAuthorizationHeader())->send();
     // We check the response code
     // If the code is 401, then the Token might be expired.
     // If it is the case, we re-authenticate the client using the stored credentials.
     //
     if ($response->code == 401) {
         // We have to re-authenticate
         $auth_response = \Marketcloud\Marketcloud::authenticate();
         return self::_PUT($url, $body);
     } else {
         return $response;
     }
 }
 public static function CallAPI($method, $url, $data = false)
 {
     $response = null;
     switch ($method) {
         case "GET":
             $response = \Httpful\Request::get($url)->expects("json")->send();
             break;
         case "POST":
             $response = \Httpful\Request::post($url)->body($data)->sendsAndExpects("json")->send();
             break;
         case "PUT":
             $response = \Httpful\Request::put($url)->body($data)->sendsAndExpects("json")->send();
             break;
         case "DELETE":
             $response = \Httpful\Request::delete($url)->body($data)->sendsAndExpects("json")->send();
             break;
     }
     return is_null($response) ? null : $response->body;
 }
 /**
  * PUT connect to the Engager Core API
  * 
  * @param string $uri (Uri to REST action)
  * @param string $data (Data to send to server)
  */
 public function rest_core_put_connect($uri, $data)
 {
     $response = \Httpful\Request::put($uri)->body($data)->sendsJson()->expectsJson()->apiKey($this->CI->config->item('core_api_key'))->send();
     // Response error handling
     switch ($response->code) {
         case 500:
             log_message('error', $response->body);
             return $response;
             break;
         case 403:
             log_message('error', $response->body);
             return $response;
             break;
         default:
             return $response;
             break;
     }
     return $response;
 }
Beispiel #8
0
 public function callRestfulApi($method, $path, $data = null)
 {
     $uri = $this->url . $path;
     switch ($method) {
         case "POST":
             $request = Request::post($uri, $data);
             break;
         case "PUT":
             $request = Request::put($uri, $data);
             break;
         case "GET":
             if ($data) {
                 $uri .= '?' . http_build_query($data);
             }
             $request = Request::get($uri);
             break;
         default:
             throw new \Exception("Unsupported method {$method}");
     }
     $response = $request->send();
     return $response->body;
 }
 public function processAction(CRM_Civirules_TriggerData_TriggerData $triggerData)
 {
     //do the http post process
     $uri = $this->getFullUri($triggerData);
     $method = $this->getHttpMethod();
     $body = http_build_query($this->getBodyParams($triggerData));
     switch (strtolower($method)) {
         case 'post':
             $request = \Httpful\Request::post($uri, $body);
             break;
         case 'put':
             $request = \Httpful\Request::put($uri, $body);
             break;
         case 'delete':
             $request = \Httpful\Request::delete($uri);
             break;
         case 'head':
             $request = \Httpful\Request::head($uri);
             break;
         case 'patch':
             $request = \Httpful\Request::patch($uri, $body);
             break;
         case 'options':
             $request = \Httpful\Request::options($uri, $body);
             break;
         case 'get':
             $request = $response = \Httpful\Request::get($uri);
             break;
         default:
             throw new Exception('Invalid HTTP Method');
     }
     $request->neverSerializePayload();
     $request = $this->alterHttpRequestObject($request, $triggerData);
     $response = $request->send();
     $this->handleResponse($response, $request, $triggerData);
 }
Beispiel #10
0
 /**
  * Заропс PUT
  * @param string $uri
  * @return mixed
  */
 public function put($uri)
 {
     $this->request = Request::put($uri);
     return $this;
 }
    $config = loadConfig();
    $handle = fopen('ip.txt', 'c+');
    if ($handle === false) {
        return 1;
    }
    $currentIp = trim(stream_get_contents($handle));
    $ip = trim(file_get_contents('https://i.ngx.cc'));
    // If the IP checked different from the current IP logged (to file), update
    // CloudFlare DNS record for and send and email notification
    if ($currentIp !== $ip) {
        ftruncate($handle, 0);
        fwrite($handle, $ip);
        if ($currentIp !== '') {
            // Update CloudFlare DNS using API call
            $cfPutData = ['content' => $ip, 'type' => 'A', 'name' => $config['cloudflare_domain_name']];
            $response = Request::put("https://api.cloudflare.com/client/v4/zones/{$config['cloudflare_zone_id']}/dns_records/{$config['cloudflare_domain_id']}")->sendsJson()->addHeaders(array('X-Auth-Key' => $config['cloudflare_api_key'], 'X-Auth-Email' => $config['cloudflare_email']))->body(json_encode($cfPutData))->send();
            if ($response->code !== 200) {
                throw new Exception('Attempt to update CloudFlare DNS record failed!');
            }
            // Send email using Mailgun
            $mg = new Mailgun($config['mailgun_api_key']);
            $mg->sendMessage($config['mailgun_domain'], ['from' => $config['report_from_email'], 'to' => $config['report_to_email'], 'subject' => 'Home IP has changed', 'text' => 'Ngoc, your new IP is ' . $ip]);
        }
    }
} catch (Exception $e) {
    echo $e->getMessage();
    return 1;
} finally {
    if ($handle !== null) {
        fclose($handle);
    }
Beispiel #12
0
 /**
  * Updates an existing entity.
  * @param Entity $instance
  * @return Entity
  */
 public function update(Entity $instance)
 {
     if (!$instance->isAllowedMethod(__FUNCTION__)) {
         throw new \DomainException(__FUNCTION__ . ' not allowed on this entity.');
     }
     $url = sprintf('%s/%s/%s', $this->getApiUrl(), $this->getNetworkId(), $this->getEndpointName($instance));
     $response = \Httpful\Request::put($url)->authenticateWith($this->getLogin(), $this->getPassword())->sendsJson()->body($instance)->send();
     if ($response->hasErrors()) {
         $exception = json_decode($response->raw_body);
         throw new \UnexpectedValueException(sprintf("API response raised a '%s' exception with a message: '%s'. Status code %s", $exception->name, $exception->message, $response->code));
     }
     return $instance;
 }
Beispiel #13
0
echo "response http status: " . $response->code . "\n\n";
echo "Teilinhalt der response: " . $response->body->createdPersonWithName . "\n\n";
// var_dump($response);
// ------------- der anfang des var_dump - outputs hier: ---------------------
// ["body"]=>
// object(stdClass)#14 (2) {
// ["func"]=>
// string(6) "create"
// ["createdPersonWithName"]=>
// string(4) "emma"
// }
// ["raw_body"]=>
// string(48) "{"func":"create","createdPersonWithName":"emma"}"
// ===================================================================
// PUT Request  (update single person)
// ===================================================================
$uri = "http://localhost/testapp/index.php/api/persons/emma";
$payload = array('attributeToBeUPdated' => 'newValue');
echo "\n\n================ PUT:  {$uri} \n";
$response = \Httpful\Request::put($uri)->sendsJson()->body($payload)->send();
// and finally, fire that thing off!
# var_dump($response);
echo "response http status: " . $response->code . "\n\n";
echo "Teilinhalt der response: " . $response->body->updatedPersonWithId . "\n\n";
// ===================================================================
// DELETE Request  (delete single person)
// ===================================================================
$uri = "http://localhost/testapp/index.php/api/persons/todelete";
echo "\n\n================ DELETE:  {$uri} \n";
$response = \Httpful\Request::delete($uri)->send();
echo "response http status: " . $response->code . "\n\n";
Beispiel #14
0
 /**
  * Performs a HTTP PUT request.
  *
  * @param string $resource
  *            the requested resource
  * @param string $payload
  *            extra data (optional)
  * @param string $mime
  *            the expected MIME type (optional)
  * @return \Httpful\Request the API's response
  */
 public function do_put($resource, $payload = NULL, $mime = NULL)
 {
     $uri = $this->make_uri($resource);
     $result = Request::put($uri, $payload, $mime)->send();
     return $result;
 }
Beispiel #15
0
function MVwriteRecord($uri)
{
    global $username, $password, $json_record;
    $response = \Httpful\Request::put($uri)->sendsJson()->authenticateWith($username, $password)->body($json_record)->send();
    return $response;
}
Beispiel #16
0
 /**
  * Uploads the fixed course syllabus
  * @param string $corrected_error - The html that has been fixed
  * @param string $error_html      - The html to be fixed
  */
 public function uploadFixedSyllabus($corrected_error, $error_html)
 {
     $get_uri = $this->base_uri . "/api/v1/courses/" . $this->course_id . "/?include[]=syllabus_body&access_token=" . $this->api_key;
     $content = Request::get($get_uri)->send();
     $html = $content->body->syllabus_body;
     $error_html = HTMLMinify::minify(str_replace($this->annoying_entities, $this->entity_replacements, $error_html), ['doctype' => 'html5']);
     $corrected_error = HTMLMinify::minify(str_replace($this->annoying_entities, $this->entity_replacements, $corrected_error), ['doctype' => 'html5']);
     $html = HTMLMinify::minify(str_replace($this->annoying_entities, $this->entity_replacements, htmlentities($html)), ['doctype' => 'html5']);
     $html = str_replace($error_html, $corrected_error, html_entity_decode($html));
     $put_uri = $this->base_uri . "/api/v1/courses/" . $this->course_id . "/?&access_token=" . $this->api_key;
     Request::put($put_uri)->body(['course[syllabus_body]' => $html])->sendsType(\Httpful\Mime::FORM)->send();
 }
Beispiel #17
0
 /**
  * Creates a user in the _user database.
  */
 public function save()
 {
     $con = $this->config;
     // Prepare doc
     $new_fields = array("_id" => $con->user_doc_name($this->name), "name" => $this->name, "groups" => $this->groups, "type" => "user", "roles" => array());
     if ($this->admin_mode == false) {
         $new_fields['password'] = $this->pass;
     }
     // If we've already loaded a doc, then update it.
     if (isset($this->doc['_rev'])) {
         $old_doc = $this->doc;
         foreach ($new_fields as $field_key => $field_value) {
             $old_doc[$field_key] = $field_value;
         }
         $new_doc = $old_doc;
         $response = h\Request::put($con->user_doc_url($this->name, "main"))->authenticateWith($con->constants->ADMIN_U, $con->constants->ADMIN_P)->sendsJson()->body(json_encode($new_doc))->send();
     } else {
         // otherwise, make a new doc
         $new_doc = $new_fields;
         $response = h\Request::put($con->user_doc_url($this->name, "main"))->authenticateWith($con->constants->ADMIN_U, $con->constants->ADMIN_P)->sendsJson()->body(json_encode($new_doc))->send();
     }
     return json_decode($response, true);
 }
 private function updatingData()
 {
     if ($_POST['loginu']) {
         $json = array();
         $json['firstName'] = $_POST['fname'];
         $json['lastName'] = $_POST['lname'];
         $json['login'] = $_POST['loginu'];
         $json['email'] = $_POST['email'];
         $json['city'] = $_POST['city'];
         $json['address'] = $_POST['address'];
         $json['zipCode'] = $_POST['zipc'];
         $json['phone'] = $_POST['phone'];
         $uri = 'http://localhost:8080/users/' . $_POST['loginu'];
         $sendJson = json_encode($json);
         $response = \Httpful\Request::put($uri)->sendsJson()->body($sendJson)->send();
     }
 }
 protected function put($uri, array $params = null)
 {
     $params = self::clean_array($params);
     return self::process_response(Request::put(self::$base_uri . $uri)->body($params)->send());
 }
 public function exported(ApiResource $resource)
 {
     if (!isset($resource->exported)) {
         $resource->exported = false;
     }
     $idField = $resource->getIdField();
     $url = $this->generateUrl($resource->{$idField} . '/exported');
     $response = \Httpful\Request::put($url)->body(json_encode(array('exported' => $resource->exported)))->sendsJson()->send();
     $this->checkResponseErrors($response);
     /*
     $response = null;
     
     try {
         $response = \Httpful\Request::put($url)
             ->body(json_encode(array('exported' => $resource->exported)))
             ->sendsJson()
             ->send();
     } catch (\Exception $e) {
         if ($e->getMessage() == 'Unable to parse response as JSON') {
             // keep working
         } else {
             throw new RequestException($e->getMessage(), $e->getCode());
         }
     }
     */
     return $response;
 }
 /**
  * @depends testCreateBucket
  */
 public function testPresigedUri()
 {
     $object_name = "中文测试";
     $content = "presigned";
     self::$fds_client->putObject(self::$bucket_name, $object_name, $content);
     $uri = self::$fds_client->generatePresignedUri(self::$bucket_name, $object_name, time() * 1000 + 60000);
     $download = file_get_contents($uri);
     $this->assertEquals($content, $download);
     // test put object with presigned uri, content-type setted
     $object_name = "presigned_uri";
     $content = "blahblah";
     // get uri
     $content_type = "text/blah";
     $uri = self::$fds_client->generatePresignedUri(self::$bucket_name, $object_name, time() * 1000 + 60000, "PUT", $content_type);
     // put object
     $headers = array();
     $headers[Common::CONTENT_TYPE] = $content_type;
     $request = Request::put($uri, $content);
     $response = $request->addHeaders($headers)->send();
     // check object
     $object = self::$fds_client->getObject(self::$bucket_name, $object_name);
     $this->assertNotNull($object);
     $this->assertEquals($content, $object->getObjectContent());
     $this->assertEquals($content_type, $object->getObjectMetadata()->getContentType());
 }
Beispiel #22
0
 public function edit()
 {
     $subscriber = array("msisdn" => $this->msisdn, "name" => $this->name, "balance" => $this->balance, "authorized" => $this->authorized, "subscription_status" => $this->subscription_status, "location" => $this->location);
     try {
         $response = \Httpful\Request::put($this->path . "/" . $this->msisdn)->body($subscriber)->sendsJson()->send();
     } catch (Httpful\Exception\ConnectionErrorException $e) {
         throw new SubscriberException($e->getMessage());
     }
     $data = $response->body;
     if ($data->status == 'failed') {
         throw new SubscriberException($data->error);
     }
 }
Beispiel #23
0
 /**
  * @param $params
  * @param $token
  * @param bool $secure
  * @return mixed
  * @throws ResponseClientError
  * @throws ResponseRedirectionError
  * @throws ResponseServerError
  * @throws UnknownResponseCodeException
  */
 public static function changePassword($params, $token, $secure = true)
 {
     $uri = static::genUrl(__FUNCTION__, $secure);
     $headers = static::getHeaders($token);
     $response = \Httpful\Request::put($uri)->sendsJson()->body($params)->addHeaders($headers)->send();
     static::checkCode($response->meta_data['http_code'], $response->body);
     return $response->body;
 }
Beispiel #24
0
 /**
  * Void a payment
  * @param GUID $paymentId 
  * @param int $amount 
  * @return mixed
  */
 public function void($paymentId, $amount)
 {
     $uri = Braspag::$apiBase . "sales/{$paymentId}/void";
     if ($amount != null) {
         $uri = $uri . "?amount={$amount}";
     }
     $response = Request::put($uri)->sendsJson()->addHeaders($this->headers)->send();
     if ($response->code == HttpStatus::Ok) {
         $voidResponse = new VoidResponse();
         $voidResponse->status = $response->body->Status;
         $voidResponse->reasonCode = $response->body->ReasonCode;
         $voidResponse->reasonMessage = $response->body->ReasonMessage;
         $voidResponse->links = $this->parseLinks($response->body->Links);
         return $voidResponse;
     } elseif ($response->code == HttpStatus::BadRequest) {
         Utils::handleApiError($response);
     }
     return $response->code;
 }
 private function put($url, $body)
 {
     return \Httpful\Request::put($url)->body($body)->method('PUT')->withoutStrictSsl()->expectsJson()->sendsType('application/x-www-form-urlencoded')->send();
 }
Beispiel #26
0
 /**
  * This saves the supplied security doc to the group's database.
  * @param new_doc Must be a complete CouchDB doc
  * @return httpful/Response object.
  */
 public function set_security_doc($new_doc = null)
 {
     if ($new_doc == null) {
         throw InvalidArgumentException("Cowardly refusing to save a blank security doc.");
     }
     $con = $this->config;
     return h\Request::put($con->group_doc_url("_security", $this->name, "main"))->authenticateWith($con->constants->ADMIN_U, $con->constants->ADMIN_P)->sendsJson()->body(json_encode($new_doc))->send();
 }
 /**
  * Deactivate one recurrent payment
  * @param mixed $recurrentId 
  */
 public function reactivate($recurrentId, $amount)
 {
     $uri = BraspagApiConfig::apiUri . "RecurrentPayment/{$recurrentId}/Reactivate";
     $response = \Httpful\Request::put($uri)->addHeaders($this->headers)->addHeader("content-type", "text/json")->send();
     if ($response->code == BraspagHttpStatus::BadRequest) {
         return BraspagUtils::getBadRequestErros($response->body);
     }
     return $response->code;
 }
Beispiel #28
0
 /**
  * Void a payment
  * @param GUID $paymentId 
  * @param int $amount 
  * @return mixed
  */
 public function void($paymentId, $amount)
 {
     $uri = BraspagApiConfig::apiUri . "sales/{$paymentId}/void";
     if ($amount != null) {
         $uri = $uri . "?amount={$amount}";
     }
     $response = \Httpful\Request::put($uri)->sendsJson()->addHeaders($this->headers)->send();
     if ($response->code == BraspagHttpStatus::Ok) {
         $voidResponse = new BraspagVoidResponse();
         $voidResponse->status = $response->body->Status;
         $voidResponse->reasonCode = $response->body->ReasonCode;
         $voidResponse->reasonMessage = $response->body->ReasonMessage;
         $voidResponse->links = $this->parseLinks($response->body->Links);
         return $voidResponse;
     } elseif ($response->code == BraspagHttpStatus::BadRequest) {
         return BraspagUtils::getBadRequestErros($response->body);
     }
     return $response->code;
 }
 /**
  * Sets preferences.
  * @param array $preferences
  * Example of $preferences
  * {
  *   'calltracking_webhook':'<url>'
  * }
  * @return True or exception
  * @throws \Exception
  */
 public function setPreferences(array $preferences)
 {
     $apiMethodUrl = $this->getMethodUrl('/preferences/');
     $response = \Httpful\Request::put($apiMethodUrl)->sendsJson()->expectsJson()->addHeaders($this->getAuthHeader())->body(json_encode($preferences))->send();
     if (property_exists($response, 'body')) {
         return $response->body;
     } else {
         throw new \Exception($response->raw_body);
     }
 }
Beispiel #30
-5
 /**
  * @param Request $request
  *
  * @return HttpServer
  */
 public function getHttpServer(Request $request)
 {
     $url = $request->getUri();
     switch ($request->getMethod()) {
         case Request::METHOD_POST:
             $httpServer = HttpServer::post($url);
             break;
         case Request::METHOD_PUT:
             $httpServer = HttpServer::put($url);
             break;
         case Request::METHOD_DELETE:
             $httpServer = HttpServer::delete($url);
             break;
         default:
             $httpServer = HttpServer::get($url);
             break;
     }
     if ($request->headers) {
         $httpServer->addHeaders($request->headers->all());
     }
     if ($request->getUser()) {
         $httpServer->authenticateWith($request->getUser(), $request->getPassword());
     }
     if ($request->getContent()) {
         $httpServer->body($request->getContent());
     }
     return $httpServer;
 }