lib/securetrading/connection.rb in securetrading-0.1.0 vs lib/securetrading/connection.rb in securetrading-0.2.0

- old
+ new

@@ -11,16 +11,46 @@ 'User-Agent' => 'Securetrading Ruby gem; '\ "version: #{Securetrading::VERSION}", 'Connection' => 'close' ) - def post_with(xml, options = {}) - self.class.post('/', options.merge(body: xml, headers: dynamic_headers)) + def to_xml + Ox.dump(ox_xml) end private + def doc + @doc ||= XmlDoc.new(request_type, @account_type).doc + end + + def request_type + fail NotImplementedError, 'Implement :request_type method in subclas!' + end + + def ox_xml + fail NotImplementedError, 'Implement :ox_xml method in subclas!' + end + + def perform_with(method, xml, options = {}) + self.class.public_send(method, + '/', + options.merge(body: xml, + headers: dynamic_headers)) + end + def dynamic_headers { 'Authorization' => "Basic #{Securetrading.config.auth}" } + end + + def prepare_doc + return doc if xml_prepared? + yield + @xml_prepared = true + doc + end + + def xml_prepared? + @xml_prepared end end end