Sha256: 1be30d54d9a65ff7ac7571ee3aa58cbd0fddd85dc69046e248e775478362efc7

Contents?: true

Size: 738 Bytes

Versions: 6

Compression:

Stored size: 738 Bytes

Contents

# frozen_string_literal: true

module Infreemation
  ##
  # This class represents a FOI or EIR request
  #
  class Request
    class << self
      def path
        '/foi/'
      end

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

      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
    end

    attr_reader :attributes

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
infreemation-0.2.4 lib/infreemation/request.rb
infreemation-0.2.3 lib/infreemation/request.rb
infreemation-0.2.2 lib/infreemation/request.rb
infreemation-0.2.1 lib/infreemation/request.rb
infreemation-0.2.0 lib/infreemation/request.rb
infreemation-0.1.0 lib/infreemation/request.rb