Class: TheCity::ApiReader

Inherits:
Object
  • Object
show all
Defined in:
lib/readers/api_reader.rb

Overview

This adapter is the standard for all loading objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/readers/api_reader.rb', line 5

def headers
  @headers
end

Instance Method Details

#load_feedObject

Loads the list

Returns:

  • the data loaded in a JSON object.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/readers/api_reader.rb', line 14

def load_feed
  # if [email protected]? and [email protected]_cache_expired?( @class_key )
  #   data = @cacher.get_data( @class_key )
  # else
    @url_data_params ||= {}
    @url_data_params = stringify_array_params(@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

#rate_limitObject

Returns either the value of the x-city-ratelimit-limit-by-ip header or x-city-ratelimit-limit-by-account header, whichever is lower.



31
32
33
34
35
# File 'lib/readers/api_reader.rb', line 31

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

#rate_limit_remainingObject

Returns either the value of the x-city-ratelimit-remaining-by-ip header or x-city-ratelimit-remaining-by-account header, whichever is lower.



39
40
41
42
43
# File 'lib/readers/api_reader.rb', line 39

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