class BigMachines::Client
Attributes
Public Class Methods
The partner.wsdl is used by default but can be changed by passing in a new :wsdl option. A client_id can be
# File lib/big_machines/client.rb, line 9 def initialize(site_name, options={}) @site_name = site_name raise "Valid Site Name must be provided" if @site_name.nil? || @site_name.empty? @process_var_name = options[:process_name] || "quotes_process" @logger = options[:logger] || false @namespaces = { "xmlns:bm" => "urn:soap.bigmachines.com" } @security_wsdl = File.dirname(__FILE__) + "/../../resources/security.wsdl.xml" @commerce_wsdl = File.dirname(__FILE__) + "/../../resources/commerce.wsdl.xml" @endpoint = "https://#{@site_name}.bigmachines.com/v1_0/receiver" @client = Savon.client(configuration) end
Public Instance Methods
Deletes the file associated with the specified field in BigMachines
.
# File lib/big_machines/client.rb, line 209 def delete_attachment(transaction_id, variable_name, document_number: 1) delete = { mode: 'delete', attachments: { attachment: { document_number: document_number, variable_name: variable_name } }, transaction: { process_var_name: @process_var_name, id: transaction_id } } commerce_call(:import_file_attachments, delete) end
Returns a single BigMachines::Attachment
based on the variable_name provided.
# File lib/big_machines/client.rb, line 160 def get_attachment(transaction_id, variable_name, document_number: 1, mode: "content", inline: true) export = { mode: mode, inline: inline, attachments: { attachment: { document_number: document_number, variable_name: variable_name } }, transaction: { process_var_name: @process_var_name, id: transaction_id } } result = commerce_call(:export_file_attachments, export) attachments = [] result["attachments"].each do |key, data| attachments << BigMachines::Attachment.new(data) end attachments end
Commerce API
<bm:getTransaction xmlns:bm=“urn:soap.bigmachines.com” xmlns:xsi=“www.w3.org/2001/XMLSchema-instance”>
<bm:transaction> <bm:id/> <bm:return_specific_attributes> <bm:documents> <bm:document> <bm:var_name>quote_process</bm:var_name> <bm:attributes> <bm:attribute>_document_number</bm:attribute> </bm:attributes> </bm:document> </bm:documents> </bm:return_specific_attributes> </bm:transaction>
</bm:getTransaction>
# File lib/big_machines/client.rb, line 102 def get_transaction(id, document_var_name='quote_process') transaction = { transaction: { id: id, return_specific_attributes: { documents: { document: { var_name: document_var_name } } } } } result = commerce_call(:get_transaction, transaction) BigMachines::Transaction.new(result) end
Public: login
Examples
client.login(username, password) # => {...}
Returns Hash of login response and user info
# File lib/big_machines/client.rb, line 66 def login(username, password) result = nil message = {userInfo: {username: username, password: password}} response = self.security_call(:login, message) userInfo = response["userInfo"] @session_id = userInfo["sessionId"] @security_client = Savon.client(configuration) response["status"]["success"] end
Supports the following No Argument methods:
get_user_info logout
# File lib/big_machines/client.rb, line 229 def method_missing(method, *args) if [:get_user_info, :logout].include?(method) call_soap_api(security_client, method, *args) else super end end
Public: Get the names of all wsdl operations. List all available operations from the partner.wsdl
# File lib/big_machines/client.rb, line 54 def operations @client.operations end
# File lib/big_machines/client.rb, line 81 def set_session_currency(currency) security_call(:set_session_currency, sessionCurrency: currency) end
<bm:updateTransaction xmlns:bm=“urn:soap.bigmachines.com” xmlns:xsi=“www.w3.org/2001/XMLSchema-instance”>
<bm:transaction> <bm:id>26539349</bm:id> <bm:data_xml> <bm:quote_process bm:bs_id="26539349" bm:data_type="0" bm:document_number="1"> <bm:opportunityName_quote>Test Oppty Auto Approval TinderBox</bm:opportunityName_quote> <bm:siteName_quote>MY DUMMY SITE</bm:siteName_quote> </bm:quote_process> </bm:data_xml> <bm:action_data> <bm:action_var_name>_update_line_items</bm:action_var_name> </bm:action_data> </bm:transaction>
</bm:updateTransaction>
# File lib/big_machines/client.rb, line 134 def update_transaction(id, data={}) # :opportunityName_quote => 'Test Oppty Auto Approval TinderBox 12', # :siteName_quote => 'My Dummy Site' quote_process_data = { :"@bs_id" => id, :"@data_type" => 0, :"@document_number" => 1 }.merge(data) transaction = { transaction: { id: id, data_xml: { quote_process: quote_process_data }, action_data: { action_var_name: '_update_line_items' } } } commerce_call(:update_transaction, transaction) end
Uploads a single file to the specified field in BigMachines
# File lib/big_machines/client.rb, line 188 def upload_attachment(transaction_id, file, variable_name, document_number: 1) import = { mode: 'update', attachments: { attachment: { document_number: document_number, variable_name: variable_name, filename: file.path, file_content: Base64.strict_encode64(file.read) } }, transaction: { process_var_name: @process_var_name, id: transaction_id } } commerce_call(:import_file_attachments, import) end
Protected Instance Methods
# File lib/big_machines/client.rb, line 274 def call_soap_api(client, method, message={}) response = client.call(method.to_sym, message: message) # Convert SOAP XML to Hash response = response.to_hash # Get Response Body key = method.to_s.gsub(/_(\w)/) {|x| x[1].upcase } response = response["#{key}Response"] # Raise error when response contains errors if response.is_a?(Hash) && response["status"] && response["status"]["success"] == false raise Savon::Error.new(response["status"]["message"]) end return response end
# File lib/big_machines/client.rb, line 261 def client_api(wsdl) category = wsdl.include?('security') ? :security : :commerce client = Savon.client(configuration(wsdl: wsdl, soap_header: headers(category))) end
# File lib/big_machines/client.rb, line 270 def commerce_call(method, message_hash={}) call_soap_api(commerce_client, method, message_hash) end
# File lib/big_machines/client.rb, line 253 def commerce_client @commerce_client ||= client_api(@commerce_wsdl) end
# File lib/big_machines/client.rb, line 239 def configuration(custom={}) { wsdl: @security_wsdl, endpoint: @endpoint, soap_header: headers(:security), filters: [:password], convert_request_keys_to: :none, convert_response_tags_to: lambda { |tag| tag }, pretty_print_xml: true, logger: @logger, log: @logger != false }.merge(custom) end
# File lib/big_machines/client.rb, line 266 def security_call(method, message_hash={}) call_soap_api(security_client, method, message_hash) end
# File lib/big_machines/client.rb, line 257 def security_client @security_client ||= client_api(@security_wsdl) end