Class: FacebookTestAccounts::AccountCreator
- Inherits:
-
Object
- Object
- FacebookTestAccounts::AccountCreator
- Includes:
- HTTParty
- Defined in:
- lib/facebook_test_accounts/account_creator.rb
Instance Method Summary collapse
- #create_account ⇒ Object
- #create_test_account(access_token) ⇒ Object
- #fetch_access_token ⇒ Object
-
#initialize(options = { }) ⇒ AccountCreator
constructor
A new instance of AccountCreator.
- #print_account_info(response) ⇒ Object
Constructor Details
#initialize(options = { }) ⇒ AccountCreator
Returns a new instance of AccountCreator.
7 8 9 10 11 12 |
# File 'lib/facebook_test_accounts/account_creator.rb', line 7 def initialize( = { }) @app_id = [:app_id] @secret = [:secret] @installed = [:installed] @permissions = [:permissions] end |
Instance Method Details
#create_account ⇒ Object
14 15 16 |
# File 'lib/facebook_test_accounts/account_creator.rb', line 14 def create_account print_account_info(create_test_account(fetch_access_token)) end |
#create_test_account(access_token) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/facebook_test_accounts/account_creator.rb', line 40 def create_test_account(access_token) response = self.class.get( "/#{@app_id}/accounts/test-users", :query => { :installed => @installed, :permissions => @permissions, :method => "post", :access_token => access_token } ) unless response.code == 200 FacebookTestAccounts.die("unable to create test account: #{response['error']['message']}") end return response end |
#fetch_access_token ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/facebook_test_accounts/account_creator.rb', line 18 def fetch_access_token response = self.class.get( "/oauth/access_token", :query => { :client_id => @app_id, :client_secret => @secret, :grant_type => "client_credentials" } ) if response.code != 200 FacebookTestAccounts.die("unable to fetch access token: #{response['error']['message']}") end unless match = response.match(/^access_token\=(.+)$/) FacebookTestAccounts.die("unable to fetch access token: token not present in response.") end return match[1] end |
#print_account_info(response) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/facebook_test_accounts/account_creator.rb', line 58 def print_account_info(response) info = "" info << "" + "\n" info << " id:\t#{response['id']}" + "\n" info << "login_url:\t#{response['login_url']}" + "\n" info << " email:\t#{response['email']}" + "\n" info << " password:\t#{response['password']}" + "\n" info << "" + "\n" $stdout.puts(info) end |