-
Notifications
You must be signed in to change notification settings - Fork 42
Add support for ECHO 1.1 #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ancorcruz
wants to merge
3
commits into
sshaw:master
Choose a base branch
from
ancorcruz:echo-11
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| require "active_support/core_ext/module/attribute_accessors" | ||
| require "nokogiri" | ||
|
|
||
| module DDEX | ||
| module ECHO | ||
| autoload :V11, "ddex/echo/v11" | ||
|
|
||
| ROOT_ELEMENT = "ManifestMessage".freeze | ||
| VERSION_ATTR = "MessageVersionId".freeze | ||
|
|
||
| DEFAULT_CONFIG = { | ||
| "V11" => { | ||
| :schema => "http://ddex.net/xml/2011/echo/11/echo.xsd", | ||
| :version => "1.1", | ||
| :message_version_id => "2011/echo/11" | ||
| }, | ||
| }.freeze | ||
|
|
||
| mattr_reader :config | ||
| @@config = DEFAULT_CONFIG | ||
|
|
||
| def self.supported_versions | ||
| config.values.map { |cfg| cfg[:version].dup }.sort | ||
| end | ||
|
|
||
| def self.supports?(version) | ||
| version = version.downcase.strip | ||
| config.any? { |name,cfg| name == version || cfg[:version] == version || cfg[:message_version_id] == version } | ||
| end | ||
|
|
||
| # options[:validate] ??? | ||
| def self.read(xml, options = nil) | ||
| options ||= {} | ||
| raise ArgumentError, "options must be a Hash" unless options.is_a?(Hash) | ||
|
|
||
| doc = parse(xml, options) | ||
| ver = options[:version] || doc.root[VERSION_ATTR] | ||
| klass = load_version(ver) | ||
|
|
||
| begin | ||
| klass.from_xml(doc) | ||
| rescue NoMethodError => e # Yes, fo real... this is from ROXML | ||
| raise unless e.name == :root # It's legit | ||
| raise XMLLoadError, "XML is not well-formed" | ||
| # This is a subclass of Exception(!) so we must name it | ||
| rescue ROXML::RequiredElementMissing => e | ||
| raise XMLLoadError, "missing required element: #{e}" | ||
| end | ||
| end | ||
|
|
||
| def self.write(object, options = nil) | ||
| raise ArgumentError, "not a DDEX object" unless object.is_a?(DDEX::Element) | ||
|
|
||
| options ||= {} | ||
| raise ArgumentError, "options must be a Hash" unless options.is_a?(Hash) | ||
|
|
||
| xmlopts = options.reject { |k, _| k == :schema } | ||
|
|
||
| node = object.to_xml | ||
| return node.to_xml(xmlopts) unless object.respond_to?(:message_version_id) # Is it the root element? | ||
|
|
||
| schema = schema_location(object, options[:schema]) | ||
| if schema | ||
| node.add_namespace_definition(XML_SCHEMA_INSTANCE_PREFIX, XML_SCHEMA_INSTANCE_NS) | ||
| node[XML_SCHEMA_INSTANCE_ATTR] = schema | ||
| end | ||
|
|
||
| doc = Nokogiri::XML::Document.new | ||
| doc.root = node | ||
| doc.to_xml(xmlopts) | ||
| end | ||
|
|
||
| private | ||
| def self.schema_location(object, schema) | ||
| # extract version from namespace e.g., DDEX::ECHO::V11::ManifestMessage | ||
| ver = object.class.name.split("::")[-2] | ||
| return unless schema or config.include?(ver) | ||
|
|
||
| # Check if it's "NS schema" | ||
| if schema && schema.strip.include?(" ") | ||
| schema | ||
| else | ||
| sprintf "%s %s", object.class.ns[1], schema || config[ver][:schema] | ||
| end | ||
| end | ||
|
|
||
| def self.parse(xml, options) | ||
| xml = File.read(xml) if xml.is_a?(String) and xml !~ /\A\s*<[?\w]/ | ||
| Nokogiri::XML(xml, nil, options[:encoding]) { |cfg| cfg.strict } | ||
| # ArgumentError means there was a problem with types, expected an int, got a str | ||
| rescue IOError, SystemCallError, ArgumentError => e | ||
| raise XMLLoadError, "cannot load XML: #{e}" | ||
| rescue Nokogiri::XML::SyntaxError => e | ||
| raise XMLLoadError, "XML parsing error: #{e}" | ||
| end | ||
|
|
||
| def self.raise_unknown_version(version) | ||
| message = "ECHO version %s" % (version ? "'#{version}'" : "attribute missing") | ||
| raise UnknownVersionError, message | ||
| end | ||
|
|
||
| def self.load_version(version) | ||
| raise_unknown_version(version) if version.nil? | ||
|
|
||
| # Some normalization | ||
| v = version.strip.gsub(%r{//+}, "/").gsub(%r{\A/|/\Z}, "") | ||
| klass, _ = config.find do |name, cfg| | ||
| cfg[:message_version_id] == v || cfg[:version] == v | ||
| end | ||
| raise_unknown_version(version) unless klass | ||
|
|
||
| # >= 2.0 allows for one call | ||
| DDEX::ECHO.const_get(klass).const_get(ROOT_ELEMENT) | ||
| rescue LoadError, NameError => e | ||
| raise_unknown_version(version) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # | ||
| # Do not edit. Automatically generated by `rake generate:main`. | ||
| # | ||
| module DDEX | ||
| module ECHO | ||
| module V11 | ||
| extend DDEX | ||
| require_standard("echo", "1.1") | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # | ||
| # Auto-generated by jaxb2ruby v0.0.1 on 2016-07-11 13:50:26 +0100 | ||
| # https://github.com/sshaw/jaxb2ruby | ||
| # | ||
| # | ||
| # DO NOT MODIFY | ||
| # Automatically generated by jaxb2ruby v0.0.1 (https://github.com/sshaw/jaxb2ruby) | ||
| # | ||
|
|
||
| require "roxml" | ||
| require "ddex/element" | ||
|
|
||
| require "ddex/echo/v11/delivery_message" | ||
| require "ddex/v20110120/ddexc/name" | ||
| require "ddex/v20110120/ddexc/reference_title" | ||
| require "ddex/v20110120/ddexc/release_id" | ||
| require "ddex/v20110120/ddexc/release_type" | ||
|
|
||
| module DDEX module ECHO module V11 # :nodoc: all | ||
|
|
||
| class DeliveredRelease < Element | ||
| include ROXML | ||
|
|
||
|
|
||
| xml_name "DeliveredRelease" | ||
|
|
||
| xml_accessor :release_ids, :as => [DDEX::V20110120::DDEXC::ReleaseId], :from => "ReleaseId", :required => true | ||
| xml_accessor :release_type, :as => DDEX::V20110120::DDEXC::ReleaseType, :from => "ReleaseType", :required => true | ||
| xml_accessor :display_artist_names, :as => [DDEX::V20110120::DDEXC::Name], :from => "DisplayArtistName", :required => true | ||
| xml_accessor :reference_title, :as => DDEX::V20110120::DDEXC::ReferenceTitle, :from => "ReferenceTitle", :required => true | ||
| xml_accessor :delivery_message, :as => DDEX::ECHO::V11::DeliveryMessage, :from => "DeliveryMessage", :required => false | ||
|
|
||
|
|
||
|
|
||
|
|
||
| end | ||
|
|
||
| end end end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # | ||
| # Auto-generated by jaxb2ruby v0.0.1 on 2016-07-11 13:50:26 +0100 | ||
| # https://github.com/sshaw/jaxb2ruby | ||
| # | ||
| # | ||
| # DO NOT MODIFY | ||
| # Automatically generated by jaxb2ruby v0.0.1 (https://github.com/sshaw/jaxb2ruby) | ||
| # | ||
|
|
||
| require "roxml" | ||
| require "ddex/element" | ||
|
|
||
| require "ddex/echo/v11/delivered_release" | ||
|
|
||
| module DDEX module ECHO module V11 # :nodoc: all | ||
|
|
||
| class DeliveredReleaseList < Element | ||
| include ROXML | ||
|
|
||
|
|
||
| xml_name "DeliveredReleaseList" | ||
|
|
||
| xml_accessor :delivered_releases, :as => [DDEX::ECHO::V11::DeliveredRelease], :from => "DeliveredRelease", :required => true | ||
|
|
||
|
|
||
|
|
||
|
|
||
| end | ||
|
|
||
| end end end |
44 changes: 44 additions & 0 deletions
44
lib/ddex/echo/v11/delivery_frequency_change_request_message.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # | ||
| # Auto-generated by jaxb2ruby v0.0.1 on 2016-07-11 13:50:26 +0100 | ||
| # https://github.com/sshaw/jaxb2ruby | ||
| # | ||
| # | ||
| # DO NOT MODIFY | ||
| # Automatically generated by jaxb2ruby v0.0.1 (https://github.com/sshaw/jaxb2ruby) | ||
| # | ||
|
|
||
| require "roxml" | ||
| require "ddex/element" | ||
|
|
||
| require "ddex/echo/v11/maximum_deliveries_per_day" | ||
| require "ddex/v2011/amep/v11/ws_message_header" | ||
| require "ddex/v20110120/ddexc/order_type" | ||
| require "ddex/v20110120/ddexc/party_descriptor" | ||
| require "ddex/v20110120/ddexc/period" | ||
|
|
||
| module DDEX module ECHO module V11 # :nodoc: all | ||
|
|
||
| class DeliveryFrequencyChangeRequestMessage < Element | ||
| include ROXML | ||
|
|
||
| setns "echo", "http://ddex.net/xml/2011/echo/11" | ||
|
|
||
| xml_name "DeliveryFrequencyChangeRequestMessage" | ||
|
|
||
| xml_accessor :message_header, :as => DDEX::V2011::AMEP::V11::WsMessageHeader, :from => "MessageHeader", :required => true | ||
| xml_accessor :dsp, :as => DDEX::V20110120::DDEXC::PartyDescriptor, :from => "DSP", :required => true | ||
| xml_accessor :delivery_action_type, :from => "DeliveryActionType", :required => true | ||
| xml_accessor :order_type, :as => DDEX::V20110120::DDEXC::OrderType, :from => "OrderType", :required => false | ||
| xml_accessor :maximum_deliveries_per_day, :as => DDEX::ECHO::V11::MaximumDeliveriesPerDay, :from => "MaximumDeliveriesPerDay", :required => false | ||
| xml_accessor :affected_period, :as => DDEX::V20110120::DDEXC::Period, :from => "AffectedPeriod", :required => false | ||
| xml_accessor :comment, :from => "Comment", :required => false | ||
|
|
||
|
|
||
|
|
||
| xml_accessor :message_version_id, :from => "@MessageVersionId", :required => true | ||
|
|
||
|
|
||
|
|
||
| end | ||
|
|
||
| end end end |
34 changes: 34 additions & 0 deletions
34
lib/ddex/echo/v11/delivery_frequency_change_response_message.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # | ||
| # Auto-generated by jaxb2ruby v0.0.1 on 2016-07-11 13:50:26 +0100 | ||
| # https://github.com/sshaw/jaxb2ruby | ||
| # | ||
| # | ||
| # DO NOT MODIFY | ||
| # Automatically generated by jaxb2ruby v0.0.1 (https://github.com/sshaw/jaxb2ruby) | ||
| # | ||
|
|
||
| require "roxml" | ||
| require "ddex/element" | ||
|
|
||
| require "ddex/echo/v11/ws_acknowledgement" | ||
|
|
||
| module DDEX module ECHO module V11 # :nodoc: all | ||
|
|
||
| class DeliveryFrequencyChangeResponseMessage < DDEX::ECHO::V11::WsAcknowledgement | ||
| include ROXML | ||
|
|
||
| setns "echo", "http://ddex.net/xml/2011/echo/11" | ||
|
|
||
| xml_name "DeliveryFrequencyChangeResponseMessage" | ||
|
|
||
| xml_accessor :successful?, :from => "IsSuccessful", :required => false | ||
|
|
||
|
|
||
|
|
||
| xml_accessor :message_version_id, :from => "@MessageVersionId", :required => true | ||
|
|
||
|
|
||
|
|
||
| end | ||
|
|
||
| end end end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # | ||
| # Auto-generated by jaxb2ruby v0.0.1 on 2016-07-11 13:50:26 +0100 | ||
| # https://github.com/sshaw/jaxb2ruby | ||
| # | ||
| # | ||
| # DO NOT MODIFY | ||
| # Automatically generated by jaxb2ruby v0.0.1 (https://github.com/sshaw/jaxb2ruby) | ||
| # | ||
|
|
||
| require "roxml" | ||
| require "ddex/element" | ||
|
|
||
|
|
||
| module DDEX module ECHO module V11 # :nodoc: all | ||
|
|
||
| class DeliveryMessage < Element | ||
| include ROXML | ||
|
|
||
|
|
||
| xml_name "DeliveryMessage" | ||
|
|
||
| xml_accessor :message_type, :from => "MessageType", :required => true | ||
| xml_accessor :delivery_date, :as => DateTime, :from => "DeliveryDate", :required => false | ||
| xml_accessor :url, :from => "URL", :required => false | ||
| xml_accessor :message_size, :from => "MessageSize", :required => false | ||
| xml_accessor :number_of_resource_files_delivered, :as => Integer, :from => "NumberOfResourceFilesDelivered", :required => false | ||
| xml_accessor :message_id, :from => "MessageId", :required => false | ||
|
|
||
|
|
||
|
|
||
|
|
||
| end | ||
|
|
||
| end end end |
38 changes: 38 additions & 0 deletions
38
lib/ddex/echo/v11/information_about_available_release_request_message.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # | ||
| # Auto-generated by jaxb2ruby v0.0.1 on 2016-07-11 13:50:26 +0100 | ||
| # https://github.com/sshaw/jaxb2ruby | ||
| # | ||
| # | ||
| # DO NOT MODIFY | ||
| # Automatically generated by jaxb2ruby v0.0.1 (https://github.com/sshaw/jaxb2ruby) | ||
| # | ||
|
|
||
| require "roxml" | ||
| require "ddex/element" | ||
|
|
||
| require "ddex/v2011/amep/v11/ws_message_header" | ||
| require "ddex/v20110120/ddexc/party_descriptor" | ||
| require "ddex/v20110120/ddexc/period" | ||
|
|
||
| module DDEX module ECHO module V11 # :nodoc: all | ||
|
|
||
| class InformationAboutAvailableReleaseRequestMessage < Element | ||
| include ROXML | ||
|
|
||
| setns "echo", "http://ddex.net/xml/2011/echo/11" | ||
|
|
||
| xml_name "InformationAboutAvailableReleaseRequestMessage" | ||
|
|
||
| xml_accessor :message_header, :as => DDEX::V2011::AMEP::V11::WsMessageHeader, :from => "MessageHeader", :required => true | ||
| xml_accessor :dsp, :as => DDEX::V20110120::DDEXC::PartyDescriptor, :from => "DSP", :required => true | ||
| xml_accessor :period, :as => DDEX::V20110120::DDEXC::Period, :from => "Period", :required => false | ||
|
|
||
|
|
||
|
|
||
| xml_accessor :message_version_id, :from => "@MessageVersionId", :required => true | ||
|
|
||
|
|
||
|
|
||
| end | ||
|
|
||
| end end end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more or less a copy a ern.rb. Can you put this into a base class or module or something to eliminate the duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is. I'll do.