ingram_micro 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +4 -0
  6. data/CODE_OF_CONDUCT.md +13 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +123 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +7 -0
  13. data/example.rb +18 -0
  14. data/ingram_micro.gemspec +38 -0
  15. data/lib/.DS_Store +0 -0
  16. data/lib/ingram_micro.rb +42 -0
  17. data/lib/ingram_micro/.DS_Store +0 -0
  18. data/lib/ingram_micro/base_element.rb +32 -0
  19. data/lib/ingram_micro/client.rb +49 -0
  20. data/lib/ingram_micro/configuration.rb +46 -0
  21. data/lib/ingram_micro/elements/credit_card_information.rb +26 -0
  22. data/lib/ingram_micro/elements/customer.rb +23 -0
  23. data/lib/ingram_micro/elements/detail.rb +19 -0
  24. data/lib/ingram_micro/elements/message_header_no_pw.rb +21 -0
  25. data/lib/ingram_micro/elements/message_header_pw.rb +22 -0
  26. data/lib/ingram_micro/elements/purchase_order_information.rb +15 -0
  27. data/lib/ingram_micro/elements/return_authorization_line_item.rb +39 -0
  28. data/lib/ingram_micro/elements/return_authorization_submission.rb +67 -0
  29. data/lib/ingram_micro/elements/return_order_header.rb +29 -0
  30. data/lib/ingram_micro/elements/sales_order_header.rb +27 -0
  31. data/lib/ingram_micro/elements/sales_order_line_item.rb +37 -0
  32. data/lib/ingram_micro/elements/sales_order_submission.rb +62 -0
  33. data/lib/ingram_micro/elements/shipment_information.rb +69 -0
  34. data/lib/ingram_micro/elements/shipment_status.rb +44 -0
  35. data/lib/ingram_micro/elements/shipment_status_line_item.rb +28 -0
  36. data/lib/ingram_micro/errors/invalid_type.rb +2 -0
  37. data/lib/ingram_micro/errors/missing_field.rb +2 -0
  38. data/lib/ingram_micro/request_processor.rb +11 -0
  39. data/lib/ingram_micro/transmission.rb +50 -0
  40. data/lib/ingram_micro/transmissions/check_shipment_status.rb +45 -0
  41. data/lib/ingram_micro/transmissions/return_authorization.rb +50 -0
  42. data/lib/ingram_micro/transmissions/sales_order.rb +55 -0
  43. data/lib/ingram_micro/version.rb +3 -0
  44. data/xsd/.DS_Store +0 -0
  45. data/xsd/BPXML_InventoryStatus.xsd +49 -0
  46. data/xsd/inbound/BPXML-LoadReject.xsd +686 -0
  47. data/xsd/inbound/BPXML-LoadSuccess.xsd +696 -0
  48. data/xsd/inbound/BPXML-ReturnReceipt.xsd +664 -0
  49. data/xsd/inbound/BPXML-ShipAdvice.xsd +758 -0
  50. data/xsd/inbound/BPXML-StandardResponse.xsd +122 -0
  51. data/xsd/outbound/BPXML-ReturnAuthorization.xsd +641 -0
  52. data/xsd/outbound/BPXML-SalesOrder.xsd +753 -0
  53. data/xsd/outbound/BPXML-ShipmentStatus.xsd +232 -0
  54. data/xsd/xml_samples/.DS_Store +0 -0
  55. data/xsd/xml_samples/Sales_order_sample.xml +143 -0
  56. metadata +227 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f3a454c5b9cd87a1f71320f583ecd4f04345fed
