Sha256: a6866f5e0335c7172308640e39c650d2040e0263d7b70c948312b24d61a9f3e7

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'json'
require 'memoist'
require 'active_support/time'

module EveOnline
  module ESI
    class Base
      extend Memoist

      attr_reader :token, :parser

      def initialize(options = {})
        @token = options[:token]
        @parser = JSON
      end

      def url
        raise NotImplementedError
      end

      def scope
        raise NotImplementedError
      end

      def user_agent
        "EveOnline API (https://github.com/biow0lf/eve_online) v#{ VERSION }"
      end

      def content
        faraday = Faraday.new

        faraday.headers[:user_agent] = user_agent
        faraday.authorization(:Bearer, token) if token
        faraday.options.timeout = 60
        faraday.options.open_timeout = 60

        faraday.get(url).body
      rescue Faraday::TimeoutError
        raise EveOnline::Exceptions::TimeoutException
      end
      memoize :content

      def response
        parser.parse(content)
      end
      memoize :response

      private

      def parse_datetime_with_timezone(value)
        ActiveSupport::TimeZone['UTC'].parse(value)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eve_online-0.14.0 lib/eve_online/esi/base.rb
eve_online-0.13.0 lib/eve_online/esi/base.rb