tweetstream 2.6.0 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of tweetstream might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79498418145dcfe8a448cb8476d7e629800ff7d7
4
- data.tar.gz: 5c247493d57cb248abf747db3a08307780674556
3
+ metadata.gz: cbc2436b67268c7ce263b3324dba062734680ee1
4
+ data.tar.gz: 1387c9fbd9814d2aea32a386e6334c4b9e4bab4b
5
5
  SHA512:
6
- metadata.gz: 58b3795d2c33e1260326e4c35992e4f9310d0ec137bd14170077705bdad9b6141a086e65897a6b50567675645fd0c4d3eda074498ce3950ec4d82837726d5319
7
- data.tar.gz: a85c13f5509514383e6228b2d934bb316c64a7e0ae8cb055d59bf75fed67ac01a2a2b30c09e8adc52a4dbcf6e09101bafb9dce2366cb95ffd113ac775806d2cd
6
+ metadata.gz: 470e52844c7593c911979213345dceeeaf8172320c8cd38d1cf6952b407e3be5fe281d72fdb5a2b6d87b1daf2a94c85c4bdcc24241ee3433db21bdc53c7ec3aa
7
+ data.tar.gz: 7db9613458729b5cddc90eed5ce7aac631ee6b97dd60ed311551402882c1dc6c014cfcfa68da75084d989aa51d9c6251f66c8d00b0c8a3754b0b96d5d2e08a5f
data/README.md CHANGED
@@ -261,8 +261,8 @@ options when you make your method call:
261
261
 
