Class: Foxynews::PresskitSetter

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, paging) ⇒ PresskitSetter

Returns a new instance of PresskitSetter.



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

def data
  @data
end

#pagingObject

Returns the value of attribute paging.



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

def paging
  @paging
end

Class Method Details

.all(pagination_options = {}) ⇒ Object

maps to /v1/pressrooms/:pressroom_id/presskits.json pagination options take page and limit parameters



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

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

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

  if presskits.has_key?('data')
    return Foxynews::PresskitSetter.new(
      presskits['data'].each_with_object(data = []) {|pk| data << Foxynews::Presskit.new(pk) },
      Foxynews::Paging.new(presskits['paging'])
    )
  else
    return false
  end
end

.find(id) ⇒ Object

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



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/services/foxynews/presskit_setter.rb', line 32

def find(id)
  begin
    presskit = Foxynews::Parser.data("/presskits/#{id}.json")
  rescue StandardError => error
    raise GenericError(error.message)
  end

  if presskit.has_key?('data')
    return Foxynews::Presskit.new(presskit['data'])
  else
    return false
  end
end