Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit f79fe8c

Browse files
committed
Merge branch 'hotfix/require-php-7-2'
Close #54
2 parents 7156687 + 2f9be3d commit f79fe8c

File tree

5 files changed

+235
-28
lines changed

5 files changed

+235
-28
lines changed

.travis.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ language: php
55
cache:
66
directories:
77
- $HOME/.composer/cache
8-
- vendor
98

109
env:
1110
global:
1211
- COMPOSER_ARGS="--no-interaction"
12+
- COVERAGE_DEPS="satooshi/php-coveralls"
1313

1414
matrix:
1515
include:
@@ -19,7 +19,8 @@ matrix:
1919
- php: 7.1
2020
env:
2121
- DEPS=locked
22-
- CHECK_CS=true
22+
- CS_CHECK=true
23+
- TEST_COVERAGE=true
2324
- php: 7.1
2425
env:
2526
- DEPS=latest
@@ -32,22 +33,23 @@ matrix:
3233
- php: 7.2
3334
env:
3435
- DEPS=latest
35-
allow_failures:
36-
- php: 7.2
3736

3837
before_install:
39-
- if [[ $TRAVIS_PHP_VERSION =~ ^7.1 ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
40-
- travis_retry composer self-update
38+
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
4139

4240
install:
43-
- travis_retry composer install $COMPOSER_ARGS --ignore-platform-reqs
41+
- travis_retry composer install $COMPOSER_ARGS
4442
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi
4543
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi
44+
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi
4645
- stty cols 120 && composer show
4746

4847
script:
49-
- composer test
50-
- if [[ $CHECK_CS == 'true' ]]; then composer cs-check ; fi
48+
- if [[ $TEST_COVERAGE == 'true' ]]; then composer test-coverage ; else composer test ; fi
49+
- if [[ $CS_CHECK == 'true' ]]; then composer cs-check ; fi
50+
51+
after_script:
52+
- if [[ $TEST_COVERAGE == 'true' ]]; then composer upload-coverage ; fi
5153

5254
notifications:
5355
email: false

README.md

Lines changed: 194 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,201 @@
1-
# ZendService\Twitter component
1+
# zendservice-twitter
22

3-
Master: [![Build Status](https://secure.travis-ci.org/zendframework/ZendService_Twitter.png?branch=master)](http://travis-ci.org/zendframework/ZendService_Twitter)
3+
[![Build Status](https://secure.travis-ci.org/zendframework/ZendService_Twitter.svg?branch=master)](https://secure.travis-ci.org/zendframework/ZendService_Twitter)
4+
[![Coverage Status](https://coveralls.io/repos/github/zendframework/ZendService_Twitter/badge.svg?branch=master)](https://coveralls.io/github/zendframework/ZendService_Twitter?branch=master)
45

5-
You can install using Composer:
6+
Provides an object oriented PHP wrapper for the [Twitter API](https://developer.twitter.com/en/docs).
7+
8+
## Installation
9+
10+
Run the following to install this library:
611

712
```bash
813
$ composer require zendframework/zendservice-twitter
914
```
1015

11-
At that point, follow the instructions in the documentation folder for actual
12-
usage of the component. (Documentation is forthcoming.)
16+
## Usage
17+
18+
Instantiate the `Twitter` class by providing your Twitter consumer key and
19+
secret, as well as the access token and secret:
20+
21+
```php
22+
use ZendService\Twitter\Twitter;
23+
24+
$twitter = new Twitter([
25+
'access_token' => [
26+
'token' => '<token value>',
27+
'secret' => '<token secret value>',
28+
],
29+
'oauth_options' => [
30+
'consumerKey' => '<consumer key value>',
31+
'consumerSecret' => '<consumer secret value>',
32+
],
33+
]);
34+
```
35+
36+
Once you have done that, you may start making calls to the API. This can be done
37+
in one of three ways:
38+
39+
- Using direct method calls on the `Twitter` class. A full list is provided
40+
below.
41+
- Using the "proxy" functionality. In these cases, you will provide the first
42+
path element of the API, and then call a method on it:
43+
`$twitter->statuses->update($message)`.
44+
- Using the `get()` or `post()` methods.
45+
46+
## Available methods
47+
48+
- `accountVerifyCredentials() : Response`
49+
- `applicationRateLimitStatus() : Response`
50+
- `blocksCreate($id) : Response`
51+
- `blocksDestroy($id) : Response`
52+
- `blocksIds(int $cursor = -1) : Response`
53+
- `blocksList(int $cursor = -1) : Response`
54+
- `directMessagesDestroy($id) : Response`
55+
- `directMessagesMessages(array $options = []) : Response`
56+
- `directMessagesNew($user, string $text, array $extraParams = []) : Response`
57+
- `directMessagesEventsNew($user, string $text, array $extraParams = []) : Response`
58+
- `directMessagesSent(array $options = []) : Response`
59+
- `favoritesCreate($id) : Response`
60+
- `favoritesDestroy($id) : Response`
61+
- `favoritesList(array $options = []) : Response`
62+
- `followersIds($id, array $params = []) : Response`
63+
- `friendsIds($id, array $params = []) : Response`
64+
- `friendshipsCreate($id, array $params = []) : Response`
65+
- `friendshipsLookup($id, array $params = []) : Response`
66+
- `friendshipsDestroy($id) : Response`
67+
- `listsMembers($listIdOrSlug, array $params = []) : Response`
68+
- `listsMemberships($id, array $params = []) : Response`
69+
- `listsSubscribers($id, array $params = []) : Response`
70+
- `searchTweets(string $query, array $options = []) : Response`
71+
- `statusesDestroy($id) : Response`
72+
- `statusesHomeTimeline(array $options = []) : Response`
73+
- `statusesMentionsTimeline(array $options = []) : Response`
74+
- `statusesSample() : Response`
75+
- `statusesShow($id, array $options = []) : Response`
76+
- `statusesUpdate(string $status, $inReplyToStatusId = null, $extraAttributes = []) : Response`
77+
- `statusesUserTimeline(array $options = []) : Response`
78+
- `usersLookup($id, array $params = []) : Response`
79+
- `usersSearch(string $query, array $options = []) : Response`
80+
- `usersShow($id) : Response`
81+
82+
## Proxy Properties
83+
84+
The following proxy properties are allowed:
85+
86+
- account
87+
- application
88+
- blocks
89+
- directmessages
90+
- favorites
91+
- followers
92+
- friends
93+
- friendships
94+
- lists
95+
- search
96+
- statuses
97+
- users
98+
99+
In each case, you can identify available methods for the proxy by comparing the
100+
proxy name to the above list of methods. As an example, the `users` proxy allows
101+
the following:
102+
103+
```php
104+
$twitter->users->lookup($id, array $params = []);
105+
$twitter->users->search(string $query, array $options = []);
106+
$twitter->users->show($id);
107+
```
108+
109+
## Direct access
110+
111+
The Twitter API has dozens of endpoints, some more popular and/or useful than
112+
others. As such, we are only providing a subset of what is available.
113+
114+
However, we allow you to access any endpoint via either the `get()` or `post()`
115+
methods, which have the following signatures:
116+
117+
```php
118+
public function get(string $path, array $query = []) : Response;
119+
public function post(string $path, $data = null) : Response;
120+
```
121+
122+
In each case, the `$path` is the API endpoint as detailed in the Twitter API
123+
documentation, minus any `.json` suffix, and the method name corresponds to
124+
whether the request happens via HTTP GET or POST.
125+
126+
For HTTP GET requests, the `$query` argument provides any query string
127+
parameters you want to pass for that endpoint. As an example, if you were
128+
requesting `statuses/home_timeline`, you might pass `count` or `since_id`.
129+
130+
For HTTP POST requests, the `$data` argument can be one of:
131+
132+
- An associative array of data.
133+
- A serializable object of data.
134+
- A string representing the raw payload.
135+
136+
The data to provide will vary based on the endpoint.
137+
138+
## Media uploads
139+
140+
Since version 3.0, we have supported media uploads via the classes
141+
`ZendService\Twitter\Media`, `Image`, and `Video`. In each case, you will
142+
instantiate the appropriate class with the local filesystem path of the image to
143+
upload and the media type, followed by calling `upload()` with a properly
144+
configured HTTP client. The response will contain a `media_id` property, which
145+
you can then provide via the `media_ids` parameter when posting a status:
146+
147+
148+
```php
149+
$image = new Image('data/logo.png', 'image/png');
150+
$response = $image->upload($twitter->getHttpClient());
151+
152+
$twitter->statusUpdate(
153+
'A post with an image',
154+
null,
155+
['media_ids' => [$response->media_id]]
156+
);
157+
```
158+
159+
When providing media for direct messages, you must provide additional flags to
160+
the media class's constructor:
161+
162+
- A flag indicating it is for a direct message
163+
- A flag indicating whether or not the uploaded media may be shared/re-used in
164+
other direct messages.
165+
166+
```php
167+
$image = new Image(
168+
'data/logo.png',
169+
'image/png',
170+
$forDirectMessage = true,
171+
$shared = false
172+
);
173+
$upload = $image->upload($twitter->getHttpClient());
174+
```
175+
176+
Unlike non-DM media uploads, the identifier will be in the `id_str` parameter of
177+
the returned upload instance; use that as a `media_id` in your DM:
178+
179+
```php
180+
$twitter->directmessagesEventsNew(
181+
$user,
182+
$message,
183+
['media_id' => $upload->id_str]
184+
);
185+
```
186+
187+
Note: direct messages only support a single attachment.
188+
189+
## Rate limiting
190+
191+
As of version 3.0, we now provide introspection of Twitter's rate limit headers,
192+
allowing you to act on them:
193+
194+
```php
195+
$response = $twitter->statusUpdate('A post');
196+
$rateLimit = $response->getRateLimit();
197+
if ($rateLimit->remaining === 0) {
198+
// Time to back off!
199+
sleep($rateLimit->reset); // seconds left until reset
200+
}
201+
```

docs/ISSUE_TEMPLATE.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
- [ ] I was not able to find an [open](https://github.com/zendframework/ZendService_Twitter/issues?q=is%3Aopen) or [closed](https://github.com/zendframework/ZendService_Twitter/issues?q=is%3Aclosed) issue matching what I'm seeing.
2+
- [ ] This is not a question. (Questions should be asked on [slack](https://zendframework.slack.com/) ([Signup for Slack here](https://zendframework-slack.herokuapp.com/)) or our [forums](https://discourse.zendframework.com/).)
3+
14
Provide a narrative description of what you are trying to accomplish.
25

36
### Code to reproduce the issue
47

8+
<!-- Please provide the minimum code necessary to recreate the issue -->
9+
510
```php
611
```
712

813
### Expected results
914

15+
<!-- What do you think should have happened? -->
16+
1017
### Actual results
1118

19+
<!-- What did you actually observe? -->

docs/PULL_REQUEST_TEMPLATE.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
Provide a narrative description of what you are trying to accomplish:
22

3-
- Are you fixing a bug?
4-
- Detail how the bug is invoked currently.
5-
- Detail the original, incorrect behavior.
6-
- Detail the new, expected behavior.
3+
- [ ] Are you fixing a bug?
4+
- [ ] Detail how the bug is invoked currently.
5+
- [ ] Detail the original, incorrect behavior.
6+
- [ ] Detail the new, expected behavior.
7+
- [ ] Base your feature on the `master` branch, and submit against that branch.
8+
- [ ] Add a regression test that demonstrates the bug, and proves the fix.
9+
- [ ] Add a `CHANGELOG.md` entry for the fix.
710

8-
- Are you creating a new feature?
9-
- Why is the new feature needed? What purpose does it serve?
10-
- How will users use the new feature?
11+
- [ ] Are you creating a new feature?
12+
- [ ] Why is the new feature needed? What purpose does it serve?
13+
- [ ] How will users use the new feature?
14+
- [ ] Base your feature on the `develop` branch, and submit against that branch.
15+
- [ ] Add only one feature per pull request; split multiple features over multiple pull requests
16+
- [ ] Add tests for the new feature.
17+
- [ ] Add documentation for the new feature.
18+
- [ ] Add a `CHANGELOG.md` entry for the new feature.
1119

12-
- Is this related to quality assurance?
13-
- Detail why the changes are necessary.
20+
- [ ] Is this related to quality assurance?
21+
<!-- Detail why the changes are necessary -->
1422

15-
- Is this related to documentation?
16-
- Is it a typographical and/or grammatical fix?
17-
- Is it new documentation?
23+
- [ ] Is this related to documentation?
24+
<!-- Is it a typographical and/or grammatical fix? -->
25+
<!-- Is it new documentation? -->

docs/SUPPORT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ Zend Framework offers three support channels:
55
- For real-time questions, use our
66
[Slack](https://zendframework-slack.herokuapp.com)
77
- For detailed questions (e.g., those requiring examples) use our
8-
[forums](https://discourse.zendframework.com/c/contributors)
8+
[forums](https://discourse.zendframework.com/c/questions/components)
99
- To report issues, use this repository's
10-
[issue tracker](https://github.com/{org}/{repo}/issues/new)
10+
[issue tracker](https://github.com/zendframework/ZendService_Twitter/issues/new)
1111

1212
**DO NOT** use the issue tracker to ask questions; use Slack or the forums for
1313
that. Questions posed to the issue tracker will be closed.

0 commit comments

Comments
 (0)