Class: SocialNet::Facebook::Models::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/social_net/facebook/models/page.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Page

Returns a new instance of Page.



10
11
12
13
# File 'lib/social_net/facebook/models/page.rb', line 10

def initialize(attrs = {})
  @username = attrs['username']
  @likes = attrs['likes']
end

Instance Attribute Details

#likesObject (readonly)

Returns the value of attribute likes.



8
9
10
# File 'lib/social_net/facebook/models/page.rb', line 8

def likes
  @likes
end

#usernameObject (readonly)

Returns the value of attribute username.



8
9
10
# File 'lib/social_net/facebook/models/page.rb', line 8

def username
  @username
end

Class Method Details

.find_by(params = {}) ⇒ SocialNet::Facebook::Models::Page

Returns the existing Facebook page matching the provided attributes or nil when the page is not found.

@ return [nil] when the page cannot be found.

Parameters:

  • params (Hash) (defaults to: {})

    the attributes to find a page by.

Options Hash (params):

  • :username (String)

    The Facebook page’s username (case-insensitive).

Returns:



24
25
26
27
28
# File 'lib/social_net/facebook/models/page.rb', line 24

def self.find_by(params = {})
  find_by! params
rescue Errors::UnknownUser
  nil
end

.find_by!(params = {}) ⇒ SocialNet::Facebook::Models::Page

Returns the existing Facebook page matching the provided attributes or raises an error when the page is not found.

Parameters:

  • params (Hash) (defaults to: {})

    the attributes to find a page by.

Options Hash (params):

  • :username (String)

    The Facebook page’s username (case-insensitive).

Returns:

Raises:

  • (SocialNet::Errors::UnknownUser)

    if the page cannot be found.



38
39
40
41
42
43
44
45
# File 'lib/social_net/facebook/models/page.rb', line 38

def self.find_by!(params = {})
  request = Api::Request.new params
  new request.run
rescue Errors::ResponseError => error
  case error.response
    when Net::HTTPNotFound then raise Errors::UnknownUser
  end
end