Class: Foxynews::PressroomSetter

Inherits:
Object
  • Object
show all
Defined in:
app/services/foxynews/pressroom_setter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = [], paging = []) ⇒ PressroomSetter

Returns a new instance of PressroomSetter.



4
5
6
7
# File 'app/services/foxynews/pressroom_setter.rb', line 4

def initialize(data = [], paging = [])
  @data = data
  @paging = paging
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



2
3
4
# File 'app/services/foxynews/pressroom_setter.rb', line 2

def data
  @data
end

#pagingObject

Returns the value of attribute paging.



2
3
4
# File 'app/services/foxynews/pressroom_setter.rb', line 2

def paging
  @paging
end

Class Method Details

.pressroomObject

maps to /v1/pressrooms/:id.json



28
29
30
31
32
33
34
35
36
37
# File 'app/services/foxynews/pressroom_setter.rb', line 28

def pressroom
  begin
    pressroom = Foxynews::Parser.data('.json')
  rescue StandardError => error
    raise GenericError(error.message)
  end

  return (pressroom.has_key?('data')) ? Foxynews::Pressroom.new(pressroom['data']) : false

end

.search(query, locale = nil) ⇒ Object

maps to /v1/pressrooms/:id/search.json



70
71
# File 'app/services/foxynews/pressroom_setter.rb', line 70

def search(query, locale = nil)
end

.timeline(pagination_options = {}) ⇒ Object

maps to /v1/pressrooms/:id/timeline.json



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/services/foxynews/pressroom_setter.rb', line 40

def timeline(pagination_options = {})
  options = {query: pagination_options}


  begin
    timeline = Foxynews::Parser.data('/timeline.json', options)
  rescue StandardError => error
    raise GenericError(error.message)
  end

  if timeline.has_key?('data')
    grouped_by_month = timeline['data'].group_by { |t| Date.parse(t['release_date']).strftime('%B %Y') }

    grouped_by_month.each do |month, content|
      content.map! do |i|
        if i['type'] == 'clipping'
          Foxynews::Clipping.new(i)
        else
          Foxynews::PressRelease.new(i)
        end
      end
    end

    return Foxynews::PressroomSetter.new(grouped_by_month, Foxynews::Paging.new(timeline['paging']))
  else
    return false
  end
end

Instance Method Details

#filter_timeline_by_language!(language) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/services/foxynews/pressroom_setter.rb', line 10

def filter_timeline_by_language!(language)
  data.each_with_object(localized = {}) do |month|
    month.last.each do |item|
      if item.language.include? language
        if localized.has_key? month.first
          localized[month.first] << item
        else
          localized[month.first] = [item]
        end
      end
    end
  end

  self.data = localized
end