2017 © Pedro Peláez
 

library stack-exchange-api-client

StackExchange v2.2 API client

image

benatespina/stack-exchange-api-client

StackExchange v2.2 API client

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

stackExchange-logo Stack Exchange v2.2 API Client

PHP library for interacting with the Stack Exchange's version 2.2 REST API., (*1)

SensioLabsInsight Build Status Scrutinizer Code Quality Total Downloads Latest Stable Version Latest Unstable Version, (*2)

Requirements

PHP >= 7.1, (*3)

Installation

The easiest way to install this bundle is using Composer, (*4)

$ composer require benatespina/stack-exchange-api-client

Usage

If you check out the API documentation, you will see that there are some calls that do not need authentication, but nevertheless there are other calls that need it so, this library allows to instantiate StackExchange client with or without Authentication. Furthermore there two ways to use this library., (*5)

Default usage

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use BenatEspina\StackExchangeApiClient\StackExchange;

$client = StackExchange::withAuth('stack-exchange-key', 'stack-exchange-access-token');

$profile = $client->user()->me();
$answers = $client->answer()->answers();
$answer = $client->answer()->createAnswer('the-question-id', 'This is my awesome answer!');


$client = StackExchange::withoutAuth();

// Throws an AuthenticationIsRequired exception
$profile = $client->user()->me();

$answers = $client->answer()->answers();

// Throws an AuthenticationIsRequired exception
$answer = $client->answer()->createAnswer('the-question-id', 'This is my awesome answer!');

Full customized usage

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use BenatEspina\StackExchangeApiClient\Authentication\Authentication;
use BenatEspina\StackExchangeApiClient\Http\GuzzleHttpClient;
use BenatEspina\StackExchangeApiClient\Model\Answer;
use BenatEspina\StackExchangeApiClient\Serializer\ToModelSerializer;
use BenatEspina\StackExchangeApiClient\StackExchange;

$httpClient = new GuzzleHttpClient();
$authentication = new Authentication('stack-exchange-key', 'stack-exchange-access-token');

$client = new StackExchange($httpClient, $authentication);

$profile = $client->user()->me();
$answers = $client->answer()->answers();
$answer = $client->answer()->createAnswer('the-question-id', 'This is my awesome answer!');


// CUSTOM SERIALIZATION
//
// Instantiate the AnswerApi with custom serializer
// The following calls returns an answer model instance instead of a plain array

$answersApi = $client->answer(new ToModelSerializer(Answer::class));
$answers = $answersApi->answers();
$answer = $answersApi->createAnswer('the-question-id', 'This is my awesome answer!');

Current status

The API has many methods, so the calls' implementation status are separated by type in the following files: - progressed.io - 3 methods Access Tokens - progressed.io - 16 methods Answers - progressed.io - 7 methods Badges - progressed.io - 15 methods Comments - progressed.io - 1 methods Errors - progressed.io - 1 methods Events - progressed.io - 2 methods Filters - progressed.io - 4 methods Flag Options - progressed.io - 4 methods Inbox Items - progressed.io - 1 methods Network Users - progressed.io - 1 methods Merge History - progressed.io - 1 methods Network Activity - progressed.io - 4 methods Notifications - progressed.io - 3 methods Posts - progressed.io - 2 methods Privileges - progressed.io - 35 methods Questions - progressed.io - 1 methods Question Timelines - progressed.io - 1 methods Reputation - progressed.io - 2 methods Reputation History - progressed.io - 2 methods Revisions - progressed.io - 1 methods Search Excerpts - progressed.io - 1 methods Sites - progressed.io - 4 methods Suggested Edits - progressed.io - 6 methods Tags - progressed.io - 2 methods Tag Scores - progressed.io - 2 methods Tag Synonyms - progressed.io - 1 methods Tag Wikis - progressed.io - 3 methods Top Tags - progressed.io - 4 methods Users - progressed.io - 1 methods User Timeline - progressed.io - 1 methods Write Permissions, (*6)

Tests

This bundle is completely tested by [PHPSpec][3], SpecBDD framework for PHP., (*7)

Run the following command to launch tests:, (*8)

$ vendor/bin/phpspec run -fpretty

Contributing

This bundle follows PHP coding standards, so pull requests need to execute the Fabien Potencier's [PHP-CS-Fixer][4]. Furthermore, if the PR creates some not-PHP file remember that you have to put the license header manually. In order to simplify we provide a Composer script that wraps all the commands related with this process., (*9)

$ composer run-script cs

There is also a policy for contributing to this bundle. Pull requests must be explained step by step to make the review process easy in order to accept and merge them. New methods or code improvements must come paired with [PHPSpec][3] tests., (*10)

Credits

This library is created by: > @benatespina - benatespina@gmail.com, (*11)

Licensing Options

License, (*12)

The Versions

14/09 2017

dev-master

9999999-dev https://github.com/benatespina/StackExchangeApiClient

StackExchange v2.2 API client

  Sources   Download

MIT

The Requires

 

The Development Requires

api library client stackexchange

29/09 2015

v0.7.1

0.7.1.0 https://github.com/benatespina/StackExchangeApiClient

StackExchange v2.2 API client

  Sources   Download

MIT

The Requires

 

The Development Requires

api library client stackexchange

29/09 2015

v0.7.0

0.7.0.0 https://github.com/benatespina/StackExchangeApiClient

StackExchange v2.2 API client

  Sources   Download

MIT

The Requires

 

The Development Requires

api library client stackexchange