Class: AWSCosts::S3DataTransfer

Inherits:
Object
  • Object
show all
Defined in:
lib/awscosts/s3_data_transfer.rb

Constant Summary collapse

TYPES =
%w{dataXferInS3, dataXferOutS3CrossRegion, dataXferOutS3}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ S3DataTransfer

Returns a new instance of S3DataTransfer.



7
8
9
# File 'lib/awscosts/s3_data_transfer.rb', line 7

def initialize data
  @data = data
end

Class Method Details

.fetch(region) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/awscosts/s3_data_transfer.rb', line 15

def self.fetch region
  transformed = AWSCosts::Cache.get_jsonp("/pricing/1/s3/pricing-data-transfer-s3.min.js") do |data|
    result = {}
    data['config']['regions'].each do |r|
      types = {}
      r['types'].each do |type|
        types[type['name']] = {}
        type['tiers'].each do |tier|
          # Don't return 0.0 for "contactus" since that is misleading
          types[type['name']][tier['name']] = tier['prices']['USD'] == 'contactus' ? nil : tier['prices']['USD'].to_f
        end
      end
      result[r['region']] = types
    end
    result
  end
  self.new(transformed[region])
end

Instance Method Details

#price(type = nil) ⇒ Object



11
12
13
# File 'lib/awscosts/s3_data_transfer.rb', line 11

def price type = nil
  type.nil? ? @data : @data[type.to_s]
end