Sha256: ce38bcf80094af6de7189db5e81af562c49b0daee409ecf31d4aa4e51903ca52

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'marvel/api/api_methods'
require 'marvel/api/http_service'
require 'marvel/api/request'
require 'marvel/api/response'
require 'marvel/api/version'

module Marvel
  class Api
    include ApiMethods

    class << self
      attr_accessor :http_service
    end

    self.http_service = HTTPService

    DEFAULT_SERVER = 'http://gateway.marvel.com'.freeze

    attr_reader :public_key, :private_key, :options

    def initialize(public_key, private_key, options = {})
      @public_key = public_key
      @private_key = private_key
      @options = options
    end

    def api_call(path, args, options = {})
      request = Request.new(
        path: path,
        args: args.merge(apikey: public_key, ts: ts, hash: request_hash),
        options: options
      )
      self.class.http_service.make_request(request)
    end

    def comics(args = {})
      api_call('comics', args)
    end

    private

    def ts
      Time.now.utc.to_i
    end

    def request_hash
      Digest::MD5.hexdigest("#{ts}#{private_key}#{public_key}")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
marvel-api-0.1.0 lib/marvel/api.rb