Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This software is licensed under the Apache 2 license, quoted below.

Copyright 2014 Patrick Reilly <preilly@php.net>
Copyright 2012 Kevin Khandjian <kevinkhandjian@gmail.com>

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
bufferapp-php
BufferApp
=============

Simple PHP library for the amazing buffer at http://bufferapp.com
Simple PHP composer package for the amazing buffer at http://bufferapp.com

# Why?

There wasn't one listed on Buffer's website and a quick Google search didn't turn one up. For most use cases Buffer's plugins will work just fine, but for those of you looking to pump lots of info into buffer via PHP this may help!
There wasn't one listed on Buffer's website and a quick Google search didn't turn one up.
For most use cases Buffer's plugins will work just fine, but for those of you looking to pump lots of info into buffer via PHP this may help!

# Using this library

1. Include the file
- Make sure you've got `buffer.php` included
- Make sure you've got: "require": "buffer/app": "dev-master" included in your composer.json file
2. Create a new Buffer app
- You'll need to [register an app](http://bufferapp.com/developers/api) with buffer before you can begin
- Initialize like this `$buffer = new BufferApp($client_id, $client_secret, $callback_url);` The `callback_url` needs to be the exact same as the app you registered
3. Start adding buffers!
- Once you're in you really only need to check `$buffer->ok` to see if you can perform actions, and then `$buffer->go($endpoint, $data)` to get going!

##### Image Attachments

The Buffer API seems to be missing documentation for the `media` parameter for creating an update.
Expand All @@ -26,13 +27,13 @@ Their [example here](http://bufferapp.com/developers/api/updates#updatescreate)
To get the desired result you will need to use `media[picture]` _and_ `media[thumbnail]`.



# Example

First thing's first: start a session and require `buffer.php`. We're going to be storing the `access_token` in the session for now.
First thing's first: start a session.
We're going to be storing the `access_token` in the session for now.

session_start();
require('buffer.php');

Set this thing up with your credentials and your callback URL. Remember: `callback_url` must match what you've got in Buffer exactly!

Expand All @@ -43,21 +44,23 @@ Set this thing up with your credentials and your callback URL. Remember: `callba
Set up the new buffer client. This is a super simple action that does a few things under the hood.
If `$_GET['code']` is set on this page it assumes it came from Buffer and will attempt to trade that code for an `access_token`. If there is an `access_token` in the session it will be loaded in.


use Buffer\App\BufferApp;
$buffer = new BufferApp($client_id, $client_secret, $callback_url);

Once we've got an `access_token` set the `$buffer->ok` property will read true. It is false by default.
Once we've got an `access_token` set the `$buffer->ok` property will read true. It is false by default.
Now that we've received access we are free to run queries against Buffer endpoints! Below we pull the list of profiles associated with the logged in buffer user and submit a test update to each one.

if (!$buffer->ok) {
echo '<a href="' . $buffer->get_login_url() . '">Connect to Buffer!</a>';
} else {
//this pulls all of the logged in user's profiles
$profiles = $buffer->go('/profiles');

if (is_array($profiles)) {
foreach ($profiles as $profile) {
//this creates a status on each one
$buffer->go('/updates/create', array('text' => 'My first status update from bufferapp-php worked!', 'profile_ids[]' => $profile->id));
$buffer->go('/updates/create', array('text' => 'My first status update from BufferApp worked!', 'profile_ids[]' => $profile->id));
}
}
}
Expand All @@ -69,5 +72,7 @@ Right now this baby just stores the `access_token` in `$_SESSION['oauth']['buffe
Realistically these methods should be replaced with some sort of abstraction -- pull requests are welcome!

# License
Apache-2.0
Do whatever you like with this.
Feel free (but not obligated) to [drop me a line](http://preilly.me) or the original author [drop kevin a line](http://kevin.fm) if it helps!

Do whatever you like with this. Feel free (but not obligated) to [drop me a line](http://kevin.fm) if it helps!
207 changes: 0 additions & 207 deletions buffer.php

This file was deleted.

9 changes: 9 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "buffer/app",
"license": "Apache-2.0",
"autoload": {
"psr-0" : {
"Buffer\\App" : "src"
}
}
}
49 changes: 27 additions & 22 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
<?
session_start();
require('buffer.php');

$client_id = '';
$client_secret = '';
$callback_url = 'http://127.0.0.1/callback';

$buffer = new BufferApp($client_id, $client_secret, $callback_url);

if (!$buffer->ok) {
echo '<a href="' . $buffer->get_login_url() . '">Connect to Buffer!</a>';
} else {
$profiles = $buffer->go('/profiles');

if (is_array($profiles)) {
foreach ($profiles as $profile) {
$buffer->go('/updates/create', array('text' => 'My first status update from bufferapp-php worked!', 'profile_ids[]' => $profile->id));
}
}
}
?>
<?php

require 'vendor/autoload.php';

use Buffer\App\BufferApp;

session_start();

$client_id = '';
$client_secret = '';
$callback_url = 'http://127.0.0.1/callback';

$buffer = new BufferApp($client_id, $client_secret, $callback_url);

if (!$buffer->ok) {
echo '<a href="' . $buffer->get_login_url() . '">Connect to Buffer!</a>';
} else {
$profiles = $buffer->go('/profiles');

if (is_array($profiles)) {
foreach ($profiles as $profile) {
$buffer->go('/updates/create', array(
'text' => 'My first status update from BufferApp worked!',
'profile_ids[]' => $profile->id));
}
}
}
Loading