Class: Users
- Inherits:
-
Thor
- Object
- Thor
- Users
- Defined in:
- lib/sacrifice/users.rb
Class Method Summary collapse
Instance Method Summary collapse
- #change ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #erase ⇒ Object
- #friend ⇒ Object
- #friends ⇒ Object
- #generate ⇒ Object
- #list ⇒ Object
- #rm ⇒ Object
Class Method Details
.exit_on_failure? ⇒ Boolean
9 10 11 |
# File 'lib/sacrifice/users.rb', line 9 def self.exit_on_failure?() true end |
Instance Method Details
#change ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/sacrifice/users.rb', line 80 def change user = App.find!([:app]).find_user([:user]) puts user if user success = user.change() if success puts 'Successfully changed user' else puts 'Failed to change user' end else raise Thor::Error, "Unknown user '#{[:user]}'" end end |
#create ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sacrifice/users.rb', line 40 def create app = App.find!([:app]) attrs = .select { |k, v| %w(name installed locale).include? k.to_s } user = app.create_user(attrs) if user puts "User ID: #{user.id}" puts "Access Token: #{user.access_token}" puts "Login URL: #{user.login_url}" puts "Email: #{user.email}" puts "Password: #{user.password}" end end |
#destroy ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/sacrifice/users.rb', line 135 def destroy app = App.find!([:app]) while (users = app.users).size > 0 users.each { |user| user.destroy puts "remove user ##{user.id}" } end end |
#erase ⇒ Object
158 159 160 |
# File 'lib/sacrifice/users.rb', line 158 def erase Csv.erase [:app], [:file] end |
#friend ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sacrifice/users.rb', line 58 def friend users = App.find!([:app]).users friends = [] [[:user1], [:user2]].each { |user| friends.push (users.find { |u| u.id.to_s == user } or raise Thor::Error, "No user found w/id #{user.inspect}") } # The first request is just a request, the second request accepts the first request. friends.each_index { |idx| friends[idx].send_friend_request_to(friends[(idx + 1) % 2]) } end |
#friends ⇒ Object
168 169 170 171 172 |
# File 'lib/sacrifice/users.rb', line 168 def friends app = App.find!([:app]) user = app.find_user([:user]) Csv.friends user, Csv.ids(app, [:friends]) end |
#generate ⇒ Object
150 151 152 |
# File 'lib/sacrifice/users.rb', line 150 def generate Csv.generate [:app], [:file], [:friends] end |
#list ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sacrifice/users.rb', line 16 def list app = App.find!([:app]) if app.users.any? shell.print_table([ ['User ID', 'Access Token', 'Login URL'], *(app.users.map do |user| [user.id, user.access_token, user.login_url] end) ]) else puts "App #{app.name} has no users." end end |
#rm ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/sacrifice/users.rb', line 101 def rm user = App.find!([:app]).find_user([:user]) if user result = user.destroy if result puts "User ID #{user.id} removed" else if @message.match /(\(#2903\) Cannot delete this test account because it is associated with other applications.)/ error = <<-EOMSG.unindent.gsub(/^\|/, '') #$1 Run: | sacrifice users list-apps --app #{[:app]} --user #{user.id} | then for each of the other apps, run: | sacrifice apps rm-user --app APP-NAME --user #{user.id} | Then re-run this command. EOMSG else error = @message end raise Thor::Error, error end else raise Thor::Error, "Unknown user '#{[:user]}'" end end |