Class: FacebookTestUsers::CLI::Apps

Inherits:
Base
  • Object
show all
Defined in:
lib/facebook_test_users/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#bad_request_message, #find_app!, #handle_bad_request

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


39
# File 'lib/facebook_test_users/cli.rb', line 39

def self.exit_on_failure?() true end

Instance Method Details

#add_userObject



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/facebook_test_users/cli.rb', line 73

def add_user
  to_app   = find_app!(options[:to_app])
  from_app = find_app!(options[:from_app])
  add_user_options = options.select do |k, v|
    %w[installed permissions].include? k.to_s
  end
  add_user_options[:uid] = options[:user]
  add_user_options[:owner_access_token] = from_app.access_token
  handle_bad_request do
    result = to_app.add_user(add_user_options)
    puts "User #{result.id} added to app '#{options[:to_app]}'"
  end
end

#listObject



56
57
58
59
60
# File 'lib/facebook_test_users/cli.rb', line 56

def list
  App.all.each do |app|
    puts "#{app.name} (id: #{app.id})"
  end
end

#registerObject



50
51
52
53
# File 'lib/facebook_test_users/cli.rb', line 50

def register
  FacebookTestUsers::App.create!(:name => options[:name], :id => options[:app_id], :secret => options[:app_secret])
  list
end

#rm_userObject



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/facebook_test_users/cli.rb', line 92

def rm_user
  app  = find_app!(options[:app])
  result = handle_bad_request do
    app.rm_user(options[:user])
  end
  if result
    puts "User #{options[:user]} removed from app '#{options[:app]}'"
  else
    puts "User #{options[:user]} not removed from app '#{options[:app]}'"
  end
end