neo4apis-twitter 0.1.0 → 0.2.0

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: 1427ba9cc8ac90d30eb484718d84bc01fdde663d
4
- data.tar.gz: b7459019f9bee650ad02163056336dee1a796c4e
3
+ metadata.gz: f4ea71535fbe17e2305b38c9acc1a20c3362ea53
4
+ data.tar.gz: d2f2266563615e7adc2c6e1e4f8d59a9c6f18003
5
5
  SHA512:
6
- metadata.gz: 6f9850d9a63dcfb44a42695d6c8b182e4118aecd19f9b420f34791fc2b03482c02865665891e055b0287a72a501f9fab3287553c3123462798e79aa32560eab6
7
- data.tar.gz: a971a013742cd92e61ee61b4129b897a8913b12c4e38a04659a9b75d576aeb8345648254d6a8d3c445dba9839ee4197fe12a6b6510890ff540ad0e7561e42658
6
+ metadata.gz: b71ebd8a79a4cb0b8fe966c7dc9abb38a379e183543b100d2b434b128eabf382f5a481c26e1d7d0356165774cd37d56b5105ca20563875cf7062084de396a2ad
7
+ data.tar.gz: 4c4ebf38beea41ed436230bfc103bc7f9d50c12ba3fcfcf6b43ac0d62208d6f5705689473ddf42ffcd73420e697eec31eed7afbc1a8edc662fd37fd5d53f05d6
data/README.md CHANGED
@@ -18,7 +18,7 @@ neo4japis_twitter.batch do
18
18
  # * The tweeter,
19
19
  # * The original tweet if a retweet
20
20
  # * The user for the original tweet
21
- import :Tweet, tweet
21
+ neo4apis_client.import :Tweet, tweet
22
22
  end
23
23
  end
24
24
 
@@ -0,0 +1,6 @@
1
+ ---
2
+ :consumer_key: iwmENsqBZNAeN07hsrGuGwKMa
3
+ :consumer_secret: ioVqcH3pxTrTq5or5cpXdj4WJpUO1ZNjMRr3tmhFg4xT1mOQXa
4
+ :access_token: 2776665793-QPDyINltYv3hGa9RjmMeAbxFSHXJ764n0ycOu1E
5
+ :access_token_secret: hlxs1wONx6lJ7GLLY0nXm630mv6NzPHOhDlirCvqetCip
6
+
@@ -1,4 +1,5 @@
1
1
  require 'neo4apis'
2
2
 
3
3
  require 'neo4apis/twitter'
4
+ require 'neo4apis/cli/twitter'
4
5
 
@@ -0,0 +1,69 @@
1
+ require 'twitter'
2
+
3
+ module Neo4Apis
4
+ module CLI
5
+ class Twitter < Thor
6
+ class_option :config_path, type: :string, default: 'config/twitter.yml'
7
+
8
+ desc "filter TRACK", "Streams tweets via a filter"
9
+ def filter(track)
10
+ neo4apis_client.batch do
11
+ twitter_client(true).filter(track: track, &tweet_importer)
12
+ end
13
+ end
14
+
15
+ option :result_type, type: :string
16
+ desc "search QUERY COUNT", "Import tweets via a search query"
17
+ def search(query, count)
18
+ neo4apis_client.batch do
19
+ twitter_client(false).search(query, options).take(count.to_i).each(&tweet_importer)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def tweet_importer
26
+ Proc.new do |object|
27
+ case object
28
+ when ::Twitter::Tweet
29
+ say "got tweet from @#{object.user.screen_name}: #{object.text}"
30
+ neo4apis_client.import :Tweet, object
31
+ when ::Twitter::Streaming::StallWarning
32
+ puts "Falling behind!"
33
+ end
34
+ end
35
+ end
36
+
37
+ NEO4APIS_CLIENT_CLASS = ::Neo4Apis::Twitter
38
+
39
+ def neo4apis_client
40
+ @neo4apis_client ||= NEO4APIS_CLIENT_CLASS.new(Neo4j::Session.open(:server_db, parent_options[:neo4j_url]), import_retweets: true, import_hashtags: true)
41
+ end
42
+
43
+ def twitter_client(streaming)
44
+ return @twitter_client if @twitter_client
45
+
46
+ twitter_client_class = streaming ? ::Twitter::Streaming::Client : ::Twitter::REST::Client
47
+
48
+ @twitter_client = twitter_client_class.new do |config|
49
+ yml_config.each do |key, value|
50
+ config.send("#{key}=", value)
51
+ end
52
+ end
53
+ end
54
+
55
+ # For reference for this gem's documentation:
56
+ # https://github.com/sferik/twitter/blob/master/examples/Configuration.md
57
+ def yml_config
58
+ require 'yaml'
59
+ @yml_config ||= YAML.load(File.open(options[:config_path]).read)
60
+ end
61
+ end
62
+
63
+ class Base < Thor
64
+ desc "twitter SUBCOMMAND ...ARGS", "methods of importing data automagically from Twitter"
65
+ subcommand "twitter", CLI::Twitter
66
+ end
67
+ end
68
+ end
69
+
@@ -45,5 +45,6 @@ module Neo4Apis
45
45
  end
46
46
 
47
47
  end
48
+
48
49
  end
49
50
 
@@ -3,7 +3,7 @@ $:.unshift lib unless $:.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "neo4apis-twitter"
6
- s.version = '0.1.0'
6
+ s.version = '0.2.0'
7
7
  s.required_ruby_version = ">= 1.9.1"
8
8
 
9
9
  s.authors = "Brian Underwood"
@@ -18,7 +18,7 @@ A ruby gem using neo4apis to make importing twitter data to neo4j easy
18
18
  s.require_path = 'lib'
19
19
  s.files = Dir.glob("{bin,lib,config}/**/*") + %w(README.md Gemfile neo4apis-twitter.gemspec)
20
20
 
21
- s.add_dependency('neo4apis', "~> 0.2.0")
22
- s.add_dependency('twitter', "~> 5.12.0")
21
+ s.add_dependency('neo4apis', '~> 0.3.0')
22
+ s.add_dependency('twitter', '~> 5.12.0')
23
23
 
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neo4apis-twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Underwood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-02 00:00:00.000000000 Z
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neo4apis
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0
19
+ version: 0.3.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0
26
+ version: 0.3.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: twitter
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -47,7 +47,9 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - Gemfile
49
49
  - README.md
50
+ - config/twitter.yml
50
51
  - lib/neo4apis-twitter.rb
52
+ - lib/neo4apis/cli/twitter.rb
51
53
  - lib/neo4apis/twitter.rb
52
54
  - neo4apis-twitter.gemspec
53
55
  homepage: https://github.com/neo4jrb/neo4apis-twitter/