Class: Infreemation::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/infreemation/request.rb

Overview

This class represents a FOI or EIR request

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) {|_self| ... } ⇒ Request

Returns a new instance of Request.

Yields:

  • (_self)

Yield Parameters:



26
27
28
29
# File 'lib/infreemation/request.rb', line 26

def initialize(attributes = {})
  @attributes = attributes
  yield self if block_given?
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



24
25
26
# File 'lib/infreemation/request.rb', line 24

def attributes
  @attributes
end

Class Method Details

.create!(attributes = {}) ⇒ Object



13
14
15
# File 'lib/infreemation/request.rb', line 13

def create!(attributes = {})
  new(attributes, &:save!)
end

.pathObject



9
10
11
# File 'lib/infreemation/request.rb', line 9

def path
  '/foi/'
end

.where(options = {}) ⇒ Object



17
18
19
20
21
# File 'lib/infreemation/request.rb', line 17

def where(options = {})
  type = options.fetch(:rt).downcase.to_sym
  requests_data = API.get(path, options).dig(type, :request) || []
  requests_data.map { |attributes| new(attributes) }
end

Instance Method Details

#save!Object



31
32
33
34
# File 'lib/infreemation/request.rb', line 31

def save!
  @attributes.merge!(API.post(self.class.path, attributes))
  true
end