class Storexplore::Api

Main entry point to the library

Public Class Methods

browse(store_url) click to toggle source

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

# File lib/storexplore/api.rb, line 40
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) click to toggle source

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

# File lib/storexplore/api.rb, line 31
def self.define(name, &block)
  builder = Dsl.walker_builder(&block)

  register_builder(name, builder)
end
undef(name) click to toggle source

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

# File lib/storexplore/api.rb, line 53
def self.undef(name)
  builders.delete(name)
end

Private Class Methods

builder(store_url) click to toggle source
# File lib/storexplore/api.rb, line 63
def self.builder(store_url)
  builders.each do |name, builder|
    if store_url.include?(name)
      return builder
    end
  end
  raise NotImplementedError.new("Could not find a store item api for '#{store_url}'")
end
builders() click to toggle source
# File lib/storexplore/api.rb, line 72
def self.builders
  @builders ||= {}
end
register_builder(name, builder) click to toggle source
# File lib/storexplore/api.rb, line 59
def self.register_builder(name, builder)
  builders[name] = builder
end