Sha256: cb8e28318dd4b231f6c968ae5938e706e2db45bcd75c8ac0c2f6a25b45e1410b

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Immobilienscout
  module API
    class Report
      class << self
        def retrieve(is24_id, date_from, date_to)
          raise ArgumentError unless is24_id.present? && date_from.present? && date_to.present?

          query_params = query_params(date_from, date_to)
          url = retrieve_url(is24_id)

          execute_get_request(url, query_params)
        end

        private

        def execute_get_request(url, query_params)
          parsed_response = Immobilienscout::Request.new(url, query_params).get
          raise Immobilienscout::Errors::InvalidRequest, parsed_response.messages.map(&:messages) unless parsed_response.success?

          parsed_response
        end

        def query_params(date_from, date_to)
          {
            dateFrom: date_from.to_s,
            dateTo: date_to.to_s
          }
        end

        def retrieve_url(is24_id)
          "#{Immobilienscout::Client.api_url}/restapi/api/offer/v1.0/user/me/realestate/#{is24_id}/dailyreport"
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
immobilienscout-0.0.2 lib/immobilienscout/api/report.rb
immobilienscout-0.0.1 lib/immobilienscout/api/report.rb