class Apist

Constants

VERSION

Attributes

current_method[R]
requester[R]
suppress_exceptions[RW]

Public Class Methods

base_url(url=nil) click to toggle source

Allows setting a base url to be used for each request.

class Foo < Apist
  base_url 'http://en.wikipedia.org'
end
# File lib/apist.rb, line 23
def self.base_url(url=nil)
  return @base_url unless url
  @base_url = url
end
current() click to toggle source

Create new filter object with current node as filter result

class Foo < Apist
  base_url 'http://en.wikipedia.org'
  def index
    get '/wiki/Main_Page',
        portals: filter('a[title^="Portal:"]').each(
          link: current.attr('href'),
          label: current.text
        ),
  end
end

@return [Apist::Filter]

# File lib/apist.rb, line 69
def self.current
  self.filter '*'
end
filter(css_selector) click to toggle source

Create new filter in blueprint

class Foo < Apist
  base_url 'http://en.wikipedia.org'
  def index
    get '/wiki/Main_Page',
        welcome_message: filter('#mp-topbanner div:first').text,
  end
end

@return [Apist::Filter]

# File lib/apist.rb, line 38
def self.filter(css_selector)
  Apist::Selector.new css_selector
end
new() click to toggle source
# File lib/apist.rb, line 13
def initialize
  @requester = Apist::Request.new self.class.base_url
  @suppress_exceptions = true
end

Public Instance Methods

current() click to toggle source

Create new filter object with current node as filter result

class Foo < Apist
  base_url 'http://en.wikipedia.org'
  def index
    get '/wiki/Main_Page',
        portals: filter('a[title^="Portal:"]').each(
          link: current.attr('href'),
          label: current.text
        ),
  end
end

@return [Apist::Filter]

# File lib/apist.rb, line 86
def current
  self.class.current
end
delete(url, blueprint = nil, options = {}) click to toggle source

Perform DELETE http-request

# File lib/apist.rb, line 124
def delete(url, blueprint = nil, options = {})
  request 'delete', url, blueprint, options
end
filter(css_selector) click to toggle source

Create new filter in blueprint

class Foo < Apist
  base_url 'http://en.wikipedia.org'
  def index
    get '/wiki/Main_Page',
        welcome_message: filter('#mp-topbanner div:first').text,
  end
end

@return [Apist::Filter]

# File lib/apist.rb, line 52
def filter(css_selector)
  self.class.filter css_selector
end
get(url, blueprint = nil, options = {}) click to toggle source

Perform GET http-request

# File lib/apist.rb, line 99
def get(url, blueprint = nil, options = {})
  request 'get', url, blueprint, options
end
head(url, blueprint = nil, options = {}) click to toggle source

Perform HEAD http-request

# File lib/apist.rb, line 104
def head(url, blueprint = nil, options = {})
  request 'head', url, blueprint, options
end
parse(content, blueprint) click to toggle source
# File lib/apist.rb, line 90
def parse(content, blueprint)
  @current_method = Apist::Method.new self, nil, blueprint
  @current_method.set_content content
  result = @current_method.parse_blueprint blueprint
  @current_method = nil
  result
end
patch(url, blueprint = nil, options = {}) click to toggle source

Perform PATCH http-request

# File lib/apist.rb, line 119
def patch(url, blueprint = nil, options = {})
  request 'patch', url, blueprint, options
end
post(url, blueprint = nil, options = {}) click to toggle source

Perform POST http-request

# File lib/apist.rb, line 109
def post(url, blueprint = nil, options = {})
  request 'post', url, blueprint, options
end
put(url, blueprint = nil, options = {}) click to toggle source

Perform PUT http-request

# File lib/apist.rb, line 114
def put(url, blueprint = nil, options = {})
  request 'put', url, blueprint, options
end

Private Instance Methods

request(http_method, url, blueprint = nil, options = []) click to toggle source

Perform http-request with options and parse result by blueprint

# File lib/apist.rb, line 131
def request(http_method, url, blueprint = nil, options = [])
  @current_method = Apist::Method.new self, url, blueprint
  @current_method.method = http_method
  result = @current_method.get options
  @current_method = nil
  result
end