Commit d9177f32280bce23ed500524f5d2203c7c8d3c74
1 parent
291179ed
create sor model; create sorqbs bo files; create sor test
Showing
8 changed files
with
206 additions
and
2 deletions
Show diff stats
lib/syspro.rb
| ... | ... | @@ -25,10 +25,12 @@ require 'syspro/api_operations/query' |
| 25 | 25 | require 'syspro/business_objects/combrw' |
| 26 | 26 | require 'syspro/business_objects/comfch' |
| 27 | 27 | require 'syspro/business_objects/comfnd' |
| 28 | +require 'syspro/business_objects/sorqbs' | |
| 28 | 29 | |
| 29 | 30 | require 'syspro/business_objects/parsers/combrw_parser' |
| 30 | 31 | require 'syspro/business_objects/parsers/comfch_parser' |
| 31 | 32 | require 'syspro/business_objects/parsers/comfnd_parser' |
| 33 | +require 'syspro/business_objects/parsers/sorqbs_parser' | |
| 32 | 34 | |
| 33 | 35 | # Main Module |
| 34 | 36 | module Syspro | ... | ... |
lib/syspro/api_operations/query.rb
| 1 | +module Syspro | |
| 2 | + module BusinessObjects | |
| 3 | + module Models | |
| 4 | + class Sor | |
| 5 | + attr_accessor :customer, :name, :customer_po_number, :cust_stock_code, :stock_code, :description, | |
| 6 | + :supply_wh, :release_manager, :release_status, :purchase_order, :shipment_days, | |
| 7 | + :num_day_drops, :num_week_drops, :day_in_week, :num_month_drops, :day_in_month, | |
| 8 | + :price_contract_num, :stock_uom, :contract_qty, :total_delivered, :total_received, | |
| 9 | + :opening_cume, :data_last_inv, :base_date, :expiry_date, :last_invoice, :buying_group, | |
| 10 | + :last_dispatch_note, :confirmed_release_details, :unconfirmed_release_details, :release_details, | |
| 11 | + :delivery_history_details, :release_history_details, :sor_detail, :contract_item | |
| 12 | + end | |
| 13 | + end | |
| 14 | + end | |
| 15 | +end | |
| 16 | + | ... | ... |
lib/syspro/business_objects/parsers/sorqbs_parser.rb
0 → 100644
| 1 | +# frozen_string_literal: true | |
| 2 | + | |
| 3 | +module Syspro | |
| 4 | + module BusinessObjects | |
| 5 | + module Parsers | |
| 6 | + class SorQbs | |
| 7 | + attr_reader :doc | |
| 8 | + | |
| 9 | + def initialize(doc) | |
| 10 | + @doc = doc | |
| 11 | + end | |
| 12 | + | |
| 13 | + def parse | |
| 14 | + binding.pry | |
| 15 | + sor = Syspro::BusinessObjects::Models::Sor.new() | |
| 16 | + end | |
| 17 | + end | |
| 18 | + end | |
| 19 | + end | |
| 20 | +end | |
| 21 | + | ... | ... |
| 1 | +<?xml version="1.0" encoding="Windows-1252"?> | |
| 2 | +<Query xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="SORQBS.XSD"> | |
| 3 | + <Option> | |
| 4 | + <IncludeSalesOrderDetails><%= @include_sales_order_details %></IncludeSalesOrderDetails> | |
| 5 | + <IncludeContractDetails><%= @include_contact_details %></IncludeContractDetails> | |
| 6 | + <IncludeDeliveryHistory><%= @include_delivery_history %></IncludeDeliveryHistory> | |
| 7 | + <IncludeUnconfirmedReleases><%= @include_unconfirmed_releases %></IncludeUnconfirmedReleases> | |
| 8 | + <IncludeConfirmedReleases><%= @include_confirmed_releases %></IncludeConfirmedReleases> | |
| 9 | + <IncludeReleaseDetails><%= @include_release_details %></IncludeReleaseDetails> | |
| 10 | + <IncludeReleaseHistory><%= @include_release_history %></IncludeReleaseHistory> | |
| 11 | + </Option> | |
| 12 | + <% unless @filters.empty? %> | |
| 13 | + <Filter> | |
| 14 | + <% for filter in @filters %> | |
| 15 | + <<%= filter[:name] %> FilterType="<% filter[:type] %>" FilterValue="<% filter[:value] %>"/> | |
| 16 | + <% end %> | |
| 17 | + </Filter> | |
| 18 | + <% end %> | |
| 19 | +</Query> | |
| 20 | + | ... | ... |
| 1 | +# frozen_string_literal: true | |
| 2 | + | |
| 3 | +require 'syspro/business_objects/parsers/sorqbs_parser' | |
| 4 | +require 'erb' | |
| 5 | + | |
| 6 | +module Syspro | |
| 7 | + module BusinessObjects | |
| 8 | + class SorQbs < ApiResource | |
| 9 | + include Syspro::ApiOperations::Query | |
| 10 | + include Syspro::BusinessObjects::Parsers | |
| 11 | + | |
| 12 | + attr_accessor :include_sales_order_details, :include_contact_details, :include_delivery_history, | |
| 13 | + :include_unconfirmed_releases, :include_confirmed_releases, :include_release_details, | |
| 14 | + :include_release_history, :filters | |
| 15 | + | |
| 16 | + def call(user_id) | |
| 17 | + xml_in = template.result(binding) | |
| 18 | + business_object = 'SORQBS' | |
| 19 | + params = { 'UserId' => user_id, 'BusinessObject' => business_object, 'XmlIn' => xml_in } | |
| 20 | + resp = SorQbs.query(params) | |
| 21 | + parse_response(resp) | |
| 22 | + end | |
| 23 | + | |
| 24 | + def template | |
| 25 | + ERB.new File.read(File.expand_path('schemas/sorqbs.xml.erb', File.dirname(__FILE__))), nil, '%' | |
| 26 | + end | |
| 27 | + | |
| 28 | + def parse_response(resp) | |
| 29 | + handle_errors(resp) | |
| 30 | + parser = SorQbsParser.new(respo[0].data) | |
| 31 | + parser.parse | |
| 32 | + end | |
| 33 | + | |
| 34 | + def handle_errors(resp) | |
| 35 | + body = resp[0].http_body | |
| 36 | + raise SysproError, body if body =~ /^(ERROR)/ | |
| 37 | + end | |
| 38 | + end | |
| 39 | + end | |
| 40 | +end | |
| 41 | + | ... | ... |
| 1 | +--- | |
| 2 | +http_interactions: | |
| 3 | +- request: | |
| 4 | + method: get | |
| 5 | + uri: http://syspro.wildlandlabs.com:90/SYSPROWCFService/Rest/logon?CompanyId=L&CompanyPassword=&Operator=wland&OperatorPassword=piperita2016 | |
| 6 | + body: | |
| 7 | + encoding: US-ASCII | |
| 8 | + string: '' | |
| 9 | + headers: | |
| 10 | + User-Agent: | |
| 11 | + - Syspro/7 RubyBindings/1.0.0.alpha.1 | |
| 12 | + Content-Type: | |
| 13 | + - application/x-www-form-urlencoded | |
| 14 | + Accept-Encoding: | |
| 15 | + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 | |
| 16 | + Accept: | |
| 17 | + - "*/*" | |
| 18 | + response: | |
| 19 | + status: | |
| 20 | + code: 200 | |
| 21 | + message: OK | |
| 22 | + headers: | |
| 23 | + Content-Length: | |
| 24 | + - '36' | |
| 25 | + Content-Type: | |
| 26 | + - application/octet-stream | |
| 27 | + Server: | |
| 28 | + - Microsoft-HTTPAPI/2.0 | |
| 29 | + Date: | |
| 30 | + - Wed, 11 Apr 2018 19:00:49 GMT | |
| 31 | + body: | |
| 32 | + encoding: UTF-8 | |
| 33 | + string: 'E621DED6B5E98C4783D130230F6B29E700 ' | |
| 34 | + http_version: | |
| 35 | + recorded_at: Wed, 11 Apr 2018 19:00:49 GMT | |
| 36 | +- request: | |
| 37 | + method: get | |
| 38 | + uri: http://syspro.wildlandlabs.com:90/SYSPROWCFService/Rest/Query/Query?BusinessObject=SORQBS&UserId=E621DED6B5E98C4783D130230F6B29E700%20%20&XmlIn=%3C?xml%20version=%221.0%22%20encoding=%22Windows-1252%22?%3E%0A%3CQuery%20xmlns:xsd=%22http://www.w3.org/2001/XMLSchema-instance%22%20xsd:noNamespaceSchemaLocation=%22SORQBS.XSD%22%3E%0A%20%20%3COption%3E%0A%20%20%20%20%3CIncludeSalesOrderDetails%3Etrue%3C/IncludeSalesOrderDetails%3E%0A%20%20%20%20%3CIncludeContractDetails%3Etrue%3C/IncludeContractDetails%3E%0A%20%20%20%20%3CIncludeDeliveryHistory%3Etrue%3C/IncludeDeliveryHistory%3E%0A%20%20%20%20%3CIncludeUnconfirmedReleases%3Etrue%3C/IncludeUnconfirmedReleases%3E%0A%20%20%20%20%3CIncludeConfirmedReleases%3Etrue%3C/IncludeConfirmedReleases%3E%0A%20%20%20%20%3CIncludeReleaseDetails%3Etrue%3C/IncludeReleaseDetails%3E%0A%20%20%20%20%3CIncludeReleaseHistory%3Etrue%3C/IncludeReleaseHistory%3E%0A%20%20%3C/Option%3E%0A%20%20%20%0A%20%20%20%20%3CFilter%3E%0A%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%3CCustomer%20FilterType=%22%22%20FilterValue=%22%22/%3E%0A%20%20%20%20%20%20%0A%20%20%20%20%3C/Filter%3E%0A%20%20%0A%3C/Query%3E%0A%0A | |
| 39 | + body: | |
| 40 | + encoding: US-ASCII | |
| 41 | + string: '' | |
| 42 | + headers: | |
| 43 | + User-Agent: | |
| 44 | + - Syspro/7 RubyBindings/1.0.0.alpha.1 | |
| 45 | + Content-Type: | |
| 46 | + - application/x-www-form-urlencoded | |
| 47 | + Accept-Encoding: | |
| 48 | + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 | |
| 49 | + Accept: | |
| 50 | + - "*/*" | |
| 51 | + response: | |
| 52 | + status: | |
| 53 | + code: 200 | |
| 54 | + message: OK | |
| 55 | + headers: | |
| 56 | + Content-Length: | |
| 57 | + - '102' | |
| 58 | + Content-Type: | |
| 59 | + - application/octet-stream | |
| 60 | + Server: | |
| 61 | + - Microsoft-HTTPAPI/2.0 | |
| 62 | + Date: | |
| 63 | + - Wed, 11 Apr 2018 19:00:53 GMT | |
| 64 | + body: | |
| 65 | + encoding: UTF-8 | |
| 66 | + string: 'ERROR: Access denied to Functional Area ''SorBlanketSo'' for operator | |
| 67 | + ''WLAND'' (Business Object ''SORQBS'')' | |
| 68 | + http_version: | |
| 69 | + recorded_at: Wed, 11 Apr 2018 19:00:53 GMT | |
| 70 | +recorded_with: VCR 4.0.0 | ... | ... |
| 1 | +# frozen_string_literal: true | |
| 2 | + | |
| 3 | +require 'test_helper' | |
| 4 | + | |
| 5 | +class SorTest < Minitest::Test | |
| 6 | + extend Minitest::Spec::DSL | |
| 7 | + before { VCR.insert_cassette name } | |
| 8 | + after { VCR.eject_cassette } | |
| 9 | + | |
| 10 | + let(:username) { 'wland' } | |
| 11 | + let(:password) { 'piperita2016' } | |
| 12 | + let(:company) { 'L' } | |
| 13 | + let(:company_password) { '' } | |
| 14 | + let(:user_id) do | |
| 15 | + Syspro::Logon.logon(username, password, company, company_password) | |
| 16 | + end | |
| 17 | + | |
| 18 | + def test_sor_query | |
| 19 | + sorqbs = Syspro::BusinessObjects::SorQbs.new | |
| 20 | + | |
| 21 | + sorqbs.include_sales_order_details = true | |
| 22 | + sorqbs.include_contact_details = true | |
| 23 | + sorqbs.include_delivery_history = true | |
| 24 | + sorqbs.include_unconfirmed_releases = true | |
| 25 | + sorqbs.include_confirmed_releases = true | |
| 26 | + sorqbs.include_release_details = true | |
| 27 | + sorqbs.include_release_history = true | |
| 28 | + sorqbs.filters = [ | |
| 29 | + { name: 'Customer', type: 'A', value: 'JJJ001' } | |
| 30 | + ] | |
| 31 | + | |
| 32 | + sor_result = sorqbs.call(user_id.guid) | |
| 33 | + refute_nil sor_result | |
| 34 | + end | |
| 35 | +end | |
| 36 | + | ... | ... |