geppetto 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 Ternary Labs. All Rights Reserved.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,17 @@
1
+ Geppetto is a simple command line tool to help manage Facebook test users and the generation of content.
2
+
3
+ h2. Installation
4
+
5
+ @gem install geppetto@
6
+
7
+ h2. Usage
8
+
9
+ @geppetto help@
10
+
11
+ h2. Dependencies
12
+
13
+ A working version of ImageMagick library is required.
14
+
15
+ To install on OS X via port
16
+
17
+ @port install tiff -macosx imagemagick +q8 +gs +wmf@
data/bin/geppetto ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'geppetto'
4
+ require 'geppetto/cli'
5
+
6
+ name = File.basename(__FILE__)
7
+ settings_path = ".#{name}/settings.yaml"
8
+
9
+ if File.exist?(settings_path)
10
+ ::Settings = YAML.load_file(settings_path)
11
+ elsif File.exists?(File.expand_path("~/#{settings_path}"))
12
+ ::Settings = YAML.load_file(File.expand_path("~/#{settings_path}"))
13
+ else
14
+ puts "You need to create a settings file in ~/#{settings_path}. Sample content:"
15
+ sample = <<HERE
16
+ dev: &defaults
17
+ app_id: <-- YOUR APP ID -->
18
+ secret: <-- YOUR APP SECRET -->
19
+ # http://developers.facebook.com/docs/authentication/permissions/
20
+ default_permissions: [read_stream, offline_access, publish_stream, friends_hometown, friends_location]
21
+ qa:
22
+ app_id: <-- YOUR APP ID -->
23
+ secret: <-- YOUR APP SECRET -->
24
+ <<: *defaults
25
+ HERE
26
+ puts sample
27
+ exit
28
+ end
29
+
30
+ begin
31
+ Geppetto::CLI.start
32
+ rescue Koala::Facebook::APIError => e
33
+ puts e
34
+ rescue Interrupt => e
35
+ puts "\nQuitting..."
36
+ exit 1
37
+ end
@@ -0,0 +1,271 @@
1
+ require 'thor'
2
+ require 'koala'
3
+ require 'ostruct'
4
+ require 'yaml'
5
+ require 'progressbar'
6
+ require 'rmagick'
7
+ require 'tempfile'
8
+
9
+ module Geppetto
10
+ class CLI < Thor
11
+ include Koala
12
+
13
+ method_option :env, :type => :string, :default => 'dev', :desc => "App environment"
14
+ def initialize(*args)
15
+ super
16
+ unless Settings[options.env]
17
+ puts "Environement #{options.env} is not defined in the settings.yaml file"
18
+ exit
19
+ end
20
+ @test_users = Facebook::TestUsers.new(:app_id => Settings[options.env]['app_id'], :secret => Settings[options.env]['secret'])
21
+ end
22
+
23
+ desc "version", "Show program version"
24
+ def version
25
+ say "Version: #{::Geppetto::VERSION}", :white
26
+ end
27
+
28
+ desc "create [NB]", "Create one or many test users"
29
+ method_option :connected, :type => :boolean, :default => true, :alias => :string, :desc => "Whether the user has 'installed' the FB application"
30
+ method_option :networked, :type => :boolean, :default => false, :alias => :string, :desc => "Automatically befriend every user with each other"
31
+ def create(nb=1)
32
+ create_users(nb, options.connected?, options.networked?, Settings[options.env]['default_permissions'])
33
+ end
34
+
35
+ desc "list", "List all test users"
36
+ def list
37
+ users_hash = @test_users.list
38
+ say "Listing #{users_hash.size} test users", :white
39
+ users_hash.each{|user_hash|
40
+ dump(user_hash)
41
+ }
42
+ end
43
+
44
+ desc "delete ID", "Delete a test user"
45
+ def delete(id)
46
+ if yes? "Are you sure you want to delete user #{id}?", :red
47
+ @test_users.delete(id)
48
+ say "Deleted 1 user", :white
49
+ end
50
+ end
51
+
52
+ desc "delete_all", "Delete all test users"
53
+ def delete_all
54
+ if yes? "Are you sure you want to delete ALL existing test users?", :red
55
+ size = get_test_users.size
56
+ say "Deleting #{size} users", :white
57
+ progress = ProgressBar.new("Deleting", size)
58
+ get_test_users.each{|user_hash|
59
+ @test_users.delete(user_hash)
60
+ progress.inc
61
+ }
62
+ progress.finish
63
+ end
64
+ end
65
+
66
+ desc "about ID", "Display information about the given user"
67
+ def about(id)
68
+ @graph = Facebook::GraphAPI.new(get_token_for_user_id(id))
69
+ account = @graph.get_object("me")
70
+ dump(account)
71
+ end
72
+
73
+ desc "befriend ID1 ID2", "Friend two users"
74
+ def befriend(id1, id2)
75
+ @test_users.befriend(get_user_hash(id1), get_user_hash(id2))
76
+ end
77
+
78
+ desc "wall_post ID TEXT", "Post to the user's wall"
79
+ def wall_post(id, text)
80
+ @graph = Facebook::GraphAPI.new(get_token_for_user_id(id))
81
+ @graph.put_wall_post(text)
82
+ end
83
+
84
+ desc "generate_status", "Every user will post a new status update"
85
+ def generate_status
86
+ users_hash = get_test_users
87
+ say "Posting status for #{users_hash.size} users", :white
88
+ progress = ProgressBar.new("Posting", users_hash.size)
89
+ users_hash.each{|user_hash|
90
+ # Post on the user's wall
91
+ @graph = Facebook::GraphAPI.new(get_token_for_user_id(user_hash['id']))
92
+ @graph.put_wall_post("Status update created at #{Time.now}")
93
+ progress.inc
94
+ }
95
+ progress.finish
96
+ end
97
+
98
+ desc "generate_posts", "Every user will post on their friend's wall"
99
+ def generate_posts
100
+ users_hash = get_test_users
101
+ say "Posting for #{users_hash.size} users", :white
102
+ users_hash.each{|user_hash|
103
+ @graph = Facebook::GraphAPI.new(get_token_for_user_id(user_hash['id']))
104
+
105
+ # Post on friend's wall
106
+ friends = @graph.get_connections(user_hash['id'], 'friends')
107
+ progress = ProgressBar.new("Posting", friends.size)
108
+ friends.each{|friend_hash|
109
+ @graph.put_wall_post("Post created at #{Time.now}", {}, friend_hash['id'])
110
+ progress.inc
111
+ }
112
+ progress.finish
113
+ }
114
+ end
115
+
116
+ desc "generate_likes", "Every user will like all their friend's posts"
117
+ def generate_likes
118
+ users_hash = get_test_users
119
+ say "Posting likes for #{users_hash.size} users", :white
120
+ users_hash.each{|user_hash|
121
+ # Get this user's feed
122
+ token = get_token_for_user_id(user_hash['id'])
123
+ @graph = Facebook::GraphAPI.new(token)
124
+ feed = @graph.get_connections('me', 'home')
125
+ progress = ProgressBar.new("Liking", feed.size)
126
+ feed.each {|item|
127
+ @graph.put_like(item['id'])
128
+ progress.inc
129
+ }
130
+ progress.finish
131
+ }
132
+ end
133
+
134
+ desc "generate_comments", "Every user will add a comment to each post in their feed"
135
+ def generate_comments
136
+ users_hash = get_test_users
137
+ say "Posting comments for #{users_hash.size} users", :white
138
+ users_hash.each{|user_hash|
139
+ # Get this user's feed
140
+ @graph = Facebook::GraphAPI.new(get_token_for_user_id(user_hash['id']))
141
+ feed = @graph.get_connections('me', 'home')
142
+ progress = ProgressBar.new("Comments", feed.size)
143
+ feed.each {|item|
144
+ @graph.put_comment(item['id'], "Comment created at #{Time.now}")
145
+ progress.inc
146
+ }
147
+ progress.finish
148
+ }
149
+ end
150
+
151
+ desc "generate_images", "Every user will post a picture to their feed"
152
+ def generate_images
153
+ users_hash = get_test_users
154
+ say "Posting images for #{users_hash.size} users", :white
155
+ progress = ProgressBar.new("Images", users_hash.size)
156
+ users_hash.each{|user_hash|
157
+ # Get this user's feed
158
+ @graph = Facebook::GraphAPI.new(get_token_for_user_id(user_hash['id']))
159
+ file = Tempfile.new('geppetto')
160
+ begin
161
+ create_image(file.path)
162
+ @graph.put_picture(file.path, 'image/jpeg', {:message => "Image created at #{Time.now}"})
163
+ ensure
164
+ file.close
165
+ file.unlink
166
+ end
167
+ progress.inc
168
+ }
169
+ progress.finish
170
+ end
171
+
172
+ desc "build", "Built test user network and generate posts, likes, images"
173
+ def build
174
+ say "Build test setup", :white
175
+ delete_all
176
+ create_users(10, true, true, Settings[options.env]['default_permissions'])
177
+ generate_status
178
+ generate_posts
179
+ generate_images
180
+ generate_comments
181
+ generate_likes
182
+ end
183
+
184
+ desc "frenzy", "Genera posts, likes, images, etc. for all users in a random fashion. CTRL-C to cancel."
185
+ def frenzy
186
+ say "Frenzy! (CTRL-C to stop)", :white
187
+ actions = %w(generate_status generate_posts generate_images generate_comments generate_likes)
188
+ while (true)
189
+ send actions[rand(actions.size)]
190
+ say "Sleeping"
191
+ sleep 2.0
192
+ end
193
+ end
194
+
195
+ private
196
+ def dump(hash)
197
+ say "-" * 80
198
+ max_key_width = hash.keys.collect{|key| key.size}.max
199
+ format_string = "%#{max_key_width}s: %s"
200
+ hash.each{|key,value| say format(format_string, key, value)}
201
+ say "-" * 80
202
+ end
203
+
204
+ # Returned a sanitized version of the test users list. For some reason, some test users
205
+ # are now returned without oauth access token.
206
+ def get_test_users
207
+ @test_users.list.delete_if {|user_hash| !user_hash.include?('access_token') }
208
+ end
209
+
210
+ def get_user_hash(user_id)
211
+ if user_id
212
+ get_test_users.each {|user_hash| return user_hash if user_hash['id'] == user_id}
213
+ end
214
+ raise Facebook::APIError.new({"type" => 'Error', 'message' => "This user id is unknown"})
215
+ end
216
+
217
+ def get_token_for_user_id(user_id)
218
+ return get_user_hash(user_id)['access_token']
219
+ end
220
+
221
+ # Crate an image containing text
222
+ def create_image(file)
223
+ image = Magick::Image.new(320, 240, Magick::HatchFill.new("##{'%02X' % rand(255)}#{'%02X' % rand(255)}#{'%02X' % rand(255)}"))
224
+ image.format = "jpg"
225
+ image.write(file)
226
+ end
227
+
228
+ def create_users(nb, connected, networked, permissions)
229
+ if networked
230
+ say "Creating #{nb} networked test users", :white
231
+ users_hash = create_network(nb.to_i, connected, permissions.join(","))
232
+ users_hash.each{|user_hash|
233
+ dump(user_hash)
234
+ }
235
+ else
236
+ say "Creating #{nb} test users", :white
237
+ while(nb.to_i > 0)
238
+ user_hash = @test_users.create(connected, permissions.join(","))
239
+ dump(user_hash)
240
+ nb = nb.to_i-1
241
+ end
242
+ end
243
+ end
244
+
245
+ def create_network(network_size, installed = true, permissions = '')
246
+ network_size = 100 if network_size > 100
247
+ progress = ProgressBar.new("Creating", network_size)
248
+ users = (0...network_size).collect {
249
+ progress.inc
250
+ @test_users.create(installed, permissions)
251
+ }
252
+ progress.finish
253
+
254
+ friends = users.clone
255
+ users.each do |user|
256
+ # Remove this user from list of friends
257
+ friends.delete_at(0)
258
+ # befriend all the others
259
+ friends.each do |friend|
260
+ say "Befriending #{user['id']} #{friend['id']}"
261
+ begin
262
+ @test_users.befriend(user, friend)
263
+ rescue Facebook::APIError => e
264
+ say "Problem befriending: #{e}", :red
265
+ end
266
+ end
267
+ end
268
+ return users
269
+ end
270
+ end
271
+ end
@@ -0,0 +1,3 @@
1
+ module Geppetto
2
+ VERSION = '0.9.2'
3
+ end
data/lib/geppetto.rb ADDED
@@ -0,0 +1 @@
1
+ require 'geppetto/version'
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: geppetto
3
+ version: !ruby/object:Gem::Version
4
+ hash: 63
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 2
10
+ version: 0.9.2
11
+ platform: ruby
12
+ authors:
13
+ - Georges Auberger
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-26 00:00:00 -07:00
19
+ default_executable: geppetto
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: koala
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 62196359
30
+ segments:
31
+ - 1
32
+ - 0
33
+ - 0
34
+ - beta
35
+ - 2
36
+ version: 1.0.0.beta2
37
+ type: :runtime
38
+ version_requirements: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: thor
41
+ prerelease: false
42
+ requirement: &id002 !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ hash: 3
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: progressbar
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rmagick
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ type: :runtime
80
+ version_requirements: *id004
81
+ description: A simple command line tool to help manage Facebook test users and the generation of content.
82
+ email: georges@ternarylabs.com
83
+ executables:
84
+ - geppetto
85
+ extensions: []
86
+
87
+ extra_rdoc_files: []
88
+
89
+ files:
90
+ - bin/geppetto
91
+ - lib/geppetto/cli.rb
92
+ - lib/geppetto/version.rb
93
+ - lib/geppetto.rb
94
+ - LICENSE
95
+ - README.textile
96
+ has_rdoc: true
97
+ homepage: https://github.com/ternarylabs/geppetto
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ hash: 3
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ requirements:
124
+ - ImageMagick
125
+ rubyforge_project:
126
+ rubygems_version: 1.6.2
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: A simple command line tool to help manage Facebook test users and the generation of content.
130
+ test_files: []
131
+