fog-xml-0.1.1/0000755000175000017500000000000012436264140014352 5ustar balasankarcbalasankarcfog-xml-0.1.1/LICENSE.md0000644000175000017500000000220012436264140015750 0ustar balasankarcbalasankarcThe MIT License (MIT) Copyright (c) 2014-2014 [CONTRIBUTORS.md](https://github.com/zertico/fog-xml/blob/master/CONTRIBUTORS.md) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.fog-xml-0.1.1/Gemfile0000644000175000017500000000013412436264140015643 0ustar balasankarcbalasankarcsource "https://rubygems.org" # Specify your gem's dependencies in fog-xml.gemspec gemspec fog-xml-0.1.1/gemfiles/0000755000175000017500000000000012436264140016145 5ustar balasankarcbalasankarcfog-xml-0.1.1/gemfiles/Gemfile.1.8.70000644000175000017500000000024312436264140020111 0ustar balasankarcbalasankarcsource :rubygems gem 'mime-types', '< 2.0' gem 'nokogiri', '< 1.6' gem 'rest-client', '~> 1.6.8' gem 'fog-core', :github => 'fog/fog-core' gemspec :path => '../'fog-xml-0.1.1/gemfiles/Gemfile.1.9.2+0000644000175000017500000000022212436264140020155 0ustar balasankarcbalasankarcsource :rubygems gem 'activesupport', '>= 3.0', '< 4' gem 'mime-types', '< 2.0' gem 'fog-core', :github => 'fog/fog-core' gemspec :path => '../'fog-xml-0.1.1/.gitignore0000644000175000017500000000031012436264140016334 0ustar balasankarcbalasankarc*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp *.bundle *.so *.o *.a mkmf.log gemfiles/*.lockfog-xml-0.1.1/Rakefile0000644000175000017500000000033212436264140016015 0ustar balasankarcbalasankarcrequire "bundler/gem_tasks" require "rake/testtask" Rake::TestTask.new do |t| t.libs.push %w(spec) t.test_files = FileList["spec/**/*_spec.rb"] t.verbose = true end desc "Default Task" task :default => [:test] fog-xml-0.1.1/metadata.yml0000644000175000017500000001032612436264140016657 0ustar balasankarcbalasankarc--- !ruby/object:Gem::Specification name: fog-xml version: !ruby/object:Gem::Version version: 0.1.1 platform: ruby authors: - Wesley Beary (geemus) - Paul Thornthwaite (tokengeek) - The fog team autorequire: bindir: bin cert_chain: [] date: 2014-11-06 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: fog-core requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: nokogiri requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.5' - - ">=" - !ruby/object:Gem::Version version: 1.5.11 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.5' - - ">=" - !ruby/object:Gem::Version version: 1.5.11 - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: minitest requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: turn requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: pry requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: coveralls requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' description: |- Extraction of the XML parsing tools shared between a number of providers in the 'fog' gem email: - geemus@gmail.com - tokengeek@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - ".gitignore" - ".rubocop.yml" - ".ruby-gemset" - ".ruby-version" - ".travis.yml" - CONTRIBUTING.md - CONTRIBUTORS.md - Gemfile - LICENSE.md - README.md - Rakefile - fog-xml.gemspec - gemfiles/Gemfile.1.8.7 - gemfiles/Gemfile.1.9.2+ - lib/fog/parsers/base.rb - lib/fog/to_hash_document.rb - lib/fog/xml.rb - lib/fog/xml/connection.rb - lib/fog/xml/sax_parser_connection.rb - lib/fog/xml/version.rb - spec/fog/parsers/base_spec.rb - spec/fog/xml/connection_spec.rb - spec/minitest_helper.rb homepage: https://github.com/fog/fog-xml licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.2.2 signing_key: specification_version: 4 summary: XML parsing for fog providers test_files: - spec/fog/parsers/base_spec.rb - spec/fog/xml/connection_spec.rb - spec/minitest_helper.rb fog-xml-0.1.1/.ruby-gemset0000644000175000017500000000000712436264140016613 0ustar balasankarcbalasankarcfog-xmlfog-xml-0.1.1/lib/0000755000175000017500000000000012436264140015120 5ustar balasankarcbalasankarcfog-xml-0.1.1/lib/fog/0000755000175000017500000000000012436264140015673 5ustar balasankarcbalasankarcfog-xml-0.1.1/lib/fog/xml/0000755000175000017500000000000012436264140016473 5ustar balasankarcbalasankarcfog-xml-0.1.1/lib/fog/xml/version.rb0000644000175000017500000000007012436264140020502 0ustar balasankarcbalasankarcmodule Fog module Xml VERSION = "0.1.1" end end fog-xml-0.1.1/lib/fog/xml/connection.rb0000644000175000017500000000043012436264140021154 0ustar balasankarcbalasankarcmodule Fog module XML class Connection < SAXParserConnection def request(params, &_block) parser = params.delete(:parser) if parser super(parser, params) else original_request(params) end end end end end fog-xml-0.1.1/lib/fog/xml/sax_parser_connection.rb0000644000175000017500000000350612436264140023412 0ustar balasankarcbalasankarcrequire "fog/core/connection" module Fog module XML class SAXParserConnection < ::Fog::Core::Connection # Makes a request using the connection using Excon # # @param [Hash] params # @option params [String] :body text to be sent over a socket # @option params [Hash] :headers The default headers to supply in a request # @option params [String] :host The destination host"s reachable DNS name or IP, in the form of a String # @option params [String] :path appears after "scheme://host:port/" # @option params [Fixnum] :port The port on which to connect, to the destination host # @option params [Hash] :query appended to the "scheme://host:port/path/" in the form of "?key=value" # @option params [String] :scheme The protocol; "https" causes OpenSSL to be used # @option params [Proc] :response_block # @option params [Nokogiri::XML::SAX::Document] :parser # # @return [Excon::Response] # # @raise [Excon::Errors::StubNotFound] # @raise [Excon::Errors::Timeout] # @raise [Excon::Errors::SocketError] # def request(parser, params) reset unless @persistent # Prepare the SAX parser data_stream = Nokogiri::XML::SAX::PushParser.new(parser) response_string = "" params[:response_block] = lambda do |chunk, _remaining, _total| response_string << chunk if ENV["DEBUG_RESPONSE"] data_stream << chunk end # Make request which read chunks into parser response = @excon.request(params) Fog::Logger.debug "\n#{response_string}" if ENV["DEBUG_RESPONSE"] # Cease parsing and override response.body with parsed data data_stream.finish response.body = parser.response response end end end end fog-xml-0.1.1/lib/fog/to_hash_document.rb0000644000175000017500000000327512436264140021552 0ustar balasankarcbalasankarcmodule Fog class ToHashDocument < Nokogiri::XML::SAX::Document def initialize @stack = [] end def characters(string) @value ||= "" @value << string.strip end def end_element(name) last = @stack.pop if last.empty? && @value.empty? @stack.last[name.to_sym] = "" elsif last == { :i_nil => "true" } @stack.last[name.to_sym] = nil elsif !@value.empty? @stack.last[name.to_sym] = @value end @value = "" end def body @stack.first end def response body end def start_element(name, attributes = []) @value = "" parsed_attributes = {} until attributes.empty? if attributes.first.is_a?(Array) key, value = attributes.shift else key, value = attributes.shift, attributes.shift end parsed_attributes[key.gsub(":", "_").to_sym] = value end if @stack.last.is_a?(Array) @stack.last << { name.to_sym => parsed_attributes } else data = if @stack.empty? @stack.push(parsed_attributes) parsed_attributes elsif @stack.last[name.to_sym] unless @stack.last[name.to_sym].is_a?(Array) @stack.last[name.to_sym] = [@stack.last[name.to_sym]] end @stack.last[name.to_sym] << parsed_attributes @stack.last[name.to_sym].last else @stack.last[name.to_sym] = {} @stack.last[name.to_sym].merge!(parsed_attributes) @stack.last[name.to_sym] end @stack.push(data) end end end end fog-xml-0.1.1/lib/fog/xml.rb0000644000175000017500000000046512436264140017025 0ustar balasankarcbalasankarcrequire "fog/xml/version" require "nokogiri" module Fog autoload :ToHashDocument, "fog/to_hash_document" module XML autoload :SAXParserConnection, "fog/xml/sax_parser_connection" autoload :Connection, "fog/xml/connection" end module Parsers autoload :Base, "fog/parsers/base" end end fog-xml-0.1.1/lib/fog/parsers/0000755000175000017500000000000012436264140017352 5ustar balasankarcbalasankarcfog-xml-0.1.1/lib/fog/parsers/base.rb0000644000175000017500000000215012436264140020607 0ustar balasankarcbalasankarcrequire "nokogiri" module Fog module Parsers class Base < Nokogiri::XML::SAX::Document attr_reader :response def initialize reset end def attr_value(name, attrs) (entry = attrs.find {|a| a.localname == name }) && entry.value end def reset @response = {} end def characters(string) @value ||= '' @value << string end # ############################################################################### # This is a workaround. Original implementation from Nokogiri is overwritten with # one that does not join namespace prefix with local name. def start_element_namespace name, attrs = [], prefix = nil, uri = nil, ns = [] start_element name, attrs end def end_element_namespace name, prefix = nil, uri = nil end_element name end # ############################################################################### def start_element(name, attrs = []) @value = nil end def value @value && @value.dup end end end end fog-xml-0.1.1/.ruby-version0000644000175000017500000000000512436264140017012 0ustar balasankarcbalasankarc2.1.2fog-xml-0.1.1/CONTRIBUTING.md0000644000175000017500000000151712436264140016607 0ustar balasankarcbalasankarc## Getting Involved New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another. ### Coding * Pick a task: * Offer feedback on open [pull requests](https://github.com/fog/fog-xml/pulls). * Review open [issues](https://github.com/fog/fog-xml/issues) for things to help on. * [Create an issue](https://github.com/fog/fog-xml/issues/new) to start a discussion on additions or features. * Fork the project, add your changes and tests to cover them in a topic branch. * Commit your changes and rebase against `fog/fog-xml` to ensure everything is up to date. * [Submit a pull request](https://github.com/fog/fog-xml/compare/) ### Non-Coding * Offer feedback on open [issues](https://github.com/fog/fog-xml/issues). * Organize or volunteer at events.fog-xml-0.1.1/fog-xml.gemspec0000644000175000017500000000235012436264140017270 0ustar balasankarcbalasankarc# coding: utf-8 lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "fog/xml/version" Gem::Specification.new do |spec| spec.name = "fog-xml" spec.version = Fog::Xml::VERSION spec.authors = ["Wesley Beary (geemus)", "Paul Thornthwaite (tokengeek)", "The fog team"] spec.email = ["geemus@gmail.com", "tokengeek@gmail.com"] spec.summary = "XML parsing for fog providers" spec.description = "Extraction of the XML parsing tools shared between a number of providers in the 'fog' gem" spec.homepage = "https://github.com/fog/fog-xml" spec.license = "MIT" spec.files = `git ls-files -z`.split("\x0") spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) } spec.test_files = spec.files.grep(/^(test|spec|features)\//) spec.require_paths = %w(lib) spec.add_dependency "fog-core" spec.add_dependency "nokogiri", "~> 1.5", ">= 1.5.11" spec.add_development_dependency "rake" spec.add_development_dependency "minitest" spec.add_development_dependency "turn" spec.add_development_dependency "pry" spec.add_development_dependency "coveralls" if RUBY_VERSION.to_f >= 1.9 end fog-xml-0.1.1/spec/0000755000175000017500000000000012436264140015304 5ustar balasankarcbalasankarcfog-xml-0.1.1/spec/minitest_helper.rb0000644000175000017500000000153612436264140021031 0ustar balasankarcbalasankarcrequire "minitest/spec" require "minitest/autorun" require "turn" require "excon" require "fog/core" Turn.config do |c| # use one of output formats: # :outline - turn's original case/test outline mode [default] # :progress - indicates progress with progress bar # :dotted - test/unit's traditional dot-progress mode # :pretty - new pretty reporter # :marshal - dump output as YAML (normal run mode only) # :cue - interactive testing # c.format = :outline # turn on invoke/execute tracing, enable full backtrace c.trace = 20 # use humanized test names (works only with :outline format) c.natural = true end if ENV["COVERAGE"] require "coveralls" require "simplecov" SimpleCov.start do add_filter "/spec/" end end require File.join(File.dirname(__FILE__), "../lib/fog/xml") Coveralls.wear! if ENV["COVERAGE"] fog-xml-0.1.1/spec/fog/0000755000175000017500000000000012436264140016057 5ustar balasankarcbalasankarcfog-xml-0.1.1/spec/fog/xml/0000755000175000017500000000000012436264140016657 5ustar balasankarcbalasankarcfog-xml-0.1.1/spec/fog/xml/connection_spec.rb0000644000175000017500000000156112436264140022360 0ustar balasankarcbalasankarcrequire "minitest_helper" describe Fog::XML::Connection do before do @connection = Fog::XML::Connection.new("http://localhost") end after do Excon.stubs.clear end it "responds to #request" do assert_respond_to @connection, :request end describe "when request is passed a parser" do it "returns the body after parsing" do @parser = Fog::ToHashDocument.new Excon.stub({}, { :status => 200, :body => "" }) response = @connection.request(:parser => @parser, :mock => true) assert_equal({ :xml => "" }, response.body) end end describe "when request excludes a parser" do it "returns the response body without change" do Excon.stub({}, { :status => 200, :body => "" }) response = @connection.request(:mock => true) assert_equal("", response.body) end end end fog-xml-0.1.1/spec/fog/parsers/0000755000175000017500000000000012436264140017536 5ustar balasankarcbalasankarcfog-xml-0.1.1/spec/fog/parsers/base_spec.rb0000644000175000017500000000310312436264140022004 0ustar balasankarcbalasankarcrequire "minitest_helper" describe Fog::Parsers::Base do def parse(input, parser_class) document = parser_class.new parser = Nokogiri::XML::SAX::Parser.new(document) parser.parse input document.response end describe 'value' do class ValueTest < Fog::Parsers::Base def start_element(name, attrs) @stack.push({}) super end def reset super @stack = [@response] end def end_element name top = @stack.pop if top.empty? @stack.last[name] = value else @stack.last[name] = top if @stack.any? end end end it 'extracts the characters for the current element' do doc = <<-XML FooValue BarValue XML assert_equal({'Test'=> {'Foo' => 'FooValue', 'Bar' => 'BarValue'}}, parse(doc, ValueTest)) end end describe 'attr_value' do class AttrParser < Fog::Parsers::Base def start_element(name, attrs=[]) super @response[name] = {'foo' => attr_value('foo', attrs)} end end describe 'the attribute exists' do it 'returns the value' do doc = <<-XML XML assert_equal({'Test'=> {'foo' => 'bar'}}, parse(doc, AttrParser)) end end describe 'the attribute does not exist' do it 'returns nil' do doc = <<-XML XML assert_equal({'Test'=> {'foo' => nil}}, parse(doc, AttrParser)) end end end endfog-xml-0.1.1/CONTRIBUTORS.md0000644000175000017500000000024312436264140016630 0ustar balasankarcbalasankarc* Michael Hale * Paul Thornthwaite * Paulo Henrique Lopes Ribeiro * Wesley Beary fog-xml-0.1.1/.travis.yml0000644000175000017500000000102312436264140016457 0ustar balasankarcbalasankarcmatrix: include: - rvm: 1.8.7 gemfile: gemfiles/Gemfile.1.8.7 - rvm: 1.9.2 gemfile: gemfiles/Gemfile.1.9.2+ env: COVERAGE=true - rvm: 1.9.3 gemfile: gemfiles/Gemfile.1.9.2+ env: COVERAGE=true - rvm: 2.0.0 gemfile: gemfiles/Gemfile.1.9.2+ env: COVERAGE=true - rvm: 2.1.1 gemfile: gemfiles/Gemfile.1.9.2+ env: COVERAGE=true - rvm: ree gemfile: gemfiles/Gemfile.1.8.7 - rvm: jruby gemfile: gemfiles/Gemfile.1.9.2+ env: COVERAGE=truefog-xml-0.1.1/README.md0000644000175000017500000000123012436264140015625 0ustar balasankarcbalasankarc# Fog::Xml Shared XML related functionality for fog [![Build Status](https://secure.travis-ci.org/fog/fog-xml.png?branch=master)](http://travis-ci.org/fog/fog-xml) ## Installation Add this line to your application's Gemfile: gem 'fog-xml' And then execute: $ bundle Or install it yourself as: $ gem install fog-xml ## Usage TODO: Write usage instructions here ## Contributing 1. Fork it ( https://github.com/fog/fog-xml/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request fog-xml-0.1.1/.rubocop.yml0000644000175000017500000000047412436264140016631 0ustar balasankarcbalasankarcMetrics/LineLength: Enabled: false Style/EachWithObject: Enabled: false Style/Encoding: EnforcedStyle: when_needed Style/FormatString: Enabled: false Style/HashSyntax: EnforcedStyle: hash_rockets Style/SignalException: EnforcedStyle: only_raise Style/StringLiterals: EnforcedStyle: double_quotes