fishbowl 0.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +9 -4
- data/Gemfile +9 -2
- data/Guardfile +13 -0
- data/README.md +25 -5
- data/fishbowl.gemspec +5 -5
- data/lib/fishbowl/configuration.rb +9 -0
- data/lib/fishbowl/connection.rb +100 -0
- data/lib/fishbowl/errors.rb +18 -8
- data/lib/fishbowl/ext.rb +15 -0
- data/lib/fishbowl/objects/account.rb +8 -12
- data/lib/fishbowl/objects/address.rb +86 -0
- data/lib/fishbowl/objects/base_object.rb +42 -9
- data/lib/fishbowl/objects/carrier.rb +15 -0
- data/lib/fishbowl/objects/carton.rb +54 -0
- data/lib/fishbowl/objects/uom.rb +47 -0
- data/lib/fishbowl/objects/user.rb +15 -0
- data/lib/fishbowl/objects.rb +5 -0
- data/lib/fishbowl/requests/add_inventory.rb +34 -0
- data/lib/fishbowl/requests/add_sales_order_item.rb +42 -0
- data/lib/fishbowl/requests/adjust_inventory.rb +28 -0
- data/lib/fishbowl/requests/get_account_balance.rb +15 -0
- data/lib/fishbowl/requests/get_account_list.rb +13 -0
- data/lib/fishbowl/requests/get_carrier_list.rb +14 -0
- data/lib/fishbowl/requests/get_customer_list.rb +12 -0
- data/lib/fishbowl/requests/get_customer_name_list.rb +12 -0
- data/lib/fishbowl/requests/get_export_list.rb +12 -0
- data/lib/fishbowl/requests/get_import_list.rb +12 -0
- data/lib/fishbowl/requests/get_location_group_list.rb +12 -0
- data/lib/fishbowl/requests/get_location_list.rb +12 -0
- data/lib/fishbowl/requests/get_product.rb +18 -0
- data/lib/fishbowl/requests/get_product_price.rb +21 -0
- data/lib/fishbowl/requests/get_uom_list.rb +12 -0
- data/lib/fishbowl/requests/get_vendor_list.rb +12 -0
- data/lib/fishbowl/requests/get_vendor_name_list.rb +12 -0
- data/lib/fishbowl/requests/get_work_order_list.rb +12 -0
- data/lib/fishbowl/requests/inventory_quantity.rb +17 -0
- data/lib/fishbowl/requests/load_sales_order.rb +21 -0
- data/lib/fishbowl/requests/make_payment.rb +32 -0
- data/lib/fishbowl/requests/save_sales_order.rb +86 -0
- data/lib/fishbowl/requests/total_inventory.rb +18 -0
- data/lib/fishbowl/requests/void_sales_order.rb +18 -0
- data/lib/fishbowl/requests.rb +5 -0
- data/lib/fishbowl/version.rb +1 -1
- data/lib/fishbowl.rb +12 -95
- data/lib/status_codes.yml +183 -0
- data/spec/connection_spec.rb +99 -99
- data/spec/errors_spec.rb +11 -9
- data/spec/examples/account.xml +6 -0
- data/spec/examples/address.xml +30 -0
- data/spec/examples/carrier.xml +3 -0
- data/spec/examples/carton.xml +93 -0
- data/spec/examples/contact_information.xml +5 -0
- data/spec/examples/contacts.xml +7 -0
- data/spec/examples/credit_card.xml +10 -0
- data/spec/examples/customer.xml +54 -0
- data/spec/examples/location.xml +14 -0
- data/spec/examples/location_group.xml +5 -0
- data/spec/examples/location_group_string.xml +1 -0
- data/spec/examples/order_history.xml +8 -0
- data/spec/examples/part.xml +105 -0
- data/spec/examples/payment.xml +6 -0
- data/spec/examples/pick.xml +265 -0
- data/spec/examples/pick_item.xml +236 -0
- data/spec/examples/product.xml +159 -0
- data/spec/examples/purchase_order.xml +53 -0
- data/spec/examples/receipt.xml +146 -0
- data/spec/examples/report.xml +10 -0
- data/spec/examples/report_tree.xml +7 -0
- data/spec/examples/sales_order.xml +47 -0
- data/spec/examples/sales_order_item.xml +32 -0
- data/spec/examples/shipping.xml +127 -0
- data/spec/examples/tag.xml +28 -0
- data/spec/examples/tax_rate.xml +10 -0
- data/spec/examples/tracking.xml +14 -0
- data/spec/examples/tracking_item.xml +12 -0
- data/spec/examples/transfer_order.xml +257 -0
- data/spec/examples/transfer_order_item.xml +147 -0
- data/spec/examples/uom.xml +26 -0
- data/spec/examples/uom_conversion.xml +8 -0
- data/spec/examples/user.xml +8 -0
- data/spec/examples/vendor.xml +19 -0
- data/spec/examples/vendor_part_number.xml +3 -0
- data/spec/examples/work_order.xml +228 -0
- data/spec/examples/work_order_item.xml +172 -0
- data/spec/objects/account_spec.rb +33 -27
- data/spec/objects/address_information_spec.rb +18 -0
- data/spec/objects/address_spec.rb +36 -0
- data/spec/objects/base_object_spec.rb +67 -23
- data/spec/objects/carrier_spec.rb +15 -0
- data/spec/objects/carton_spec.rb +23 -0
- data/spec/objects/country_spec.rb +16 -0
- data/spec/objects/shipping_item_spec.rb +21 -0
- data/spec/objects/state_spec.rb +17 -0
- data/spec/objects/uom_conversion_spec.rb +20 -0
- data/spec/objects/uom_spec.rb +20 -0
- data/spec/objects/user_spec.rb +20 -0
- data/spec/requests/add_inventory_spec.rb +79 -0
- data/spec/requests/add_sales_order_item_spec.rb +85 -0
- data/spec/requests/adjust_inventory_spec.rb +62 -0
- data/spec/requests/calculate_sales_order_spec.rb +48 -0
- data/spec/requests/close_short_sales_order_spec.rb +45 -0
- data/spec/requests/cycle_count_spec.rb +49 -0
- data/spec/requests/delete_sales_order_spec.rb +45 -0
- data/spec/requests/export_spec.rb +45 -0
- data/spec/requests/get_account_balance_spec.rb +52 -0
- data/spec/requests/get_account_list_spec.rb +51 -0
- data/spec/requests/get_carrier_list_spec.rb +54 -0
- data/spec/requests/get_customer_list_spec.rb +51 -0
- data/spec/requests/get_customer_name_list_spec.rb +45 -0
- data/spec/requests/get_customer_spec.rb +45 -0
- data/spec/requests/get_export_list_spec.rb +45 -0
- data/spec/requests/get_import_list_spec.rb +45 -0
- data/spec/requests/get_inventory_quantity_spec.rb +65 -0
- data/spec/requests/get_light_part_list_spec.rb +51 -0
- data/spec/requests/get_location_group_list_spec.rb +45 -0
- data/spec/requests/get_location_list_spec.rb +45 -0
- data/spec/requests/get_next_number_spec.rb +45 -0
- data/spec/requests/get_part_cost_spec.rb +45 -0
- data/spec/requests/get_part_information_spec.rb +45 -0
- data/spec/requests/get_part_list_spec.rb +65 -0
- data/spec/requests/get_pick_spec.rb +45 -0
- data/spec/requests/get_product_information_spec.rb +46 -0
- data/spec/requests/get_purchase_order_list_spec.rb +45 -0
- data/spec/requests/get_receipt_spec.rb +49 -0
- data/spec/requests/get_receiving_list_spec.rb +49 -0
- data/spec/requests/get_sales_order_list_spec.rb +49 -0
- data/spec/requests/get_ship_list_spec.rb +49 -0
- data/spec/requests/get_ship_now_list_spec.rb +48 -0
- data/spec/requests/get_shipment_spec.rb +45 -0
- data/spec/requests/get_system_property_spec.rb +45 -0
- data/spec/requests/get_total_inventory_spec.rb +46 -0
- data/spec/requests/get_transfer_order_list_spec.rb +45 -0
- data/spec/requests/get_uom_list_spec.rb +45 -0
- data/spec/requests/get_user_property_spec.rb +45 -0
- data/spec/requests/get_vendor_list_spec.rb +45 -0
- data/spec/requests/get_vendor_name_list_spec.rb +45 -0
- data/spec/requests/get_vendor_spec.rb +48 -0
- data/spec/requests/get_work_order_list_spec.rb +45 -0
- data/spec/requests/get_work_order_spec.rb +45 -0
- data/spec/requests/import_spec.rb +49 -0
- data/spec/requests/issues_sales_order_spec.rb +45 -0
- data/spec/requests/load_sales_order_spec.rb +45 -0
- data/spec/requests/load_transfer_order_spec.rb +45 -0
- data/spec/requests/location_query_spec.rb +49 -0
- data/spec/requests/make_payment_spec.rb +50 -0
- data/spec/requests/move_spec.rb +49 -0
- data/spec/requests/part_query_spec.rb +46 -0
- data/spec/requests/pick_query_spec.rb +49 -0
- data/spec/requests/print_report_spec.rb +48 -0
- data/spec/requests/product_query_spec.rb +46 -0
- data/spec/requests/quick_ship_spec.rb +45 -0
- data/spec/requests/quickbooks_export_spec.rb +43 -0
- data/spec/requests/save_customer_spec.rb +48 -0
- data/spec/requests/save_discount_spec.rb +48 -0
- data/spec/requests/save_pick_spec.rb +48 -0
- data/spec/requests/save_purchase_order_spec.rb +48 -0
- data/spec/requests/save_receipt_spec.rb +48 -0
- data/spec/requests/save_report_spec.rb +49 -0
- data/spec/requests/save_sales_order_spec.rb +48 -0
- data/spec/requests/save_shipment_spec.rb +48 -0
- data/spec/requests/save_tax_rate_spec.rb +48 -0
- data/spec/requests/save_transfer_order_spec.rb +48 -0
- data/spec/requests/save_upc_spec.rb +48 -0
- data/spec/requests/save_vendor_spec.rb +48 -0
- data/spec/requests/save_work_order_spec.rb +48 -0
- data/spec/requests/set_default_part_location_spec.rb +48 -0
- data/spec/requests/set_system_property_spec.rb +48 -0
- data/spec/requests/set_user_property_spec.rb +48 -0
- data/spec/requests/ship_spec.rb +48 -0
- data/spec/requests/void_sales_order_spec.rb +43 -0
- data/spec/spec_helper.rb +48 -16
- data/spec/support/examples_loader.rb +5 -0
- data/spec/support/response_mocks.rb +27 -0
- metadata +304 -35
- data/spec/support/fake_login.rb +0 -15
@@ -0,0 +1,42 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.add_sales_order_item(options = {})
|
3
|
+
options = options.symbolize_keys
|
4
|
+
|
5
|
+
%w{order_number id product_number sales_order_id description taxable
|
6
|
+
quantity product_price total_price uom_code item_type status
|
7
|
+
quickbooks_class_name new_item_flag}.each do |required_field|
|
8
|
+
raise ArgumentError if options[required_field.to_sym].nil?
|
9
|
+
end
|
10
|
+
|
11
|
+
request = format_add_sales_order_item_request(options)
|
12
|
+
Fishbowl::Objects::BaseObject.new.send_request(request, 'AddSOItemRs')
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.format_add_sales_order_item_request(options)
|
18
|
+
Nokogiri::XML::Builder.new do |xml|
|
19
|
+
xml.request {
|
20
|
+
xml.AddSOItemRq {
|
21
|
+
xml.OrderNum options[:order_number]
|
22
|
+
xml.SalesOrderItem {
|
23
|
+
xml.ID options[:id]
|
24
|
+
xml.ProductNumber options[:product_number]
|
25
|
+
xml.SOID options[:sales_order_id]
|
26
|
+
xml.Description options[:description]
|
27
|
+
xml.Taxable options[:taxable]
|
28
|
+
xml.Quantity options[:quantity]
|
29
|
+
xml.ProductPrice options[:product_price]
|
30
|
+
xml.TotalPrice options[:total_price]
|
31
|
+
xml.UOMCode options[:uom_code]
|
32
|
+
xml.ItemType options[:item_type]
|
33
|
+
xml.Status options[:status]
|
34
|
+
xml.QuickBooksClassName options[:quickbooks_class_name]
|
35
|
+
xml.NewItemFlag options[:new_item_flag]
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.adjust_inventory(options = {})
|
3
|
+
options = options.symbolize_keys
|
4
|
+
|
5
|
+
%w{tag_number quantity}.each do |required_field|
|
6
|
+
raise ArgumentError if options[required_field.to_sym].nil?
|
7
|
+
end
|
8
|
+
|
9
|
+
raise ArgumentError unless options[:tracking].nil? || options[:tracking].is_a?(Fishbowl::Object::Tracking)
|
10
|
+
|
11
|
+
request = format_adjust_inventory_request(options)
|
12
|
+
Fishbowl::Objects::BaseObject.new.send_request(request, 'AdjustInventoryRs')
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.format_adjust_inventory_request(options)
|
18
|
+
Nokogiri::XML::Builder.new do |xml|
|
19
|
+
xml.request {
|
20
|
+
xml.AdjustInventoryRq {
|
21
|
+
xml.TagNum options[:tag_number]
|
22
|
+
xml.Quantity options[:quantity]
|
23
|
+
xml.Tracking options[:tracking] unless options[:tracking].nil?
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_account_balance(account_name)
|
3
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
4
|
+
xml.request {
|
5
|
+
xml.GetAccountBalanceRq {
|
6
|
+
xml.Account (account.is_a?(Account) ? account.name : account)
|
7
|
+
}
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request(builder, "GetAccountBalanceRs")
|
12
|
+
|
13
|
+
response.xpath("//Account/Balance").first.inner_text
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_account_list
|
3
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request('GetAccountListRq', 'GetAccountListRs')
|
4
|
+
|
5
|
+
results = []
|
6
|
+
|
7
|
+
response.xpath("//Account").each do |account_xml|
|
8
|
+
results << Account.new(account_xml)
|
9
|
+
end
|
10
|
+
|
11
|
+
results
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_carrier_list
|
3
|
+
puts "getting carriers"
|
4
|
+
code, response = Fishbowl::Objects::BaseObject.new.send_request('CarrierListRq', 'FbiMsgsRs/CarrierListRs')
|
5
|
+
|
6
|
+
results = []
|
7
|
+
|
8
|
+
response.xpath("//Carriers/Name").each do |carrier_xml|
|
9
|
+
results << Fishbowl::Objects::Carrier.new(carrier_xml)
|
10
|
+
end
|
11
|
+
|
12
|
+
results
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_customer_list
|
3
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request('CustomerListRq', 'CustomerListRs')
|
4
|
+
|
5
|
+
results = []
|
6
|
+
response.xpath("//Customer").each do |customer_xml|
|
7
|
+
results << Fishbowl::Objects::Customer.new(customer_xml)
|
8
|
+
end
|
9
|
+
|
10
|
+
results
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_customer_name_list
|
3
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request('CustomerNameListRq', 'CustomerNameListRs')
|
4
|
+
|
5
|
+
results = []
|
6
|
+
response.xpath("//Customer/Name").each do |customer_xml|
|
7
|
+
results << customer_xml.inner_text
|
8
|
+
end
|
9
|
+
|
10
|
+
results
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_export_list
|
3
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request('ExportListRq', 'ExportListRs')
|
4
|
+
|
5
|
+
results = []
|
6
|
+
#response.xpath("//Customer/Name").each do |customer_xml|
|
7
|
+
# results << customer_xml.inner_text
|
8
|
+
#end
|
9
|
+
|
10
|
+
results
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_import_list
|
3
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request('ImportListRq', 'ImportListRs')
|
4
|
+
|
5
|
+
results = []
|
6
|
+
#response.xpath("//Customer/Name").each do |customer_xml|
|
7
|
+
# results << customer_xml.inner_text
|
8
|
+
#end
|
9
|
+
|
10
|
+
results
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_location_group_list
|
3
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request('LocationGroupRq', 'LocationGroupRs')
|
4
|
+
|
5
|
+
results = []
|
6
|
+
#response.xpath("//Customer/Name").each do |customer_xml|
|
7
|
+
# results << customer_xml.inner_text
|
8
|
+
#end
|
9
|
+
|
10
|
+
results
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_location_list
|
3
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request('LocationListRq', 'LocationListRs')
|
4
|
+
|
5
|
+
results = []
|
6
|
+
#response.xpath("//Customer/Name").each do |customer_xml|
|
7
|
+
# results << customer_xml.inner_text
|
8
|
+
#end
|
9
|
+
|
10
|
+
results
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_product(product_number)
|
3
|
+
raise ArgumentError if product_number.nil?
|
4
|
+
|
5
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
6
|
+
xml.request {
|
7
|
+
xml.ProductGetRq {
|
8
|
+
xml.Number product_number
|
9
|
+
xml.GetImage false
|
10
|
+
}
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
code, response = Fishbowl::Objects::BaseObject.new.send_request(builder, "ProductGetRs")
|
15
|
+
|
16
|
+
response.xpath("//FbiXml/FbiMsgsRs/ProductGetRs/Product")
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_product_price(options)
|
3
|
+
options.symbolize_keys
|
4
|
+
|
5
|
+
%w{product_number customer_name qauntity date}.each do |required_field|
|
6
|
+
raise ArgumentError if options[required_field.to_sym].nil?
|
7
|
+
end
|
8
|
+
|
9
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
10
|
+
xml.request {
|
11
|
+
xml.ProductPriceRq {
|
12
|
+
xml.ProductNumber
|
13
|
+
}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request(builder, "GetAccountBalanceRs")
|
18
|
+
|
19
|
+
response.xpath("//Account/Balance").first.inner_text
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_uom_list
|
3
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request('UOMRq', 'UOMRs')
|
4
|
+
|
5
|
+
results = []
|
6
|
+
response.xpath("//UOM").each do |uom_xml|
|
7
|
+
results << Fishbowl::Objects::UOM.new(uom_xml)
|
8
|
+
end
|
9
|
+
|
10
|
+
results
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_location_group_list
|
3
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request('VendorListRq', 'VendorListRs')
|
4
|
+
|
5
|
+
results = []
|
6
|
+
response.xpath("//Vendor").each do |vendor_xml|
|
7
|
+
results << Fishbowl::Objects::Vendor.new(vendor_xml)
|
8
|
+
end
|
9
|
+
|
10
|
+
results
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_location_group_list
|
3
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request('VendorNameListRq', 'VendorNameListRs')
|
4
|
+
|
5
|
+
results = []
|
6
|
+
#response.xpath("//Customer/Name").each do |customer_xml|
|
7
|
+
# results << customer_xml.inner_text
|
8
|
+
#end
|
9
|
+
|
10
|
+
results
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.get_work_order_list
|
3
|
+
_, _, response = Fishbowl::Objects::BaseObject.new.send_request('WorkOrderListRq', 'WorkOrderListRs')
|
4
|
+
|
5
|
+
results = []
|
6
|
+
response.xpath("//WO").each do |work_order_xml|
|
7
|
+
results << Fishbowl::Objects::WorkOrder.new(work_order_xml)
|
8
|
+
end
|
9
|
+
|
10
|
+
results
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.inventory_quantity(part_num)
|
3
|
+
raise ArgumentError if part_num.nil?
|
4
|
+
|
5
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
6
|
+
xml.request {
|
7
|
+
xml.InvQtyRq {
|
8
|
+
xml.PartNum part_num
|
9
|
+
}
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
code, response = Fishbowl::Objects::BaseObject.new.send_request(builder, "InvQtyRs")
|
14
|
+
|
15
|
+
response.xpath("//FbiXml/FbiMsgsRs/InvQtyRs")
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.load_sales_order(order_number)
|
3
|
+
raise Fishbowl::Errors.ArgumentError if order_number.nil?
|
4
|
+
request = load_order_request(order_number)
|
5
|
+
Fishbowl::Objects::BaseObject.new.send_request(request, 'LoadSORs')
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def self.load_order_request(order_number)
|
11
|
+
Nokogiri::XML::Builder.new do |xml|
|
12
|
+
xml.request {
|
13
|
+
xml.LoadSORq {
|
14
|
+
xml.Number order_number.to_s
|
15
|
+
}
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.make_payment(options)
|
3
|
+
# options = options.symbolize_keys
|
4
|
+
#
|
5
|
+
%w{amount so_number payment_method}.each do |required_field|
|
6
|
+
raise ArgumentError if options[required_field.to_sym].nil?
|
7
|
+
end
|
8
|
+
|
9
|
+
request = format_payment(options)
|
10
|
+
Fishbowl::Objects::BaseObject.new.send_request(request, 'MakePaymentRs')
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def self.format_payment(payment)
|
16
|
+
Nokogiri::XML::Builder.new do |xml|
|
17
|
+
xml.request {
|
18
|
+
xml.MakePaymentRq {
|
19
|
+
xml.Payment {
|
20
|
+
xml.Amount payment[:amount] unless payment[:amount].nil?
|
21
|
+
xml.SalesOrderNumber payment[:so_number] unless payment[:so_number].nil?
|
22
|
+
xml.PaymentDate payment[:payment_date] unless payment[:payment_date].nil?
|
23
|
+
xml.PaymentMethod payment[:payment_method] unless payment[:payment_method].nil?
|
24
|
+
xml.TransactionID payment[:transaction_id] unless payment[:transaction_id].nil?
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.save_sales_order(options)
|
3
|
+
# options = options.symbolize_keys
|
4
|
+
#
|
5
|
+
# %w{number salesman customer_name status
|
6
|
+
# items}.each do |required_field|
|
7
|
+
# raise ArgumentError if options[required_field.to_sym].nil?
|
8
|
+
# end
|
9
|
+
|
10
|
+
request = format_sales_order(options)
|
11
|
+
Fishbowl::Objects::BaseObject.new.send_request(request, 'SaveSORs')
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.format_sales_order(sales_order)
|
17
|
+
Nokogiri::XML::Builder.new do |xml|
|
18
|
+
xml.request {
|
19
|
+
xml.SOSaveRq {
|
20
|
+
xml.SalesOrder {
|
21
|
+
xml.Number sales_order[:number] unless sales_order[:number].nil?
|
22
|
+
xml.Salesman sales_order[:salesman] unless sales_order[:salesman].nil?
|
23
|
+
xml.CustomerName sales_order[:customer_name] unless sales_order[:customer_name].nil?
|
24
|
+
xml.Status "10" if sales_order[:status].nil?
|
25
|
+
xml.Status sales_order[:status] unless sales_order[:status].nil?
|
26
|
+
xml.Carrier sales_order[:carrier] unless sales_order[:carrier].nil?
|
27
|
+
xml.PaymentTerms sales_order[:payment_terms] unless sales_order[:payment_terms].nil?
|
28
|
+
xml.CustomerPO sales_order[:customer_po] unless sales_order[:customer_po].nil?
|
29
|
+
xml.VendorPO sales_order[:vendor_po] unless sales_order[:vendor_po].nil?
|
30
|
+
xml.QuickBooksClassName sales_order[:quick_books_class_name] unless sales_order[:quick_books_class_name].nil?
|
31
|
+
xml.BillTo {
|
32
|
+
xml.Name sales_order[:bill_to][:name] unless sales_order[:bill_to][:name].nil?
|
33
|
+
xml.AddressField sales_order[:bill_to][:address] unless sales_order[:bill_to][:address].nil?
|
34
|
+
xml.City sales_order[:bill_to][:city] unless sales_order[:bill_to][:city].nil?
|
35
|
+
xml.Zip sales_order[:bill_to][:zip] unless sales_order[:bill_to][:zip].nil?
|
36
|
+
xml.Country sales_order[:bill_to][:country] unless sales_order[:bill_to][:country].nil?
|
37
|
+
xml.State sales_order[:bill_to][:state] unless sales_order[:bill_to][:state].nil?
|
38
|
+
}
|
39
|
+
xml.Ship {
|
40
|
+
xml.Name sales_order[:ship_to][:name] unless sales_order[:ship_to][:name].nil?
|
41
|
+
xml.AddressField sales_order[:ship_to][:address] unless sales_order[:ship_to][:address].nil?
|
42
|
+
xml.City sales_order[:ship_to][:city] unless sales_order[:ship_to][:city].nil?
|
43
|
+
xml.Zip sales_order[:ship_to][:zip] unless sales_order[:ship_to][:zip].nil?
|
44
|
+
xml.Country sales_order[:ship_to][:country] unless sales_order[:ship_to][:country].nil?
|
45
|
+
xml.State sales_order[:ship_to][:state] unless sales_order[:ship_to][:state].nil?
|
46
|
+
}
|
47
|
+
xml.CustomFields {
|
48
|
+
sales_order[:custom_fields].each do |field|
|
49
|
+
xml.CustomField {
|
50
|
+
xml.ID field[:id] unless field[:id].nil?
|
51
|
+
xml.Name field[:name] unless field[:name].nil?
|
52
|
+
xml.Type field[:type] unless field[:type].nil?
|
53
|
+
xml.Info field[:info] unless field[:info].nil?
|
54
|
+
xml.Description field[:description] unless field[:description].nil?
|
55
|
+
}
|
56
|
+
end
|
57
|
+
} unless sales_order[:custom_fields].nil?
|
58
|
+
xml.Items {
|
59
|
+
sales_order[:items].each do |item|
|
60
|
+
xml.SalesOrderItem {
|
61
|
+
xml.ID item[:id] unless item[:id].nil?
|
62
|
+
xml.ProductNumber item[:product_number] unless item[:product_number].nil?
|
63
|
+
xml.ProductPrice item[:product_price] unless item[:product_price].nil?
|
64
|
+
xml.TotalPrice item[:total_price] unless item[:total_price].nil?
|
65
|
+
xml.Quantity item[:quantity] unless item[:quantity].nil?
|
66
|
+
xml.UOMCode item[:uom_code] unless item[:uom_code].nil?
|
67
|
+
xml.Description item[:description] unless item[:description].nil?
|
68
|
+
xml.LineNumber item[:line_number] unless item[:line_number].nil?
|
69
|
+
xml.QuickBooksClassName item[:quick_books_class_name] unless item[:quick_books_class_name].nil?
|
70
|
+
xml.NewItemFlag "false"
|
71
|
+
xml.ItemType item[:item_type] || "10"
|
72
|
+
xml.Status "10"
|
73
|
+
xml.AdjustPercentage item[:adjust_percentage] unless item[:adjust_percentage].nil?
|
74
|
+
} unless sales_order[:items].nil?
|
75
|
+
end
|
76
|
+
}
|
77
|
+
}
|
78
|
+
xml.IssueFlag "false"
|
79
|
+
xml.IgnoreItems "false"
|
80
|
+
}
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.total_inventory(part_num, location_group)
|
3
|
+
raise ArgumentError if part_num.nil?
|
4
|
+
|
5
|
+
builder = Nokogiri::XML::Builder.new do |xml|
|
6
|
+
xml.request {
|
7
|
+
xml.GetTotalInventoryRq {
|
8
|
+
xml.PartNumber part_num
|
9
|
+
xml.LocationGroup location_group
|
10
|
+
}
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
code, response = Fishbowl::Objects::BaseObject.new.send_request(builder, "GetTotalInventoryRs")
|
15
|
+
|
16
|
+
response.xpath("//FbiXml/FbiMsgsRs/GetTotalInventoryRs")
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Fishbowl::Requests
|
2
|
+
def self.void_sales_order(number)
|
3
|
+
request = format_add_sales_order_item_request(number.to_s)
|
4
|
+
Fishbowl::Objects::BaseObject.new.send_request(request, 'VoidSORs')
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def self.format_add_sales_order_item_request(number)
|
10
|
+
Nokogiri::XML::Builder.new do |xml|
|
11
|
+
xml.request {
|
12
|
+
xml.VoidSORq {
|
13
|
+
xml.SONumber number
|
14
|
+
}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/fishbowl/version.rb
CHANGED
data/lib/fishbowl.rb
CHANGED
@@ -4,107 +4,24 @@ require 'singleton'
|
|
4
4
|
|
5
5
|
require 'nokogiri'
|
6
6
|
|
7
|
+
require 'fishbowl/ext'
|
8
|
+
|
7
9
|
require 'fishbowl/version'
|
8
10
|
require 'fishbowl/errors'
|
11
|
+
require 'fishbowl/requests'
|
9
12
|
require 'fishbowl/objects'
|
13
|
+
require 'fishbowl/connection'
|
14
|
+
require 'fishbowl/configuration'
|
10
15
|
|
11
16
|
module Fishbowl # :nodoc:
|
12
|
-
class Connection
|
13
|
-
include Singleton
|
14
|
-
|
15
|
-
def self.connect(options = {})
|
16
|
-
raise Fishbowl::Errors::MissingHost if options[:host].nil?
|
17
|
-
|
18
|
-
@host = options[:host]
|
19
|
-
@port = options[:port].nil? ? 28192 : options[:port]
|
20
|
-
|
21
|
-
@connection = TCPSocket.new @host, @port
|
22
|
-
|
23
|
-
self.instance
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.login(options = {})
|
27
|
-
raise Fishbowl::Errors::ConnectionNotEstablished if @connection.nil?
|
28
|
-
raise Fishbowl::Errors::MissingUsername if options[:username].nil?
|
29
|
-
raise Fishbowl::Errors::MissingPassword if options[:password].nil?
|
30
|
-
|
31
|
-
@username, @password = options[:username], options[:password]
|
32
|
-
|
33
|
-
Fishbowl::Objects::BaseObject.new.send_request(login_request, true)
|
34
|
-
|
35
|
-
code, message, _ = get_response('LoginRs')
|
36
|
-
|
37
|
-
Fishbowl::Errors.confirm_success_or_raise(code, message)
|
38
|
-
|
39
|
-
self.instance
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.host
|
43
|
-
@host
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.port
|
47
|
-
@port
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.username
|
51
|
-
@username
|
52
|
-
end
|
53
17
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
def self.send(request)
|
59
|
-
write(request)
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.close
|
63
|
-
@connection.close
|
64
|
-
@connection = nil
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.get_response(expectation = 'FbiMsgRs')
|
68
|
-
response = read
|
69
|
-
|
70
|
-
status_code = response.xpath("//#{expectation}/@statusCode").first.value
|
71
|
-
status_message = response.xpath("//#{expectation}/@statusMessage").first.value
|
72
|
-
|
73
|
-
[status_code, status_message, response]
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
|
78
|
-
def self.login_request
|
79
|
-
Nokogiri::XML::Builder.new do |xml|
|
80
|
-
xml.request {
|
81
|
-
xml.LoginRq {
|
82
|
-
xml.IAID "fishbowl-ruby"
|
83
|
-
xml.IAName "Fishbowl Ruby Gem"
|
84
|
-
xml.IADescription "Fishbowl Ruby Gem"
|
85
|
-
xml.UserName @username
|
86
|
-
xml.UserPassword encoded_password
|
87
|
-
}
|
88
|
-
}
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.encoded_password
|
93
|
-
Base64.encode64(@password)
|
94
|
-
end
|
95
|
-
|
96
|
-
def self.write(request)
|
97
|
-
body = request.to_xml
|
98
|
-
size = [body.size].pack("L>")
|
99
|
-
|
100
|
-
@connection.write(size)
|
101
|
-
@connection.write(body)
|
102
|
-
end
|
103
|
-
|
104
|
-
def self.read
|
105
|
-
length = @connection.recv(3).unpack('L>').join('').to_i
|
106
|
-
Nokogiri::XML.parse(@connection.recv(length))
|
107
|
-
end
|
18
|
+
class << self
|
19
|
+
attr_accessor :configuration
|
20
|
+
end
|
108
21
|
|
22
|
+
def self.configure
|
23
|
+
self.configuration ||= Configuration.new
|
24
|
+
yield(configuration)
|
109
25
|
end
|
26
|
+
|
110
27
|
end
|