lib/gotransverse-tract-api.rb in gotransverse-tract-api-0.1.12 vs lib/gotransverse-tract-api.rb in gotransverse-tract-api-0.2.0

- old
+ new

@@ -18,21 +18,28 @@ require "gotransverse-tract-api/general/system_setting" require "gotransverse-tract-api/general_ledger/general_ledger" require "gotransverse-tract-api/general_ledger/gl_account" require "gotransverse-tract-api/general_ledger/gl_account_category" +require "gotransverse-tract-api/general_ledger/gl_accounting_transaction" +require "gotransverse-tract-api/general_ledger/gl_adjustment_accounting_transaction" require "gotransverse-tract-api/general_ledger/gl_accounting_entry" require "gotransverse-tract-api/general_ledger/gl_aggregate_batch" require "gotransverse-tract-api/general_ledger/gl_aggregate_entry" +require "gotransverse-tract-api/general_ledger/gl_invoice_accounting_transaction" +require "gotransverse-tract-api/general_ledger/gl_payment_accounting_transaction" +require "gotransverse-tract-api/general_ledger/gl_transaction_batch" +require "gotransverse-tract-api/order/adjustment_category" require "gotransverse-tract-api/order/agreement" require "gotransverse-tract-api/order/bill_cycle" require "gotransverse-tract-api/order/billing_account_category" require "gotransverse-tract-api/order/order_item" require "gotransverse-tract-api/order/order_item_charge" require "gotransverse-tract-api/order/organization" require "gotransverse-tract-api/order/party_category" +require "gotransverse-tract-api/order/payment_term" require "gotransverse-tract-api/order/people" require "gotransverse-tract-api/order/product_relation" require "gotransverse-tract-api/order/renewal_order" require "gotransverse-tract-api/order/sales_order" @@ -47,10 +54,11 @@ require "gotransverse-tract-api/product/operation" require "gotransverse-tract-api/product/operation_attribute" require "gotransverse-tract-api/product/price_list" require "gotransverse-tract-api/product/product_price_range" require "gotransverse-tract-api/product/product" +require "gotransverse-tract-api/product/product_tag" require "gotransverse-tract-api/product/product_category" require "gotransverse-tract-api/product/product_price" require "gotransverse-tract-api/product/one_time_product_price" require "gotransverse-tract-api/product/product_tag" require "gotransverse-tract-api/product/recurring_product_price" @@ -126,37 +134,37 @@ if GoTransverseTractApi.configuration.cache_enabled return self.get_cached_response_from(klass, api_params) end # Unless cached - self.call(api_url, api_params, :get) + self.call(klass, api_url, api_params, :get) end # # self.post_request_for # # @param {Class} klass # @param {Hash} api_params (optional) - # @param {String} request_body + # @param {Hash} request_body # @param {String} command # def self.post_request_for(klass, api_params={}, request_body, command) api_url = GoTransverseTractApi.get_api_url_for(klass) api_url = "#{api_url}/#{command}" - self.call(api_url, api_params, :post, request_body) + self.call(klass, api_url, api_params, :post, request_body.to_xml) end # # self.put_request_for # # @param {Class} klass # @param {Hash} api_params (optional) - # @param {String} request_body + # @param {Hash} request_body # def self.put_request_for(klass, api_params={}, request_body) api_url = GoTransverseTractApi.get_api_url_for(klass) - self.call(api_url, api_params, :put, request_body) + self.call(klass, api_url, api_params, :put, request_body.to_xml) end private # @@ -176,16 +184,17 @@ end # # self.call # + # @param {Class} klass # @param {String} api_url # @param {Hash} api_params (optional) # @param {String} method (optional) # @param {String} request_body (optional, put/post requests only) # - def self.call(api_url, api_params={}, method=:get, request_body="") + def self.call(klass, api_url, api_params={}, method=:get, request_body="") # Camelize parameters api_params = camelize_keys(api_params) http_client = HTTPClient.new @@ -198,10 +207,16 @@ response = http_client.post(api_url, request_body, api_params) when :put response = http_client.put(api_url, request_body, api_params) end - Nokogiri::XML(response.body.to_s) + xml_response = Nokogiri::XML(response.body.to_s) + + klass = klass.to_s.split("::").last + hsh = Hash.from_xml(xml_response.to_s) + + hsh = hsh[klass.pluralize.camelize(:lower)][klass.camelize(:lower)] rescue Hash.from_xml(xml_response.to_s)[klass.camelize(:lower)] + return hsh end # # self.camelize_keys #