GithubHelp home page GithubHelp logo

mich5blue / php-client-library Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hasinhayder/php-client-library

0.0 1.0 0.0 912 KB

A php library for communicating with the copy cloud api

License: MIT License

php-client-library's Introduction

Copy PHP API

Latest Stable Version Composer Downloads Build Status

A php library for communicating with the copy cloud api

This library demos the binary part api, an efficient way to de-dupe and send/receive data with the Copy cloud, and the JSONRPC api used by the Copy agent, and Copy mobile devices, for doing advanced things with Copy.

This demo works with the OAUTH api, which you will need to setup at the Copy developer portal (https://www.copy.com/developer/).

The Basics

Connect to the cloud

// create a cloud api connection to Copy
$copy = new \Barracuda\Copy\API($consumerKey, $consumerSecret, $accessToken, $tokenSecret);

List items

// list items in the root
$items = $copy->listPath('/');

Uploading a file

// open a file to upload
$fh = fopen('/tmp/file', 'rb');

// upload the file in 1MB chunks
$parts = array();
while ($data = fread($fh, 1024 * 1024)) {
    $part = $copy->sendData($data);
    array_push($parts, $part);
}

// close the file
fclose($fh);

// finalize the file
$copy->createFile('/copy-file-path', $parts);

Downloading a file

// obtain a list of file and parts
$files = $copy->listPath('/copy-file-path', array("include_parts" => true));

// process each file
foreach ($files as $file) {
	$data = '';

	// enumerate the parts in the latest revision
    foreach ($file->revisions[0]->parts as $part) {
        $data .= $copy->getPart($part->fingerprint, $part->size);
    }
}

Delete a file

$copy->removeFile('/copy-file-path');

Installing via Composer

The recommended way to install the Copy PHP API is through Composer.

# Install Composer
curl -sS https://getcomposer.org/installer | php

# Add Copy API as a dependency
php composer.phar require barracuda/copy

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

Running the tests

First install the dependencies for the library using Composer. See above for how to install Composer.

composer install

Then add connection info for your Copy account as environment variables:

export CONSUMER_KEY=<check the developer portal>
export CONSUMER_SECRET=<check the developer portal>
export ACCESS_TOKEN=<OAuth token>
export ACCESS_TOKEN_SECRET=<OAuth secret>

License

This library is MIT licensed, so feel free to use it anyway you see fit.

php-client-library's People

Contributors

ablyler avatar dangerbell avatar hasinhayder avatar jasondictos avatar

Watchers

 avatar

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.