Class: Facemock::FbGraph::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/facemock/fb_graph/application.rb,
lib/facemock/fb_graph/application/user.rb,
lib/facemock/fb_graph/application/test_users.rb,
lib/facemock/fb_graph/application/user/permission.rb

Defined Under Namespace

Classes: TestUsers, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, options = {}) ⇒ Application

Returns a new instance of Application.



14
15
16
17
18
19
# File 'lib/facemock/fb_graph/application.rb', line 14

def initialize(identifier, options={})
  opts = Hashie::Mash.new(options)
  @identifier   = identifier
  @secret       = opts.secret
  @access_token = opts.access_token
end

Instance Attribute Details

#access_tokenObject

user access token



12
13
14
# File 'lib/facemock/fb_graph/application.rb', line 12

def access_token
  @access_token
end

#identifierObject

Returns the value of attribute identifier.



10
11
12
# File 'lib/facemock/fb_graph/application.rb', line 10

def identifier
  @identifier
end

#secretObject

Returns the value of attribute secret.



11
12
13
# File 'lib/facemock/fb_graph/application.rb', line 11

def secret
  @secret
end

Instance Method Details

#fetchObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/facemock/fb_graph/application.rb', line 21

def fetch
  @record = if @identifier == :app
    unless validate_access_token
      raise Facemock::FbGraph::InvalidToken.new "Invalid OAuth access token."
    end
    find_by_access_token
  else
    if @access_token && !validate_access_token
      raise Facemock::FbGraph::InvalidToken.new "Invalid OAuth access token."
    elsif !validate_identifier_and_secret
      raise Facemock::FbGraph::InvalidRequest.new "Unsupported get request."
    end
    Facemock::Application.find_by_id(@identifier)
  end

  if @record
    @identifier   = @record.id
    @secret       = @record.secret
    @access_token = nil
  end
  self
end

#test_user!(options = {}) ⇒ Object



44
45
46
47
48
# File 'lib/facemock/fb_graph/application.rb', line 44

def test_user!(options={})
  validate_and_raise_error
  options.merge!({application_id: self.identifier})
  user = User.create!(options)
end

#test_users(options = {}) ⇒ Object



50
51
52
53
# File 'lib/facemock/fb_graph/application.rb', line 50

def test_users(options={})
  validate_and_raise_error
  TestUsers.new(self.identifier, options)
end