Class: Storexplore::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/storexplore/api.rb

Overview

Main entry point to the library

Class Method Summary collapse

Class Method Details

.browse(store_url) ⇒ Object

Starts to browse a real store. Uses the first defined API whose name is included in the url of the store. Returns a Storexplore::Walker for the home page of the store



41
42
43
44
45
46
47
48
49
50
# File 'lib/storexplore/api.rb', line 41

def self.browse(store_url)
  agent = Mechanize.new do |it|
      # NOTE: by default Mechanize has infinite history, and causes memory leaks
      #it.history.max_size = 0
    end

  builder = builder(store_url)
  builder.configure_agent(agent)
  builder.new_walker(WalkerPage.open(agent,store_url))
end

.define(name, &block) ⇒ Object

Defines a new store API, with a name and a definition inside the given block. The block is evaluated in the context of a Storexplore::Dsl instance, see README



32
33
34
35
36
# File 'lib/storexplore/api.rb', line 32

def self.define(name, &block)
  builder = Dsl.walker_builder(&block)

  register_builder(name, builder)
end

.undef(name) ⇒ Object

Forgets the previously defined store API by its name. Mainly useful while testing.



54
55
56
# File 'lib/storexplore/api.rb', line 54

def self.undef(name)
  builders.delete(name)
end