Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement Tweets:Volume streams endpoint #148

Merged
merged 21 commits into from
May 23, 2022

Conversation

robertodoering
Copy link
Contributor

@robertodoering robertodoering commented May 21, 2022

1. Description

This PR adds support for streamed responses and implements the Volume streams endpoint.

To handle the streamed responses, we can use the send method on http requests.
Since they return a StreamedResponse (rather than a Response), some changed were done to the TwitterException to allow also handling exceptions for streamed responses.

The endpoint methods then just return a Future<Stream<T>>, which the user can handle like any other stream.

E.g.:

final response = await tweetsService.volumeStreams();

await for (final tweet in response) {
  print('received tweet: $tweet');
}
final response = await tweetsService.volumeStreams();

response.listen(
  (tweet) => print('received tweet: $tweet'),
  onError: (e) => print('received error: $e'),
  cancelOnError: false,
);

1.1. Checklist

  • The title of my PR starts with a Conventional Commit prefix (fix:, feat:, docs: etc).
  • I have read the Contributor Guide and followed the process outlined for submitting PRs.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples.

1.2. Breaking Change

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

1.3. Related Issues

Closes #14

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! :)

@robertodoering
Copy link
Contributor Author

Hey @myConsciousness, thanks again for this great wrapper of the v2 api :)
Feel free to review this PR and request / make changes as you see fit.


I have updated/added relevant examples in examples.

Where should I add examples to? The examples/examples.dart file?

@codecov-commenter
Copy link

codecov-commenter commented May 21, 2022

Codecov Report

Merging #148 (a01fff9) into main (80defc5) will decrease coverage by 1.16%.
The diff coverage is 74.00%.

@@            Coverage Diff             @@
##             main     #148      +/-   ##
==========================================
- Coverage   84.44%   83.27%   -1.17%     
==========================================
  Files          43       43              
  Lines         527      568      +41     
==========================================
+ Hits          445      473      +28     
- Misses         82       95      +13     
Impacted Files Coverage Δ
lib/src/client/client_context.dart 38.70% <0.00%> (-5.74%) ⬇️
lib/src/client/oauth1_client.dart 0.00% <0.00%> (ø)
lib/src/client/oauth2_client.dart 40.62% <0.00%> (-7.53%) ⬇️
lib/src/client/client.dart 100.00% <100.00%> (ø)
lib/src/service/base_service.dart 93.65% <100.00%> (+1.65%) ⬆️
lib/src/service/tweets/tweets_service.dart 99.16% <100.00%> (+0.04%) ⬆️
lib/src/twitter_exception.dart 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 80defc5...a01fff9. Read the comment docs.

@myConsciousness
Copy link
Member

Hi @robertodoering , I've seen a few differences and this is a great implementation! :) And thanks for your feedback, I'm also very glad to welcome you as a pioneer of the Twitter API library in the Dart language.

Where should I add examples to? The examples/examples.dart file?

Yes, Stream is a specification that stands out from the rest of the Twitter API, so if you have time, please add examples to
examples/examples.dart 👍

Also it's almost empty now, but I plan to create the following repository that will manage examples of this library's use for each endpoint.

Okay, I'll check your pull request when I can touch my laptop, thank you! :)

/// ## Reference
///
/// - https://developer.twitter.com/en/docs/twitter-api/tweets/volume-streams/api-reference/get-tweets-sample-stream
Future<Stream<TweetData>> volumeStreams({int? backfillMinutes});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the expansions parameter is missing, so I add List<TweetExpansion>? expansions :)

/// ## Reference
///
/// - https://developer.twitter.com/en/docs/twitter-api/tweets/volume-streams/api-reference/get-tweets-sample-stream
Future<Stream<TweetData>> volumeStreams({int? backfillMinutes, List<TweetExpansion>? expansions});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please let me fix method name to connectVolumeStreams, because there are other Stream-related endpoints, but I intend to unify the prefixes of those endpoints with connect :)

@myConsciousness
Copy link
Member

Thanks for your contribution @robertodoering ! 🚀

@myConsciousness
Copy link
Member

bors merge

@bors
Copy link
Contributor

bors bot commented May 23, 2022

Build succeeded:

@bors bors bot merged commit 9876daf into twitter-dart:main May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request service/Tweets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Tweets:Volume streams endpoint
3 participants