Sha256: 0b947a830545a2675bf405f92eea50b5d57d920be3bba94c482ea3b406ffe5ce

Contents?: true

Size: 944 Bytes

Versions: 1

Compression:

Stored size: 944 Bytes

Contents

require 'open-uri'
require 'nori'
require 'active_support/time'

module EveOnline
  class Base
    attr_reader :parser

    def initialize
      @parser = Nori.new(advanced_typecasting: false)
    end

    def result
      @result ||= eveapi.fetch('result')
    end

    def cached_until
      @cached_until ||= begin
        ActiveSupport::TimeZone['UTC'].parse(eveapi.fetch('cachedUntil'))
      end
    end

    def current_time
      @current_time ||= begin
        ActiveSupport::TimeZone['UTC'].parse(eveapi.fetch('currentTime'))
      end
    end

    def version
      # TODO: check all API for version
      raise NotImplementedError
    end

    def eveapi
      @eveapi ||= response.fetch('eveapi')
    end

    def url
      raise NotImplementedError
    end

    def content
      @content ||= open(url, open_timeout: 60, read_timeout: 60).read
    end

    def response
      @response ||= parser.parse(content)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eve_online-0.4.0 lib/eve_online/base.rb