aboutsummaryrefslogtreecommitdiffstats
path: root/actionwebservice/lib/action_web_service/protocol/abstract.rb
blob: 70b922ce733e46695be91e8a2767f775da42d6ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
module ActionWebService # :nodoc:
  module Protocol # :nodoc:
    class ProtocolError < ActionWebServiceError # :nodoc:
    end

    class AbstractProtocol # :nodoc:
      def decode_action_pack_request(action_pack_request)
      end

      def encode_action_pack_request(service_name, public_method_name, raw_body, options={})
        klass = options[:request_class] || SimpleActionPackRequest
        request = klass.new
        request.request_parameters['action'] = service_name.to_s
        request.env['RAW_POST_DATA'] = raw_body
        request.env['REQUEST_METHOD'] = 'POST'
        request.env['HTTP_CONTENT_TYPE'] = 'text/xml'
        request
      end

      def decode_request(raw_request, service_name)
      end

      def encode_request(method_name, params, param_types)
      end

      def decode_response(raw_response)
      end

      def encode_response(method_name, return_value, return_type)
      end

      def protocol_client(api, protocol_name, endpoint_uri, options)
      end

      def register_api(api)
      end
    end

    class Request # :nodoc:
      attr :protocol
      attr :method_name
      attr_accessor :method_params
      attr :service_name
      attr_accessor :api
      attr_accessor :api_method

      def initialize(protocol, method_name, method_params, service_name, api=nil, api_method=nil)
        @protocol = protocol
        @method_name = method_name
        @method_params = method_params
        @service_name = service_name
        @api = api
        @api_method = api_method
      end
    end

    class Response # :nodoc:
      attr :body
      attr :content_type
      attr :return_value

      def initialize(body, content_type, return_value)
        @body = body
        @content_type = content_type
        @return_value = return_value
      end
    end

    class SimpleActionPackRequest < ActionController::AbstractRequest # :nodoc:
      def initialize
        @env = {}
        @qparams = {}
        @rparams = {}
        @cookies = {}
        reset_session
      end

      def query_parameters
        @qparams
      end

      def request_parameters
        @rparams
      end

      def env
        @env
      end

      def host
        ''
      end

      def cookies
        @cookies
      end

      def session
        @session
      end

      def reset_session
        @session = {}
      end
    end
  end
end