julianfssen / tweetkit Goto Github PK
View Code? Open in Web Editor NEW⚠️ WIP: Twitter v2 API client for Ruby
License: MIT License
⚠️ WIP: Twitter v2 API client for Ruby
License: MIT License
I just noticed you are still depending on faraday 1.x.
That makes it impossible to use in an app that has other dependencies on faraday 2.x. Faraday 2.0.0 was released about 18 months ago, Jan 2022.
Would it be possible to expand to allowing faraday 1.x-2.x, or just 2.x?
Are you interested in a PR? It doesn't look like there's CI running here (travis doesn't really provide free CI to open source anymore); it looks like there are some specs, I haven't looked to see how good the test coverage is, does it cover enough that if tests still pass after an upgrade to faraday 2 that's pretty reliable?
Thanks for the great work!
The latest version is July 16, 2021
Thank you!
Hi! Thanks for using this gem.
tweetkit
is a Twitter v2 API wrapper inspired by the octokit
gem and the current twitter
gem. That said, tweetkit
is currently very rudimentary and is nowhere near polished enough for reliable production usage.
With that in mind, I'm working on new features and improvements to make tweetkit
suitable for serious usage, as shown below:
The search DSL is already available in tweetkit
. It is, however, quite basic and lacks documentation. In short, the search DSL allows you to easily create search statements based on Twitter's search operators.
Here's an example search code:
client.search 'lionel messi' do
contains 'psg', 'barcelona'
without 'manchester united', 'manchester city'
is_a :retweet
is_not :verified
has :media
end
This searches for retweets containing the phrase lionel messi
that also contains the words psg
and barcelona
. The matched retweets should not have any occurrences of manchester united
and manchester city
. The retweets should not be from verified accounts and it should contain a media object, such as a photo, GIF, or video, as determined by Twitter.
There is a lot to improve for this search DSL and I'm hoping to make it as easy-to-use and flexible as similar DSLs like RSpec
, builder
, and so on.
The gem currently only supports fetching and searching for tweets. The plan is to cover all v2
endpoints, both existing and upcoming. I do not plan to add v1
endpoints at the moment as it is covered completely by the current twitter
gem. It will be also be replaced by the v2
endpoints soon so they'll not be worked on unless there's demand from the community.
Create a custom error class to handle errors from the Twitter API. Currently, errors are handled by Ruby while some are returned as JSON responses from Twitter. This works OK-ish but ideally, I want to create a custom error class to improve error handling and improve debugging while using the gem.
Currently, the wrapper returns a custom Tweetkit::Response
object. This response object contains a Tweets
class, which is a collection of Tweet
objects that contain the tweet content and id
. Depending on the fields and expansions you included when calling the endpoints, you may also have access to a Resources
and/or Meta
class which contains tweet metadata, fields and expansions (read more on Twitter fields and expansions in the v2 endpoints).
The plan is to improve the response both usage and implementation-wise, so it'll be easy to work with it and also understand the code if needed.
Currently, results are returned as is from Twitter's API, with pagination handled by passing in options when calling. This can be improved by introducing pagination to every (necessary) endpoint without the need for a page
option. Instead, you can call response.next
instead to get the next page or response.prev
to go back.
Currently, the gem is relying on the internal Faraday
module to fetch results with a simple get
call. This may not work well for repeated calls in a short span of time or if concurrency is needed. I'm looking to make the connection module customizable so it can be tweaked for your desired HTTP library and specific use cases.
There is currently no documentation and tests for the gem. This will be added along the way as I work on the features and improvements.
These are the current tasks that are in my roadmap for this gem. Feel free to create issues or even submit PRs if you're interested. Thanks again for using this gem! :)
getting:
Authenticating with OAuth 2.0 Application-Only is forbidden for this endpoint
when calling the post_tweet method. What can I do to fix this? My credentials are all correct.
Interesting gem you have here 😉
I am wondering if you will be adding an explicit license to this project?
Thank you @julianfssen !
Unfortunately I'm getting an error updating to the latest version:
`
$ gem install tweetkit
ERROR: While executing gem ... (Gem::Resolver::Molinillo::CircularDependencyError)
There is a circular dependency between faraday-net_http and faraday
$ ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]
`
Originally posted by @samuel-henry in #9 (comment)
Thanks for this code!
I got really confused trying to figure out how to post a tweet using v2 API with oauth -- after my previous code that had been using v1 API got shut off by twitter last month -- and I couldn't find much to do this for me or even demo how to do in ruby. Until I found this, and it works, I can tweet!
result = client.post_tweet(text: "some text")
But I am not finding any great way to determine if the result of that operation was successful or not though.
The actual HTTP status returned by twitter might be helpful (check is it 200?), but that information does not seem to actually be preserved by tweetdeck logic, it just gets through away?
All I find to look at is if it was succesful then result.response
looks something like:
{"data"=>{"edit_history_tweet_ids"=>["999999999998"], "id"=>"9999999999999", "text"=>"some text"}}
BUT if it was NOT successful, then result.response
looks something like:
{"title"=>"Unauthorized", "type"=>"about:blank", "status"=>401, "detail"=>"Unauthorized"}
OK, so in the error case I can check result.response["status"]
... but if result.response["status"]
is NOT present, I should assume success, maybe.... this is all seeming kind of fragile and unclear.
Can/should additional fields be added to the object returned from operations like post_tweet
? An http_response_status
(200, 401, etc)? Preserve and provide access to the entire faraday response that came back, in case the caller wants to look at it? A simple success?
method, where tweetkit tries to figure out for me if the operation succeeded and just let me know? Other?
Thanks again for the code!
Hello, first off, great job so far. I am just getting started with the twitter api and had a hard time figuring it out. Seems like we're in a transition from oauth 1.a to 2 and v1 to v2. The documentation on twitter is a little all over the place. Anyway, your gem is saving me a lot of time, so thank you.
So when I first started to test this gem I noticed that if you follow the documentation and call
response = client.tweet(1234567890)
you get an error "wrong number of arguments".
I then realized that the version "v0.1.4 " is missing a lot, so I switched to
gem 'tweetkit', git: '[email protected]:julianfssen/tweetkit.git', ref: '0284331' #allows posting to twitter
The error persisted though. Looked into the code a bit and realized the options were not optional and I had to pass in a empty {}
response = client.tweet(1234567890, *{})
I know this gem is in dev, but figured it might help to point this out.
Probably should make the options optional or specify they are't optional in the documentation. The syntax of having to *{} isn't ideal.
Does it make sense to make a new tag with the latest functionality? What I needed was the .post_tweet functionality so I switched to that specific ref.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.