Class: Net::Session

Inherits:
Object show all
Defined in:
flow/net/session.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Session) initialize(base_url, &block)

Returns a new instance of Session



5
6
7
8
9
10
# File 'flow/net/session.rb', line 5

def initialize(base_url, &block)
  @base_url = base_url
  @authorization = false
  @headers = []
  self.instance_eval(&block)
end

Instance Attribute Details

- (Object) authorization (readonly)

Returns the value of attribute authorization



3
4
5
# File 'flow/net/session.rb', line 3

def authorization
  @authorization
end

Class Method Details

+ (Object) build(base_url, &block)



12
13
14
# File 'flow/net/session.rb', line 12

def self.build(base_url, &block)
  new(base_url, &block)
end

Instance Method Details

- (Object) authorize(options)

Sets the Basic authentication data to be used in all requests

Parameters:

  • options (Hash)

Options Hash (options):

  • user (String)
  • password (String)
  • token (String)


49
50
51
# File 'flow/net/session.rb', line 49

def authorize(options)
  @authorization = Authorization.new(options)
end

- (Object) header(field, value)

Sets a key/value pair header to be used in all requests in this session

Examples:

session.header("Content-Type", "application/json")

Parameters:

  • field (String)
  • value (String)


29
30
31
# File 'flow/net/session.rb', line 29

def header(field, value)
  @headers << Header.new(field, value)
end

- (Hash) headers

Returns a hash containing key/value pairs of headers

Examples:

response.headers
#=> { 'Content-Type' => 'application/josn' }

Returns:

  • (Hash)


38
39
40
41
42
# File 'flow/net/session.rb', line 38

def headers
  hash = {}
  @headers.map {|header| hash[header.field] = header.value}
  hash
end