sacrifice 0.0.9 → 0.0.12
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.
- checksums.yaml +4 -4
- data/lib/sacrifice/app.rb +6 -6
- data/lib/sacrifice/csv.rb +26 -3
- data/lib/sacrifice/users.rb +17 -4
- data/lib/sacrifice/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c74606f632f956725e2bd4fea9789a22cee4b201
|
4
|
+
data.tar.gz: f409039dd61db39757abdcd176a9661150f05b05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a513769df721b332c6a0517f18d3869a4091fdcd75d6a316125fc40bfd2dc2328767854251933776693db43c7a5a5280a0074d2091d25cf6a08b8279c66a6ddc
|
7
|
+
data.tar.gz: 6914f39fad533258a3861e1481794a0ca2a47cd4050440d715f0e0967974e983738a8223e801769ab579a6a2a5b434f4e641d265642568a2eedf340c16d83c77
|
data/lib/sacrifice/app.rb
CHANGED
@@ -70,6 +70,12 @@ class App
|
|
70
70
|
@access_token ||= AccessToken.get(id, secret)
|
71
71
|
end
|
72
72
|
|
73
|
+
def find_user(user_id)
|
74
|
+
users.find { |user|
|
75
|
+
user.id.to_s == user_id.to_s
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
73
79
|
private
|
74
80
|
|
75
81
|
def users_url
|
@@ -101,10 +107,4 @@ class App
|
|
101
107
|
end
|
102
108
|
app
|
103
109
|
end
|
104
|
-
|
105
|
-
def find_user(user_id)
|
106
|
-
users.find { |user|
|
107
|
-
user.id.to_s == user_id.to_s
|
108
|
-
}
|
109
|
-
end
|
110
110
|
end
|
data/lib/sacrifice/csv.rb
CHANGED
@@ -5,12 +5,14 @@ require 'json'
|
|
5
5
|
class Csv
|
6
6
|
CREATE_OPTIONS = [:name, :install, :locale]
|
7
7
|
CHANGE_OPTIONS = [:password]
|
8
|
-
OUTPUT_ORDER = [:id, :email, :password, :login_url, :access_token]
|
8
|
+
OUTPUT_ORDER = [:id, :name, :email, :password, :login_url, :access_token]
|
9
9
|
|
10
|
-
def self.generate app_name, file
|
10
|
+
def self.generate app_name, file, friends_file
|
11
11
|
app = App.find! app_name
|
12
12
|
output = init_output(app_name, file)
|
13
13
|
|
14
|
+
friends = ids(app, friends_file)
|
15
|
+
|
14
16
|
headers = []
|
15
17
|
CSV.read(file, headers: true, header_converters: :symbol).each { |data|
|
16
18
|
if headers.empty?
|
@@ -40,12 +42,13 @@ class Csv
|
|
40
42
|
# execute change
|
41
43
|
if change_options.any? and user.change(change_options)
|
42
44
|
user.password = change_options[:password] if change_options[:password]
|
43
|
-
|
45
|
+
elsif change_options[:password]
|
44
46
|
puts "Failed to update password to #{change_options[:password]}"
|
45
47
|
end
|
46
48
|
|
47
49
|
# print created user
|
48
50
|
user_map = user.attrs
|
51
|
+
user_map[:name] = create_options[:name] if create_options[:name]
|
49
52
|
puts user_map.map { |key, value| "#{key.upcase} : #{value}" }
|
50
53
|
|
51
54
|
# log created user
|
@@ -56,6 +59,9 @@ class Csv
|
|
56
59
|
}
|
57
60
|
line << output_line
|
58
61
|
} unless user.id.nil?
|
62
|
+
|
63
|
+
user = app.find_user(user.id)
|
64
|
+
friends user, friends
|
59
65
|
}
|
60
66
|
end
|
61
67
|
|
@@ -79,6 +85,23 @@ class Csv
|
|
79
85
|
}
|
80
86
|
end
|
81
87
|
|
88
|
+
def self.ids app, csv_file
|
89
|
+
ids = []
|
90
|
+
CSV.read(csv_file, headers: true, header_converters: :symbol).each { |data|
|
91
|
+
ids.push app.find_user(data[:id]) or raise Thor::Error, "No user found w/id #{user.inspect}"
|
92
|
+
} if csv_file
|
93
|
+
ids
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.friends user, friends
|
97
|
+
if friends.any?
|
98
|
+
friends.each { |friend|
|
99
|
+
user.send_friend_request_to(friend)
|
100
|
+
friend.send_friend_request_to(user)
|
101
|
+
}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
82
105
|
def self.init_output(app_name, file)
|
83
106
|
output = "sacrificed_#{app_name}_#{file}"
|
84
107
|
File.open(output, 'a').close
|
data/lib/sacrifice/users.rb
CHANGED
@@ -52,8 +52,8 @@ class Users < Thor
|
|
52
52
|
|
53
53
|
desc 'friend', 'Make two of an app\'s users friends'
|
54
54
|
method_option 'app', :aliases => %w[-a], :type => :string, :required => true, :banner => 'Name of the app'
|
55
|
-
method_option 'user1', :aliases => %w[-1
|
56
|
-
method_option 'user2', :aliases => %w[-2
|
55
|
+
method_option 'user1', :aliases => %w[-1], :type => :string, :required => true, :banner => 'First user ID'
|
56
|
+
method_option 'user2', :aliases => %w[-2], :type => :string, :required => true, :banner => 'Second user ID'
|
57
57
|
|
58
58
|
def friend
|
59
59
|
users = App.find!(options[:app]).users
|
@@ -64,7 +64,7 @@ class Users < Thor
|
|
64
64
|
}
|
65
65
|
|
66
66
|
# The first request is just a request, the second request accepts the first request.
|
67
|
-
friends.each_index { |idx| friends[idx].send_friend_request_to[(idx + 1) % 2] }
|
67
|
+
friends.each_index { |idx| friends[idx].send_friend_request_to(friends[(idx + 1) % 2]) }
|
68
68
|
end
|
69
69
|
|
70
70
|
desc 'change', 'Change a test user\'s name and/or password'
|
@@ -145,9 +145,10 @@ class Users < Thor
|
|
145
145
|
desc 'generate', 'Generate facebook test users'
|
146
146
|
method_option 'app', aliases: %w[-a], type: :string, banner: 'app name that test user generate on' #, required: true
|
147
147
|
method_option 'file', aliases: %w[-f], type: :string, banner: 'csv file to read (required in type csv)', required: true
|
148
|
+
method_option 'friends', type: :string, banner: 'csv file that include friend ids for generated users(required in type csv)'
|
148
149
|
|
149
150
|
def generate
|
150
|
-
Csv.generate options[:app], options[:file]
|
151
|
+
Csv.generate options[:app], options[:file], options[:friends]
|
151
152
|
end
|
152
153
|
|
153
154
|
desc 'erase', 'Erase facebook test users'
|
@@ -157,4 +158,16 @@ class Users < Thor
|
|
157
158
|
def erase
|
158
159
|
Csv.erase options[:app], options[:file]
|
159
160
|
end
|
161
|
+
|
162
|
+
|
163
|
+
desc 'friends', 'Make friends for user'
|
164
|
+
method_option 'app', :aliases => %w[-a], :type => :string, :required => true, :banner => 'Name of the app'
|
165
|
+
method_option 'user', :aliases => %w[-u], :type => :string, :required => true, :banner => 'User ID'
|
166
|
+
method_option 'friends', :aliases => %w[-f], :type => :string, :required => true, :banner => 'Csv file lists friends IDs'
|
167
|
+
|
168
|
+
def friends
|
169
|
+
app = App.find!(options[:app])
|
170
|
+
user = app.find_user(options[:user])
|
171
|
+
Csv.friends user, Csv.ids(app, options[:friends])
|
172
|
+
end
|
160
173
|
end
|
data/lib/sacrifice/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sacrifice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- toiroakr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|