### Home Classes Methods

### In Files

- lib/stella/client.rb

### Parent

Object

### Methods

- ::new
- #clear_previous_request
- #content_type?
- #cookie
- #cookies
- #current_event
- #doc
- #error
- #fail
- #find_response_handler
- #follow
- #form
- #forms
- #generate_request
- #handle_response
- #location
- #prepare_request
- #quit
- #redirect?
- #repeat
- #response_handler?
- #status
- #wait

### Files

- LICENSE.txt
- TODO

### Class/Module Index

Quicksearch

- Stella
- Stella::API
- Stella::API::Unauthorized
- Stella::Asserts
- Stella::CLI
- Stella::Client
- Stella::Common
- Stella::Common::PrivacyMethods
- Stella::ET
- Stella::Engine
- Stella::Engine::Base
- Stella::Engine::Base::ClassMethods
- Stella::Engine::Checkup
- Stella::EventTemplate
- Stella::ForcedRedirect
- Stella::HTTPError
- Stella::Log
- Stella::Log::HTTP
- Stella::PageError
- Stella::RT
- Stella::RepeatRequest
- Stella::Report
- Stella::Report::Content
- Stella::Report::Content::ReportMethods
- Stella::Report::Errors
- Stella::Report::Errors::ReportMethods
- Stella::Report::Headers
- Stella::Report::Metrics
- Stella::Report::Metrics::ReportMethods
- Stella::Report::Plugin
- Stella::Report::Plugin::ClassMethods
- Stella::Report::Statuses
- Stella::Report::Statuses::ReportMethods
- Stella::RequestError
- Stella::RequestTemplate
- Stella::Session
- Stella::StringTemplate
- Stella::TP
- Stella::Testplan
- Stella::Testplan::ClassMethods
- Stella::TestplanQuit
- Stella::Testrun
- Stella::TimeoutError
- Stella::UC
- Stella::Usecase
- Stella::Usecase::ClassMethods
- Stella::UsecaseError
- Stella::UsecaseFail
- Stella::Utils
- Stella::VERSION
- Addressable
- Addressable::URI
- Time
- Time::Units
- Array
- DefaultTestplan
- Float
- Hash
- MatchData
- MetricsPack
- Numeric
- Object
- OpenStruct
- StellaBehavior
- StellaError
- String
- Symbol
- Thread

No matching classes.

# Stella::Session

### Attributes

base_uri[RW]
events[R]
exception[RW]
handler[R]
header[RW]
headers[RW]
http_auth[R]
http_client[RW]
http_method[RW]
param[RW]
params[RW]
previous_doc[R]
redirect_uri[RW]
req[R]
res[R]
response[R]
response_handler[R]
rt[R]
session[R]
uri[RW]
vars[R]

### Public Class Methods

new(base_uri=nil) click to toggle source

    # File lib/stella/client.rb, line 235
    def initialize(base_uri=nil)
      @base_uri = base_uri
      @vars = indifferent_hash
      @base_uri &&= Addressable::URI.parse(@base_uri) if String === @base_uri
      @events = SelectableArray.new
    end

### Public Instance Methods

clear_previous_request() click to toggle source

    # File lib/stella/client.rb, line 379
    def clear_previous_request
      [:doc, :location, :res, :req, :rt, :params, :headers, :cookie, :form, :response_handler, :http_method, :exception].each do |n|
        instance_variable_set :"@#{n}", nil
      end
    end

content_type?(guess) click to toggle source

    # File lib/stella/client.rb, line 350
    def content_type? guess
      guess = Regexp.new guess unless Regexp === guess
      guess.match((res.header['Content-Type'] || []).first)
    end

cookie() click to toggle source

    # File lib/stella/client.rb, line 338
    def cookie
      return @cookie unless @cookie.nil?
      return nil unless http_client.cookie_manager
      return nil if http_client.cookie_manager.cookies.empty?
      @cookie = indifferent_hash
      http_client.cookie_manager.cookies.each do |c|
        next unless c.match?(uri)
        @cookie[c.name] = c.value
      end
      @cookie
    end

Also aliased as: cookies
cookies() click to toggle source
Alias for: cookie
current_event() click to toggle source

    # File lib/stella/client.rb, line 241
    def current_event
      @events.last
    end

doc() click to toggle source

    # File lib/stella/client.rb, line 296
    def doc
      return @doc unless @doc.nil?
      return nil if @res.content.nil? || @res.content.empty?
      str = RUBY_VERSION >= "1.9.0" ? @res.content.force_encoding("UTF-8") : @res.content
      # NOTE: It's important to parse the document on every
      # request because this container is available for the
      # entire life of a usecase.
      @doc = case (@res.header['Content-Type'] || []).first
      when /text\/html/
        Nokogiri::HTML(str)
      when /text\/xml/
        Nokogiri::XML(str)
      when /text\/yaml/
        YAML.load(str)
      when /application\/json/
        Yajl::Parser.parse(str)
      end
      @doc.replace indifferent_params(@doc) if Hash === @doc
      @doc
    end

