GithubHelp home page GithubHelp logo

zaxbux / backblaze-b2-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cwhite92/b2-sdk-php

4.0 1.0 5.0 359 KB

SDK for Backblaze's B2 storage service.

License: MIT License

PHP 99.54% Dockerfile 0.46%
backblaze-b2 backblaze api

backblaze-b2-php's Introduction

Backblaze B2 SDK for PHP

GitHub Packagist Version

backblaze-b2-php is a client library for working with the B2 cloud storage service from Backblaze.

Documentation

Full documentation of the Backblaze B2 API can be found here.

Complete documentation for this library does not exist yet, however most methods are already documented in the source code.

Installation

Installation is via Composer:

$ composer require zaxbux/backblaze-b2-php

Getting Started

<?php

use Zaxbux\BackblazeB2\Client;

$accountId      = '...';
$applicationKey = '...';

$client = new Client([$accountId, $applicationKey]);

// Retrieve an array of Bucket objects on your account.
$buckets = $client->listBuckets();

Authorization Cache

If you want to cache the authorization token to reduce the number of API calls, create a class that implements Zaxbux\BackblazeB2\Interfaces\AuthorizationCacheInterface.

<?php

use Zaxbux\BackblazeB2\Client;

$authCache = new AuthorizationCacheExample;

$client = new Client(new Config($accountId, $applicationKey, [
  'authorizationCache' => $authCache,
]));

Sample Authorization Cache

<?php

use Zaxbux\BackblazeB2\Interfaces\AuthorizationCacheInterface;

class AuthorizationCacheExample implements AuthorizationCacheInterface {
	public function cache($key, $value) {
		$myCache->remember($key, $value, AuthorizationCacheInterface::EXPIRES)
	}

	public function get($key) {
		$myCache->get($key);
	}
}

The AuthorizationCacheInterface::EXPIRES constant is how long the authorization token is valid for, in seconds. Currently, this is equivalent to 24 hours. Requests made after the token expires will result in an ExpiredAuthTokenException exception being thrown. You will need to get a new authorization token with authorizeAccount().

Tests

Tests are run with PHPUnit. After installing PHPUnit via Composer:

$ vendor/bin/phpunit

Contributing

Feel free to contribute in any way by reporting an issue, making a suggestion, or submitting a pull request.

Licence

MIT

backblaze-b2-php's People

Contributors

arajcany avatar mahony0 avatar matslindh avatar miyurusankalpa avatar svenluijten avatar zaxbux avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

backblaze-b2-php's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.