Module: FacebookTestUsers::CLI::Utils

Included in:
Base
Defined in:
lib/facebook_test_users/cli.rb

Instance Method Summary collapse

Instance Method Details

#bad_request_message(bad_request) ⇒ Object



16
17
18
19
20
# File 'lib/facebook_test_users/cli.rb', line 16

def bad_request_message(bad_request)
  response = bad_request.response
  json = MultiJson.decode(response)
  json['error']['message'] rescue json.inspect
end

#find_app!(name) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/facebook_test_users/cli.rb', line 8

def find_app!(name)
  app = App.find_by_name(name)
  unless app
    raise Thor::Error, "Unknown app #{name}. Run 'fbtu apps' to see known apps."
  end
  app
end

#handle_bad_request(raise_error = true) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/facebook_test_users/cli.rb', line 22

def handle_bad_request(raise_error=true)
  begin
    yield
  rescue RestClient::BadRequest => bad_request
    @message = bad_request_message(bad_request)
    raise Thor::Error, "#{bad_request.class}: #@message" if raise_error
    nil
  end
end