Class: BigMachines::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/big_machines/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site_name, options = {}) ⇒ Client

The partner.wsdl is used by default but can be changed by passing in a new :wsdl option. A client_id can be



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Supports the following No Argument methods:


logout


229
230
231
232
233
234
235
# 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

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/big_machines/client.rb', line 4

def client
  @client
end

#headers(type = :security) ⇒ Object (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/big_machines/client.rb', line 5

def headers
  @headers
end

Instance Method Details

#delete_attachment(transaction_id, variable_name, document_number: 1) ⇒ Object

Deletes the file associated with the specified field in BigMachines.



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# 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

#get_attachment(transaction_id, variable_name, document_number: 1, mode: "content", inline: true) ⇒ Object

Returns a single BigMachines::Attachment based on the variable_name provided.



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# 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

#get_transaction(id, document_var_name = 'quote_process') ⇒ Object

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>



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# 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

#login(username, password) ⇒ Object Also known as: authenticate

Public: login

Examples

client.(username, password)
# => {...}

Returns Hash of login response and user info



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/big_machines/client.rb', line 66

def (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

#operationsObject

Public: Get the names of all wsdl operations. List all available operations from the partner.wsdl



54
55
56
# File 'lib/big_machines/client.rb', line 54

def operations
  @client.operations
end

#set_session_currency(currency) ⇒ Object



81
82
83
# File 'lib/big_machines/client.rb', line 81

def set_session_currency(currency)
  security_call(:set_session_currency, sessionCurrency: currency)
end

#update_transaction(id, data = {}) ⇒ Object

<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>



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# 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

#upload_attachment(transaction_id, file, variable_name, document_number: 1) ⇒ Object

Uploads a single file to the specified field in BigMachines



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# 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