lib/fanswatch/posting.rb in fanswatch-0.0.0 vs lib/fanswatch/posting.rb in fanswatch-0.1.0
- old
+ new
@@ -1,37 +1,36 @@
+# frozen_string_literal: true
require_relative 'fb_api'
require_relative 'attachment'
module FansWatch
# Single posting on group's feed
class Posting
- attr_reader :message, :created_time, :id
+ attr_reader :message, :created_time, :id, :attachment
- def initialize(fb_api, data: nil)
- @fb_api = fb_api
+ def initialize(data: nil)
load_data(data)
end
def attachment
return @attachment if @attachment
- attached_data = @fb_api.posting_attachments(@id)
- @attachment = Attachment.new(attached_data)
+ attached_data = FbApi.posting_attachments(@id)
end
- def self.find(fb_api, id:)
- posting_data = fb_api.posting(id)
- new(fb_api, data:posting_data)
+ def self.find(id:)
+ posting_data = FbApi.posting(id)
+ new(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']
+ @message = posting_data['message']
+
+ attached = attachment
@attachment = Attachment.new(attached) if attached
end
end
end