Sha256: 7f99397a8afa06202d165b038e89ba432420c8564c5cc67a8073aee4fb9dc786

Contents?: true

Size: 891 Bytes

Versions: 1

Compression:

Stored size: 891 Bytes

Contents

require "net/http"
require "uri"
require "json"

require "johki/dota2_match"
require "johki/econ_dota2"
require "johki/steam_user"
require "johki/error"

module Johki
  class Client
    ROOT_URL = "https://api.steampowered.com/"

    def initialize(token)
      @token = token
    end

    def get(path, params = {})
      params[:key] = @token
      path += "?" + URI.encode_www_form(params)
      uri = URI.parse(ROOT_URL + path)
      result = Net::HTTP.get_response(uri)
      self.parse(result)
    end

    def parse(result)
      if result.code != "200"
        raise JohkiError.new(result.body)
      end
      JSON.parse(result.body, symbolize_names: true)
    end

    def dota2_match(appid = 570)
      IDOTA2Match.new(self, appid)
    end

    def econ_dota2(appid = 570)
      IEconDota2.new(self, appid)
    end

    def steam_user
      ISteamUser.new(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
johki-0.1.8 lib/johki/client.rb