tomodachi 0.0.1 → 0.1.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: b91958003340781c775727224505750485de9bd9
4
- data.tar.gz: 068a5d7f176e9f0ff0bad4077a47961718332b02
3
+ metadata.gz: 3c09aafd7639e1e9b0edafc93c585e1e6b2105dd
4
+ data.tar.gz: e1c35f10a6d7204fd0bbb3f44088d9159deb403e
5
5
  SHA512:
6
- metadata.gz: 42282ec56d4214ee0b06e07cae4c65d61516aa246f114bb69b21862e2d49cfc57cc3a533a8100f61ba66755925711a349418f1decb1a34e6380667fdf2b76d02
7
- data.tar.gz: a560d24e582995d65f4f58318e5fd300f3a4381a696796366730f2c5f51e1b99c72aab6245b5771a30e5b15fc0ae41212e3c7c706aac81d2b9a01fefa4664e35
6
+ metadata.gz: 5f2f21fffac66a864a97d70b0a4ebf9d880fb40a0ab21ca5d197f847de63c7e7c70d924cf26f6a77810632f78a109dd19320e407c1570455e1606b15c75d8945
7
+ data.tar.gz: a8d799e1f03be6cec8c6e79cad5b498caa2f2aa139cb88043cd1f18c147910bf63bf3d74750ba14013779b1a24e5671fd7277e9fde8b841cd89c48465d11a7be
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 ikstrm
1
+ Copyright (c) 2013 Takashi Kokubun
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,24 +1,25 @@
1
1
  # Tomodachi
2
2
 
3
- TODO: Write a gem description
3
+ Automatic follow back tool with Twitter streaming API
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ ```bash
8
+ $ gem install tomodachi
9
+ ```
8
10
 
9
- gem 'tomodachi'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
11
+ ## Usage
16
12
 
17
- $ gem install tomodachi
13
+ ```bash
14
+ # authenticate a twitter user and save its access token
15
+ $ tomodachi auth
18
16
 
19
- ## Usage
17
+ # list your authenticated accounts' screen_name
18
+ $ tomodachi list
20
19
 
21
- TODO: Write usage instructions here
20
+ # start automatic following back
21
+ $ tomodachi start screen_name
22
+ ```
22
23
 
23
24
  ## Contributing
24
25
 
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- # -*- coding: utf-8 -*-
3
2
 
4
3
  lib = File.dirname(__FILE__) + '/../lib'
5
4
  $:.unshift lib unless $:.include? lib
6
5
 
7
6
  require 'tomodachi'
8
7
 
9
- Tomodachi::setup
8
+ tomodachi = Tomodachi.new
9
+ tomodachi.setup
@@ -1,32 +1,55 @@
1
- require "tomodachi/version"
2
- require "tomodachi/auth"
3
- require "tomodachi/client"
1
+ require 'tomodachi/version'
2
+ require 'tomodachi/auth'
3
+ require 'tomodachi/client'
4
+ require 'unindent'
4
5
 
5
- module Tomodachi
6
- # Twitter for iPhone consumer
7
- CONSUMER_KEY = 'IQKbtAYlXLripLGPWd0HUA'
6
+ class Tomodachi
7
+ CONSUMER_KEY = 'IQKbtAYlXLripLGPWd0HUA'
8
8
  CONSUMER_SECRET = 'GgDYlkSvaPxGxC4X8liwpUoqKwwr3lCADbz8A7ADU'
9
9
 
10
- def self.setup
11
- case ARGV[0]
12
- when "auth"
13
- auth = Tomodachi::Auth.new
10
+ def setup
11
+ case command
12
+ when 'auth'
14
13
  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
14
+ when 'list'
15
+ auth.list
16
+ when 'start'
17
+ return print_start_usage if screen_name.nil?
18
+
19
+ client = Tomodachi::Client.new(screen_name)
20
+ client.start
23
21
  else
24
- print(<<-"EOS")
25
- Usage:
26
- tomodachi auth
27
- tomodachi list
28
- tomodachi start screen_name
29
- EOS
22
+ print_usage
30
23
  end
31
24
  end
25
+
26
+ private
27
+
28
+ def command
29
+ ARGV[0]
30
+ end
31
+
32
+ def screen_name
33
+ ARGV[1]
34
+ end
35
+
36
+ def auth
37
+ @auth ||= Tomodachi::Auth.new
38
+ end
39
+
40
+ def print_usage
41
+ puts <<-EOS.unindent
42
+ Usage:
43
+ tomodachi auth # add account
44
+ tomodachi list # authenticated account list
45
+ tomodachi start [screen_name] # start automatic following back
46
+ EOS
47
+ end
48
+
49
+ def print_start_usage
50
+ puts <<-EOS.unindent
51
+ Usage:
52
+ tomodachi start [screen_name]
53
+ EOS
54
+ end
32
55
  end
