Skip to content

Commit

Permalink
Merge pull request #1 from 8fold/initial
Browse files Browse the repository at this point in the history
Initial
  • Loading branch information
joshbruce authored Apr 30, 2023
2 parents 706c986 + ee6e084 commit bf45932
Show file tree
Hide file tree
Showing 50 changed files with 2,881 additions and 2,108 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/php82.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: PHP 8.2

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP Action
uses: shivammathur/setup-php@2.15.0
with:
php-version: '8.2'

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run style check
run: composer run style

- name: Run static analyzer
run: composer run stan

- name: Run tests
run: composer run test
128 changes: 116 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,144 @@

{brief description}


## Installation

{how does one install the product}

## Usage

To create a connection:
### Initialize Client

```
```php
use Eightfold\Printify\Client;
use Eightfold\Printify\Printify;

$printify = Printify::init({'YOUR_ACCESS_TOKEN'});
$client = Client::connect(
Printify::account({'your Printify access token'})
);
```

We want to minimize the number API calls made; therefore, the recommended starting point to receive a list of products and variations in a single call is as follows:
### Use Client

The Client is the recommended entry point and leverages a fluent approach.

**Retrieve a list of shops in a Printify account**

```php
// API call
$client->getShops();
```
use Eightfold\Printify\Printify;

$products = Printify::init({'YOUR_ACCESS_TOKEN'})->getProductsIn({'THE_SHOP_ID'});
*Retrieve a single shop (from the list of shops)*

```php
// API call
$client->getShop({shop id});
```

*Retrieve a Shop instance (supports lazy loading)*

```php
// No API call
$shop = $client->shop({shop id});

$shop->id();

// API call
$shop->title();
```

**Retrieve a list of products in a Shop**

```php
// API call
$client->getProducts($shop);
```

*Retrieve a single Product*

```php
// API call
$client->getProduct({product id});
```

*Retrieve a Product instance (supports lazy loading)*

```php
// No API call
$product = $client->getProduct($shop, {product id});

$product->id();

$product->shopId();

// API call
$product->title();

$product->description();

// and other properties
```

*Retrieve a collection of Variants for a Product*

```php
// API call
$variants = $product->variants();
```

*Retrieve a single Variant from a Product*

```php
// API call
$variant = $product->variants()->atIndex(0);

$variant = $product->variants()->variantWithId({variant id});
```

*Retrieve a collection of Images for a Product*

```php
$images = $product->images();
```

*Retrieve array of Images for a Variant*

```php
$images = $variant->images($product);

$images = $product->imagesForVariant($variant);
```

To get a single product in a single call:
*Retrieve default Image for a Variant*

```php
$image = $variant->defaultImage($product);

$image = $product->defaultForVariant($variant);

$image = $product->imagesForVariant($variant, defaultOnly: true);
```

use Eightfold\Printify\Printify;```
**Set Product publish status to succeeded**

$product = Printify::init({'YOUR_ACCESS_TOKEN'})
->getProductWithIn({'THE_PRODUCT_ID'}, {'THE_SHOP_ID'});
```php
$client->postPublishingSucceededForProduct($product);
```

## Details

Methods starting with `get` perform API requests; specifically, a `GET` request.
The project's folder structure is designed to mirror the Printify API endpoint structures.

We delay API calls until the last responsible moment. We afford you the opportunity to do the same.

Methods starting with `get` perform API requests, specifically, a `GET` request.

Methods starting with `post` perform API requests, specifically, a `POST` request.

Methods starting with `delete` perform API requests, specifically, a `DELETE` request.

Methods starting with `put` perform API requests, specifically, a `PUT` request.

## Other

Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
"php": "^8.1",
"kriswallsmith/buzz": "^1.2",
"nyholm/psr7": "^1.5",
"vlucas/phpdotenv": "^5.4"
"nyholm/psr7-server": "^1.0"
},
"require-dev": {
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.7"
"phpunit/phpunit": "^10.0",
"squizlabs/php_codesniffer": "^3.7",
"vlucas/phpdotenv": "^5.5"
},
"autoload": {
"psr-4": {
Expand All @@ -44,7 +45,7 @@
"scripts": {
"prod": "@production",
"production": [
"composer dumuutoload -o",
"composer dumpautoload -o",
"@style",
"@stan",
"@test"
Expand Down
Loading

0 comments on commit bf45932

Please sign in to comment.