ex_twitter 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -8
- data/ex_twitter.gemspec +1 -1
- data/lib/ex_twitter/client.rb +194 -0
- data/lib/ex_twitter/existing_api.rb +122 -0
- data/lib/ex_twitter/log_subscriber.rb +79 -0
- data/lib/ex_twitter/new_api.rb +238 -0
- data/lib/ex_twitter/utils.rb +293 -0
- data/lib/ex_twitter.rb +1 -805
- metadata +7 -4
- data/lib/ex_stream.rb +0 -68
- data/lib/ex_twitter_subscriber.rb +0 -8
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shinohara Teruki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: twitter
|
@@ -91,9 +91,12 @@ files:
|
|
91
91
|
- README.md
|
92
92
|
- Rakefile
|
93
93
|
- ex_twitter.gemspec
|
94
|
-
- lib/ex_stream.rb
|
95
94
|
- lib/ex_twitter.rb
|
96
|
-
- lib/
|
95
|
+
- lib/ex_twitter/client.rb
|
96
|
+
- lib/ex_twitter/existing_api.rb
|
97
|
+
- lib/ex_twitter/log_subscriber.rb
|
98
|
+
- lib/ex_twitter/new_api.rb
|
99
|
+
- lib/ex_twitter/utils.rb
|
97
100
|
- spec/ex_twitter_spec.rb
|
98
101
|
- spec/helper.rb
|
99
102
|
homepage: http://github.com/ts-3156/ex-twitter/
|
data/lib/ex_stream.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'twitter'
|
3
|
-
require 'yaml'
|
4
|
-
require 'active_support'
|
5
|
-
require 'parallel'
|
6
|
-
|
7
|
-
# extended twitter
|
8
|
-
class ExStream < Twitter::Streaming::Client
|
9
|
-
attr_accessor :cache, :cache_expires_in
|
10
|
-
|
11
|
-
MAX_ATTEMPTS = 1
|
12
|
-
WAIT = false
|
13
|
-
CACHE_EXPIRES_IN = 300
|
14
|
-
|
15
|
-
def initialize(config={})
|
16
|
-
self.cache_expires_in = (config[:cache_expires_in] || CACHE_EXPIRES_IN)
|
17
|
-
self.cache = ActiveSupport::Cache::FileStore.new(File.join(Dir::pwd, 'ex_twitter_cache'),
|
18
|
-
{expires_in: self.cache_expires_in, race_condition_ttl: self.cache_expires_in})
|
19
|
-
super
|
20
|
-
end
|
21
|
-
|
22
|
-
def print_filter_stream(topics)
|
23
|
-
filter(track: topics.join(",")) do |object|
|
24
|
-
puts object.text if object.is_a?(Twitter::Tweet)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def print_sample_stream
|
29
|
-
sample do |object|
|
30
|
-
puts object.text if object.is_a?(Twitter::Tweet)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# An object may be one of the following:
|
35
|
-
# Twitter::DirectMessage
|
36
|
-
# Twitter::Streaming::DeletedTweet
|
37
|
-
# Twitter::Streaming::Event
|
38
|
-
# Twitter::Streaming::FriendList
|
39
|
-
# Twitter::Streaming::StallWarning
|
40
|
-
# Twitter::Tweet
|
41
|
-
def print_user_stream
|
42
|
-
user do |object|
|
43
|
-
case object
|
44
|
-
when Twitter::Tweet
|
45
|
-
puts "It's a tweet!"
|
46
|
-
when Twitter::DirectMessage
|
47
|
-
puts "It's a direct message!"
|
48
|
-
when Twitter::Streaming::StallWarning
|
49
|
-
warn "Falling behind!"
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
if __FILE__ == $0
|
56
|
-
puts '--start--'
|
57
|
-
yml_config = YAML.load_file('config.yml')
|
58
|
-
config = {
|
59
|
-
consumer_key: yml_config['consumer_key'],
|
60
|
-
consumer_secret: yml_config['consumer_secret'],
|
61
|
-
access_token: yml_config['access_token'],
|
62
|
-
access_token_secret: yml_config['access_token_secret']
|
63
|
-
}
|
64
|
-
client = ExStream.new(config)
|
65
|
-
client.print_sample_stream
|
66
|
-
end
|
67
|
-
|
68
|
-
|