@@ -3,124 +3,86 @@ require 'oauth'
3
3
  require 'thor'
4
4
  require 'thor/group'
5
5
  require 'twitter'
6
+ require 'pry'
6
7
 
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
8
+ class Tomodachi::Auth < Thor::Group
9
+ include Thor::Actions
20
10
 
21
- say request_token.authorize_url
22
- system 'open', request_token.authorize_url
23
- pin = ask 'PIN:'
11
+ CONFIG_PATH = File.expand_path('~/.tomodachi')
24
12
 
25
- access_token = request_token.get_access_token(oauth_verifier: pin)
13
+ def create
14
+ load_access_token(access_token)
26
15
 
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
16
+ accounts = load_config || []
17
+ if accounts.find { |account| account[:id] == user[:id] }
18
+ puts "#{user[:screen_name]} is already added."
19
+ else
20
+ accounts += [
21
+ id: user[:id],
22
+ screen_name: user[:screen_name],
23
+ access_token: access_token.token,
24
+ access_token_secret: access_token.secret,
25
+ ]
26
+ save_config(accounts)
27
+ puts "Added configuration for #{user[:screen_name]}"
48
28
  end
29
+ end
49
30
 
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."
31
+ def list
32
+ accounts = load_config
33
+ if accounts
34
+ puts "Available accounts:"
35
+ accounts.each do |conf|
36
+ puts " #{conf[:screen_name]}"
58
37
  end
38
+ else
39
+ puts "There is no authenticated account."
59
40
  end
41
+ end
60
42
 
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
43
+ def load_config
44
+ if File.exists?(CONFIG_PATH)
45
+ yaml = File.read(CONFIG_PATH)
46
+ YAML.load(yaml)
47
+ else
48
+ nil
81
49
  end
50
+ end
82
51
 
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
52
+ private
100
53
 
101
- def self.load_token(screen_name)
102
- str = nil
103
- File.open(CONFIG_PATH, 'r') do |f|
104
- str = f.read
105
- end
54
+ def access_token
55
+ return @access_token if @access_token
106
56
 
107
- if str
108
- conf_all = YAML.load(str)
57
+ request_token = consumer.get_request_token
58
+ system('open', request_token.authorize_url)
59
+ @access_token = request_token.get_access_token(oauth_verifier: ask('PIN:'))
60
+ end
109
61
 
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
62
+ def load_access_token(access_token)
63
+ Twitter.configure do |config|
64
+ config.consumer_key = Tomodachi::CONSUMER_KEY
65
+ config.consumer_secret = Tomodachi::CONSUMER_SECRET
66
+ config.oauth_token = access_token.token
67
+ config.oauth_token_secret = access_token.secret
118
68
  end
69
+ end
119
70
 
120
- def self.save_config(conf)
121
- File.open(CONFIG_PATH, 'w') do |f|
122
- f << conf.to_yaml
123
- end
71
+ def user
72
+ @user ||= Twitter.user
73
+ end
74
+
75
+ def consumer
76
+ @consumer ||= OAuth::Consumer.new(
77
+ Tomodachi::CONSUMER_KEY,
78
+ Tomodachi::CONSUMER_SECRET,
79
+ site: 'https://api.twitter.com',
80
+ )
81
+ end
82
+
83
+ def save_config(conf)
84
+ File.open(CONFIG_PATH, 'w') do |f|
85
+ f << conf.to_yaml
124
86
  end
125
87
  end
126
88
  end
@@ -1,36 +1,60 @@
1
- require 'twitter'
2
1
  require 'user_stream'
3
2
 
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."
3
+ class Tomodachi::Client
4
+ def initialize(screen_name)
5
+ @screen_name = screen_name
6
+ end
7
+
8
+ def start
9
+ unless account
10
+ puts "#{screen_name} is not authenticated."
11
+ return
12
+ end
13
+
14
+ configure(account)
15
+ client.user do |status|
16
+ if status['event'] == 'follow' && status['source']['screen_name'] != @screen_name
17
+ puts "followed #{status['source']['screen_name']}"
18
+ Twitter.follow(status['source']['id'])
33
19
  end
34
20
  end
35
21
  end
