ex_twitter 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9fda73eb287f6236f329fc5fb989b8bf5d92a47
4
- data.tar.gz: 6cb1aba39cd22832b8cc1bdab2ded68dc2fa83a4
3
+ metadata.gz: 68eb499d7d42d9fa3351be383a820068509588b1
4
+ data.tar.gz: 9a5977112d10a15feb4e4b5544ae164cd1f69d36
5
5
  SHA512:
6
- metadata.gz: dc8aef3495f721143296c30b661562eb5edf45a04e0c9d116809213ef1808626f19aa1c6c57e720422a11bd0af74c8bb4796551fb520509a16acf6a7c96c4ec1
7
- data.tar.gz: 0be798a390977de38e5cea7cc525c53d8971b8c7f1f498ec86642f72f7dbe4b0a0907e37b44236123381fcc4c4eac4803a07e4ed9ffabbe871e323d108d7011a
6
+ metadata.gz: 7dc179bd00f61fe17739bdfc60a99124193afb8372121869ceba71bfd6f8854cabb77491a38af577af4be6e6801b58e4af290b657dc384d837e481fe20d22ac1
7
+ data.tar.gz: 361e9707b96c3d40c2ecc6a1d45f17d29901dce7a17af85acb2df5c773a051d7f16d4e463571ab11a5c1a94a6497a3e235424113704d6e85c6c8e196e9589cad
data/README.md CHANGED
@@ -51,3 +51,10 @@ end
51
51
  client.user_timeline
52
52
  ```
53
53
 
54
+ ## Memo
55
+
56
+ ```
57
+ be rake build
58
+ be rake release
59
+ ```
60
+
data/ex_twitter.gemspec CHANGED
@@ -20,5 +20,5 @@ Gem::Specification.new do |spec|
20
20
  spec.require_paths = %w[lib]
21
21
  spec.summary = spec.description
22
22
  spec.test_files = Dir.glob('spec/**/*')
23
- spec.version = '0.0.3'
23
+ spec.version = '0.0.4'
24
24
  end
data/lib/ex_twitter.rb CHANGED
@@ -67,14 +67,20 @@ class ExTwitter < Twitter::REST::Client
67
67
  logger.info "#{method_name}, #{args.inspect} #{options.inspect}"
68
68
 
69
69
  max_paginates = options.delete(:max_paginates) || MAX_PAGINATES
70
- data = last_response = send(method_name, *args, options)
70
+ data = []
71
+ last_response = send(method_name, *args, options)
72
+ if block_given?
73
+ last_response = yield(data, last_response)
74
+ else
75
+ data.concat(last_response) if last_response.is_a?(Array)
76
+ end
71
77
 
72
78
  if auto_paginate
73
79
  num_retries = 0
74
80
  (max_paginates - 1).times do
75
- break unless last_response.any?
81
+ break if last_response.blank?
76
82
 
77
- options[:max_id] = last_response.last.id - 1
83
+ options[:max_id] = last_response.last[:id] - 1
78
84
 
79
85
  begin
80
86
  last_response = send(method_name, *args, options)
@@ -102,7 +108,7 @@ class ExTwitter < Twitter::REST::Client
102
108
  end
103
109
 
104
110
  if block_given?
105
- yield(data, last_response)
111
+ last_response = yield(data, last_response)
106
112
  else
107
113
  data.concat(last_response) if last_response.is_a?(Array)
108
114
  end
@@ -214,51 +220,47 @@ class ExTwitter < Twitter::REST::Client
214
220
  processed_users.sort_by{|p| p[:i] }.map{|p| p[:users] }.flatten
215
221
  end
216
222
 
217
-
218
-
219
- # ここから下は実装できているのか不明
223
+ # Returns tweets that match a specified query.
224
+ #
225
+ # @see https://dev.twitter.com/docs/api/1.1/get/search/tweets
226
+ # @see https://dev.twitter.com/docs/using-search
227
+ # @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.
228
+ # @rate_limited Yes
229
+ # @authentication Requires user context
230
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
231
+ # @param q [String] A search term. (from|to):hello min_retweets:3 OR min_faves:3 OR min_replies:3, #nhk @hello (in|ex)clude:retweets https://twitter.com/search-advanced
232
+ # @param options [Hash] A customizable set of options.
233
+ # @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.
234
+ # @option options [String] :lang Restricts tweets to the given language, given by an ISO 639-1 code.
235
+ # @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.
236
+ # @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."
237
+ # @option options [Integer] :count The number of tweets to return per page, up to a maximum of 100.
238
+ # @option options [String] :until Optional. Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD.
239
+ # @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.
240
+ # @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
241
+ # @return [Twitter::SearchResults] Return tweets that match a specified query with search metadata
242
+ alias :old_search :search
243
+ def search(*args)
244
+ options = {count: 100, result_type: 'recent'}.merge(args.extract_options!)
245
+ collect_with_max_id(:old_search, *args, options) do |data, last_response|
246
+ statuses = last_response.attrs[:statuses]
247
+ data.concat(statuses)
248
+ statuses
249
+ end
250
+ end
220
251
 
221
252
  # mentions_timeline is to fetch the timeline of Tweets mentioning the authenticated user
222
253
  # get_mentions is to fetch the Tweets mentioning the screen_name's user
223
254
  def get_mentions(screen_name)
224
- search_tweets("to:#{screen_name}", {result_type: 'recent', count: 100})
255
+ search("to:#{screen_name}")
225
256
  end
226
257
 
227
258
  def search_japanese_tweets(str)
228
- search_tweets(str, {result_type: 'recent', count: 100, lang: 'ja'})
259
+ search(str, {lang: 'ja'})
229
260
  end
230
261
 
231
262
  def search_tweets_except_rt(str)
232
- search_tweets("#{str} -rt", {result_type: 'recent', count: 100})
233
- end
234
-
235
- def search_tweets(str, options)
236
- num_retries = 0
237
- begin
238
- num_retries += 1
239
- result = search(str, options)
240
- [result.take(100), nil]
241
- rescue Twitter::Error::TooManyRequests => e
242
- if num_retries <= MAX_RETRIES
243
- if WAIT
244
- sleep e.rate_limit.reset_in
245
- retry
246
- else
247
- puts "retry #{e.rate_limit.reset_in} seconds later"
248
- [[], e]
249
- end
250
- else
251
- puts "fail. num_retries > MAX_RETRIES(=#{MAX_RETRIES})"
252
- [[], e]
253
- end
254
- rescue => e
255
- if num_retries <= MAX_RETRIES
256
- retry
257
- else
258
- puts "fail. num_retries > MAX_RETRIES(=#{MAX_RETRIES}), something error #{e.inspect}"
259
- [[], e]
260
- end
261
- end
263
+ search("#{str} exclude:retweets")
262
264
  end
263
265
  end
264
266
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ex_twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shinohara Teruki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2015-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: twitter