Download the PHP package mtownsend/snipcart-api without Composer

On this page you can find all versions of the php package mtownsend/snipcart-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package snipcart-api

The easiest and fastest way to get up and running with Snipcart's api.

Snipcart API - mtownsend/snipcart-api

First steps

Installation

Install via composer:

This package can be used with any PHP 7.0+ application but has special support for Laravel.

Registering the service provider (Laravel users)

For Laravel 5.4 and lower, add the following line to your config/app.php:

For Laravel 5.5 and greater, the package will auto register the provider for you.

Using Lumen

To register the service provider, add the following line to app/bootstrap/app.php:

Publishing the config file (Laravel users)

`

Once your snipcart.php has been published your to your config folder, add the api key you obtained from Snipcart. If you are using Laravel and put your Snipcart api key in the config file, Laravel will automatically set your api key every time you instantiate the class through the helper or facade.

Quick start

Using the class

HTTP methods

This package supports RESTful HTTP methods including GET (default), POST, PUT, PATCH and DELETE.

GET example

POST example

PUT example

DELETE example

Class methods

->to(string '/url') or ->from(string '/url')

The to or from methods are identical and only exist to make your syntax make more semantic sense (get()->from() or post()->to()). These methods expect to receive a relative url path for the Snipcart endpoint you're attempting to communicate with. For example, if you want to get a list of orders from https://app.snipcart.com/api/orders, you would utilize your method of choice and pass it an argument of /orders.

Note: It does not matter if you prepend a slash, append a slash, both, or exclude both. The package gracefully handles your usage of prepended/appended slashes of the relative url. Any of these examples would be acceptable arguments: /orders/, /orders, orders/, or orders.

->payload(array ['key' => 'value']) or ->payload('key', 'value')

The payload method allows you to pass data through with your request.

If the request is a GET operation the payload will be converted to a valid query string. E.g. ['from' => '2018-05-05', 'to' => '2019-05-05'] will produce ?from=2018-05-05&to=2019-05-05 and be automatically appended to your request url.

Alternatively, if your preference is to manually include your query string for GET requests you may omit the payload method entirely and append your query string to the to/from method. E.g. ->get()->from('/orders?limit=10&offset=5')->send().

If the request is a POST, PUT, PATCH or DELETE operation the payload will automatically be converted to json and sent in the request's body.

->send()

The send method triggers the api call to be sent and returns the response.

->addHeader(string 'key', string 'value')

The addHeader method accepts two arguments. The first is the header key and the second is the header value. By default this package sets the Accept and Content-Type for you.

->addHeaders(array ['key' => 'value'])

The addHeaders method accepts an associative array of key/values to set as headers for the api request.

->responseCode()

The responseCode method returns the http code received from the server for the request. Note: this method should only be used if you are breaking up your api call into multiple variables.

->successful()

The successful method parses the http code received from the server and checks for any 2XX code and returns a boolean. Note: this method should only be used if you are breaking up your api call into multiple variables.

Checking for failed api calls

Snipcart's api provides graceful failure in many circumstances. If you were to make an api call to the endpoint /does-not-exist, the response would be null. You could easily check the value of your request object with a simple if statement before attempting to perform any logic.

Alternatively, if you prefer to split up your api call into multiple variables, the SnipcartApi class comes with a successful method.

Using the global helper (Laravel users)

If you are using Laravel, this package provides a convenient helper function which is globally accessible. The package will automatically set your api key from your config/snipcart.php file.

Using the facade (Laravel users)

If you are using Laravel, this package provides a facade. To register the facade add the following line to your config/app.php under the aliases key. The package will automatically set your api key from your config/snipcart.php file.

``

Credits

Testing

Tests coming soon...

You can run the tests with:

License

The MIT License (MIT). Please see License File for more information.


All versions of snipcart-api with dependencies

PHP Build Version
Package Version
Requires php Version ~7.0|~8.0
guzzlehttp/guzzle Version ^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mtownsend/snipcart-api contains the following files

Loading the files please wait ....