Class: FacebookTestAccounts::AccountCreator

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/facebook_test_accounts/account_creator.rb

Instance Method Summary collapse

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(options = { })
  @app_id      = options[:app_id]
  @secret      = options[:secret]
  @installed   = options[:installed]
  @permissions = options[:permissions]
end

Instance Method Details

#create_accountObject



14
15
16
# File 'lib/facebook_test_accounts/account_creator.rb', line 14

def 
  ((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 (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_tokenObject



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


58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/facebook_test_accounts/account_creator.rb', line 58

def (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