Class: SteamMist::RequestUri

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/steam_mist/request_uri.rb

Overview

This represents a request that may be made to the steam api. It is mainly used for obtaining paths to request to.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ RequestUri

Initialize the request. Can take a hash. Options for the hash can be ‘:interface`, `:method`, `:version`, `:domain` and `:arguments`.

Anything else will cause an argument error. See the attributes for each respectively on what they’re for.

Parameters:

  • options (Hash)

    the options to be used.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/steam_mist/request_uri.rb', line 40

def initialize(options)
  {
    :interface => "", 
    :method => "", 
    :arguments => {}, 
    :version   => 0,  
    :domain => "api.steampowered.com"
   }.merge(options).each do |k, v|
    if respond_to? "#{k}="
      send "#{k}=", v
    else
      raise ArgumentError, "don't know how to handle #{k}!"
    end
  end
end

Instance Attribute Details

#argumentsEnumerable

These are the arguments that will be passed for the request.

Returns:

  • (Enumerable)


22
23
24
# File 'lib/steam_mist/request_uri.rb', line 22

def arguments
  @arguments
end

#domainString

The domain to make the reuqest to.

Returns:

  • (String)


32
33
34
# File 'lib/steam_mist/request_uri.rb', line 32

def domain
  @domain
end

#interfaceString

This is the interface the request will be made to, like ISteamUser.

Returns:

  • (String)


12
13
14
# File 'lib/steam_mist/request_uri.rb', line 12

def interface
  @interface
end

#methodString

This is the method of the interface the request will be made to.

Returns:

  • (String)


17
18
19
# File 'lib/steam_mist/request_uri.rb', line 17

def method
  @method
end

#versionNumeric

The version of the method to request.

Returns:

  • (Numeric)


27
28
29
# File 'lib/steam_mist/request_uri.rb', line 27

def version
  @version
end

Instance Method Details

#format_uriURI

Takes the request data and formats it into an URI.

Returns:

  • (URI)

    the URI of the request.



59
60
61
62
63
64
65
66
# File 'lib/steam_mist/request_uri.rb', line 59

def format_uri
  basic = "http://%s/%s/%s/v%04d" % [domain, interface, method, version]

  uri = URI(basic)
  uri.query = URI.encode_www_form(arguments)

  uri
end

#to_sString

Outputs a string version of the request.

Returns:

  • (String)

    the fully formated URL of the request.



71
72
73
# File 'lib/steam_mist/request_uri.rb', line 71

def to_s
  format_uri.to_s
end