Class: AppStore::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/app_store/agent.rb

Overview

Define an agent which is linked to a specific store front and can perform all calls to this specific store. Accepts every AppStore class as a method, ex :

Examples

agent = AppStore::Agent.new(:store_front => :fr)
agent.category.featured                           # => will call Category.featured with store front set to :fr
agent.application.find_by_id(42)                  # => will call Application.find_by_id(42) with store front set to :fr
agent.application.find_by_id(42, :bleh => 'yeah') # => also accepts extra arguments and merge them with store front

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Agent

Returns a new instance of Agent.


14
15
16
17
# File 'lib/app_store/agent.rb', line 14

def initialize(args = {})
  @store_front = args[:store_front] || AppStore::Client::DefaultStoreFrontName
  @client = AppStore::Client.new(:store_front => @store_front)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object (private)


20
21
22
23
24
# File 'lib/app_store/agent.rb', line 20

def method_missing(method, *args)
  # OPTIMIZE: we should use a 'camelize' method instead of capitalize
  AppStore::Helper::Proxy.new :to => "AppStore::#{method.to_s.capitalize}".constantize,
                              :extra => {:client => @client}
end