Sha256: e492d3ab8fd9eb0911e4837f9f454c086994e5bba7902c24a6077d4adc64b41b

Contents?: true

Size: 1.32 KB

Versions: 15

Compression:

Stored size: 1.32 KB

Contents

module TheCity

  # This adapter is the standard for all loading objects.
  class ApiReader
    attr_reader :headers

    # Constructor
    # def initialize
    # end

    # Loads the list
    #
    # @return the data loaded in a JSON object.
    def load_feed
      # if !@cacher.nil? and !@cacher.is_cache_expired?( @class_key )
      #   data = @cacher.get_data( @class_key )
      # else
        @url_data_params ||= {}
        response = TheCity::admin_request(:get, @url_data_path, @url_data_params)
        data = JSON.parse(response.body)
        @headers = response.headers
        @cacher.save_data(@class_key, data) unless @cacher.nil?
      #end   

      return data
    end

    # Returns either the value of the x-city-ratelimit-limit-by-ip header or
    # x-city-ratelimit-limit-by-account header, whichever is lower.
    def rate_limit
      if @headers
        [@headers['x-city-ratelimit-limit-by-ip'].to_i, @headers['x-city-ratelimit-limit-by-account'].to_i].min
      end
    end

    # Returns either the value of the x-city-ratelimit-remaining-by-ip header or
    # x-city-ratelimit-remaining-by-account header, whichever is lower.
    def rate_limit_remaining
      if @headers
        [@headers['x-city-ratelimit-remaining-by-ip'].to_i, @headers['x-city-ratelimit-remaining-by-account'].to_i].min
      end
    end

  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
the-city-admin-0.7.0 lib/readers/api_reader.rb
the-city-admin-0.6.9 lib/readers/api_reader.rb
the-city-admin-0.6.8 lib/readers/api_reader.rb
the-city-admin-0.6.7 lib/readers/api_reader.rb
the-city-admin-0.6.6 lib/readers/api_reader.rb
the-city-admin-0.6.5 lib/readers/api_reader.rb
the-city-admin-0.6.4 lib/readers/api_reader.rb
the-city-admin-0.6.3 lib/readers/api_reader.rb
the-city-admin-0.6.2 lib/readers/api_reader.rb
the-city-admin-0.6.1 lib/readers/api_reader.rb
the-city-admin-0.6.0 lib/readers/api_reader.rb
the-city-admin-0.5.2 lib/readers/api_reader.rb
the-city-admin-0.5.1 lib/readers/api_reader.rb
the-city-admin-0.5.0 lib/readers/api_reader.rb
the-city-admin-0.4.0 lib/readers/api_reader.rb