dpb587 / ravelry-api
A PHP library for interacting with the Ravelry API.
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: 4.0.2
- guzzlehttp/guzzle-services: 0.2.0
- guzzlehttp/oauth-subscriber: dev-master
This package is not auto-updated.
Last update: 2022-04-16 05:24:14 UTC
README
A PHP library for interacting with the Ravelry API.
Consider this a functional prototype. This library's API may change. Not all the API calls have been tested.
This project is not affiliated with Ravelry.
Getting Started
The source code is located in ./src
and dependencies are managed with Composer.
Download
For integration, it's easiest to require with composer
...
composer.phar require dpb587/ravelry-api=dev-master
For development, it's easiest to clone with git
...
git clone https://github.com/dpb587/ravelry-api-php
cd ravelry-api-php
composer.phar install
Authentication
There are two authentication methods for you to decide between. In both cases you can find the necessary keys from the apps tab of your Ravelry Pro account.
For OAuth, use an OauthTokenStorage
handler
and include your access and secret key...
$auth = new RavelryApi\Authentication\OauthAuthentication(
new RavelryApi\Authentication\OauthTokenStorage\FileTokenStorage(),
$accessKey,
$secretKey
);
For personal use with your own account, you can use your access and personal key...
$auth = new RavelryApi\Authentication\BasicAuthentication($accessKey, $personalKey);
Usage
Create a new RavelryApi\Client
, including the authentication handler you're using...
$ravelry = new RavelryApi\Client($auth);
And now you can make API calls, using the returned result like an array...
# find the first message from the inbox
$id =
$ravelry->messages->list([ 'folder' => 'inbox' ])
['messages'][0]['id'];
# load and show the message
$message =
$ravelry->messages->show([ 'id' => $id ])
['message'];
echo $message['content_html'];
#> <p>I’m a message from the API!</p>
# then mark it as read
$ravelry->messages->markRead([ 'id' => $id ]);
Internally, the results are an object which provides some additional values...
get_class($message);
#= 'RavelryApi\\Model'
$message->toArray();
#= ['message'=>['sent_at'=>...]]
$message->getEtag();
#= '"18aa948e83e5e6b131d6b60998690fd5"'
$message->getStatusCode();
#= 200
$message->getStatusText();
#= 'OK'
Tests
The testing code is located in ./test
and are run with phpunit
.
Functional Tests
The functional tests will actually communicate with the Ravelry API to run through various API calls and validate the
expected responses. You must configure a RAVELRY_TEST_ACCESS_KEY
and RAVELRY_TEST_PERSONAL_KEY
to use for
authentication with the tests. All tests run as specifically as possible and avoid changing things that tests didn't
create, however, it is testing so you should probably use a dedicated test account.
There is a ./test/cleanup.php
script which will clean up any objects left behind from failed tests.
References
- http://www.ravelry.com/api - Ravelry's API Documentation
- https://github.com/dpb587/ravelry-api-cli.php - a CLI for the API (uses this library)