Skip to content

Commit

Permalink
Merge pull request #1 from mhetreramesh/master
Browse files Browse the repository at this point in the history
Added initial files for library
  • Loading branch information
mhetreramesh committed Aug 3, 2017
2 parents 6fdb1ba + 3e68420 commit 54b4f7d
Show file tree
Hide file tree
Showing 44 changed files with 11,969 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
/vendor
composer.lock
9 changes: 9 additions & 0 deletions .travis.yml
@@ -0,0 +1,9 @@
language: php

php:
- '5.6'
- '7.0'
- '7.1'
- nightly

before_script: composer install
Empty file modified LICENSE 100644 → 100755
Empty file.
95 changes: 95 additions & 0 deletions README.md
@@ -0,0 +1,95 @@
## Backblaze B2 for PHP

`backblaze-b2` is a client library for working with Backblaze's B2 storage service. It aims to make using the service as
easy as possible by exposing a clear API and taking influence from other SDKs that you may be familiar with.

## Example

This is just a short example, full examples to come on the wiki.

```php
use BackblazeB2\Client;
use BackblazeB2\Bucket;

$client = new Client('accountId', 'applicationKey');

// Returns a Bucket object.
$bucket = $client->createBucket([
'BucketName' => 'my-special-bucket',
'BucketType' => Bucket::TYPE_PRIVATE // or TYPE_PUBLIC
]);

// Change the bucket to private. Also returns a Bucket object.
$updatedBucket = $client->updateBucket([
'BucketId' => $bucket->getId(),
'BucketType' => Bucket::TYPE_PUBLIC
]);

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

// Delete a bucket.
$client->deleteBucket([
'BucketId' => '4c2b957661da9c825f465e1b'
]);

// Upload a file to a bucket. Returns a File object.
$file = $client->upload([
'BucketName' => 'my-special-bucket',
'FileName' => 'path/to/upload/to',
'Body' => 'I am the file content'

// The file content can also be provided via a resource.
// 'Body' => fopen('/path/to/input', 'r')
]);

// Download a file from a bucket. Returns the file content.
$fileContent = $client->download([
'FileId' => $file->getId()

// Can also identify the file via bucket and path:
// 'BucketName' => 'my-special-bucket',
// 'FileName' => 'path/to/file'

// Can also save directly to a location on disk. This will cause download() to not return file content.
// 'SaveAs' => '/path/to/save/location'
]);

// Delete a file from a bucket. Returns true or false.
$fileDelete = $client->deleteFile([
'FileId' => $file->getId()

// Can also identify the file via bucket and path:
// 'BucketName' => 'my-special-bucket',
// 'FileName' => 'path/to/file'
]);

// Retrieve an array of file objects from a bucket.
$fileList = $client->listFiles([
'BucketId' => '4d2dbbe08e1e983c5e6f0d12'
]);
```

## Installation

Installation is via Composer:

```bash
$ composer require gliterd/backblaze-b2
```

## Tests

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

```bash
$ vendor/bin/phpunit
```

## Contributors

Feel free to contribute in any way you can whether that be reporting issues, making suggestions or sending PRs. :)

## License

MIT.
33 changes: 33 additions & 0 deletions composer.json
@@ -0,0 +1,33 @@
{
"name": "gliterd/backblaze-b2",
"type": "library",
"description": "PHP SDK for working with backblaze B2 cloud storage.",
"keywords": ["cloud-storage", "b2", "storage", "backblaze", "cloud", "filesystem", "backup"],
"homepage": "https://github.com/gliterd/b2-sdk-php",
"license": "MIT",
"authors": [
{
"name": "Ramesh Mhetre",
"email": "mhetreramesh@gmail.com",
"homepage": "https://gliterd.com",
"role": "Developer"
}
],
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.1"
},
"require-dev": {
"phpunit/phpunit": "4.8.*"
},
"autoload": {
"psr-4": {
"BackblazeB2\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"BackblazeB2\\Tests\\": "tests/"
}
}
}
18 changes: 18 additions & 0 deletions phpunit.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="b2-sdk-php tests">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
42 changes: 42 additions & 0 deletions src/Bucket.php
@@ -0,0 +1,42 @@
<?php

namespace BackblazeB2;

class Bucket
{
const TYPE_PUBLIC = 'allPublic';
const TYPE_PRIVATE = 'allPrivate';

protected $id;
protected $name;
protected $type;

/**
* Bucket constructor.
*
* @param $id
* @param $name
* @param $type
*/
public function __construct($id, $name, $type)
{
$this->id = $id;
$this->name = $name;
$this->type = $type;
}

public function getId()
{
return $this->id;
}

public function getName()
{
return $this->name;
}

public function getType()
{
return $this->type;
}
}

0 comments on commit 54b4f7d

Please sign in to comment.