Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: sferik/twitter
...
head fork: sferik/twitter
  • 13 commits
  • 16 files changed
  • 0 commit comments
  • 4 contributors
View
9 CHANGELOG.md
@@ -1,3 +1,12 @@
+4.1.2
+-----
+* [Add abort_on_exception to `Enumerable#threaded_map`](https://github.com/sferik/twitter/commit/15c9a7c221f24226c1003b76b287d2b2ed9306cb) ([@aheaven87](http://twitter.com/aheaven87))
+
+4.1.1
+-----
+* [Fix bug in `Twitter::Tweet#full_text`](https://github.com/sferik/twitter/commit/9646a5bed6d2d119b1cc1d5757113988de2516d6)
+* [Add `Twitter::Tweet#favouriters`, `Twitter::User#favoriters_count`, and `Twitter::User#favouriters_count` aliases](https://github.com/sferik/twitter/commit/60fce1ea0cdf8239262ca46588b4fe766f07288e)
+
4.1.0
-----
* [Handle new API v1.1 list response format](https://github.com/sferik/twitter/commit/2aace25fcf946de995e5ce1788f24ad35bc79438)
View
2  CONTRIBUTING.md
@@ -16,8 +16,10 @@ inconsistent whitespace)
* by refactoring code
* by fixing [issues][]
* by reviewing patches
+* [financially][pledgie]
[issues]: https://github.com/sferik/twitter/issues
+[pledgie]: http://pledgie.com/campaigns/18388
## Submitting an Issue
We use the [GitHub issue tracker][issues] to track bugs and features. Before
View
18 README.md
@@ -2,10 +2,12 @@
[![Build Status](https://secure.travis-ci.org/sferik/twitter.png?branch=master)][travis]
[![Dependency Status](https://gemnasium.com/sferik/twitter.png?travis)][gemnasium]
[![Code Climate](https://codeclimate.com/badge.png)][codeclimate]
+[![Click here to make a donation](http://www.pledgie.com/campaigns/18388.png)][pledgie]
[travis]: http://travis-ci.org/sferik/twitter
[gemnasium]: https://gemnasium.com/sferik/twitter
[codeclimate]: https://codeclimate.com/github/sferik/twitter
+[pledgie]: http://pledgie.com/campaigns/18388
A Ruby interface to the Twitter API.
@@ -47,7 +49,7 @@ wiki][apps]!
## What's new in version 4?
-### Twitter API v1.1
+#### Twitter API v1.1
Version 4 of this library targets Twitter API v1.1. To understand the
implications of this change, please read the following announcements from
@@ -77,7 +79,7 @@ discussion][discussion].
[user_timeline]: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
[discussion]: https://dev.twitter.com/discussions/10644
-### Rate Limiting
+#### Rate Limiting
Another consequence of Twitter API v1.1 is that the
`Twitter::Client#rate_limit` method has been removed, since the concept of a
@@ -105,7 +107,7 @@ rescue Twitter::Error::TooManyRequests => error
end
end
```
-### Methods Missing
+#### Methods Missing
As a consequence of moving to Twitter API v1.1, the following methods from
version 3 are no longer available in version 4:
@@ -126,7 +128,7 @@ version 3 are no longer available in version 4:
* `Twitter::Client#rate_limit`
* `Twitter::RateLimit#class`
-### Custom Endpoints
+#### Custom Endpoints
The `Twitter::API#update_with_media` method no longer uses the custom
`upload.twitter.com` endpoint, so `media_endpoint` configuration has been
@@ -134,7 +136,7 @@ removed. Likewise, the `Twitter::API#search` method no longer uses the custom
`search.twitter.com` endpoint, so `search_endpoint` configuration has also been
removed.
-### Errors
+#### Errors
It's worth mentioning new error classes:
@@ -149,7 +151,7 @@ library will raise `Twitter::Error::TooManyRequests` for all rate limit errors.
The `Twitter::Error::EnhanceYourCalm` class has been aliased to
`Twitter::Error::TooManyRequests`.
-### Identity Map
+#### Identity Map
In version 4, the identity map is [disabled by default][disabled]. If you want
to enable this feature, you can use the [default identity map][default] or
@@ -209,7 +211,7 @@ After configuration, requests can be made like so:
Twitter.update("I'm tweeting with @gem!")
```
-### Thread Safety
+#### Thread Safety
Applications that make requests on behalf of multiple Twitter users should
avoid using global configuration. In this case, you may still specify the
@@ -259,7 +261,7 @@ a `Twitter::Client`:
This may be useful if you're using multiple consumer key/secret pairs.
-### Middleware
+#### Middleware
The Faraday middleware stack is fully configurable and is exposed as a
`Faraday::Builder` object. You can modify the default middleware in-place:
View
8 lib/twitter/api.rb
@@ -1358,8 +1358,7 @@ def saved_search_destroy(*args)
#
# @see https://dev.twitter.com/docs/api/1.1/get/search/tweets
# @see https://dev.twitter.com/docs/using-search
- # @see https://dev.twitter.com/docs/history-rest-search-api
- # @note As of April 1st 2010, the Search API provides an option to retrieve "popular tweets" in addition to real-time search results. In an upcoming release, this will become the default and clients that don't want to receive popular tweets in their search results will have to explicitly opt-out. See the result_type parameter below for more information.
+ # @note Please note that Twitter's search service and, by extension, the Search API is not meant to be an exhaustive source of Tweets. Not all Tweets will be indexed or made available via the search interface.
# @rate_limited Yes
# @authentication_required Requires user context
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
@@ -1368,13 +1367,12 @@ def saved_search_destroy(*args)
# @option options [String] :geocode Returns tweets by users located within a given radius of the given latitude/longitude. The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile. The parameter value is specified by "latitude,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers). Note that you cannot use the near operator via the API to geocode arbitrary locations; however you can use this geocode parameter to search near geocodes directly.
# @option options [String] :lang Restricts tweets to the given language, given by an ISO 639-1 code.
# @option options [String] :locale Specify the language of the query you are sending (only ja is currently effective). This is intended for language-specific clients and the default should work in the majority of cases.
- # @option options [Integer] :page The page number (starting at 1) to return, up to a max of roughly 1500 results (based on rpp * page).
# @option options [String] :result_type Specifies what type of search results you would prefer to receive. Options are "mixed", "recent", and "popular". The current default is "mixed."
- # @option options [Integer] :rpp The number of tweets to return per page, up to a max of 100.
+ # @option options [Integer] :count The number of tweets to return per page, up to a maximum of 100.
# @option options [String] :until Optional. Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD.
# @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID. There are limits to the number of Tweets which can be accessed through the API. If the limit of Tweets has occured since the since_id, the since_id will be forced to the oldest ID available.
# @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
- # @option options [Boolean, String, Integer] :with_twitter_user_id When set to either true, t or 1, the from_user_id and to_user_id values in the response will map to "official" user IDs which will match those returned by the REST API.
+ # @option options [Boolean, String, Integer] :include_entities Specifies that each tweet should include an 'entities' node including metadata about the tweet such as: user_mentions, urls, and hashtags.
# @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
# @example Returns tweets related to twitter
# Twitter.search('twitter')
View
5 lib/twitter/base.rb
@@ -8,10 +8,7 @@ class Base
# Define methods that retrieve the value from an initialized instance variable Hash, using the attribute as a key
#
- # @overload self.attr_reader(attr)
- # @param attr [Symbol]
- # @overload self.attr_reader(attrs)
- # @param attrs [Array<Symbol>]
+ # @param attrs [Array, Set, Symbol]
def self.attr_reader(*attrs)
attrs.each do |attribute|
class_eval do
View
3  lib/twitter/basic_user.rb
@@ -4,5 +4,8 @@ module Twitter
class BasicUser < Twitter::Identity
attr_reader :following, :screen_name
alias following? following
+ alias handle screen_name
+ alias username screen_name
+ alias user_name screen_name
end
end
View
20 lib/twitter/core_ext/enumerable.rb
@@ -1,11 +1,23 @@
module Enumerable
def threaded_map
- threads = []
- each do |object|
- threads << Thread.new{yield object}
+ abort_on_exception do
+ threads = []
+ each do |object|
+ threads << Thread.new { yield object }
+ end
+ threads.map(&:value)
end
- threads.map(&:value)
+ end
+
+ private
+
+ def abort_on_exception
+ initial_abort_on_exception = Thread.abort_on_exception
+ Thread.abort_on_exception ||= true
+ value = yield
+ Thread.abort_on_exception = initial_abort_on_exception
+ value
end
end
View
4 lib/twitter/geo/point.rb
@@ -6,13 +6,13 @@ class Point < Twitter::Geo
# @return [Integer]
def latitude
- self.coordinates[0]
+ coordinates[0]
end
alias lat latitude
# @return [Integer]
def longitude
- self.coordinates[1]
+ coordinates[1]
end
alias long longitude
alias lng longitude
View
2  lib/twitter/request/multipart_with_file.rb
@@ -6,8 +6,8 @@ class MultipartWithFile < Faraday::Middleware
CONTENT_TYPE = 'Content-Type'.freeze
class << self
attr_accessor :mime_type
+ mime_type = 'multipart/form-data'.freeze
end
- self.mime_type = 'multipart/form-data'.freeze
def call(env)
if env[:body].is_a?(Hash)
View
10 lib/twitter/tweet.rb
@@ -22,6 +22,7 @@ class Tweet < Twitter::Identity
alias favorited? favorited
alias favourited favorited
alias favourited? favorited
+ alias favouriters favoriters
alias retweeted? retweeted
alias truncated? truncated
@@ -31,7 +32,9 @@ def favoriters_count
favoriters_count.to_i if favoriters_count
end
alias favorite_count favoriters_count
+ alias favorites_count favoriters_count
alias favourite_count favoriters_count
+ alias favourites_count favoriters_count
alias favouriters_count favoriters_count
# @return [String]
@@ -42,7 +45,12 @@ def from_user
# @return [String]
# @note May be > 140 characters.
def full_text
- retweeted_status && retweeted_status.user ? "RT @#{retweeted_status.user.screen_name}: #{retweeted_status.text}" : text
+ if retweeted_status
+ prefix = text[/\A(RT @[a-z0-9_]{1,20}: )/i, 1]
+ [prefix, retweeted_status.text].compact.join
+ else
+ text
+ end
end
# @return [Twitter::Geo]
View
2  lib/twitter/user.rb
@@ -22,8 +22,10 @@ class User < Twitter::BasicUser
alias default_profile_image? default_profile_image
alias follow_request_sent? follow_request_sent
alias favorite_count favourites_count
+ alias favoriters_count favourites_count
alias favorites_count favourites_count
alias favourite_count favourites_count
+ alias favouriters_count favourites_count
alias follower_count followers_count
alias friend_count friends_count
alias geo_enabled? geo_enabled
View
2  lib/twitter/version.rb
@@ -2,7 +2,7 @@ module Twitter
class Version
MAJOR = 4 unless defined? Twitter::MAJOR
MINOR = 1 unless defined? Twitter::MINOR
- PATCH = 0 unless defined? Twitter::PATCH
+ PATCH = 2 unless defined? Twitter::PATCH
PRE = nil unless defined? Twitter::PRE
class << self
View
2  spec/fixtures/status.json
@@ -1 +1 @@
-{"place":{"country_code":"US","place_type":"neighborhood","url":"http:\/\/api.twitter.com\/1\/geo\/id\/41bcb736f84a799e.json","country":"The United States of America","attributes":{},"full_name":"Mission Bay, San Francisco","name":"Mission Bay","id":"41bcb736f84a799e","bounding_box":{"type":"Polygon","coordinates":[[[-122.40618084,37.76405301],[-122.38151184,37.76405301],[-122.38151184,37.78199199],[-122.40618084,37.78199199]]]}},"retweet_count":null,"geo":null,"retweeted":false,"in_reply_to_status_id":null,"source":"web","truncated":false,"in_reply_to_status_id_str":null,"created_at":"Thu Sep 30 01:43:44 +0000 2010","in_reply_to_user_id":3191321,"favorited":false,"in_reply_to_user_id_str":"3191321","user":{"contributors_enabled":false,"time_zone":"Pacific Time (US & Canada)","description":"Adventures in hunger and foolishness.","geo_enabled":true,"profile_sidebar_fill_color":"DDEEF6","followers_count":898,"notifications":false,"verified":false,"profile_use_background_image":true,"profile_sidebar_border_color":"C0DEED","follow_request_sent":false,"url":null,"profile_background_image_url":"http:\/\/a3.twimg.com\/profile_background_images\/162641967\/we_concept_bg2.png","lang":"en","created_at":"Mon Jul 16 12:59:01 +0000 2007","profile_background_color":"000000","location":"San Francisco","profile_background_tile":false,"protected":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/323331048\/me_normal.jpg","listed_count":28,"friends_count":88,"profile_text_color":"333333","name":"Erik Michaels-Ober","statuses_count":2968,"following":false,"screen_name":"sferik","id":7505382,"id_str":"7505382","show_all_inline_media":true,"utc_offset":-28800,"favourites_count":727,"profile_link_color":"0084B4"},"contributors":null,"coordinates":null,"in_reply_to_screen_name":"noradio","id":25938088801,"id_str":"25938088801","text":"@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"}
+{"created_at":"Wed Apr 06 19:13:37 +0000 2011","id":55709764298092545,"id_str":"55709764298092545","text":"The problem with your code is that it's doing exactly what you told it to do.","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":2479,"friends_count":200,"listed_count":132,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":4421,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":8730,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":{"type":"Point","coordinates":[37.78349999,-122.39362884]},"coordinates":{"type":"Point","coordinates":[-122.39362884,37.78349999]},"place":{"id":"5c92ab5379de3839","url":"https:\/\/api.twitter.com\/1.1\/geo\/id\/5c92ab5379de3839.json","place_type":"neighborhood","name":"South Beach","full_name":"South Beach, San Francisco","country_code":"US","country":"United States","bounding_box":{"type":"Polygon","coordinates":[[[-122.403482,37.777529],[-122.387436,37.777529],[-122.387436,37.794486],[-122.403482,37.794486]]]},"attributes":{}},"contributors":null,"retweet_count":316,"entities":{"hashtags":[],"urls":[],"user_mentions":[]},"favorited":false,"retweeted":false}
View
20 spec/twitter/api/statuses_spec.rb
@@ -51,7 +51,7 @@
tweets = @client.favorite(25938088801)
expect(tweets).to be_an Array
expect(tweets.first).to be_a Twitter::Tweet
- expect(tweets.first.text).to eq "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
+ expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
end
end
@@ -67,7 +67,7 @@
tweets = @client.unfavorite(25938088801)
expect(tweets).to be_an Array
expect(tweets.first).to be_a Twitter::Tweet
- expect(tweets.first.text).to eq "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
+ expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
end
end
@@ -288,7 +288,7 @@
it "returns a Tweet" do
tweet = @client.status(25938088801)
expect(tweet).to be_a Twitter::Tweet
- expect(tweet.text).to eq "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
+ expect(tweet.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
end
end
@@ -304,7 +304,7 @@
tweets = @client.statuses(25938088801)
expect(tweets).to be_an Array
expect(tweets.first).to be_a Twitter::Tweet
- expect(tweets.first.text).to eq "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
+ expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
end
end
@@ -351,7 +351,7 @@
tweets = @client.status_destroy(25938088801)
expect(tweets).to be_an Array
expect(tweets.first).to be_a Twitter::Tweet
- expect(tweets.first.text).to eq "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
+ expect(tweets.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
end
end
@@ -375,16 +375,16 @@
describe "#tweet" do
before do
- stub_post("/1.1/statuses/update.json").with(:body => {:status => "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ stub_post("/1.1/statuses/update.json").with(:body => {:status => "The problem with your code is that it's doing exactly what you told it to do."}).to_return(:body => fixture("status.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
- @client.update("@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!")
- expect(a_post("/1.1/statuses/update.json").with(:body => {:status => "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"})).to have_been_made
+ @client.update("The problem with your code is that it's doing exactly what you told it to do.")
+ expect(a_post("/1.1/statuses/update.json").with(:body => {:status => "The problem with your code is that it's doing exactly what you told it to do."})).to have_been_made
end
it "returns a Tweet" do
- tweet = @client.update("@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!")
+ tweet = @client.update("The problem with your code is that it's doing exactly what you told it to do.")
expect(tweet).to be_a Twitter::Tweet
- expect(tweet.text).to eq "@noradio working on implementing #NewTwitter API methods in the twitter gem. Twurl is making it easy. Thank you!"
+ expect(tweet.text).to eq "The problem with your code is that it's doing exactly what you told it to do."
end
end
View
2  spec/twitter/client_spec.rb
@@ -53,7 +53,7 @@
end
end
- context "after initilization" do
+ context "after initialization" do
it "overrides the module configuration after initialization" do
client = Twitter::Client.new
client.configure do |config|
View
2  spec/twitter/tweet_spec.rb
@@ -81,7 +81,7 @@
expect(tweet.full_text).to eq "BOOSH"
end
it "returns the full text of a retweeted Tweet" do
- tweet = Twitter::Tweet.new(:id => 28669546014, :retweeted_status => {:id => 28561922516, :text => 'BOOSH', :user => {:id => 7505382, :screen_name => 'sferik'}})
+ tweet = Twitter::Tweet.new(:id => 28669546014, :text => 'RT @sferik: BOOSH', :retweeted_status => {:id => 28561922516, :text => 'BOOSH'})
expect(tweet.full_text).to be_a String
expect(tweet.full_text).to eq "RT @sferik: BOOSH"
end

No commit comments for this range

Something went wrong with that request. Please try again.