Class: AcumenClient

Inherits:
Object
  • Object
show all
Defined in:
lib/huginn_acumen_product_agent/acumen_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(faraday, auth) ⇒ AcumenClient

Returns a new instance of AcumenClient.



5
6
7
8
# File 'lib/huginn_acumen_product_agent/acumen_client.rb', line 5

def initialize(faraday, auth)
  @faraday = faraday
  @auth = auth
end

Instance Method Details

#execute_in_list_query(body, headers) ⇒ Object



52
53
54
55
# File 'lib/huginn_acumen_product_agent/acumen_client.rb', line 52

def execute_in_list_query(body, headers)
    response = @faraday.run_request(:post, "#{@auth['endpoint']}/QueryByInList", body, headers)
    ::MultiXml.parse(response.body, {})
end

#execute_query(body, headers) ⇒ Object



47
48
49
50
# File 'lib/huginn_acumen_product_agent/acumen_client.rb', line 47

def execute_query(body, headers)
    response = @faraday.run_request(:post, "#{@auth['endpoint']}/Query", body, headers)
    ::MultiXml.parse(response.body, {})
end

#get_contributor_types(ids) ⇒ Object



34
35
36
37
38
# File 'lib/huginn_acumen_product_agent/acumen_client.rb', line 34

def get_contributor_types(ids)
  body = build_product_contributor_type_query(ids)
  response = execute_in_list_query(body, {})
  get_results(response, 'ProdMkt_Contributor')
end

#get_linked_products(ids) ⇒ Object



22
23
24
25
26
# File 'lib/huginn_acumen_product_agent/acumen_client.rb', line 22

def get_linked_products(ids)
    body = build_linked_product_query(ids)
    response = execute_in_list_query(body, {})
    get_results(response, 'Product_Link')
end

#get_product_categories(skus) ⇒ Object



40
41
42
43
44
# File 'lib/huginn_acumen_product_agent/acumen_client.rb', line 40

def get_product_categories(skus)
    q = build_product_categories_query(skus)
    response = execute_in_list_query(q, {})
    get_results(response, 'ProdMkt_WPC')
end

#get_product_contributors(ids) ⇒ Object



28
29
30
31
32
# File 'lib/huginn_acumen_product_agent/acumen_client.rb', line 28

def get_product_contributors(ids)
    body = build_product_contributor_link_query(ids)
    response = execute_in_list_query(body, {})
    get_results(response, 'ProdMkt_Contrib_Link')
end

#get_products(ids) ⇒ Object



10
11
12
13
14
# File 'lib/huginn_acumen_product_agent/acumen_client.rb', line 10

def get_products(ids)
    body = build_product_request(ids)
    response = execute_in_list_query(body, {})
    get_results(response, 'Inv_Product')
end

#get_products_marketing(ids) ⇒ Object



16
17
18
19
20
# File 'lib/huginn_acumen_product_agent/acumen_client.rb', line 16

def get_products_marketing(ids)
    body = build_product_marketing_query(ids)
    response = execute_in_list_query(body, {})
    get_results(response, 'ProdMkt')
end

#get_results(response, name) ⇒ Object



57
58
59
60
61
# File 'lib/huginn_acumen_product_agent/acumen_client.rb', line 57

def get_results(response, name)
    result_set = response['Envelope']['Body']['acusoapResponse']['result_set.' + name]
    results = result_set.nil? ? [] : result_set[name]
    results.is_a?(Array) ? results : [results]
end