Class: Foxynews::PressReleaseSetter

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}, paging = {}) ⇒ PressReleaseSetter

Returns a new instance of PressReleaseSetter.



4
5
6
7
# File 'app/services/foxynews/press_release_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/press_release_setter.rb', line 2

def data
  @data
end

#pagingObject

Returns the value of attribute paging.



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

def paging
  @paging
end

Class Method Details

.all(includes = nil, order = nil, locales = nil) ⇒ Object

maps to /v1/pressrooms/:pressroom_id/press_releases.json Note: all parameters must be strings



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/foxynews/press_release_setter.rb', line 12

def all(includes = nil, order = nil, locales = nil)
  options = {query: {includes: includes, order: order, locales: locales}}


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

  if press_releases.has_key?('data')
    return Foxynews::PressReleaseSetter.new(
      press_releases['data'].each_with_object(data = []) {|pr| data << Foxynews::PressRelease.new(pr) },
      Foxynews::Paging.new(press_releases['paging'])
    )
  else
    return false
  end
end

.find(id, includes = nil) ⇒ Object

maps to /v1/pressrooms/:pressroom_id/press_releases/:id.json



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/services/foxynews/press_release_setter.rb', line 33

def find(id, includes = nil)
  options = {query: {includes: includes}}

  begin
    press_release = Foxynews::Parser.data("/press_releases/#{id}.json", options)
  rescue StandardError => error
    raise GenericError(error.message)
  end

  if press_release.has_key?('data')
    # return the hash in open struct to allow for @press_release.body_html calls
    return Foxynews::PressRelease.new(press_release['data'])
  else
    return false
  end
end