Class: SteamMist::Connector Abstract
- Inherits:
-
Object
- Object
- SteamMist::Connector
- Includes:
- Enumerable
- Defined in:
- lib/steam_mist/connector.rb
Overview
Subclass and implement #each to create a connector usable by SteamMist.
Test caching.
Direct Known Subclasses
SteamMist::Connectors::EagerConnector, SteamMist::Connectors::LazyConnector
Instance Attribute Summary collapse
-
#data ⇒ Hash?
readonly
This is the data that the connector received from Steam.
-
#headers ⇒ Hash
readonly
This is a hash of headers that will be sent upon request.
-
#made_request ⇒ Boolean
readonly
Whether or not the connector has made the request to the API.
-
#request_uri ⇒ RequestUri
readonly
This is the request that the connector used to grab information from the steam api.
Instance Method Summary collapse
-
#[](_) ⇒ Object
Retrieve data from #data.
-
#cache? ⇒ Boolean
Whether or not this connector will cache the response.
-
#disable_caching ⇒ false
Disables caching on this connector.
-
#each ⇒ void
This loops through the data.
-
#enable_caching(path) ⇒ Object
Enables caching on this connector.
-
#force_request!(force = false) ⇒ Hash
If the connector is lazy, this should force the connector to make the request to Steam.
-
#initialize(request_uri) ⇒ Connector
constructor
This initializes the connector.
Constructor Details
#initialize(request_uri) ⇒ Connector
This initializes the connector.
39 40 41 42 43 |
# File 'lib/steam_mist/connector.rb', line 39 def initialize(request_uri) @request_uri = request_uri @headers = {} @cache = false end |
Instance Attribute Details
#data ⇒ Hash? (readonly)
This is the data that the connector received from Steam. It may be null if the connector is lazy (in terms of when it grabs data).
18 19 20 |
# File 'lib/steam_mist/connector.rb', line 18 def data @data end |
#headers ⇒ Hash (readonly)
This is a hash of headers that will be sent upon request.
34 35 36 |
# File 'lib/steam_mist/connector.rb', line 34 def headers @headers end |
#made_request ⇒ Boolean (readonly)
Whether or not the connector has made the request to the API.
29 30 31 |
# File 'lib/steam_mist/connector.rb', line 29 def made_request @made_request end |
#request_uri ⇒ RequestUri (readonly)
This is the request that the connector used to grab information from the steam api.
24 25 26 |
# File 'lib/steam_mist/connector.rb', line 24 def request_uri @request_uri end |
Instance Method Details
#[](_) ⇒ Object
Retrieve data from #data. This is normally used to force the connector (if it’s lazy) to grab data.
51 52 53 |
# File 'lib/steam_mist/connector.rb', line 51 def [](_) raise NotImplementedError end |
#cache? ⇒ Boolean
Whether or not this connector will cache the response.
85 86 87 |
# File 'lib/steam_mist/connector.rb', line 85 def cache? !!@cache end |
#disable_caching ⇒ false
Disables caching on this connector.
92 93 94 |
# File 'lib/steam_mist/connector.rb', line 92 def disable_caching @cache = false end |
#each ⇒ void
This method returns an undefined value.
This loops through the data. It should be implented for enumerable access.
60 61 62 |
# File 'lib/steam_mist/connector.rb', line 60 def each raise NotImplementedError end |
#enable_caching(path) ⇒ Object
Enables caching on this connector.
78 79 80 |
# File 'lib/steam_mist/connector.rb', line 78 def enable_caching(path) @cache = path end |
#force_request!(force = false) ⇒ Hash
If the connector is lazy, this should force the connector to make the request to Steam.
70 71 72 |
# File 'lib/steam_mist/connector.rb', line 70 def force_request!(force = false) @data = with_cache(force) { Oj.load(request, :mode => :strict) } end |