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

Methods inherited from BasicService

#on_create_document, #on_response_document

Constructor Details

#initialize(username, password, environment = ServiceEnvironment.SANDBOX) ⇒ AuthenticatedService

Constructor

Parameters

username

Username, such as [email protected]

password

Password



11
12
13
14
15
# File 'lib/authenticated_service.rb', line 11

def initialize(username, password, environment = ServiceEnvironment.SANDBOX)
  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.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/authenticated_service.rb', line 19

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