aaronflorey / laravel-shopify

MIT License
10 stars 14 forks source link

Is this working for you? #2

Open billivycarter opened 9 years ago

billivycarter commented 9 years ago

Seems incompatible with updated Guzzle... especially with the class names. Error after error trying to shove a request through shopify.php Can you add a bit of documentation, or at least a note that this no longer works with recent Laravel and Guzzle versions?


UPDATE:

Got it working by:

Below is my working code for shopify.php. I have tested with GET requests only so far. Have a feeling POST/PUT/DELETE will take some doing.

public function __construct($domain, $key, $password)
        {
            $url          = "https://" . $key . ":" . $password . "@" . $domain . "/admin/";
            $this->client = new Client([
                'base_url' => $url,
                'defaults' => ['headers' => ['Content-Type' => 'application/json']]
            ]);
        }

        /**
         * send off the request to Shopify, encoding the data as JSON
         *
         * @param  string $method
         * @param  string $page
         * @param  array  $data
         *
         * @return array
         */
        private function makeRequest($method, $page, $data = [])
        {

            $r = $this->client->createRequest($method, $page, $data);

            if ($data && $method != 'GET') {
                $r->setBody(json_encode($data), 'application/json');
            }

            if ($method == 'GET' && !empty($data)) {
            }

            try {
                $response = $this->client->send($r);
                return $response->json();
            } catch (ClientErrorResponseException $e) {
                return [
                    'error'    => $e->getMessage(),
                    'url'      => $e->getRequest()
                                    ->getUrl(),
                    'request'  => $e->getRequest(),
                    'status'   => $e->getResponse()
                                    ->getStatusCode(),
                    'response' => $e->getResponse()
                ];

            } catch (BadResponseException $e) {
                return [
                    'error'    => $e->getMessage(),
                    'url'      => $e->getRequest()
                                    ->getUrl(),
                    'request'  => $e->getRequest(),
                    'status'   => $e->getResponse()
                                    ->getStatusCode(),
                    'response' => $e->getResponse()
                ];
            }

        }

To access in a controller, I use:

    public function index()
    {
        $data = ['query'=>['limit'=>'250']];
        return Shopify::getProducts($data);
    }

Maybe this will help someone down the line—

aaronflorey commented 9 years ago

Sorry about that, it sems like i don't get emails from GitHub when someone comments on my repo.

I see you fixed it up in your own fork, did you want to send a pull request?