Class: Viewpoint::SPWS::Connection

Inherits:
Object
  • Object
show all
Includes:
Viewpoint::SPWS
Defined in:
lib/viewpoint/spws/connection.rb

Constant Summary

Constants included from Viewpoint::SPWS

VERSION

Instance Attribute Summary collapse

Attributes included from Viewpoint::SPWS

#logger

Instance Method Summary collapse

Methods included from Viewpoint::SPWS

root_logger, set_log_level

Constructor Details

#initialize(site_base) ⇒ Connection

Returns a new instance of Connection.

Parameters:

  • site_base (String)

    the base URL of the site not including the web service part. @example https://<site>/mysite/<default.aspx>



8
9
10
11
12
13
14
# File 'lib/viewpoint/spws/connection.rb', line 8

def initialize(site_base)
  @log = Logging.logger[self.class.name.to_s.to_sym]
  @httpcli = HTTPClient.new
  # Up the keep-alive so we don't have to do the NTLM dance as often.
  @httpcli.keep_alive_timeout = 60
  @site_base = URI.parse(normalize_site_name(site_base))
end

Instance Attribute Details

#site_baseObject (readonly)

Returns the value of attribute site_base.



4
5
6
# File 'lib/viewpoint/spws/connection.rb', line 4

def site_base
  @site_base
end

Instance Method Details

#authenticate(websvc) ⇒ Boolean

Authenticate to the web service. You don’t have to do this because authentication will happen on the first request if you don’t do it here.

Returns:

  • (Boolean)

    true if authentication is successful, false otherwise



23
24
25
# File 'lib/viewpoint/spws/connection.rb', line 23

def authenticate(websvc)
  self.get(websvc) && true
end

#get(websvc) ⇒ String

Send a GET to the web service

Returns:

  • (String)

    If the request is successful (200) it returns the body of the response.



30
31
32
# File 'lib/viewpoint/spws/connection.rb', line 30

def get(websvc)
  check_response( @httpcli.get(@site_base + URI.encode(websvc)) )
end

#post(websvc, xmldoc) ⇒ String

Send a POST to the web service

Returns:

  • (String)

    If the request is successful (200) it returns the body of the response.



37
38
39
40
41
# File 'lib/viewpoint/spws/connection.rb', line 37

def post(websvc, xmldoc)
  headers = {'Content-Type' => 'application/soap+xml; charset=utf-8'}
  url = (@site_base + websvc).to_s
  check_response( @httpcli.post(url, xmldoc, headers) )
end

#set_auth(user, pass) ⇒ Object



16
17
18
# File 'lib/viewpoint/spws/connection.rb', line 16

def set_auth(user,pass)
  @httpcli.set_auth(@site_base.to_s, user, pass)
end