Class: Stew::Store::StoreClient

Inherits:
Object
  • Object
show all
Defined in:
lib/stew/store/store_client.rb

Overview

Creation of app objects from URLs or app_ids

Can create apps for any steam region. When no region is given, it defaults to the default region in the configuration

Examples:

Creation of a Stew::Store::App from a URL

Stew::StoreClient.new.create_app('http://store.steampowered.com/app/211420') #=> Stew::StoreClient::App

Creation of a Stew::Store::App from an id

Stew::StoreClient.new.create_app(211420) #=> Stew::StoreClient::App

Creation of a Stew::Store::App from a URL with a different region

Stew::StoreClient.new.create_app('http://store.steampowered.com/app/211420?cc=uk') #=> Stew::StoreClient::App

Creation of a Stew::Store::App from an id and a region

Stew::StoreClient.new.app(211420, :uk) #=> Stew::StoreClient::App

Constant Summary collapse

STORE_URL =
'http://store.steampowered.com'

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ StoreClient

Returns a new instance of StoreClient.



22
23
24
# File 'lib/stew/store/store_client.rb', line 22

def initialize(opts = {})
  @client = opts[:client] || Stew.config[:default_web_client].new(STORE_URL)
end

Instance Method Details

#app(app_id, region = Stew.config[:default_region]) ⇒ Object



33
34
35
# File 'lib/stew/store/store_client.rb', line 33

def app(app_id,region = Stew.config[:default_region])
  Store::App.new(@client.get("/app/#{app_id}",:cc => region.to_sym), app_id.to_i)
end

#create_app(data) ⇒ Object

Raises:



26
27
28
29
30
31
# File 'lib/stew/store/store_client.rb', line 26

def create_app(data)
  return app(data) if data.class == Fixnum
  return app($1,$2) if data =~ /store.steampowered.com\/app\/([0-9]+)\/?\?cc=([a-zA-Z]{2})/
  return app($1) if data =~ /store.steampowered.com\/app\/([0-9]+)/
  raise AppIdNotFoundError
end