Method: Pushpad::Notification.find_all

Defined in:
lib/pushpad/notification.rb

.find_all(options = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pushpad/notification.rb', line 56

def self.find_all(options = {})
  project_id = options[:project_id] || Pushpad.project_id
  raise "You must set project_id" unless project_id

  query_parameters = {}
  query_parameters[:page] = options[:page] if options.key?(:page)

  response = Request.get("https://pushpad.xyz/api/v1/projects/#{project_id}/notifications",
                         query_parameters: query_parameters)

  unless response.code == "200"
    raise FindError, "Response #{response.code} #{response.message}: #{response.body}"
  end

  JSON.parse(response.body, symbolize_names: true).map do |attributes|
    new(attributes).readonly!
  end
end