tomodachi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b91958003340781c775727224505750485de9bd9
4
+ data.tar.gz: 068a5d7f176e9f0ff0bad4077a47961718332b02
5
+ SHA512:
6
+ metadata.gz: 42282ec56d4214ee0b06e07cae4c65d61516aa246f114bb69b21862e2d49cfc57cc3a533a8100f61ba66755925711a349418f1decb1a34e6380667fdf2b76d02
7
+ data.tar.gz: a560d24e582995d65f4f58318e5fd300f3a4381a696796366730f2c5f51e1b99c72aab6245b5771a30e5b15fc0ae41212e3c7c706aac81d2b9a01fefa4664e35
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tomodachi.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 ikstrm
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Tomodachi
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'tomodachi'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install tomodachi
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ lib = File.dirname(__FILE__) + '/../lib'
5
+ $:.unshift lib unless $:.include? lib
6
+
7
+ require 'tomodachi'
8
+
9
+ Tomodachi::setup
@@ -0,0 +1,32 @@
1
+ require "tomodachi/version"
2
+ require "tomodachi/auth"
3
+ require "tomodachi/client"
4
+
5
+ module Tomodachi
6
+ # Twitter for iPhone consumer
7
+ CONSUMER_KEY = 'IQKbtAYlXLripLGPWd0HUA'
8
+ CONSUMER_SECRET = 'GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU'
9
+
10
+ def self.setup
11
+ case ARGV[0]
12
+ when "auth"
13
+ auth = Tomodachi::Auth.new
14
+ auth.create
15
+ when "list"
16
+ Tomodachi::Auth.list
17
+ when "start"
18
+ if ARGV[1]
19
+ Tomodachi::Client.start(ARGV[1])
20
+ else
21
+ puts "Usage: tomodachi start screen_name"
22
+ end
23
+ else
24
+ print(<<-"EOS")
25
+ Usage:
26
+ tomodachi auth
27
+ tomodachi list
28
+ tomodachi start screen_name
29
+ EOS
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,126 @@
1
+ require 'yaml'
2
+ require 'oauth'
3
+ require 'thor'
4
+ require 'thor/group'
5
+ require 'twitter'
6
+
7
+ module Tomodachi
8
+ class Auth < Thor::Group
9
+ include Thor::Actions
10
+
11
+ CONFIG_PATH = File.expand_path('~/.tomodachi/config.yml')
12
+
13
+ def create
14
+ consumer = OAuth::Consumer.new(
15
+ CONSUMER_KEY,
16
+ CONSUMER_SECRET,
17
+ :site => 'https://api.twitter.com'
18
+ )
19
+ request_token = consumer.get_request_token
20
+
21
+ say request_token.authorize_url
22
+ system 'open', request_token.authorize_url
23
+ pin = ask 'PIN:'
24
+
25
+ access_token = request_token.get_access_token(oauth_verifier: pin)
26
+
27
+ Twitter.configure do |config|
28
+ config.consumer_key = CONSUMER_KEY
29
+ config.consumer_secret = CONSUMER_SECRET
30
+ config.oauth_token = access_token.token
31
+ config.oauth_token_secret = access_token.secret
32
+ end
33
+ user = Twitter.user
34
+
35
+ conf = Array.new unless conf = Auth.load_config
36
+ if Auth.exist_by_id?(user[:id])
37
+ puts user[:screen_name] + ' is already added.'
38
+ else
39
+ conf += [
40
+ id: user[:id],
41
+ screen_name: user[:screen_name],
42
+ access_token: access_token.token,
43
+ access_token_secret: access_token.secret
44
+ ]
45
+ Auth.save_config(conf)
46
+ puts 'Added configuration for ' + user[:screen_name]
47
+ end
48
+ end
49
+
50
+ def self.list
51
+ current_conf = Auth.load_config
52
+ if current_conf
53
+ current_conf.each do |conf|
54
+ puts conf[:screen_name]
55
+ end
56
+ else
57
+ puts "There is no authenticated account."
58
+ end
59
+ end
60
+
61
+ def self.exist?(screen_name)
62
+ if confs = Auth.load_config
63
+ confs.each do |conf|
64
+ if conf[:screen_name] == screen_name
65
+ return true
66
+ end
67
+ end
68
+ end
69
+ false
70
+ end
71
+
72
+ def self.exist_by_id?(id)
73
+ if confs = Auth.load_config
74
+ confs.each do |conf|
75
+ if conf[:id] == id
76
+ return true
77
+ end
78
+ end
79
+ end
80
+ false
81
+ end
82
+
83
+ def self.load_config
84
+ path = File.expand_path('~/.tomodachi/')
85
+ if FileTest.exist?(path) == false
86
+ FileUtils.mkdir_p(path)
87
+ return nil
88
+ end
89
+
90
+ if FileTest.exist?(CONFIG_PATH)
91
+ str = nil
92
+ File.open(CONFIG_PATH, 'r') do |f|
93
+ str = f.read
94
+ end
95
+ YAML.load(str)
96
+ else
97
+ nil
98
+ end
99
+ end
100
+
101
+ def self.load_token(screen_name)
102
+ str = nil
103
+ File.open(CONFIG_PATH, 'r') do |f|
104
+ str = f.read
105
+ end
106
+
107
+ if str
108
+ conf_all = YAML.load(str)
109
+
110
+ conf_all.each do |conf|
111
+ if conf[:screen_name] == screen_name
112
+ return conf
113
+ end
114
+ end
115
+ else
116
+ nil
117
+ end
118
+ end
119
+
120
+ def self.save_config(conf)
121
+ File.open(CONFIG_PATH, 'w') do |f|
122
+ f << conf.to_yaml
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,36 @@
1
+ require 'twitter'
2
+ require 'user_stream'
3
+
4
+ module Tomodachi
5
+ class Client
6
+ def self.start(screen_name)
7
+ if Auth.exist?(screen_name)
8
+ conf = Auth.load_token(screen_name)
9
+ UserStream.configure do |config|
10
+ config.consumer_key = CONSUMER_KEY
11
+ config.consumer_secret = CONSUMER_SECRET
12
+ config.oauth_token = conf[:access_token]
13
+ config.oauth_token_secret = conf[:access_token_secret]
14
+ end
15
+
16
+ Twitter.configure do |config|
17
+ config.consumer_key = CONSUMER_KEY
18
+ config.consumer_secret = CONSUMER_SECRET
19
+ config.oauth_token = conf[:access_token]
20
+ config.oauth_token_secret = conf[:access_token_secret]
21
+ end
22
+
23
+ client = UserStream.client
24
+ client.user do |status|
25
+ if status["event"] == "follow" && status["source"]["screen_name"] != screen_name
26
+ puts 'followed ' + status["source"]["screen_name"]
27
+ Twitter.follow(status["source"]["id"])
28
+ end
29
+ end
30
+
31
+ else
32
+ puts screen_name + " is not authenticated."
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Tomodachi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ describe Auth do
2
+ end
@@ -0,0 +1,2 @@
1
+ describe Client do
2
+ end
@@ -0,0 +1 @@
1
+ require 'tomodachi'
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tomodachi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tomodachi"
8
+ spec.version = Tomodachi::VERSION
9
+ spec.authors = ["ikstrm"]
10
+ spec.email = ["igzarion.1993@gmail.com"]
11
+ spec.description = %q{Automatic follow back tool with Twitter streaming API}
12
+ spec.summary = %q{Automatic follow back tool with Twitter streaming API}
13
+ spec.homepage = "https://github.com/ikstrm/tomodachi"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = ["tomodachi"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "twitter"
24
+ spec.add_development_dependency "userstream"
25
+ spec.add_development_dependency "thor"
26
+ spec.add_development_dependency "oauth"
27
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tomodachi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ikstrm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: twitter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: userstream
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: oauth
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Automatic follow back tool with Twitter streaming API
98
+ email:
99
+ - igzarion.1993@gmail.com
100
+ executables:
101
+ - tomodachi
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - .gitignore
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/tomodachi
111
+ - lib/tomodachi.rb
112
+ - lib/tomodachi/auth.rb
113
+ - lib/tomodachi/client.rb
114
+ - lib/tomodachi/version.rb
115
+ - spec/auth_spec.rb
116
+ - spec/client_spec.rb
117
+ - spec/spec_helper.rb
118
+ - tomodachi.gemspec
119
+ homepage: https://github.com/ikstrm/tomodachi
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.0.0
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Automatic follow back tool with Twitter streaming API
143
+ test_files:
144
+ - spec/auth_spec.rb
145
+ - spec/client_spec.rb
146
+ - spec/spec_helper.rb