Project

cxml-ruby

0.01
Low commit activity in last 3 years
No release in over a year
Ruby library to parse/generate documents with the cXML protocol
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.12
~> 13.0
~> 3.9
~> 0.81

Runtime

~> 2.13
 Project Readme

cXML-Ruby

Ruby Specs

Ruby implementation of the cXML protocol.

Currently supports these top-level documents in v1.2.037:

  • Request
    • InvoiceDetailRequest
    • OrderRequest
    • PunchOutSetupRequest
    • ConfirmationRequest
  • Response
    • Status
    • PunchOutSetupResponse
  • Message
    • PunchOutOrderMessage
  • Pull requests welcome to support more!

Usage

some_xml = '....'
parsed_hash = CXML::Parser.new(data: some_xml).parse
# or
doc = CXML::Document.new.from_xml(some_xml)
# or
doc = CXML::Document.new(parsed_hash)
# raises CXML::UnknownAttributeError if unknown fields are present

doc.response.status.code
# => 200
doc.response.status.success?
# => true

# initialize docs with a hash
CXML::Document.new(response: { status: { code: '200' } }).to_xml
# => '<?xml.....'

# initialize docs with instances
status = CXML::Status.new(code: '200')
response = CXML::Response.new(status: status)
CXML::Document.new(response: response).to_xml
# => '<?xml.....'

# Set a different version
CXML::Document.new(version: '1.1.0', response: { status: { code: '200' } }).to_xml
# => '<?xml.....'

Installation

Add this line to the application's Gemfile:

gem 'cxml-ruby'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cxml-ruby

Configuration

CXML.configure do |config|
  # Set this to false to log intead of raise exception on unknown elements
  # defaults to true, raises CXML::UnknownAttributeError
  config.raise_unknown_elements = true

  # Optionally set a custom logger, used for parsing error logging
  # defaults to Logger.new(STDOUT, level: :warn)
  config.logger = Logger.new(STDOUT, level: :warn)
end

Running Tests

Install dependencies:

bundle install

Run suite:

rspec

Documentation

Procotol specifications could be found here http://xml.cxml.org/current/cXMLUsersGuide.pdf