Class: AuthenticatedService

Inherits:
BasicService
  • Object
show all
Defined in:
lib/authenticated_service.rb

Overview

Base service for all services demanding a security token.

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ AuthenticatedService

Returns a new instance of AuthenticatedService.



7
8
9
10
11
# File 'lib/authenticated_service.rb', line 7

def initialize(username, password)
  super(username, password)

  @token_service = TokenService::TokenService.new(@username, @password)
end

Instance Method Details

#invoke_authenticated(action, &block) ⇒ Object

Invokes the given action and also adds the security token to the SOAP header. Using this method authentication is totally hidden from the rest of the application.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/authenticated_service.rb', line 15

def invoke_authenticated(action, &block)

  security_token = @token_service.get_security_token

  response = invoke(action) do |message|
    doc = message.document
    
    # Build the login header
    build_service_header(doc, security_token)

    yield(message, doc)
  end

  return response
end