Пример #1
0
 /**
  * @return \ActiveResource\Connections\GuzzleConnection
  */
 public function getConnection()
 {
     if (empty($this->connection)) {
         $adapter = Guzzle::getAdapter();
         $this->connection = new GuzzleConnection("https://{$this->shopName}.myshopify.com");
         $this->connection->setClient($adapter);
         $this->connection->setBasePath('/admin');
         $accessToken = $this->getAuth()->getAccessToken();
         if ($accessToken) {
             $this->connection->getClient()->appendRequestHeader('X-Shopify-Access-Token', $accessToken);
         }
     }
     return $this->connection;
 }
Пример #2
0
<?php

//load the classes
require 'vendor/autoload.php';
//create a http guzzle adapter, no matter which guzzle version is loaded
$adapter = \cdyweb\http\guzzle\Guzzle::getAdapter();
//GET some example REST data
$str = $adapter->get('http://jsonplaceholder.typicode.com/posts/1')->getBody();
$post = json_decode($str, true);
var_dump($post);
//PUT (update) the data
$post['title'] = 'test123';
$str = json_encode($post);
$response = $adapter->put('http://jsonplaceholder.typicode.com/posts/1', array(), $str);
var_dump($response->getReasonPhrase());
//POST (create) new data
unset($post['id']);
$str = json_encode($post);
$response = $adapter->post('http://jsonplaceholder.typicode.com/posts', array(), $str);
$str = $response->getBody()->getContents();
$json = json_decode($str, true);
var_dump($json);
$id = $json['id'];
//DELETE a record
$response = $adapter->delete('http://jsonplaceholder.typicode.com/posts/' . $id);
var_dump($response->getReasonPhrase());
Пример #3
0
 public function setUp()
 {
     $this->adapter = \cdyweb\http\guzzle\Guzzle::getAdapter();
 }
Пример #4
0
 /**
  * @return \ActiveResource\Connections\GuzzleConnection
  */
 public function getConnection()
 {
     if (empty($this->connection)) {
         $adapter = Guzzle::getAdapter();
         $this->connection = new GuzzleConnection("https://{$this->shopName}.myshopify.com");
         $this->connection->setClient($adapter);
         $this->connection->setBasePath('/admin');
     }
     return $this->connection;
 }