Class: FbPageApi::Edge::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fb_page_api/edge/base.rb

Direct Known Subclasses

AdminLabel, AdminNote, Conversation, LabelUser, Message, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = { parent_id: Config.page_id, page_access_token: Config.page_access_token }) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
# File 'lib/fb_page_api/edge/base.rb', line 6

def initialize(options = { parent_id: Config.page_id, page_access_token: Config.page_access_token })
  self.page_access_token = options[:page_access_token]
  self.parent_id = options[:parent_id]
  self.custom_request_fields = options[:custom_request_fields] || []
end

Instance Attribute Details

#custom_request_fieldsObject

Returns the value of attribute custom_request_fields.



4
5
6
# File 'lib/fb_page_api/edge/base.rb', line 4

def custom_request_fields
  @custom_request_fields
end

#next_urlObject

Returns the value of attribute next_url.



4
5
6
# File 'lib/fb_page_api/edge/base.rb', line 4

def next_url
  @next_url
end

#page_access_tokenObject

Returns the value of attribute page_access_token.



4
5
6
# File 'lib/fb_page_api/edge/base.rb', line 4

def page_access_token
  @page_access_token
end

#page_afterObject

Returns the value of attribute page_after.



4
5
6
# File 'lib/fb_page_api/edge/base.rb', line 4

def page_after
  @page_after
end

#page_beforeObject

Returns the value of attribute page_before.



4
5
6
# File 'lib/fb_page_api/edge/base.rb', line 4

def page_before
  @page_before
end

#page_idObject

Returns the value of attribute page_id.



4
5
6
# File 'lib/fb_page_api/edge/base.rb', line 4

def page_id
  @page_id
end

#parent_idObject

Returns the value of attribute parent_id.



4
5
6
# File 'lib/fb_page_api/edge/base.rb', line 4

def parent_id
  @parent_id
end

Instance Method Details

#collection(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/fb_page_api/edge/base.rb', line 12

def collection(*args)
  options = args.extract_options!
  @collection = []
  begin
    rs = http_request(:get, self.next_url || api_endpoint, query: body_params(options))
    data = rs.parsed_response['data']
    if data.present?
      @collection = @collection | data
      if rs.parsed_response['paging'].present?
        if rs.parsed_response['paging']['cursors'].present?
          self.page_after = rs.parsed_response['paging']['cursors']['after']
          self.next_url = nil
        elsif rs.parsed_response['paging']['next'].present?
          self.next_url = rs.parsed_response['paging']['next']
          self.page_after = nil
        else
          data = []
        end
      else
        data = []
      end
    end
  end while data.present?
  @collection
end

#create(*args) ⇒ Object



46
47
48
49
# File 'lib/fb_page_api/edge/base.rb', line 46

def create(*args)
  options = args.extract_options!
  http_request(:post, api_endpoint, query: body_params(options)).parsed_response
end

#delete(object_id) ⇒ Object



42
43
44
# File 'lib/fb_page_api/edge/base.rb', line 42

def delete(object_id)
  http_request(:delete, object_api_endpoint(object_id), query: body_params).parsed_response
end

#get(object_id) ⇒ Object



38
39
40
# File 'lib/fb_page_api/edge/base.rb', line 38

def get(object_id)
  http_request(:get, object_api_endpoint(object_id), query: body_params).parsed_response
end