Class: Geppetto::CLI
Instance Method Summary collapse
- #about(id) ⇒ Object
- #befriend(id1, id2) ⇒ Object
- #befriend_all ⇒ Object
- #build ⇒ Object
- #create(nb = 1) ⇒ Object
- #delete(id) ⇒ Object
- #delete_all ⇒ Object
- #frenzy ⇒ Object
- #generate_comments ⇒ Object
- #generate_images ⇒ Object
- #generate_likes ⇒ Object
- #generate_posts ⇒ Object
- #generate_status ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #list ⇒ Object
- #version ⇒ Object
- #wall_post(id, text) ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
13 14 15 16 17 18 19 20 |
# File 'lib/geppetto/cli.rb', line 13 def initialize(*args) super unless Settings[.env] puts "Environement #{.env} is not defined in the settings.yaml file" exit end @test_users = Facebook::TestUsers.new(:app_id => Settings[.env]['app_id'], :secret => Settings[.env]['secret']) end |
Instance Method Details
#about(id) ⇒ Object
66 67 68 69 70 |
# File 'lib/geppetto/cli.rb', line 66 def about(id) @graph = Facebook::GraphAPI.new(get_token_for_user_id(id)) account = @graph.get_object("me") dump(account) end |
#befriend(id1, id2) ⇒ Object
73 74 75 |
# File 'lib/geppetto/cli.rb', line 73 def befriend(id1, id2) @test_users.befriend(get_user_hash(id1), get_user_hash(id2)) end |
#befriend_all ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/geppetto/cli.rb', line 78 def befriend_all if yes? "Are you sure you want to befriend ALL existing test users (this could take a while)?", :red users = get_test_users friends = users.clone users.each do |user| # Remove this user from list of friends friends.delete_at(0) # befriend all the others friends.each do |friend| say "Befriending #{user['id']} #{friend['id']}" begin @test_users.befriend(user, friend) rescue Facebook::APIError => e say "Problem befriending: #{e}", :red end end end end end |
#build ⇒ Object
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/geppetto/cli.rb', line 189 def build say "Build test setup", :white delete_all create_users(10, true, true, Settings[.env]['default_permissions']) generate_status generate_posts generate_images generate_comments generate_likes end |
#create(nb = 1) ⇒ Object
30 31 32 |
# File 'lib/geppetto/cli.rb', line 30 def create(nb=1) create_users(nb, .connected?, .networked?, Settings[.env]['default_permissions']) end |
#delete(id) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/geppetto/cli.rb', line 44 def delete(id) if yes? "Are you sure you want to delete user #{id}?", :red @test_users.delete(id) say "Deleted 1 user", :white end end |
#delete_all ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/geppetto/cli.rb', line 52 def delete_all if yes? "Are you sure you want to delete ALL existing test users?", :red size = get_test_users.size say "Deleting #{size} users", :white progress = ProgressBar.new("Deleting", size) get_test_users.each{|user_hash| @test_users.delete(user_hash) progress.inc } progress.finish end end |
#frenzy ⇒ Object
201 202 203 204 205 206 207 208 209 |
# File 'lib/geppetto/cli.rb', line 201 def frenzy say "Frenzy! (CTRL-C to stop)", :white actions = %w(generate_status generate_posts generate_images generate_comments generate_likes) while (true) send actions[rand(actions.size)] say "Sleeping" sleep 2.0 end end |
#generate_comments ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/geppetto/cli.rb', line 155 def generate_comments users_hash = get_test_users say "Posting comments for #{users_hash.size} users", :white users_hash.each{|user_hash| # Get this user's feed @graph = Facebook::GraphAPI.new(get_token_for_user_id(user_hash['id'])) feed = @graph.get_connections('me', 'home') progress = ProgressBar.new("Comments", feed.size) feed.each {|item| @graph.put_comment(item['id'], "Comment created at #{Time.now}") progress.inc } progress.finish } end |
#generate_images ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/geppetto/cli.rb', line 172 def generate_images users_hash = get_test_users say "Posting images for #{users_hash.size} users", :white progress = ProgressBar.new("Images", users_hash.size*2) users_hash.each{|user_hash| # Get this user's feed @graph = Facebook::GraphAPI.new(get_token_for_user_id(user_hash['id'])) %w(640_480.png 480_640.png).each {|file_name| file_path = File.join(File.dirname(__FILE__), file_name) @graph.put_picture(file_path, 'image/png', {:message => "Image created at #{Time.now}"}) progress.inc } } progress.finish end |
#generate_likes ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/geppetto/cli.rb', line 137 def generate_likes users_hash = get_test_users say "Posting likes for #{users_hash.size} users", :white users_hash.each{|user_hash| # Get this user's feed token = get_token_for_user_id(user_hash['id']) @graph = Facebook::GraphAPI.new(token) feed = @graph.get_connections('me', 'home') progress = ProgressBar.new("Liking", feed.size) feed.each {|item| @graph.put_like(item['id']) progress.inc } progress.finish } end |
#generate_posts ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/geppetto/cli.rb', line 119 def generate_posts users_hash = get_test_users say "Posting for #{users_hash.size} users", :white users_hash.each{|user_hash| @graph = Facebook::GraphAPI.new(get_token_for_user_id(user_hash['id'])) # Post on friend's wall friends = @graph.get_connections(user_hash['id'], 'friends') progress = ProgressBar.new("Posting", friends.size) friends.each{|friend_hash| @graph.put_wall_post("Post created at #{Time.now}", {}, friend_hash['id']) progress.inc } progress.finish } end |
#generate_status ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/geppetto/cli.rb', line 105 def generate_status users_hash = get_test_users say "Posting status for #{users_hash.size} users", :white progress = ProgressBar.new("Posting", users_hash.size) users_hash.each{|user_hash| # Post on the user's wall @graph = Facebook::GraphAPI.new(get_token_for_user_id(user_hash['id'])) @graph.put_wall_post("Status update created at #{Time.now}") progress.inc } progress.finish end |
#list ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/geppetto/cli.rb', line 35 def list users_hash = @test_users.list say "Listing #{users_hash.size} test users", :white users_hash.each{|user_hash| dump(user_hash) } end |
#version ⇒ Object
23 24 25 |
# File 'lib/geppetto/cli.rb', line 23 def version say "Version: #{::Geppetto::VERSION}", :white end |
#wall_post(id, text) ⇒ Object
99 100 101 102 |
# File 'lib/geppetto/cli.rb', line 99 def wall_post(id, text) @graph = Facebook::GraphAPI.new(get_token_for_user_id(id)) @graph.put_wall_post(text) end |