Created
February 11, 2014 19:41
-
-
Save amiel/8942571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Navision | |
class ItemGateway | |
def initialize(options = {}) | |
@client = options.fetch(:client) { Navision.item_client } # item_client => Savon.client(...) | |
end | |
def get_product_by_number(number) | |
get_result client.call :read, message: { 'No' => number } | |
end | |
private | |
attr_reader :client | |
def get_result(response) | |
body = response.body || {} | |
result = body.fetch(:read_result) { {} } | |
result.fetch(:website_items) { {} } | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Navision | |
class ItemVariantMapper | |
def initialize(variant, options = {}) | |
@variant = variant | |
@gateway = options.fetch(:gateway) { Navision.item_gateway } | |
end | |
def to_variant | |
Variant.new(navision_key, msrp, dimensions, weight) # Variant is a Struct | |
end | |
private | |
attr_reader :variant, :gateway | |
delegate :mpn, to: :variant | |
def gateway_attributes | |
@_gateway_attributes ||= gateway.get_product_by_number mpn | |
end | |
def navision_key | |
gateway_attributes[:key] | |
end | |
def msrp | |
gateway_attributes[:msrp] | |
end | |
def dimensions | |
dims = gateway_attributes.values_at(:item_uom_length, :item_uom_width, :item_uom_height) | |
dims.join('x') if dims.all? | |
end | |
def weight | |
gateway_attributes[:item_uom_weight] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment