agris 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +21 -0
  6. data/README.md +36 -0
  7. data/Rakefile +6 -0
  8. data/agris.gemspec +30 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/agris.rb +61 -0
  12. data/lib/agris/api.rb +21 -0
  13. data/lib/agris/api/accounts_payables.rb +30 -0
  14. data/lib/agris/api/accounts_receivables.rb +11 -0
  15. data/lib/agris/api/accounts_receivables/invoice.rb +166 -0
  16. data/lib/agris/api/accounts_receivables/invoices.rb +29 -0
  17. data/lib/agris/api/accounts_receivables/specific_invoice_extract.rb +17 -0
  18. data/lib/agris/api/document_query_response.rb +59 -0
  19. data/lib/agris/api/grain.rb +12 -0
  20. data/lib/agris/api/grain/new_ticket.rb +118 -0
  21. data/lib/agris/api/grain/new_ticket_application.rb +34 -0
  22. data/lib/agris/api/grain/new_ticket_remark.rb +23 -0
  23. data/lib/agris/api/grain/tickets.rb +17 -0
  24. data/lib/agris/api/inventory.rb +16 -0
  25. data/lib/agris/api/inventory/delivery_ticket.rb +84 -0
  26. data/lib/agris/api/inventory/delivery_ticket_line_item.rb +59 -0
  27. data/lib/agris/api/inventory/delivery_tickets.rb +30 -0
  28. data/lib/agris/api/inventory/orders.rb +51 -0
  29. data/lib/agris/api/inventory/specific_delivery_ticket_extract.rb +17 -0
  30. data/lib/agris/api/inventory/specific_order_extract.rb +18 -0
  31. data/lib/agris/api/messages.rb +25 -0
  32. data/lib/agris/api/messages/import.rb +40 -0
  33. data/lib/agris/api/messages/message_base.rb +42 -0
  34. data/lib/agris/api/messages/query_base.rb +37 -0
  35. data/lib/agris/api/messages/query_changed_delivery_tickets.rb +41 -0
  36. data/lib/agris/api/messages/query_changed_invoices.rb +48 -0
  37. data/lib/agris/api/messages/query_changed_orders.rb +41 -0
  38. data/lib/agris/api/messages/query_delivery_ticket_documents.rb +35 -0
  39. data/lib/agris/api/messages/query_invoice_documents.rb +40 -0
  40. data/lib/agris/api/messages/query_order_documents.rb +35 -0
  41. data/lib/agris/api/new_order.rb +86 -0
  42. data/lib/agris/api/new_order_remark.rb +22 -0
  43. data/lib/agris/api/new_voucher.rb +113 -0
  44. data/lib/agris/api/order.rb +63 -0
  45. data/lib/agris/api/order_line.rb +32 -0
  46. data/lib/agris/api/post_result.rb +24 -0
  47. data/lib/agris/api/remark.rb +16 -0
  48. data/lib/agris/api/support.rb +77 -0
  49. data/lib/agris/api/tran_code.rb +17 -0
  50. data/lib/agris/client.rb +39 -0
  51. data/lib/agris/context.rb +6 -0
  52. data/lib/agris/credentials.rb +7 -0
  53. data/lib/agris/credentials/anonymous.rb +11 -0
  54. data/lib/agris/credentials/basic_auth.rb +15 -0
  55. data/lib/agris/process_message_response.rb +58 -0
  56. data/lib/agris/resources/post_sales_order.xml +93 -0
  57. data/lib/agris/resources/post_sales_order_response.xml +21 -0
  58. data/lib/agris/savon_request.rb +73 -0
  59. data/lib/agris/user_agent.rb +7 -0
  60. data/lib/agris/version.rb +3 -0
  61. data/lib/agris/xml_model.rb +62 -0
  62. metadata +188 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a30b79856223878a7295a197f00c5e68b8dc079
