Class: Awsprice::Info

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

Direct Known Subclasses

EC2

Constant Summary collapse

@@REGIONS =
{
  'us-east-1' => 'us-east',
  'us-west-1' => 'us-west',
  'us-west-2' => 'us-west-2',
  'eu-west-1' => 'eu-ireland',
  'ap-southeast-1' => 'apac-sin',
  'ap-southeast-2' => 'apac-syd',
  'ap-northeast-1' => 'apac-tokyo',
  'sa-east-1' => 'sa-east-1'
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeInfo

Returns a new instance of Info.



22
23
24
25
26
# File 'lib/awsprice.rb', line 22

def initialize
  # @store = PStore.new %(#{ENV['HOME']}/awsprice.pstore)

  # @store[:regions] = []
end

Class Method Details

.fetch_url(url) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/awsprice.rb', line 28

def self.fetch_url url
  uri = URI.parse(url)
  page = Net::HTTP.get_response(uri)

  body = page.body.gsub("callback(", "").reverse.sub(")", "").reverse
  if body.split("\n").last == ";"

    body = body.reverse.sub(";", "").reverse
  elsif body[-1] == ";"
    body.chop!
  end

  begin
    JSON.parse(body)
  rescue JSON::ParserError
    JSON.parse(body.gsub(/(\w+)\s*:/, '"\1":'))
  end
end