22
+
23
+ private
24
+
25
+ def client
26
+ @client ||= UserStream.client
27
+ end
28
+
29
+ def configure(account)
30
+ UserStream.configure do |config|
31
+ config.consumer_key = Tomodachi::CONSUMER_KEY
32
+ config.consumer_secret = Tomodachi::CONSUMER_SECRET
33
+ config.oauth_token = account[:access_token]
34
+ config.oauth_token_secret = account[:access_token_secret]
35
+ end
36
+
37
+ Twitter.configure do |config|
38
+ config.consumer_key = Tomodachi::CONSUMER_KEY
39
+ config.consumer_secret = Tomodachi::CONSUMER_SECRET
40
+ config.oauth_token = account[:access_token]
41
+ config.oauth_token_secret = account[:access_token_secret]
42
+ end
43
+ end
44
+
45
+ def account
46
+ return @account if @account
47
+
48
+ accounts = auth.load_config
49
+ @account = accounts.find { |account| account[:screen_name] == @screen_name }
50
+ end
51
+
52
+ def account_exists?(screen_name)
53
+ accounts = auth.load_config
54
+ accounts.find { |account| account[:screen_name] == screen_name }
55
+ end
56
+
57
+ def auth
58
+ @auth ||= Tomodachi::Auth.new
59
+ end
36
60
  end
@@ -1,3 +1,3 @@
1
- module Tomodachi
2
- VERSION = "0.0.1"
1
+ class Tomodachi
2
+ VERSION = '0.1.0'
3
3
  end
@@ -4,24 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'tomodachi/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "tomodachi"
7
+ spec.name = 'tomodachi'
8
8
  spec.version = Tomodachi::VERSION
9
- spec.authors = ["ikstrm"]
10
- spec.email = ["igzarion.1993@gmail.com"]
9
+ spec.authors = ['Takashi Kokubun']
10
+ spec.email = ['takashikkbn@gmail.com']
11
11
  spec.description = %q{Automatic follow back tool with Twitter streaming API}
12
12
  spec.summary = %q{Automatic follow back tool with Twitter streaming API}
13
- spec.homepage = "https://github.com/ikstrm/tomodachi"
14
- spec.license = "MIT"
13
+ spec.homepage = 'https://github.com/k0kubun/tomodachi'
14
+ spec.license = 'MIT'
15
15
 
16
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"]
17
+ spec.executables = ['tomodachi']
18
+ spec.require_paths = ['lib']
20
19
 
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"
20
+ spec.add_dependency 'faraday', '~> 0.8.0'
21
+ spec.add_dependency 'twitter', '~> 4.8.1'
22
+ spec.add_dependency 'thor', '~> 0.18.1'
23
+ spec.add_dependency 'userstream', '~> 1.4.0'
24
+ spec.add_dependency 'oauth', '~> 0.4.7'
25
+ spec.add_dependency 'unindent', '~> 1.0'
26
+ spec.add_dependency 'pry', '~> 0.9.12.6'
27
+
28
+ spec.add_development_dependency 'bundler'
27
29
  end
metadata CHANGED
@@ -1,87 +1,115 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tomodachi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - ikstrm
7
+ - Takashi Kokubun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-14 00:00:00.000000000 Z
11
+ date: 2014-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :development
19
+ version: 0.8.0
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: '1.3'
26
+ version: 0.8.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: twitter
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
33
+ version: 4.8.1
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 4.8.1
41
41
  - !ruby/object:Gem::Dependency
42
- name: twitter
42
+ name: thor
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
47
+ version: 0.18.1
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.18.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: userstream
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
61
+ version: 1.4.0
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.4.0
69
69
  - !ruby/object:Gem::Dependency
70
- name: thor
70
+ name: oauth
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
75
+ version: 0.4.7
76
+ type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ~>
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.4.7
83
83
  - !ruby/object:Gem::Dependency
84
- name: oauth
84
+ name: unindent
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.12.6
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.12.6
111
+ - !ruby/object:Gem::Dependency
112
+ name: bundler
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - '>='
@@ -96,7 +124,7 @@ dependencies:
96
124
  version: '0'
97
125
  description: Automatic follow back tool with Twitter streaming API
98
126
  email:
99
- - igzarion.1993@gmail.com
127
+ - takashikkbn@gmail.com
100
128
  executables:
101
129
  - tomodachi
102
130
  extensions: []
@@ -112,11 +140,8 @@ files:
112
140
  - lib/tomodachi/auth.rb
113
141
  - lib/tomodachi/client.rb
114
142
  - lib/tomodachi/version.rb
115
- - spec/auth_spec.rb
116
- - spec/client_spec.rb
117
- - spec/spec_helper.rb
118
143
  - tomodachi.gemspec
119
- homepage: https://github.com/ikstrm/tomodachi
144
+ homepage: https://github.com/k0kubun/tomodachi
120
145
  licenses:
121
146
  - MIT
122
147
  metadata: {}
@@ -136,11 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
161
  version: '0'
137
162
  requirements: []
138
163
  rubyforge_project:
139
- rubygems_version: 2.0.0
164
+ rubygems_version: 2.0.3
140
165
  signing_key:
141
166
  specification_version: 4
142
167
  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
168
+ test_files: []
@@ -1,2 +0,0 @@
1
- describe Auth do
2
- end
@@ -1,2 +0,0 @@
1
- describe Client do
2
- end
@@ -1 +0,0 @@
1
- require 'tomodachi'