262
262
  ```ruby
263
263
  TweetStream::Client.new.track('intridea',
264
- :delete => Proc.new{ |status_id, user_id| # do something },
265
- :limit => Proc.new{ |skip_count| # do something }
264
+ :delete => proc{ |status_id, user_id| # do something },
265
+ :limit => proc{ |skip_count| # do something }
266
266
  ) do |status|
267
267
  # do something with the status like normal
268
268
  end
data/Rakefile CHANGED
@@ -5,7 +5,17 @@ require 'rspec/core/rake_task'
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
 
7
7
  task :test => :spec
8
- task :default => :spec
9
8
 
10
9
  require 'yard'
11
10
  YARD::Rake::YardocTask.new
11
+
12
+ begin
13
+ require 'rubocop/rake_task'
14
+ Rubocop::RakeTask.new
15
+ rescue LoadError
16
+ task :rubocop do
17
+ $stderr.puts 'Rubocop is disabled'
18
+ end
19
+ end
20
+
21
+ task :default => [:spec, :rubocop]
@@ -18,7 +18,7 @@ module TweetStream
18
18
  # Alias for TweetStream::Client.new
19
19
  #
20
20
  # @return [TweetStream::Client]
21
- def new(options={})
21
+ def new(options = {})
22
22
  TweetStream::Client.new(options)
23
23
  end
24
24
 
@@ -6,6 +6,5 @@ module TweetStream
6
6
  @options = args.last.is_a?(::Hash) ? args.pop : {}
7
7
  super(args)
8
8
  end
9
-
10
9
  end
11
10
  end
@@ -21,7 +21,7 @@ module TweetStream
21
21
  #
22
22
  # For information about a daemonized TweetStream client,
23
23
  # view the TweetStream::Daemon class.
24
- class Client
24
+ class Client # rubocop:disable ClassLength
25
25
  extend Forwardable
26
26
 
27
27
  OPTION_CALLBACKS = [:delete,
@@ -40,14 +40,14 @@ module TweetStream
40
40
  :user_withheld].freeze unless defined?(OPTION_CALLBACKS)
41
41
 
42
42
  # @private
43
- attr_accessor *Configuration::VALID_OPTIONS_KEYS
43
+ attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
44
44
  attr_accessor :options
45
45
  attr_reader :control_uri, :control, :stream
46
46
 
47
47
  def_delegators :@control, :add_user, :remove_user, :info, :friends_ids
48
48
 
49
49
  # Creates a new API
50
- def initialize(options={})
50
+ def initialize(options = {})
51
51
  self.options = options
52
52
  merged_options = TweetStream.options.merge(options)
53
53
  Configuration::VALID_OPTIONS_KEYS.each do |key|
@@ -116,8 +116,8 @@ module TweetStream
116
116
 
117
117
  # Specifies a set of bounding boxes to track. Only tweets that are both created
118
118
  # using the Geotagging API and are placed from within a tracked bounding box will
119
- # be included in the stream the users location field is not used to filter tweets
120
- # (e.g. if a user has their location set to San Francisco”, but the tweet was not created
119
+ # be included in the stream -- the user's location field is not used to filter tweets
120
+ # (e.g. if a user has their location set to "San Francisco", but the tweet was not created
121
121
  # using the Geotagging API and has no geo element, it will not be included in the stream).
122
122
  # Bounding boxes are specified as a comma separate list of longitude/latitude pairs, with
123
123
  # the first pair denoting the southwest corner of the box
@@ -138,19 +138,19 @@ module TweetStream
138
138
 
139
139
  # Make a call to the userstream api for currently authenticated user
140
140
  def userstream(query_params = {}, &block)
141
- stream_params = { :host => "userstream.twitter.com" }
141
+ stream_params = {:host => 'userstream.twitter.com'}
142
142
  query_params.merge!(:extra_stream_parameters => stream_params)
143
143
  start('/1.1/user.json', query_params, &block)
144
144
  end
145
145
 
146
146
  # Make a call to the userstream api
147
147
  def sitestream(user_ids = [], query_params = {}, &block)
148
- stream_params = { :host => "sitestream.twitter.com" }
149
- query_params.merge!({
148
+ stream_params = {:host => 'sitestream.twitter.com'}
149
+ query_params.merge!(
150
150
  :method => :post,
151
151
  :follow => user_ids,
152
152
  :extra_stream_parameters => stream_params
153
- })
153
+ )
154
154
  query_params.merge!(:with => 'followings') if query_params.delete(:followings)
155
155
  start('/1.1/site.json', query_params, &block)
156
156
  end
@@ -400,7 +400,7 @@ module TweetStream
400
400
  EventMachine.epoll
401
401
  EventMachine.kqueue
402
402
 
403
- EventMachine::run do
403
+ EventMachine.run do
404
404
  connect(path, query_parameters, &block)
405
405
  end
406
406
  end
@@ -424,8 +424,6 @@ module TweetStream
424
424
  next
425
425
  end
426
426
 
427
- Twitter.identity_map = false
428
-
429
427
  respond_to(hash, callbacks, &block)
430
428
 
431
429
  yield_message_to(callbacks['anything'], hash)
@@ -448,7 +446,7 @@ module TweetStream
448
446
  end
449
447
 
450
448
  @stream.on_max_reconnects do |timeout, retries|
451
- raise TweetStream::ReconnectError.new(timeout, retries)
449
+ fail TweetStream::ReconnectError.new(timeout, retries)
452
450
  end
453
451
 
454
452
  @stream.on_no_data_received do
@@ -477,9 +475,9 @@ module TweetStream
477
475
  !!@control
478
476
  end
479
477
 
480
- protected
478
+ protected
481
479
 
482
- def respond_to(hash, callbacks, &block)
480
+ def respond_to(hash, callbacks, &block) # rubocop:disable CyclomaticComplexity
483
481
  if hash[:control] && hash[:control][:control_uri]
484
482
  @control_uri = hash[:control][:control_uri]
485
483
  require 'tweetstream/site_stream_client'
@@ -527,13 +525,13 @@ module TweetStream
527
525
 
528
526
  def auth_params
529
527
  if auth_method.to_s == 'basic'
530
- { :basic => {
528
+ {:basic => {
531
529
  :username => username,
532
530
  :password => password
533
531
  }
534
532
  }
535
533
  else
536
- { :oauth => {
534
+ {:oauth => {
537
535
  :consumer_key => consumer_key,
538
536
  :consumer_secret => consumer_secret,
539
537
  :token => oauth_token,
@@ -582,9 +580,9 @@ module TweetStream
582
580
  [stream_params, callbacks]
583
581
  end
584
582
 
585
- def warn_if_callbacks(options={})
583
+ def warn_if_callbacks(options = {})
586
584
  if OPTION_CALLBACKS.select { |callback| options[callback] }.size > 0
587
- Kernel.warn("Passing callbacks via the options hash is deprecated and will be removed in TweetStream 3.0")
585
+ Kernel.warn('Passing callbacks via the options hash is deprecated and will be removed in TweetStream 3.0')
588
586
  end
589
587
  end
590
588
  end
@@ -53,7 +53,7 @@ module TweetStream
53
53
  DEFAULT_OAUTH_TOKEN_SECRET = nil
54
54
 
55
55
  # @private
56
- attr_accessor *VALID_OPTIONS_KEYS
56
+ attr_accessor(*VALID_OPTIONS_KEYS)
57
57
 
58
58
  # When this module is extended, set all configuration options to their default values
59
59
  def self.extended(base)
@@ -67,12 +67,12 @@ module TweetStream
67
67
 
68
68
  # Create a hash of options and their values
69
69
  def options
70
- Hash[*VALID_OPTIONS_KEYS.map {|key| [key, send(key)] }.flatten]
70
+ Hash[*VALID_OPTIONS_KEYS.collect { |key| [key, send(key)] }.flatten]
71
71
  end
72
72
 
73
73
  # Create a hash of options and their values
74
74
  def oauth_options
75
- Hash[*OAUTH_OPTIONS_KEYS.map {|key| [key, send(key)] }.flatten]
75
+ Hash[*OAUTH_OPTIONS_KEYS.collect { |key| [key, send(key)] }.flatten]
76
76
  end
77
77
 
78
78
  # Reset all configuration options to defaults
@@ -30,9 +30,8 @@ require 'daemons'
30
30
  # is posted.
31
31
  #
32
32
  class TweetStream::Daemon < TweetStream::Client
33
-
34
33
  DEFAULT_NAME = 'tweetstream'.freeze
35
- DEFAULT_OPTIONS = { :multiple => true }
34
+ DEFAULT_OPTIONS = {:multiple => true}
36
35
 
37
36
  attr_accessor :app_name, :daemon_options
38
37
 
@@ -4,8 +4,7 @@ require 'em-http/middleware/json_response'
4
4
 
5
5
  module TweetStream
6
6
  class SiteStreamClient
7
-
8
- attr_accessor *Configuration::OAUTH_OPTIONS_KEYS
7
+ attr_accessor(*Configuration::OAUTH_OPTIONS_KEYS)
9
8
 
10
9
  def initialize(config_uri, oauth = {})
11
10
  @config_uri = config_uri
@@ -28,14 +27,14 @@ module TweetStream
28
27
  end
29
28
 
30
29
  def info(&block)
31
- options = { :error_msg => 'Failed to retrieve SiteStream info.' }
30
+ options = {:error_msg => 'Failed to retrieve SiteStream info.'}
32
31
  request(:get, info_path, options, &block)
33
32
  end
34
33
 
35
34
  def add_user(user_id, &block)
36
35
  options = {
37
36
  :error_msg => 'Failed to add user to SiteStream',
38
- :body => { 'user_id' => normalized_user_ids(user_id) }
37
+ :body => {'user_id' => normalized_user_ids(user_id)}
39
38
  }
40
39
 
41
40
  request(:post, add_user_path, options, &block)
@@ -44,20 +43,20 @@ module TweetStream
44
43
  def remove_user(user_id, &block)
45
44
  options = {
46
45
  :error_msg => 'Failed to remove user from SiteStream.',
47
- :body => { 'user_id' => normalized_user_ids(user_id) }
46
+ :body => {'user_id' => normalized_user_ids(user_id)}
48
47
  }
49
48
 
50
49
  request(:post, remove_user_path, options, &block)
51
50
  end
52
51
 
53
52
  def friends_ids(user_id, &block)
54
- options = { :error_msg => 'Failed to retrieve SiteStream friends ids.',
55
- :body => { 'user_id' => user_id }
53
+ options = {:error_msg => 'Failed to retrieve SiteStream friends ids.',
54
+ :body => {'user_id' => user_id}
56
55
  }
57
56
  request(:post, friends_ids_path, options, &block)
58
57
  end
59
58
 
60
- private
59
+ private
61
60
 
62
61
  def connection
63
62
  return @conn if defined?(@conn)
@@ -92,18 +91,16 @@ module TweetStream
92
91
  @config_uri + '/friends/ids.json'
93
92
  end
94
93
 
95
- def request(method, path, options, &block)
94
+ def request(method, path, options, &block) # rubocop:disable CyclomaticComplexity, ParameterLists
96
95
  error_msg = options.delete(:error_msg)
97
96
 
98
97
  http = connection.send(method, options.merge(:path => path))
99
98
  http.callback do
100
- if http.response_header.status == 200
101
- if block && block.kind_of?(Proc)
102
- if block.arity == 1
103
- block.call http.response
104
- else
105
- block.call
106
- end
99
+ if http.response_header.status == 200 && block && block.kind_of?(Proc)
100
+ if block.arity == 1
101
+ block.call http.response
102
+ else
103
+ block.call
107
104
  end
108
105
  else
109
106
  @on_error.call(error_msg) if @on_error && @on_error.kind_of?(Proc)
@@ -116,11 +113,10 @@ module TweetStream
116
113
 
117
114
  def normalized_user_ids(user_id)
118
115
  if user_id.kind_of?(Array)
119
- user_id.join(',')
116
+ user_id.join(',')
120
117
  else
121
118
  user_id.to_s
122
119
  end
123
120
  end
124
-
125
121
  end
126
122
  end
@@ -1,3 +1,3 @@
1
1
  module TweetStream
2
- VERSION = '2.6.0' unless defined?(TweetStream::VERSION)
2
+ VERSION = '2.6.1'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "delete": {
3
3
  "status": {
4
- "id": 1234,
4
+ "id": 123,
5
5
  "user_id": 3
6
6
  }
7
7
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "limit": {
3
- "track": 1234
3
+ "track": 123
4
4
  }
5
5
  }
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "scrub_geo": {
3
- "user_id": 1234,
4
- "user_id_str": "1234",
5
- "up_to_status_id":9876,
6
- "up_to_status_id_string": "9876"
3
+ "user_id": 123,
4
+ "user_id_str": "123",
5
+ "up_to_status_id":987,
6
+ "up_to_status_id_string": "987"
7
7
  }
8
8
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "status_withheld":{
3
3
  "id":1234567890,
4
- "user_id":123456,
4
+ "user_id":123,
5
5
  "withheld_in_countries":["de", "ar"]
6
6
  }
7
7
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "user_withheld":{
3
- "id":123456,
3
+ "id":123,
4
4
  "withheld_in_countries":["de","ar"]
5
5
  }
6
6
  }
@@ -6,7 +6,9 @@ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
6
  Coveralls::SimpleCov::Formatter
7
7
  ]
8
8
  SimpleCov.start do
9
- add_filter '.bundle'
9
+ add_filter '/vendor/bundle/'
10
+ add_filter '/spec/'
11
+ minimum_coverage(97.86)
10
12
  end
11
13
 
12
14
  require 'tweetstream'
@@ -46,7 +48,7 @@ def sample_direct_messages
46
48
  end
47
49
 
48
50
  def fixture_path
49
- File.expand_path("../fixtures", __FILE__)
51
+ File.expand_path('../fixtures', __FILE__)
50
52
  end
51
53
 
52
54
  def fixture(file)
@@ -54,6 +56,9 @@ def fixture(file)
54
56
  end
55
57
 
56
58
  FakeHttp = Class.new do
57
- def callback; end
58
- def errback; end
59
+ def callback
60
+ end
61
+
62
+ def errback
63
+ end
59
64
  end
@@ -2,23 +2,23 @@ require 'helper'
2
2
 
3
3
  describe TweetStream::Client do
4
4
  before do
5
- @stream = double("EM::Twitter::Client",
6
- :connect => true,
7
- :unbind => true,
8
- :each => true,
9
- :on_error => true,
10
- :on_max_reconnects => true,
11
- :on_reconnect => true,
12
- :connection_completed => true,
13
- :on_no_data_received => true,
14
- :on_unauthorized => true,
15
- :on_enhance_your_calm => true
5
+ @stream = double('EM::Twitter::Client',
6
+ :connect => true,
7
+ :unbind => true,
8
+ :each => true,
9
+ :on_error => true,
10
+ :on_max_reconnects => true,
11
+ :on_reconnect => true,
12
+ :connection_completed => true,
13
+ :on_no_data_received => true,
14
+ :on_unauthorized => true,
15
+ :on_enhance_your_calm => true
16
16
  )
17
17
  allow(EM).to receive(:run).and_yield
18
18
  allow(EM::Twitter::Client).to receive(:connect).and_return(@stream)
19
19
  end
20
20
 
21
- describe "basic auth" do
21
+ describe 'basic auth' do
22
22
  before do
23
23
  TweetStream.configure do |config|
24
24
  config.username = 'tweetstream'
@@ -29,7 +29,7 @@ describe TweetStream::Client do
29
29
  @client = TweetStream::Client.new
30
30
  end
31
31
 
32
- it "tries to connect via a JSON stream with basic auth" do
32
+ it 'tries to connect via a JSON stream with basic auth' do
33
33
  expect(EM::Twitter::Client).to receive(:connect).with(
34
34
  :path => '/1.1/statuses/filter.json',
35
35
  :method => 'POST',
@@ -47,7 +47,7 @@ describe TweetStream::Client do
47
47
  end
48
48
  end
49
49
 
50
- describe "oauth" do
50
+ describe 'oauth' do
51
51
  before do
52
52
  TweetStream.configure do |config|
53
53
  config.consumer_key = '123456789'
@@ -60,7 +60,7 @@ describe TweetStream::Client do
60
60
  @client = TweetStream::Client.new
61
61
  end
62
62
 
63
- it "tries to connect via a JSON stream with oauth" do
63
+ it 'tries to connect via a JSON stream with oauth' do
64
64
  expect(EM::Twitter::Client).to receive(:connect).with(
65
65
  :path => '/1.1/statuses/filter.json',
66
66
  :method => 'POST',