2017 © Pedro Peláez
 

library yaspa

Yet Another Shopify PHP API

image

paulchiu/yaspa

Yet Another Shopify PHP API

  • Friday, October 27, 2017
  • by paulchiu
  • Repository
  • 3 Watchers
  • 3 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 2 Versions
  • 11 % Grown

The README.md

Yet Another Shopify PHP API (yaspa)

CircleCI, (*1)

Installation

Do not install this library. It is currently under active development and is in no way stable., (*2)

Purpose

Most Shopify APIs appear to be thin wrappers around Guzzle that makes things slightly more convenient but still makes it feel like you are interacting with a REST API., (*3)

The goal of this project is to go one step beyond and provide something closer to a SDK whereby the library offers everything through PHP without the developer needing to think too much about the REST API., (*4)

Examples

The following examples show how CRUD works with the API. For full documentation, see the Yaspa Gitbook., (*5)

Please note that all examples utilise private authentication., (*6)

Create private authentication credentials

Credentials are stored in a POPO (Plain Old PHP Object) model., (*7)

All other examples assume the presence of the following code., (*8)

use Yaspa\Authentication\Factory\ApiCredentials;
use Yaspa\Factory;

$credentials = Factory::make(ApiCredentials::class)
    ->makePrivate(
        'my-shop',
        '4ac0000000000000000000000000035f',
        '59c0000000000000000000000000007f'
    );

Create a customer

use Yaspa\AdminApi\Customer\Builders\CreateNewCustomerRequest;
use Yaspa\AdminApi\Customer\CustomerService;
use Yaspa\AdminApi\Customer\Models\Customer;
use Yaspa\Factory;

// Prepare creation request
$customer = (new Customer())
    ->setFirstName('Steve')
    ->setLastName('Lastnameson')
    ->setEmail(uniqid('steve-').'@example.com')
    ->setTags(['foo', 'bar'])
    ->setVerifiedEmail(true)
    ->setAcceptsMarketing(true);
$request = Factory::make(CreateNewCustomerRequest::class)
    ->withCredentials($credentials)
    ->withCustomer($customer);

// Create new customer, $newCustomer is a Customer model
$service = Factory::make(CustomerService::class);
$newCustomer = $service->createNewCustomer($request);
var_dump($newCustomer);

Get all customers created in the past 7 days

use Yaspa\AdminApi\Customer\Builders\GetCustomersRequest;
use Yaspa\AdminApi\Customer\CustomerService;
use Yaspa\Factory;

// Create request
$request = Factory::make(GetCustomersRequest::class)
    ->withCredentials($credentials)
    ->withCreatedAtMin(new DateTime('-7 days'));

// Get customers, $customers is an iterator
$service = Factory::make(CustomerService::class);
$customers = $service->getCustomers($request);

// Loop through customers, each $customer is a Customer model
// paging is automated
foreach ($customers as $index => $customer) {
    var_dump($customer);
}

Update a customer

use Yaspa\AdminApi\Customer\Builders\ModifyExistingCustomerRequest;
use Yaspa\AdminApi\Customer\CustomerService;
use Yaspa\Factory;

// Create request
$customerUpdates = (new Customer())
    ->setId(6820000675)
    ->setFirstName('Alice')
$request = Factory::make(ModifyExistingCustomerRequest::class)
    ->withCredentials($credentials)
    ->withCustomer($customerUpdates);

// Modify an existing customer, $modifiedCustomer is a Customer model
$service = Factory::make(CustomerService::class);
$modifiedCustomer = $service->modifyExistingCustomer($request);
var_dump($modifiedCustomer);

Delete a customer

use Yaspa\AdminApi\Customer\CustomerService;
use Yaspa\Factory;

// Delete an existing customer
$service = Factory::make(CustomerService::class);
$service->deleteCustomerById($credentials, 6820000675);

Documentation

For full documentation, please see https://paulchiu.gitbooks.io/yaspa/content/, (*9)

Roadmap

See issue 10 for the project roadmap and to do list., (*10)

The Versions

27/10 2017

dev-master

9999999-dev

Yet Another Shopify PHP API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Paul Chiu

api client shopify

27/10 2017

0.1.0

0.1.0.0

Yet Another Shopify PHP API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Paul Chiu

api client shopify