4
+ data.tar.gz: 1ad201a273cef40da76757ab9d8fda45adddd7b7
5
+ SHA512:
6
+ metadata.gz: 8636ee3bfdb526fb6d8750c0b6b17a410fc2e0367cd16ab2e822f108e3d388499bc6abe7e56e1b670f745b95a2fa30f755f6cad3ac99075d1c97785c632c75e0
7
+ data.tar.gz: 59f30115750660e43849d8e1b9daf19965c4c77abfeaacc021cbc2d1cf34401ead9a817c30ae5c61eac381514eee5f99555975ab6aa2edf44fd22e3fd10a3b07
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in agris.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Western Milling, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # Agris
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/agris`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'agris'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install agris
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/John Gray/agris.
36
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'agris/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "agris"
8
+ spec.version = Agris::VERSION
9
+ spec.authors = ["John Gray"]
10
+ spec.email = ["wopr42@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby client library for Agris API}
13
+ spec.homepage = 'https://github.com/westernmilling/agris.rb'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'activesupport', '~> 5.0'
24
+ spec.add_dependency 'savon', '~> 2.11'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency 'webmock', '~> 2.3'
30
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "agris"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+ $LOAD_PATH.unshift File.dirname(__FILE__)
3
+
4
+ require 'active_support/core_ext/hash/conversions'
5
+ require 'active_support/core_ext/hash/slice'
6
+ require 'savon'
7
+
8
+ module Agris
9
+ class ApiError < StandardError; end
10
+ class MessageError < StandardError; end
11
+ class SystemError < StandardError; end
12
+ class UnknownError < StandardError; end
13
+
14
+ class << self
15
+ attr_accessor :credentials,
16
+ :context,
17
+ :logger,
18
+ :proxy_url,
19
+ :request_type,
20
+ :user_agent
21
+ # ```ruby
22
+ # Agris.configure do |config|
23
+ # config.credentials = Agris::Credentials::Anonymous.new
24
+ # config.context = Agris::Context.new(
25
+ # 'http://localhost:3000',
26
+ # '001',
27
+ # '\\host\apps\Agris\datasets',
28
+ # 'AgrisDB',
29
+ # 'bob',
30
+ # 'fred'
31
+ # )
32
+ # config.request_type = Agris::SavonRequest
33
+ # config.logger = Logger.new(STDOUT)
34
+ # config.user_agent = 'Otis'
35
+ # end
36
+ # ```
37
+ # elsewhere
38
+ #
39
+ # ```ruby
40
+ # client = Agris::Client.new
41
+ # ```
42
+ def configure
43
+ yield self
44
+ true
45
+ end
46
+
47
+ def root
48
+ File.expand_path('../../', __FILE__)
49
+ end
50
+ end
51
+
52
+ autoload :Api, 'agris/api'
53
+ autoload :Client, 'agris/client'
54
+ autoload :Context, 'agris/context'
55
+ autoload :Credentials, 'agris/credentials'
56
+ autoload :HTTPartyRequest, 'agris/httparty_request'
57
+ autoload :ProcessMessageResponse, 'agris/process_message_response'
58
+ autoload :SavonRequest, 'agris/savon_request'
59
+ autoload :UserAgent, 'agris/user_agent'
60
+ autoload :XmlModel, 'agris/xml_model'
61
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ autoload :AccountsReceivables, 'agris/api/accounts_receivables'
5
+ autoload :AccountsPayables, 'agris/api/accounts_payables'
6
+ autoload :DocumentQueryResponse,
7
+ 'agris/api/document_query_response'
8
+ autoload :Grain, 'agris/api/grain'
9
+ autoload :Inventory, 'agris/api/inventory'
10
+ autoload :Messages, 'agris/api/messages'
11
+ autoload :NewOrder, 'agris/api/new_order'
12
+ autoload :NewOrderRemark, 'agris/api/new_order_remark'
13
+ autoload :NewVoucher, 'agris/api/new_voucher'
14
+ autoload :Order, 'agris/api/order'
15
+ autoload :OrderLine, 'agris/api/order_line'
16
+ autoload :PostResult, 'agris/api/post_result'
17
+ autoload :Remark, 'agris/api/remark'
18
+ autoload :Support, 'agris/api/support'
19
+ autoload :TranCode, 'agris/api/tran_code'
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Agris
4
+ module Api
5
+ module AccountsPayables
6
+ module Vouchers
7
+ def create_voucher(voucher)
8
+ response = @request.process_message(
9
+ Gyoku.xml(xml: context_hash),
10
+ 82_320,
11
+ create_post_payload_xml(convert_voucher_to_details(voucher))
12
+ )
13
+
14
+ PostResult.new(response)
15
+ end
16
+
17
+ protected
18
+
19
+ # NB: We should probably refactor this into a class and write tests
20
+ # to verify conversion of a sales model to an expected payload.
21
+ def convert_voucher_to_details(voucher)
22
+ details = []
23
+ details << voucher.to_xml_hash
24
+ details << voucher.details.map(&:to_xml_hash)
25
+ details
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module AccountsReceivables
5
+ autoload :Invoice, 'agris/api/accounts_receivables/invoice'
6
+ autoload :Invoices, 'agris/api/accounts_receivables/invoices'
7
+ autoload :SpecificInvoiceExtract,
8
+ 'agris/api/accounts_receivables/specific_invoice_extract'
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,166 @@
1
+ # frozen_string_literal: true
2
+ module Agris
3
+ module Api
4
+ module AccountsReceivables
5
+ class Invoice
6
+ include XmlModel
7
+
8
+ ATTRIBUTE_NAMES = %w(
9
+ invoice_location
10
+ invoice_location_description
11
+ invoice_no
12
+ invoice_date
13
+ ship_date
14
+ pickup_delivery
15
+ due_date
16
+ discount_date
17
+ original_date
18
+ last_pay_date
19
+ trans_status
20
+ tran_status_desc
21
+ aging_period
22
+ aging_period_description
23
+ doc_type
24
+ doc_type_desc
25
+ invoice_desc
26
+ ref_order_no
27
+ xref_doc_loc
28
+ xref_doc_loc_description
29
+ xref_doc
30
+ days_to_pay
31
+ terms_code
32
+ terms_desc
33
+ first_inv_settle_no
34
+ name_id_type
35
+ name_id_type_desc
36
+ invoice_type
37
+ invoice_type_desc
38
+ state_county_code
39
+ state_county_desc
40
+ usr_order_field_1
41
+ usr_order_field_2
42
+ usr_invoice_field1
43
+ usr_invoice_field2
44
+ bill_to_id
45
+ bill_to_description
46
+ ship_to_id
47
+ ship_to_description
48
+ shipper_id
49
+ shipper_description
50
+ agent_id
51
+ agent_description
52
+ invoice_amount
53
+ discount_amount
54
+ applied_amount
55
+ due_amount
56
+ net_amount
57
+ discount_remaining
58
+ discount_applied
59
+ sales_tax
60
+ field_history_updated
61
+ use_standard_discount_ratio
62
+ delete
63
+ lastchange_datetime
64
+ lastchange_user_id
65
+ lastchange_user_name
66
+ currency_code
67
+ currency_description
68
+ exchange_rate
69
+ exchange_rate_date
70
+ integration_guid
71
+ unique_id
72
+ ).freeze
73
+
74
+ attr_reader(*(%w(line_items) + ATTRIBUTE_NAMES))
75
+
76
+ def self.from_xml_hash(hash)
77
+ super.tap do |document|
78
+ if hash['lineitems']
79
+ document.line_items.concat(
80
+ [hash['lineitems']['lineitem']]
81
+ .flatten
82
+ .map do |lineitem|
83
+ LineItem.from_xml_hash(lineitem)
84
+ end
85
+ )
86
+ end
87
+ end
88
+ end
89
+
90
+ def initialize(hash = {})
91
+ super
92
+
93
+ @line_items = []
94
+ end
95
+
96
+ class LineItem
97
+ include XmlModel
98
+
99
+ ATTRIBUTE_NAMES = %w(
100
+ line_item_no
101
+ pricing_no
102
+ item_loc
103
+ item_loc_desc
104
+ item_no
105
+ item_desc
106
+ sub_item_1
107
+ sub_item_1_desc
108
+ sub_item_2
109
+ category
110
+ category_desc
111
+ category_type
112
+ category_type_desc
113
+ qty
114
+ qty_uom
115
+ qty_uom_desc
116
+ unit_price
117
+ total_price
118
+ pre_promo_price
119
+ discount_rate
120
+ original_qty
121
+ split_percent
122
+ unit_cost
123
+ total_cost
124
+ price_uom
125
+ price_uom_desc
126
+ order_loc
127
+ order_loc_desc
128
+ order_no
129
+ other_ref
130
+ exec_id_no
131
+ exec_id_description
132
+ act_loc
133
+ act_loc_desc
134
+ sales_tax_amt
135
+ scale_ticket_num
136
+ weight_uom
137
+ weight_uom_desc
138
+ gross_wt
139
+ tare_wt
140
+ net_wt
141
+ del_ticket_loc
142
+ del_ticket_loc_desc
143
+ del_ticket_no
144
+ contract_loc
145
+ contract_loc_desc
146
+ contract_no
147
+ item_type
148
+ item_type_description
149
+ in_blend
150
+ source_type
151
+ blend_no
152
+ formula_no
153
+ source_id
154
+ target_p_est
155
+ change_type
156
+ change_type_description
157
+ cost_adjustment_status
158
+ cost_adjustment_description
159
+ ).freeze
160
+
161
+ attr_reader(*ATTRIBUTE_NAMES)
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end