Sha256: f49be25009b577d9225517221d4a3fc7ae8e90de5d47514c38fa2718e84aae86

Contents?: true

Size: 916 Bytes

Versions: 1

Compression:

Stored size: 916 Bytes

Contents

require_relative 'fb_api'
require_relative 'attachment'

module FansWatch 
  # Single posting on group's feed 
  class Posting 
    attr_reader :message, :created_time, :id
    
    def initialize(fb_api, data: nil) 
      @fb_api = fb_api
      load_data(data)
    end

    def attachment 
      return @attachment if @attachment
    
      attached_data = @fb_api.posting_attachments(@id) 
      @attachment = Attachment.new(attached_data)
    end 

    def self.find(fb_api, id:)
      posting_data = fb_api.posting(id)
      new(fb_api, data:posting_data)
    end

    private 

    def load_data(posting_data)
      @id = posting_data['id']
      # @updated_time = posting_data['updated_time'] 
      @created_time = posting_data['created_time'] 
      @message = posting_data['message'] 
      attached = posting_data['attachment'] 
      @attachment = Attachment.new(attached) if attached 
    end
  end 
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fanswatch-0.0.0 lib/fanswatch/posting.rb