class SslLabs

Constants

POLL_SLEEP

Seconds to delay between analysis polls.

USER_AGENT

User agent for client.

VERSION

Gem version.

Attributes

agent[RW]
uri[RW]

Public Class Methods

new(uri=nil) click to toggle source
# File lib/ssl_labs.rb, line 21
def initialize(uri=nil)
  @uri = URI(uri) unless uri.nil?
  @agent = Mechanize.new
  @agent.user_agent = USER_AGENT
end

Public Instance Methods

analyze(opts={}) click to toggle source

Run the analyze method and return immediately with Host response from the server. Do not wait for analysis to complete.

# File lib/ssl_labs.rb, line 29
def analyze(opts={})
  defaults = {:host => uri.host}
  opts_a = opts.flat_map do |k, v|
    case k
    when :publish, :clear_cache, :from_cache
      [k, v ? :on : :off]
    when :all
      case v
      when true
        [k, :on]
      when :done
        [k, v]
      else
        raise ArgumentError, "Invalid value #{v.inspect} for option #{k.inspect}"
      end
    else
      raise ArgumentError, "Invalid option #{k.inspect}"
    end
  end
  json = invoke(:analyze, defaults.merge(Hash[*opts_a]))
  Host.from_json(json)
end
analyze!() click to toggle source

Clears the cache and blocks until analyze returns results. Returns an Array of SslLabs::EndpointData.

# File lib/ssl_labs.rb, line 54
def analyze!
  host = analyze(:clear_cache => true)
  loop do
    sleep(POLL_SLEEP)
    host = analyze
    break if %w{READY ERROR}.include?(host.status)
  end
  host.endpoints.map { |ep| endpoint_data(ep) }
end
endpoint_data(ep, from_cache=false) click to toggle source

Return EndpointData from an EndPoint.

# File lib/ssl_labs.rb, line 65
def endpoint_data(ep, from_cache=false)
  body = invoke(:get_endpoint_data,
                :host => uri.host,
                :s => ep.ip_address,
                :from_cache => from_cache ? :on : :off)
  EndpointData.from_json(body)
end
info() click to toggle source

Return an Info object.

# File lib/ssl_labs.rb, line 74
def info
  body = invoke(:info)
  Info.from_json(body)
end
invoke(method, args={}) click to toggle source

Return the Mechanize::Page body for the given method and arguments.

# File lib/ssl_labs.rb, line 87
def invoke(method, args={})
  url = Api.url(method, args)
  @agent.get(url).body
end
status_codes() click to toggle source

Return a Hash of status codes (String => String).

# File lib/ssl_labs.rb, line 80
def status_codes
  body = invoke(:get_status_codes)
  json = JSON.parse(body)
  json['statusDetails']
end