Class: FacebookTestUsers::App
- Inherits:
-
Object
- Object
- FacebookTestUsers::App
- Defined in:
- lib/facebook_test_users/app.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
Class Method Summary collapse
-
.all ⇒ Object
query methods.
- .create!(attrs) ⇒ Object
- .find_by_name(name) ⇒ Object
Instance Method Summary collapse
- #access_token ⇒ Object
- #add_user(options) ⇒ Object
- #attrs ⇒ Object
- #create_user(options = {}) ⇒ Object
-
#initialize(attrs) ⇒ App
constructor
A new instance of App.
- #rm_user(uid) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(attrs) ⇒ App
Returns a new instance of App.
8 9 10 11 |
# File 'lib/facebook_test_users/app.rb', line 8 def initialize(attrs) @name, @id, @secret = attrs[:name].to_s, attrs[:id].to_s, attrs[:secret].to_s validate! end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/facebook_test_users/app.rb', line 6 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/facebook_test_users/app.rb', line 6 def name @name end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
6 7 8 |
# File 'lib/facebook_test_users/app.rb', line 6 def secret @secret end |
Class Method Details
.all ⇒ Object
query methods
61 62 63 64 65 66 67 |
# File 'lib/facebook_test_users/app.rb', line 61 def self.all if DB[:apps] DB[:apps].map {|attrs| new(attrs) } else [] end end |
.create!(attrs) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/facebook_test_users/app.rb', line 17 def self.create!(attrs) new_app = new(attrs) if all.find {|app| app.name == new_app.name } raise ArgumentError, "App names must be unique, and there is already an app named \"#{new_app.name}\"." end DB.update do |data| data[:apps] ||= [] data[:apps] << new_app.attrs end end |
.find_by_name(name) ⇒ Object
69 70 71 |
# File 'lib/facebook_test_users/app.rb', line 69 def self.find_by_name(name) all.find {|a| a.name == name} end |
Instance Method Details
#access_token ⇒ Object
73 74 75 |
# File 'lib/facebook_test_users/app.rb', line 73 def access_token @access_token ||= AccessToken.get(id, secret) end |
#add_user(options) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/facebook_test_users/app.rb', line 45 def add_user() raise "add_user called without uid" \ unless .has_key?(:uid) raise "add_user called without owner_access_token" \ unless .has_key?(:owner_access_token) user_data = RestClient.post(users_url, {:access_token => access_token}.merge()) User.new(MultiJson.decode(user_data)) end |
#attrs ⇒ Object
13 14 15 |
# File 'lib/facebook_test_users/app.rb', line 13 def attrs {:name => name, :id => id, :secret => secret} end |
#create_user(options = {}) ⇒ Object
40 41 42 43 |
# File 'lib/facebook_test_users/app.rb', line 40 def create_user( = {}) user_data = RestClient.post(users_url, {:access_token => access_token}.merge()) User.new(MultiJson.decode(user_data)) end |
#rm_user(uid) ⇒ Object
55 56 57 58 |
# File 'lib/facebook_test_users/app.rb', line 55 def rm_user(uid) url = rm_user_url(uid, access_token) RestClient.delete(url) end |