Skip to content

Instantly share code, notes, and snippets.

@bananarne
Created May 2, 2018 09:52
Show Gist options
  • Save bananarne/257497128eb7959ec53acd1855c1d998 to your computer and use it in GitHub Desktop.
Save bananarne/257497128eb7959ec53acd1855c1d998 to your computer and use it in GitHub Desktop.
class MagentoConnector
attr_reader :client
attr_accessor :user_name, :user_password, :current_session_id
def initialize wsdl_url,user,pass
@client = Savon::Client.new(wsdl:wsdl_url)
@client.globals[:convert_request_keys_to] = :none
self.user_name = user
self.user_password = pass
login
end
def login
session = self.client.call(:login,message:{username:user_name,apiKey:user_password}).body[:login_response][:login_return]
raise StandardError.new unless session
self.current_session_id = session
end
def customers exclude_ids=[]
client.call(:customer_customer_list,message:{sessionId:current_session_id,filters:{complex_filter:{complexObjectArray:{key:'customer_id',value:{key:'nin',value:exclude_ids.join(',')}}}} }).body[:customer_customer_list_response][:store_view][:item]
end
def orders exclude_ids=[]
client.call(:sales_order_list,message:{sessionId:current_session_id,filters:{complex_filter:{complexObjectArray:[{key:'status',value:{key:'eq',value:'complete'}},{key:'order_id',value:{key:'nin',value:exclude_ids.join(',')}}]}} }).body[:sales_order_list_response][:result][:item]
end
def order_info order_inc_id
client.call(:sales_order_info,message:{sessionId:current_session_id,orderIncrementId:order_inc_id}).body[:sales_order_info_response][:result]
end
def products exclude_ids=[]
client.call(:catalog_product_list,message:{sessionId:current_session_id,filters:{complex_filter:{complexObjectArray:[{key:'product_id',value:{key:'nin',value:exclude_ids.join(',')}}]}} }).body[:catalog_product_list_response][:store_view][:item]
end
def categories exclude_ids=[]
client.call(:catalog_category_tree,message:{sessionId:current_session_id,filters:{} }).body[:catalog_category_tree_response][:tree]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment