class Mynewsdesk
Extension namespace
Public Class Methods
new(app, options_hash = {}, &block)
click to toggle source
Calls superclass method
# File lib/middleman_mynewsdesk/extension.rb, line 14 def initialize(app, options_hash = {}, &block) # Call super to build options from the options_hash super # Require libraries only when activated require "http" require "json" @base_url = "https://www.mynewsdesk.com/services/pressroom/list/#{options.api_key}?format=json&limit=100" end
Public Instance Methods
all_items_for(item)
click to toggle source
# File lib/middleman_mynewsdesk/extension.rb, line 25 def all_items_for(item) items = [] 0.step(2000, 100) do |offset| i = items_for_offset(item, offset) return items if i.nil? # If we have offset 100 and exactly 100 posts, we get nil back items.concat i break if i.length < 100 end items end
items_for_offset(item, offset)
click to toggle source
# File lib/middleman_mynewsdesk/extension.rb, line 36 def items_for_offset(item, offset) JSON.parse(HTTP.get("#{@base_url}&type_of_media=#{item}&offset=#{offset}").to_s, object_class: RecursiveOpenStruct).items.item end
mynewsdesk_items()
click to toggle source
# File lib/middleman_mynewsdesk/extension.rb, line 40 def mynewsdesk_items @items ||= options.types_of_media.map do |item| all_items_for(item) end.flatten.sort { |a, b| Time.parse(b.published_at) <=> Time.parse(a.published_at) } @items end