error(msg=nil) click to toggle source

    # File lib/stella/client.rb, line 391
    def error(msg=nil); raise RequestError.new(msg); end

fail(msg=nil) click to toggle source

    # File lib/stella/client.rb, line 390
    def fail(msg=nil); raise UsecaseFail.new(msg); end

find_response_handler(status) click to toggle source

    # File lib/stella/client.rb, line 359
    def find_response_handler(status)
      return if response_handler.nil?
      key = response_handler.keys.select { |range| range.member?(status) }.first
      response_handler[key] if key
    end

follow(uri=nil,&blk) click to toggle source

    # File lib/stella/client.rb, line 393
    def follow(uri=nil,&blk); raise ForcedRedirect.new(uri,&blk); end

form() click to toggle source

    # File lib/stella/client.rb, line 316
    def form
      return @form unless @form.nil?
      return nil if doc.nil?
      return nil unless content_type?('text/html')
      @form = indifferent_hash
      forms = doc.css('form')
      forms.each_with_index do |html,idx|
        name = html['id'] || html['name'] || html['class']
        Stella.ld [:form, idx, name].inspect
        form = indifferent_hash
        # Store form attributes in keys prefixed with an underscore.
        html.each { |att,val| form["_#{att}"] = val }
        # Store input name and values in the form hash.
        html.css('input').each do |input|
          form[input['name']] = input['value']
        end
        # Store the form by the name and index in the document
        @form[name] = @form[idx] = form
      end
      @form
    end

Also aliased as: forms
forms() click to toggle source
Alias for: form
generate_request(event_id) click to toggle source

    # File lib/stella/client.rb, line 283
    def generate_request(event_id)
      @res = http_client.send(@http_method.to_s.downcase, @uri, params, headers)
      @req = @res.request
      @events << event_id
      @res
    end

handle_response() click to toggle source

    # File lib/stella/client.rb, line 354
    def handle_response
      return unless response_handler?
      instance_exec(&find_response_handler(@res.status))
      @previous_doc = doc
    end

location() click to toggle source

    # File lib/stella/client.rb, line 289
    def location
      @location ||= Addressable::URI.parse(@res.header['location'].first || '')
      @location
    end

prepare_request(uc, rt) click to toggle source

    # File lib/stella/client.rb, line 246
    def prepare_request uc, rt
      clear_previous_request
      @rt = rt
      @vars.merge! uc.class.session || {}
      registered_classes = []
      if uc.class.testplan
        @vars.merge! uc.class.testplan.class.session || {}
        registered_classes = uc.class.testplan.class.registered_classes || []
      end
      registered_classes.push *(uc.class.registered_classes || [])
      registered_classes.each do |klass|
        self.extend klass unless self.kind_of?(klass)
      end
      @http_method, @params, @headers = rt.http_method, rt.params, rt.headers
      @http_auth = uc.http_auth
      instance_exec(&rt.callback) unless rt.callback.nil?
      @uri = if @redirect_uri
        @params = {}
        @headers = {}
        @http_method = :get
        if @redirect_uri.scheme
          tmp = [@redirect_uri.scheme, '://', @redirect_uri.host].join
          tmp << ":#{@redirect_uri.port}" unless [80,443].member?(@redirect_uri.port)
          @base_uri = Addressable::URI.parse(tmp)
        end
        build_uri @redirect_uri
      else
        build_uri @rt.uri
      end
      if !http_auth.nil? && !http_auth.empty?
        Stella.ld " HTTP AUTH: #{http_auth.inspect}"
        http_auth[:domain] ||= '%s://%s:%d%s' % [base_uri.scheme, base_uri.host, base_uri.port, '/']
        http_client.set_auth http_auth[:domain], http_auth[:user], http_auth[:pass]
        Stella.ld "   #{http_client.www_auth.inspect}"
      end
      @redirect_uri = nil  # one time deal
    end

quit(msg=nil) click to toggle source

    # File lib/stella/client.rb, line 389
    def quit(msg=nil); raise TestplanQuit.new(msg); end

redirect?() click to toggle source

    # File lib/stella/client.rb, line 293
    def redirect?
      @res && (300..399).member?(@res.status)
    end

repeat(t=1) click to toggle source

    # File lib/stella/client.rb, line 392
    def repeat(t=1); raise RepeatRequest.new(t); end

response_handler?() click to toggle source

    # File lib/stella/client.rb, line 364
    def response_handler?
      status = (@res.status || 0).to_i
      !find_response_handler(status).nil?
    end

status() click to toggle source

    # File lib/stella/client.rb, line 384
    def status
      @res.status
    end

wait(t) click to toggle source

    # File lib/stella/client.rb, line 388
    def wait(t); sleep t; end

[Validate]

Generated with the Darkfish Rdoc Generator 2.