Class: AwsIp::Range

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

Constant Summary collapse

BASE_URI =
'https://ip-ranges.amazonaws.com/ip-ranges.json'

Instance Method Summary collapse

Constructor Details

#initializeRange

Returns a new instance of Range.



9
10
11
12
# File 'lib/aws_ip/range.rb', line 9

def initialize
  @uri = URI.parse(BASE_URI)
  @proxy = @uri.find_proxy
end

Instance Method Details

#getObject



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

def get
  connection = if @proxy
    Net::HTTP::Proxy(@proxy.host, @proxy.port, @proxy.user, @proxy.password).new(@uri.host, @uri.port)
  else
    Net::HTTP.new(@uri.host, @uri.port)
  end
  connection.use_ssl = true
  response = connection.start { |http| http.get(@uri) }
  case response
  when Net::HTTPSuccess
    json = response.body
    JSON.parse(json)
  else
    # raise excpetion
    response.value
  end
rescue => e
  puts e.stacktrace if ENV['DEBUG']
  abort [e.message, @uri].join(' : ')
end