Class: EmmyExtends::Savon::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/emmy_extends/savon/operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(httpi, globals, locals) ⇒ Operation

Returns a new instance of Operation.



13
14
15
16
17
18
19
# File 'lib/emmy_extends/savon/operation.rb', line 13

def initialize(httpi, globals, locals)
  @httpi = httpi
  @request = httpi.request
  @globals = globals
  @locals = locals
  setup
end

Instance Attribute Details

#globalsObject (readonly)

Returns the value of attribute globals.



8
9
10
# File 'lib/emmy_extends/savon/operation.rb', line 8

def globals
  @globals
end

#httpiObject (readonly)

Returns the value of attribute httpi.



7
8
9
# File 'lib/emmy_extends/savon/operation.rb', line 7

def httpi
  @httpi
end

#localsObject (readonly)

Returns the value of attribute locals.



9
10
11
# File 'lib/emmy_extends/savon/operation.rb', line 9

def locals
  @locals
end

#requestObject (readonly)

Returns the value of attribute request.



5
6
7
# File 'lib/emmy_extends/savon/operation.rb', line 5

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



6
7
8
# File 'lib/emmy_extends/savon/operation.rb', line 6

def response
  @response
end

Instance Method Details

#connectObject



21
22
23
# File 'lib/emmy_extends/savon/operation.rb', line 21

def connect
  @httpi.connect
end

#setupObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/emmy_extends/savon/operation.rb', line 40

def setup
  @httpi.on :success do |response, httpi, conn|
    @response = ::Savon::Response.new(response, globals, locals)
    unless @response.soap_fault
      unless @response.http_error
        success!(@response, self, conn)
      else
        error!("HTTP error (#{@response.http.code})", self, conn)
      end
    else
      error!("SOAP error (#{@response.soap_fault.to_s})", self, conn)
    end
  end

  @httpi.on :error do |error, httpi, conn|
    @connection = conn
    error!(error, self, conn)
  end
end

#syncObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/emmy_extends/savon/operation.rb', line 25

def sync
  Fiber.sync do |fiber|
    connect

    on :success do |response, savon, conn|
      fiber.resume response
    end

    on :error do |error, savon, conn|
      # FIXME: TimeoutError separate
      fiber.leave EmmyHttp::ConnectionError, error.to_s
    end
  end
end