lib/fanswatch/page.rb in fanswatch-0.0.0 vs lib/fanswatch/page.rb in fanswatch-0.1.0

- old
+ new

@@ -1,32 +1,23 @@ +# frozen_string_literal: true require_relative 'fb_api' require_relative 'posting' module FansWatch # Main class to setup a Facebook group class Page - attr_reader :name + attr_reader :name, :id, :feed - def initialize(fb_api, data:) - @fb_api = fb_api - @name = data['name'] - @id = data['id'] + def initialize(page_data:) + @name = page_data['name'] + @id = page_data['id'] + @feed = Feed.new(feed_data: @id) + end - - def feed - return @feed if @feed - raw_feed = @fb_api.page_feed(@id) - @feed = raw_feed.map do |posting| - FansWatch::Posting.new( - @fb_api, - data: posting - ) - end - end - def self.find(fb_api, id:) - page_data = fb_api.page_info(id) - new(fb_api, data: page_data) + def self.find(id:) + page_data = FbApi.page_info(id) + page_data.include?('error') ? nil : new(page_data: page_data) end end end