4
+ data.tar.gz: de4da596e98cd56963ac0575b697cf57d98ba488
5
+ SHA512:
6
+ metadata.gz: d8bf2f4381068729b8311af77ebbc29ff0b29a55d37af7e5de7c404a0122c2db43fbad4f6a0e3e78a09cdc4448b10de9d8b7dbcd657897b76d6336d60852d41c
7
+ data.tar.gz: 35d0cf4b16c9f0ee80c9c40812ad9a099417bda5d79ddde5f53cd477ba1c2a1f8b34d76a245702a0e8e2ad7cbc84820abdcd4ff62e11088f061d70ec747d3d3b
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ .idea
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ lib/config/defaults.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ingram_micro.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Rachel Heaton
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.
data/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # IngramMicro
2
+ [![Build Status](https://travis-ci.org/WalkerAndCoBrandsInc/ingram_micro.svg?branch=develop)](https://travis-ci.org/WalkerAndCoBrandsInc/ingram_micro) Development
3
+
4
+ [![Build Status](https://travis-ci.org/WalkerAndCoBrandsInc/ingram_micro.svg?branch=master)](https://travis-ci.org/WalkerAndCoBrandsInc/ingram_micro) Latest Release
5
+
6
+
7
+ [IngramMicro](http://www.ingrammicro.com/IMD_WASWeb/jsp/login/corporate.jsp) HTTPS XML API wrapper.
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'ingram_micro'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install ingram_micro
25
+
26
+
27
+ Modify the spec_helper.rb and provide a api_root. You can create one on requestb.in
28
+
29
+ ## Run the Tests
30
+
31
+ $ rake
32
+
33
+ ## Usage
34
+
35
+ The `example.rb` script demonstrates how to use this gem. When
36
+ configured, it creates a sales order with Ingram Micro.
37
+
38
+ To see configuration options see `lib/ingram_micro/configuration.rb`
39
+
40
+ ```
41
+ IngramMicro.configure do |config|
42
+ config.api_root = "https://ingramurl.com"
43
+ config.partner_name = 'account name'
44
+ config.partner_password = 'password'
45
+ config.debug = true
46
+ config.logger = Rails.logger
47
+ end
48
+ ```
49
+
50
+ The `IngramMicro::Client` class creates the connection to the Brightpoint API
51
+ using the Faraday gem. The `Transmission` super class has subclasses (i.e. `SalesOrder`)
52
+ that correspond to different uses of the API.
53
+
54
+ These subclasses create XML files, tackling one element at a time. Hence the
55
+ `BaseElement` class and its subclasses for each element found in the forms. These
56
+ elements are designed to create XML elements that are empty or containing a
57
+ default value (hence the `DEFAULTS` hash constant) if no values are provided,
58
+ which is why the RSpec tests can create a new SalesOrder without providing any
59
+ information.
60
+
61
+ XML files are validated against the XSD schemas from the API docs and then
62
+ sent the request to the API.
63
+
64
+ More detailed instructions for use will be provided once we have tested and
65
+ calibrated this gem to work properly with the API.
66
+
67
+ ## For sites hosted in the cloud :cloud:
68
+
69
+ You may not be able to get a range of IPs for Ingram Micro to whitelist.
70
+ To get around this, you can route requests through [tinyproxy](https://github.com/tinyproxy/tinyproxy).
71
+
72
+ Make sure to allow the ports that IngramMicro gives you to connect to e.g.
73
+
74
+ tinyproxy.conf
75
+
76
+ ```
77
+ [...]
78
+ ConnectPort 9443
79
+ [...]
80
+ ```
81
+
82
+ ## Development
83
+
84
+ 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.
85
+
86
+ 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).
87
+
88
+ ## Development with tinyproxy
89
+
90
+ e.g. on a mac with homebrew (homebrew puts tinyproxy in sbin)
91
+
92
+ $ brew install tinyproxy
93
+
94
+ - create a tinyproxy.conf [Example](https://github.com/tinyproxy/tinyproxy/blob/186bbc3efb4b47caac0b5e14465c97918c99e442/etc/tinyproxy.conf.in)
95
+ - set your LogFile (config file does not understand ~ and needs full path)
96
+ - set ConnectPort for ports IMM uses
97
+
98
+ ### Configuring Ingram Micro for a proxy
99
+
100
+ ```
101
+ IngramMicro.configure do |config|
102
+ [...]
103
+ config.proxy = 'http://localhost:8888'
104
+ end
105
+ ```
106
+
107
+ ### Testing the proxy with curl
108
+
109
+ ```
110
+ $ tinyproxy -d -c path/to/tinyproxy.conf
111
+ $ tail -f path/to/file.log
112
+ $ curl -x localhost:8888 https://blog.engineyard.com -v
113
+ ```
114
+
115
+ You should see logging that the proxy is working!
116
+
117
+ ## Contributing
118
+
119
+ Bug reports and pull requests are welcome on GitHub at https://github.com/WalkerAndCoBrandsInc/ingram_micro. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
120
+
121
+ ## License
122
+
123
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ingram_micro"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/example.rb ADDED
@@ -0,0 +1,18 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'ingram_micro'
5
+ require 'logger'
6
+
7
+ IngramMicro.configure do |config|
8
+ config.api_root = ''
9
+ config.partner_name = 'Your company'
10
+ config.partner_password = ''
11
+ config.customer_id = '12345'
12
+ config.debug = true
13
+ config.logger = Logger.new(STDOUT)
14
+ end
15
+
16
+ options = {}
17
+ transmission = IngramMicro::SalesOrder.new(options)
18
+ transmission.send_request
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ingram_micro/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ingram_micro"
8
+ spec.version = IngramMicro::VERSION
9
+ spec.authors = ["Rachel Heaton","Joseph Nguyen", "Ben Christel"]
10
+ spec.email = ["rachelmheaton@gmail.com"]
11
+
12
+ spec.summary = %q{Rubygem wrapper for Ingram Micro API}
13
+ spec.homepage = "https://github.com/WalkerAndCoBrandsInc/ingram_micro"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "faraday"
30
+ spec.add_dependency "faraday_middleware"
31
+ spec.add_dependency "nokogiri", "~> 1.6"
32
+ spec.add_development_dependency "activesupport"
33
+ spec.add_development_dependency "bundler", "~> 1.10"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec"
36
+ spec.add_development_dependency "pry"
37
+ spec.add_development_dependency "factory_girl", "~>4.0"
38
+ end
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,42 @@
1
+ require "nokogiri"
2
+ require "faraday"
3
+ require "faraday_middleware"
4
+ require "ingram_micro/version"
5
+ require "ingram_micro/configuration"
6
+ require "ingram_micro/client"
7
+ require "ingram_micro/base_element"
8
+ require "ingram_micro/transmission"
9
+ require "ingram_micro/transmissions/sales_order"
10
+ require "ingram_micro/transmissions/check_shipment_status"
11
+ require "ingram_micro/transmissions/return_authorization"
12
+ require "ingram_micro/elements/customer"
13
+ require "ingram_micro/request_processor"
14
+ require "ingram_micro/elements/shipment_information"
15
+ require "ingram_micro/elements/credit_card_information"
16
+ require "ingram_micro/elements/sales_order_header"
17
+ require "ingram_micro/elements/return_order_header"
18
+ require "ingram_micro/elements/detail"
19
+ require "ingram_micro/elements/sales_order_line_item"
20
+ require "ingram_micro/elements/shipment_status_line_item"
21
+ require "ingram_micro/elements/return_authorization_line_item"
22
+ require "ingram_micro/elements/message_header_pw"
23
+ require "ingram_micro/elements/message_header_no_pw"
24
+ require "ingram_micro/elements/sales_order_submission"
25
+ require "ingram_micro/elements/return_authorization_submission"
26
+ require "ingram_micro/elements/purchase_order_information"
27
+ require "ingram_micro/elements/shipment_status"
28
+ require "ingram_micro/errors/invalid_type"
29
+ require "ingram_micro/errors/missing_field"
30
+
31
+ module IngramMicro
32
+ GEM_DIR = (File.dirname(__FILE__) + '/../').freeze
33
+
34
+ def self.configuration
35
+ @configuration ||= IngramMicro::Configuration.new
36
+ end
37
+
38
+ def self.configure
39
+ yield configuration
40
+ configuration.assert_valid
41
+ end
42
+ end
Binary file
@@ -0,0 +1,32 @@
1
+ class IngramMicro::BaseElement
2
+
3
+ attr_accessor :element
4
+
5
+ def initialize(options={})
6
+ @element = {}
7
+ self.defaults.each do |field, default|
8
+ value = (options[field] ? options[field] : default)
9
+ @element[field] = value
10
+ end
11
+ @element[:customer_id] ||= IngramMicro.configuration.customer_id
12
+ end
13
+
14
+ def build(builder)
15
+ self.defaults.keys.each do |field|
16
+ element_name = field.to_s.gsub('_', '-')
17
+ element_value = @element[field]
18
+ builder.send(element_name, element_value)
19
+ end
20
+ end
21
+
22
+ def parse(message_hash)
23
+ defaults.each do |field|
24
+ element_name = field.to_s.gsub('_', '-')
25
+ @element[field] = message_hash[element_name]
26
+ end
27
+ end
28
+
29
+ def integer?(string)
30
+ Integer(string) != nil rescue false
31
+ end
32
+ end
@@ -0,0 +1,49 @@
1
+ require 'uri'
2
+ class IngramMicro::Client
3
+
4
+ attr_reader :uri, :conn
5
+
6
+ def initialize(url=api_root)
7
+ @uri = URI.parse(url)
8
+ @conn = Faraday.new(url: uri) do |faraday|
9
+ faraday.request :url_encoded
10
+ faraday.response :logger, logger, bodies: log_request_body
11
+ faraday.adapter Faraday.default_adapter
12
+ faraday.proxy proxy if proxy
13
+ end
14
+ end
15
+
16
+ def get
17
+ conn.get uri.request_uri
18
+ end
19
+
20
+ def post(data)
21
+ conn.post do |req|
22
+ req.url uri.request_uri
23
+ req.headers['Content-Type'] = 'application/xml'
24
+ req.body = data
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def api_root
31
+ configuration.api_root
32
+ end
33
+
34
+ def logger
35
+ configuration.logger
36
+ end
37
+
38
+ def log_request_body
39
+ configuration.log_request_body
40
+ end
41
+
42
+ def proxy
43
+ configuration.proxy
44
+ end
45
+
46
+ def configuration
47
+ IngramMicro.configuration
48
+ end
49
+ end
@@ -0,0 +1,46 @@
1
+ require 'yaml'
2
+
3
+ module IngramMicro
4
+ class Configuration
5
+ attr_accessor :api_root, :debug, :logger,
6
+ :partner_name, :partner_password,
7
+ :log_request_body, :customer_id, :proxy
8
+
9
+ def assert_valid
10
+ assert_present :partner_name
11
+ assert_present :api_root
12
+ assert_present :customer_id
13
+ fail Error.new('logger must be set if debug is set') unless logger_valid?
14
+ fail Error.new('customer_id must be an integer') unless customer_id_valid?
15
+ fail Error.new('proxy must have protocol http://') unless proxy_valid?
16
+ end
17
+
18
+ private
19
+
20
+ def assert_present(field_name)
21
+ fail Error.new("#{field_name} is required") unless present?(field_name)
22
+ end
23
+
24
+ def logger_valid?
25
+ return true unless debug
26
+
27
+ present?(:logger)
28
+ end
29
+
30
+ def customer_id_valid?
31
+ customer_id.to_s =~ /^\d+$/
32
+ end
33
+
34
+ def proxy_valid?
35
+ return true if proxy.nil?
36
+
37
+ proxy =~ /^http:\/\//
38
+ end
39
+
40
+ def present?(field_name)
41
+ !send(field_name).nil?
42
+ end
43
+
44
+ class Error < StandardError; end
45
+ end
46
+ end