Class: SteamMist::PseudoInterface::PseudoMethod
- Inherits:
-
Object
- Object
- SteamMist::PseudoInterface::PseudoMethod
- Defined in:
- lib/steam_mist/pseudo_interface/pseudo_method.rb
Overview
A representation of a Steam Web API method.
Instance Attribute Summary collapse
-
#arguments ⇒ Hash
readonly
The arguments passed along with the method.
-
#cached ⇒ Boolean
readonly
Whether or not the connector is going to implement caching.
-
#interface ⇒ PseudoInterface
readonly
The interface that this method is a part of.
-
#name ⇒ Symbol
readonly
The name of the method.
-
#version ⇒ Numeric
readonly
The version of the method.
Instance Method Summary collapse
-
#api_name ⇒ String
Turns the method name into the name the Steam Web API uses.
-
#get ⇒ Connector
Open up a connector for use.
-
#initialize(interface, method, version = 1) ⇒ PseudoMethod
constructor
Initialize the method.
-
#inspect ⇒ String
Pretty inspection.
-
#request_uri ⇒ RequestUri
This turns the method into its corresponding RequestUri.
-
#with_arguments(new_arguments) ⇒ PseudoMethod
This merges the passed hash with the arguments.
-
#with_arguments!(new_arguments) ⇒ self
This merges the current arguments with the passed arguments.
-
#with_caching(path) ⇒ PseudoMethod
This makes sure the connector is set up to cache its results.
-
#with_caching!(path) ⇒ self
This modifies the current method to make sure the connector is set up to cache its results.
-
#with_version(new_version) ⇒ PseudoMethod
This sets the version.
-
#with_version!(new_version) ⇒ self
Sets the version of the current method.
-
#without_caching ⇒ PseudoMethod
This makes sure the connector is set up to not cache its results.
-
#without_caching! ⇒ self
This modifies the current method to make sure the connector is set up to not cache its results.
Constructor Details
#initialize(interface, method, version = 1) ⇒ PseudoMethod
Initialize the method.
40 41 42 43 44 45 46 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 40 def initialize(interface, method, version=1) @interface = interface @name = method @version = version @arguments = {} @cached = false end |
Instance Attribute Details
#arguments ⇒ Hash (readonly)
The arguments passed along with the method.
25 26 27 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 25 def arguments @arguments end |
#cached ⇒ Boolean (readonly)
Whether or not the connector is going to implement caching.
30 31 32 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 30 def cached @cached end |
#interface ⇒ PseudoInterface (readonly)
The interface that this method is a part of.
20 21 22 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 20 def interface @interface end |
#name ⇒ Symbol (readonly)
The name of the method.
15 16 17 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 15 def name @name end |
#version ⇒ Numeric (readonly)
The version of the method. Used for RequestUri.
10 11 12 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 10 def version @version end |
Instance Method Details
#api_name ⇒ String
Turns the method name into the name the Steam Web API uses. It turns the method name from snake case to camel case if the first character isn’t uppercase. Otherwise, it uses the string form of it.
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 141 def api_name @_api_name ||= begin str = name.to_s if str[0] =~ /[A-Z]/ str else str.gsub!(/_[a-z]/) { |m| m[1].upcase } str[0] = str[0].upcase str end end end |
#get ⇒ Connector
Open up a connector for use. This is cached with this method.
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 124 def get @_connector ||= begin connector = interface.session.connector.new(request_uri) if @cached connector.enable_caching @cached end connector end end |
#inspect ⇒ String
Pretty inspection.
169 170 171 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 169 def inspect "#<SteamMist::PseudoInterface::PseudoMethod #{interface.name}/#{name}>" end |
#request_uri ⇒ RequestUri
This turns the method into its corresponding RequestUri. It uses #api_name and SteamMist::PseudoInterface#api_name to help create the uri.
159 160 161 162 163 164 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 159 def request_uri @_request_uri ||= RequestUri.new :interface => interface.api_name, :method => api_name, :arguments => interface.session.default_arguments.dup.merge(arguments), :version => version end |
#with_arguments(new_arguments) ⇒ PseudoMethod
This merges the passed hash with the arguments.
52 53 54 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 52 def with_arguments(new_arguments) dup.with_arguments! new_arguments end |
#with_arguments!(new_arguments) ⇒ self
This merges the current arguments with the passed arguments. This modifies the instance it is called on. Invalidates the current connector.
62 63 64 65 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 62 def with_arguments!(new_arguments) @arguments.merge!(new_arguments) reset_connector end |
#with_caching(path) ⇒ PseudoMethod
This makes sure the connector is set up to cache its results. Does not modify the connector until #get is called.
91 92 93 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 91 def with_caching(path) dup.with_caching!(path) end |
#with_caching!(path) ⇒ self
This modifies the current method to make sure the connector is set up to cache its results. Invalidates the current connector.
100 101 102 103 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 100 def with_caching!(path) @cached = path reset_connector end |
#with_version(new_version) ⇒ PseudoMethod
This sets the version.
72 73 74 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 72 def with_version(new_version) dup.with_version!(new_version) end |
#with_version!(new_version) ⇒ self
Sets the version of the current method. This modifies the instance it is called on. Invalidates the current connector.
81 82 83 84 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 81 def with_version!(new_version) @version = new_version reset_connector end |
#without_caching ⇒ PseudoMethod
This makes sure the connector is set up to not cache its results.
108 109 110 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 108 def without_caching dup.without_caching! end |
#without_caching! ⇒ self
This modifies the current method to make sure the connector is set up to not cache its results. Invalidates the current connector.
116 117 118 119 |
# File 'lib/steam_mist/pseudo_interface/pseudo_method.rb', line 116 def without_caching! @cached = false reset_connector end |