laximo 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.BSD +24 -0
  5. data/README.md +87 -0
  6. data/laximo.gemspec +26 -0
  7. data/lib/laximo.rb +38 -0
  8. data/lib/laximo/am.rb +113 -0
  9. data/lib/laximo/defaults.rb +10 -0
  10. data/lib/laximo/oem.rb +398 -0
  11. data/lib/laximo/options.rb +92 -0
  12. data/lib/laximo/query.rb +201 -0
  13. data/lib/laximo/request.rb +78 -0
  14. data/lib/laximo/respond.rb +106 -0
  15. data/lib/laximo/respond/find_detail.rb +42 -0
  16. data/lib/laximo/respond/find_oem.rb +42 -0
  17. data/lib/laximo/respond/find_oem_correction.rb +42 -0
  18. data/lib/laximo/respond/find_replacements.rb +20 -0
  19. data/lib/laximo/respond/find_vehicle_by_frame.rb +16 -0
  20. data/lib/laximo/respond/find_vehicle_by_vin.rb +16 -0
  21. data/lib/laximo/respond/find_vehicle_by_wizard.rb +16 -0
  22. data/lib/laximo/respond/find_vehicle_by_wizard2.rb +16 -0
  23. data/lib/laximo/respond/get_catalog_info.rb +16 -0
  24. data/lib/laximo/respond/get_filter_by_detail.rb +16 -0
  25. data/lib/laximo/respond/get_filter_by_unit.rb +16 -0
  26. data/lib/laximo/respond/get_unit_info.rb +16 -0
  27. data/lib/laximo/respond/get_vehicle_info.rb +16 -0
  28. data/lib/laximo/respond/get_wizard.rb +16 -0
  29. data/lib/laximo/respond/get_wizard2.rb +16 -0
  30. data/lib/laximo/respond/get_wizard_next_step2.rb +16 -0
  31. data/lib/laximo/respond/list_catalogs.rb +16 -0
  32. data/lib/laximo/respond/list_categories.rb +16 -0
  33. data/lib/laximo/respond/list_detail_by_unit.rb +16 -0
  34. data/lib/laximo/respond/list_image_map_by_unit.rb +16 -0
  35. data/lib/laximo/respond/list_manufacturer.rb +20 -0
  36. data/lib/laximo/respond/list_quick_detail.rb +16 -0
  37. data/lib/laximo/respond/list_quick_group.rb +16 -0
  38. data/lib/laximo/respond/list_units.rb +16 -0
  39. data/lib/laximo/respond/manufacturer_info.rb +20 -0
  40. data/lib/laximo/version.rb +6 -0
  41. metadata +97 -0
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+ module Laximo
3
+
4
+ module Options
5
+
6
+ extend self
7
+
8
+ def ssl_key(str = nil)
9
+
10
+ return @ssl_key if str.nil?
11
+ raise ::LoadError.new("File #{str} is not found") unless File.exists?(str)
12
+
13
+ @ssl_key = ::OpenSSL::PKey::RSA.new(::File.read(str))
14
+
15
+ end # ssl_key
16
+
17
+ def ssl_cert(str = nil)
18
+
19
+ return @ssl_cert if str.nil?
20
+ raise ::LoadError.new("File #{str} is not found") unless File.exists?(str)
21
+
22
+ @ssl_cert = ::OpenSSL::X509::Certificate.new(::File.read(str))
23
+
24
+ end # ssl_cert
25
+
26
+ def ssl_verify(str = nil)
27
+
28
+ return @ssl_verify if str.nil?
29
+ @ssl_verify = (str === true ? ::OpenSSL::SSL::VERIFY_PEER : ::OpenSSL::SSL::VERIFY_NONE)
30
+
31
+ end # ssl_verify
32
+
33
+ def use_ssl(str = nil)
34
+
35
+ return @use_ssl if str.nil?
36
+ @use_ssl = str === true
37
+
38
+ end # use_ssl
39
+
40
+ def timeout(str = nil)
41
+
42
+ return @timeout if str.nil?
43
+ @timeout = String(str).to_i(10).abs
44
+
45
+ end # timeout
46
+
47
+ def user_agent(str = nil)
48
+
49
+ return @user_agent if str.nil?
50
+ @user_agent = str
51
+
52
+ end # user_agent
53
+
54
+ def debug(str = nil)
55
+ @debug = (str === true)
56
+ end # debug
57
+
58
+ def debug?
59
+ @debug === true
60
+ end # debug?
61
+
62
+ def am_soap_action(str = nil)
63
+
64
+ return @am_soap_action if str.nil?
65
+ @am_soap_action = str
66
+
67
+ end # am_soap_action
68
+
69
+ def am_soap_endpoint(str = nil)
70
+
71
+ return @am_soap_endpoint if str.nil?
72
+ @am_soap_endpoint = str
73
+
74
+ end # am_soap_endpoint
75
+
76
+ def oem_soap_action(str = nil)
77
+
78
+ return @oem_soap_action if str.nil?
79
+ @oem_soap_action = str
80
+
81
+ end # oem_soap_action
82
+
83
+ def oem_soap_endpoint(str = nil)
84
+
85
+ return @oem_soap_endpoint if str.nil?
86
+ @oem_soap_endpoint = str
87
+
88
+ end # oem_soap_endpoint
89
+
90
+ end # Options
91
+
92
+ end # Laximo
@@ -0,0 +1,201 @@
1
+ # encoding: utf-8
2
+ module Laximo
3
+
4
+ class Query
5
+
6
+ def initialize(func_name)
7
+
8
+ @func_name = func_name
9
+ @query = {}
10
+
11
+ end # initialize
12
+
13
+ def locale(v = nil)
14
+
15
+ @str = nil
16
+ @locale = v.blank? ? '' : ":Locale=#{escape(v)}"
17
+ self
18
+
19
+ end # locale
20
+
21
+ def ssd(v = nil)
22
+
23
+ @str = nil
24
+ @query[:ssd] = escape(v)
25
+ self
26
+
27
+ end # ssd
28
+
29
+ def catalog(v = nil)
30
+
31
+ @str = nil
32
+ @query[:Catalog] = escape(v)
33
+ self
34
+
35
+ end # catalog
36
+
37
+ def localized(v = false)
38
+
39
+ @str = nil
40
+ @query[:Localized] = (v === true)
41
+ self
42
+
43
+ end # localized
44
+
45
+ def wizard_id(v = nil)
46
+
47
+ @str = nil
48
+ @query[:WizardId] = escape(v)
49
+ self
50
+
51
+ end # wizard_id
52
+
53
+ def value_id(v = nil)
54
+
55
+ @str = nil
56
+ @query[:ValueId] = escape(v)
57
+ self
58
+
59
+ end # value_id
60
+
61
+ def options(args = [])
62
+
63
+ @str = nil
64
+ @query[:Options] = args.empty? ? nil : args.join(',')
65
+ self
66
+
67
+ end # options
68
+
69
+ def brand(v = nil)
70
+
71
+ @str = nil
72
+ @query[:Brand] = escape(v)
73
+ self
74
+
75
+ end # brand
76
+
77
+ def oem(v = nil)
78
+
79
+ @str = nil
80
+ @query[:OEM] = escape(v)
81
+ self
82
+
83
+ end # oem
84
+
85
+ def detail_id(v = nil)
86
+
87
+ @str = nil
88
+ @query[:DetailId] = escape(v)
89
+ self
90
+
91
+ end # detail_id
92
+
93
+ def manufacturer_id(v = nil)
94
+
95
+ @str = nil
96
+ @query[:ManufacturerId] = escape(v)
97
+ self
98
+
99
+ end # manufacturer_id
100
+
101
+ def vin(v = nil)
102
+
103
+ @str = nil
104
+ @query[:VIN] = escape(v)
105
+ self
106
+
107
+ end # vin
108
+
109
+ def frame(v = nil)
110
+
111
+ @str = nil
112
+ @query[:Frame] = escape(v)
113
+ self
114
+
115
+ end # frame
116
+
117
+ def frame_no(v = nil)
118
+
119
+ @str = nil
120
+ @query[:FrameNo] = escape(v)
121
+ self
122
+
123
+ end # frame_no
124
+
125
+ def vehicle_id(v = nil)
126
+
127
+ @str = nil
128
+ @query[:VehicleId] = escape(v)
129
+ self
130
+
131
+ end # vehicle_id
132
+
133
+ def category_id(v = nil)
134
+
135
+ @str = nil
136
+ @query[:CategoryId] = escape(v)
137
+ self
138
+
139
+ end # category_id
140
+
141
+ def unit_id(v = nil)
142
+
143
+ @str = nil
144
+ @query[:UnitId] = escape(v)
145
+ self
146
+
147
+ end # unit_id
148
+
149
+ def filter(v = nil)
150
+
151
+ @str = nil
152
+ @query[:Filter] = escape(v)
153
+ self
154
+
155
+ end # filter
156
+
157
+ def quick_group_id(v = nil)
158
+
159
+ @str = nil
160
+ @query[:QuickGroupId] = escape(v)
161
+ self
162
+
163
+ end # quick_group_id
164
+
165
+ def all(v = nil)
166
+
167
+ @str = nil
168
+ @query[:All] = (v === true || v == 1 || v == '1' ? 1 : 0)
169
+ self
170
+
171
+ end # all
172
+
173
+ def call(request)
174
+ request.call(self.to_s)
175
+ end # call
176
+
177
+ def to_s
178
+
179
+ return @str unless @str.nil?
180
+
181
+ @str = "#{@func_name}#{@locale}"
182
+
183
+ @query.each { |key, value|
184
+ @str << "|#{key}=#{value}" unless value.nil?
185
+ }
186
+
187
+ @str
188
+
189
+ end # to_s
190
+
191
+ alias :to_str :to_s
192
+
193
+ private
194
+
195
+ def escape(str)
196
+ str.nil? ? nil : ::String.new(str)
197
+ end # escape
198
+
199
+ end # Query
200
+
201
+ end # Laximo
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+ module Laximo
3
+
4
+ REQUEST_MSG = %q(<?xml version="1.0" encoding="UTF-8"?>
5
+ <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
6
+ xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
7
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
8
+ <SOAP-ENV:Body>
9
+ <ns5692:QueryData xmlns:ns5692="%{act}">
10
+ <request xsi:type="xsd:string">%{msg}</request>
11
+ </ns5692:QueryData>
12
+ </SOAP-ENV:Body>
13
+ </SOAP-ENV:Envelope>).freeze
14
+
15
+ class Request
16
+
17
+ def initialize(soap_endpoint, soap_action)
18
+
19
+ @soap_endpoint = soap_endpoint
20
+ @soap_action = soap_action
21
+
22
+ uri = URI(soap_endpoint)
23
+ @http = ::Net::HTTP.new(uri.host, uri.port)
24
+ @request = ::Net::HTTP::Post.new(uri.request_uri)
25
+
26
+ set_request_params
27
+ set_http_params
28
+
29
+ end # initialize
30
+
31
+ def call(msg)
32
+
33
+ @request.body = REQUEST_MSG % {
34
+ msg: msg,
35
+ act: @soap_action
36
+ }
37
+
38
+ begin
39
+ @http.request(@request)
40
+ rescue => ex
41
+ ex
42
+ end
43
+
44
+ end # call
45
+
46
+ private
47
+
48
+ def set_http_params
49
+
50
+ @http.set_debug_output($stdout) if ::Laximo.options.debug?
51
+
52
+ @http.use_ssl = ::Laximo.options.use_ssl
53
+ @http.key = ::Laximo.options.ssl_key
54
+ @http.cert = ::Laximo.options.ssl_cert
55
+ @http.verify_mode = ::Laximo.options.ssl_verify
56
+
57
+ @http.open_timeout = ::Laximo.options.timeout
58
+ @http.read_timeout = ::Laximo.options.timeout
59
+ @http.ssl_timeout = ::Laximo.options.timeout
60
+
61
+ self
62
+
63
+ end # set_http_params
64
+
65
+ def set_request_params
66
+
67
+ @request['User-Agent'] = ::Laximo.options.user_agent
68
+ @request['Accept'] = "*/*"
69
+ @request['Content-Type'] = "text/xml; charset=UTF-8"
70
+ @request['SOAPAction'] = "\"#{@soap_action}\""
71
+
72
+ self
73
+
74
+ end # set_request_params
75
+
76
+ end # Request
77
+
78
+ end # Laximo
@@ -0,0 +1,106 @@
1
+ # encoding: utf-8
2
+ module Laximo
3
+
4
+ module Respond
5
+
6
+ class Base
7
+
8
+ RESPONSE_PATH = '//QueryDataResponse/return'.freeze
9
+
10
+ def initialize(request)
11
+
12
+ @error = nil
13
+ @result = []
14
+
15
+ prepare_request(request)
16
+
17
+ end # initialize
18
+
19
+ def success?
20
+ @error.nil?
21
+ end # success?
22
+
23
+ def failure?
24
+ !@error.nil?
25
+ end # failure?
26
+
27
+ alias :error? :failure?
28
+
29
+ def error
30
+ @error
31
+ end # error
32
+
33
+ def result
34
+ @result
35
+ end # result
36
+
37
+ def parsing_result(str)
38
+ ::NotImplementedError.new("Метод `parsing_result` не реализован в классе #{self.class.name}")
39
+ end # parsing_result
40
+
41
+ private
42
+
43
+ def attrs_to_hash(node)
44
+
45
+ return {} if node.nil?
46
+
47
+ h = {}
48
+ node.attributes.each { |key, snd|
49
+ h[key.to_sym] = snd.value
50
+ }
51
+ h
52
+
53
+ end # attrs_to_hash
54
+
55
+ def prepare_request(request)
56
+
57
+ if request.is_a?(::Net::HTTPOK)
58
+ prepare_http(request)
59
+ else
60
+ prepare_error(request)
61
+ end
62
+
63
+ end # prepare_request
64
+
65
+ def prepare_error(err)
66
+
67
+ @result = []
68
+ @error = err
69
+
70
+ end # prepare_error
71
+
72
+ def prepare_http(http)
73
+
74
+ begin
75
+
76
+ doc = ::Nokogiri::XML(http.body)
77
+ doc.remove_namespaces!
78
+
79
+ res = doc.xpath(RESPONSE_PATH).children[0].to_s
80
+ str_to_xml_tags!(res)
81
+
82
+ @error = nil
83
+ @result = parsing_result(::Nokogiri::XML(res))
84
+
85
+ rescue => ex
86
+ prepare_error(ex)
87
+ end
88
+
89
+ end # prepare_http
90
+
91
+ def str_to_xml_tags!(str)
92
+
93
+ str.gsub!('&amp;', '&')
94
+ str.gsub!('&apos;', "'")
95
+ str.gsub!('&quot;', '"')
96
+ str.gsub!('&gt;', '>')
97
+ str.gsub!('&lt;', '<')
98
+ str
99
+
100
+ end # str_to_xml_tags!
101
+
102
+ end # Base
103
+
104
+ end # Respond
105
+
106
+ end # Laximo