Module: AWSCosts::Cache
Constant Summary collapse
- BASE_URI =
"http://aws.amazon.com"
- BASE_JSONP_URI =
"http://a0.awsstatic.com"
Instance Method Summary collapse
- #get(uri, base_uri = BASE_URI) {|| ... } ⇒ Object
- #get_jsonp(uri, base_uri = BASE_JSONP_URI) {|| ... } ⇒ Object
Instance Method Details
#get(uri, base_uri = BASE_URI) {|| ... } ⇒ Object
10 11 12 13 |
# File 'lib/awscosts/cache.rb', line 10 def get uri, base_uri = BASE_URI, &block cache["#{base_uri}#{uri}"] ||= Oj::load(HTTParty.get("#{base_uri}#{uri}").body) yield cache["#{base_uri}#{uri}"] end |
#get_jsonp(uri, base_uri = BASE_JSONP_URI) {|| ... } ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/awscosts/cache.rb', line 15 def get_jsonp uri, base_uri = BASE_JSONP_URI, &block attempts = 0 cache["#{base_uri}#{uri}"] ||= begin extract_json_from_callback(HTTParty.get("#{base_uri}#{uri}").body) rescue NoMethodError attempts += 1 retry if attempts < 5 raise "Failed to retrieve or parse data for #{base_uri}#{uri}" end yield cache["#{base_uri}#{uri}"] end |