Sha256: debeadd79be1de7adff3bb18bc26c0b7f262582d59758acf107b3bb6ac7bd7d5

Contents?: true

Size: 986 Bytes

Versions: 4

Compression:

Stored size: 986 Bytes

Contents

require 'poms/api/request'
require 'timeout'

module Poms
  # Methods for working with the merged series api from NPO.
  module MergedSeries
    extend self

    TEST_URL = 'https://rs-test.poms.omroep.nl/v1/api/media/redirects/'.freeze
    PRODUCTION_URL = 'https://rs.poms.omroep.nl/v1/api/media/redirects/'.freeze

    # Gets the merged serie mids as a hash. Expects a JSON response from
    # the server with a `map` key.
    # Throws a PomsError if the call timeouts, has an HTTP error or JSON parse
    # error.
    #
    # @param api_url the API url to query
    # @return [Hash] a hash with old_mid => new_mid pairs
    def serie_mids(api_url = PRODUCTION_URL, key = '', secret = '', origin = '')
      Timeout.timeout(3) do
        data = Poms::Api::Request.new(api_url, key, secret, origin).call.read
        JSON.parse(data).fetch('map')
      end
    rescue OpenURI::HTTPError, JSON::ParserError, Timeout::Error => e
      raise Poms::PomsError, e.message
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
poms-1.2.2 lib/poms/merged_series.rb
poms-1.2.1 lib/poms/merged_series.rb
poms-1.2.0 lib/poms/merged_series.rb
poms-1.1.0 lib/poms/merged_series.rb