woahdae-consumer 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/History.txt +4 -0
  2. data/LICENSE +20 -0
  3. data/Manifest.txt +73 -0
  4. data/PostInstall.txt +8 -0
  5. data/README.rdoc +53 -0
  6. data/Rakefile +30 -0
  7. data/app_generators/consumer/USAGE +14 -0
  8. data/app_generators/consumer/consumer_generator.rb +89 -0
  9. data/app_generators/consumer/templates/LICENSE +20 -0
  10. data/app_generators/consumer/templates/README.rdoc +3 -0
  11. data/app_generators/consumer/templates/Rakefile +57 -0
  12. data/app_generators/consumer/templates/TODO +4 -0
  13. data/app_generators/consumer/templates/config/config.yml +2 -0
  14. data/app_generators/consumer/templates/config/config.yml.sample +1 -0
  15. data/app_generators/consumer/templates/lib/base.rb +6 -0
  16. data/app_generators/consumer/templates/rails/init.rb +1 -0
  17. data/app_generators/consumer/templates/script/destroy +14 -0
  18. data/app_generators/consumer/templates/script/generate +14 -0
  19. data/app_generators/consumer/templates/spec/spec_helper.rb +11 -0
  20. data/bin/consumer +17 -0
  21. data/config/website.yml.sample +2 -0
  22. data/consumer.gemspec +48 -0
  23. data/consumer_generators/request/USAGE +25 -0
  24. data/consumer_generators/request/request_generator.rb +94 -0
  25. data/consumer_generators/request/templates/lib/request.rb +55 -0
  26. data/consumer_generators/request/templates/lib/response.rb +12 -0
  27. data/consumer_generators/request/templates/spec/request_spec.rb +27 -0
  28. data/consumer_generators/request/templates/spec/response_spec.rb +10 -0
  29. data/consumer_generators/request/templates/spec/xml/response.xml +0 -0
  30. data/examples/active_record/README.txt +1 -0
  31. data/examples/active_record/ar_spec.rb +33 -0
  32. data/examples/active_record/database.sqlite +0 -0
  33. data/examples/active_record/environment.rb +15 -0
  34. data/examples/active_record/migration.rb +21 -0
  35. data/examples/active_record/models/book.rb +13 -0
  36. data/examples/active_record/models/contributor.rb +12 -0
  37. data/examples/active_record/xml/book.xml +6 -0
  38. data/examples/active_record/xml/book_with_contributors.xml +11 -0
  39. data/examples/active_record/xml/contributor.xml +3 -0
  40. data/examples/active_record/xml/contributor_with_books.xml +19 -0
  41. data/examples/shipping/environment.rb +3 -0
  42. data/examples/shipping/rate.rb +15 -0
  43. data/examples/shipping/shipping.yml.sample +8 -0
  44. data/examples/shipping/shipping_spec.rb +27 -0
  45. data/examples/shipping/ups_rate_request.rb +182 -0
  46. data/examples/shipping/ups_rate_response.xml +340 -0
  47. data/lib/consumer/helper.rb +111 -0
  48. data/lib/consumer/mapping.rb +184 -0
  49. data/lib/consumer/request.rb +280 -0
  50. data/lib/consumer.rb +28 -0
  51. data/script/console +10 -0
  52. data/script/destroy +14 -0
  53. data/script/generate +14 -0
  54. data/script/txt2html +71 -0
  55. data/spec/helper_spec.rb +136 -0
  56. data/spec/mapping_spec.rb +94 -0
  57. data/spec/request_spec.rb +75 -0
  58. data/spec/spec.opts +1 -0
  59. data/spec/spec_helper.rb +12 -0
  60. data/spec/xml/rate_response.xml +14 -0
  61. data/spec/xml/rate_response_error.xml +35 -0
  62. data/tasks/rspec.rake +21 -0
  63. data/test/test_consumer_generator.rb +68 -0
  64. data/test/test_generator_helper.rb +29 -0
  65. data/website/index.html +11 -0
  66. data/website/index.txt +81 -0
  67. data/website/javascripts/rounded_corners_lite.inc.js +285 -0
  68. data/website/stylesheets/screen.css +159 -0
  69. data/website/template.html.erb +50 -0
  70. metadata +180 -0
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-11-10
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Woody Peterson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,73 @@
1
+ History.txt
2
+ LICENSE
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.rdoc
6
+ Rakefile
7
+ app_generators/consumer/USAGE
8
+ app_generators/consumer/consumer_generator.rb
9
+ app_generators/consumer/templates/LICENSE
10
+ app_generators/consumer/templates/README.rdoc
11
+ app_generators/consumer/templates/Rakefile
12
+ app_generators/consumer/templates/TODO
13
+ app_generators/consumer/templates/config/config.yml
14
+ app_generators/consumer/templates/config/config.yml.sample
15
+ app_generators/consumer/templates/lib/base.rb
16
+ app_generators/consumer/templates/rails/init.rb
17
+ app_generators/consumer/templates/script/destroy
18
+ app_generators/consumer/templates/script/generate
19
+ app_generators/consumer/templates/spec/spec_helper.rb
20
+ bin/consumer
21
+ config/website.yml.sample
22
+ consumer.gemspec
23
+ consumer_generators/request/USAGE
24
+ consumer_generators/request/request_generator.rb
25
+ consumer_generators/request/templates/lib/request.rb
26
+ consumer_generators/request/templates/lib/response.rb
27
+ consumer_generators/request/templates/spec/request_spec.rb
28
+ consumer_generators/request/templates/spec/response_spec.rb
29
+ consumer_generators/request/templates/spec/xml/response.xml
30
+ examples/active_record/README.txt
31
+ examples/active_record/ar_spec.rb
32
+ examples/active_record/database.sqlite
33
+ examples/active_record/environment.rb
34
+ examples/active_record/migration.rb
35
+ examples/active_record/models/book.rb
36
+ examples/active_record/models/contributor.rb
37
+ examples/active_record/xml/book.xml
38
+ examples/active_record/xml/book_with_contributors.xml
39
+ examples/active_record/xml/contributor.xml
40
+ examples/active_record/xml/contributor_with_books.xml
41
+ examples/shipping/environment.rb
42
+ examples/shipping/rate.rb
43
+ examples/shipping/shipping.yml.sample
44
+ examples/shipping/shipping_spec.rb
45
+ examples/shipping/ups_rate_request.rb
46
+ examples/shipping/ups_rate_response.xml
47
+ lib/consumer.rb
48
+ lib/consumer/helper.rb
49
+ lib/consumer/mapping.rb
50
+ lib/consumer/request.rb
51
+ rails_generators/request/USAGE
52
+ rails_generators/request/request_generator.rb
53
+ script/console
54
+ script/destroy
55
+ script/generate
56
+ script/txt2html
57
+ spec/helper_spec.rb
58
+ spec/mapping_spec.rb
59
+ spec/request_spec.rb
60
+ spec/spec.opts
61
+ spec/spec_helper.rb
62
+ spec/xml/rate_response.xml
63
+ spec/xml/rate_response_error.xml
64
+ tasks/rspec.rake
65
+ test/test_consumer_generator.rb
66
+ test/test_consumer_plugin_request_generator.rb
67
+ test/test_generator_helper.rb
68
+ test/test_rails_request_generator.rb
69
+ website/index.html
70
+ website/index.txt
71
+ website/javascripts/rounded_corners_lite.inc.js
72
+ website/stylesheets/screen.css
73
+ website/template.html.erb
data/PostInstall.txt ADDED
@@ -0,0 +1,8 @@
1
+ Getting Started with Consumer:
2
+
3
+ consumer your_gem_name
4
+ cd your_gem_name
5
+ script/generate request
6
+
7
+ The last command should help you get rolling.
8
+
data/README.rdoc ADDED
@@ -0,0 +1,53 @@
1
+ = consumer
2
+
3
+ http://consumer.rubyforge.org
4
+
5
+ == DESCRIPTION:
6
+
7
+ Consumer is a library for consuming xml resources via Builder, libxml, and some request sending / response marshaling glue. It comes with an app generator that creates an empty ready-for-rails gem that itself comes with a generator for making the request/response classes, config files, and specs (see script/generate after creating a new Consumer project).
8
+
9
+ == FEATURES:
10
+
11
+ A Consumer request class's features include required variable checks, a place for in-class and yaml defaults, a ready to use builder object for creating the xml, and a method for sending the xml to the class's request url that returns Consumer response objects.
12
+
13
+ Consumer response classes get their features via mixin instead of inheritance (unlike the request classes), so it can return instances of models that already exist in your project. The main feature here is a mapping method that specifies attribute-xpath pairs to map object attributes to an xml response. Multiple mappings can exist for a class, so it can be created from a variety of xml sources. It can return a single response object or an array of response objects, and can set attributes of a response object to other response objects (i.e. it can handle associations).
14
+
15
+ == SYNOPSIS:
16
+
17
+ FIX (code sample of usage)
18
+
19
+ == REQUIREMENTS:
20
+
21
+ libxml-ruby
22
+ builder
23
+ activesupport
24
+
25
+ == INSTALL:
26
+
27
+ * if you haven't already, <code>gem sources -a http://gems.github.com</code>
28
+ * <code>sudo gem install woahdae-consumer</code>
29
+
30
+ == LICENSE:
31
+
32
+ (The MIT License)
33
+
34
+ Copyright (c) 2008 Woody Peterson
35
+
36
+ Permission is hereby granted, free of charge, to any person obtaining
37
+ a copy of this software and associated documentation files (the
38
+ 'Software'), to deal in the Software without restriction, including
39
+ without limitation the rights to use, copy, modify, merge, publish,
40
+ distribute, sublicense, and/or sell copies of the Software, and to
41
+ permit persons to whom the Software is furnished to do so, subject to
42
+ the following conditions:
43
+
44
+ The above copyright notice and this permission notice shall be
45
+ included in all copies or substantial portions of the Software.
46
+
47
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
48
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
50
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
51
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
52
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
53
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/consumer'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('consumer', Consumer::VERSION) do |p|
7
+ p.developer('Woody Peterson', 'woody.peterson@gmail.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
+ p.rubyforge_name = p.name # TODO this is default value
11
+ p.extra_deps = [
12
+ ['activesupport','>= 2.0.2'],
13
+ ['libxml-ruby', '>= 0.8.3'],
14
+ ['builder', '>= 2.1.2']
15
+ ]
16
+ p.extra_dev_deps = [
17
+ ['newgem', ">= #{::Newgem::VERSION}"]
18
+ ]
19
+
20
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
21
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
22
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
23
+ p.rsync_args = '-av --delete --ignore-errors'
24
+ end
25
+
26
+ require 'newgem/tasks' # load /tasks/*.rake
27
+ Dir['tasks/**/*.rake'].each { |t| load t }
28
+
29
+ # TODO - want other tests/tasks run by default? Add them to the list
30
+ # task :default => [:spec, :features]
@@ -0,0 +1,14 @@
1
+ Description:
2
+
3
+ Creates an empty ready-for-rails gem primed for consuming an xml resource via
4
+ Builder, libxml, and some request sending / response marshaling glue.
5
+
6
+ Comes with a generator for making the request/response classes, config files,
7
+ and specs (see script/generate after creating the gem).
8
+
9
+ Usage:
10
+
11
+ consumer your_xml_consuming_gem_name
12
+
13
+ (there are no options)
14
+
@@ -0,0 +1,89 @@
1
+ class ConsumerGenerator < RubiGen::Base
2
+
3
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
+ Config::CONFIG['ruby_install_name'])
5
+
6
+ default_options :author => nil
7
+
8
+ attr_reader :name
9
+
10
+ def initialize(runtime_args, runtime_options = {})
11
+ super
12
+ usage if args.empty?
13
+ @destination_root = File.expand_path(args.shift)
14
+ @name = base_name
15
+ extract_options
16
+ end
17
+
18
+ def manifest
19
+ record do |m|
20
+ # Ensure appropriate folder(s) exists
21
+ m.directory ''
22
+ BASEDIRS.each { |path| m.directory path }
23
+
24
+ # Create stubs
25
+ # m.template "template.rb", "some_file_after_erb.rb"
26
+ # m.template_copy_each ["template.rb", "template2.rb"]
27
+ # m.file "file", "some_file_copied"
28
+
29
+ m.file_copy_each %w(
30
+ LICENSE
31
+ )
32
+
33
+ m.template "config/config.yml", "config/#{@name}.yml"
34
+ m.file "config/config.yml.sample", "config/#{@name}.yml.sample"
35
+
36
+ m.template_copy_each %w(
37
+ TODO
38
+ rails/init.rb
39
+ spec/spec_helper.rb
40
+ README.rdoc
41
+ Rakefile
42
+ )
43
+
44
+ m.template "lib/base.rb", "lib/#{@name}.rb"
45
+ m.directory "lib/#{@name}"
46
+
47
+ m.dependency "install_rubigen_scripts", [destination_root, 'consumer'],
48
+ :shebang => options[:shebang], :collision => :force
49
+ end
50
+ end
51
+
52
+ protected
53
+ def banner
54
+ <<-EOS
55
+ Creates a ...
56
+
57
+ USAGE: #{spec.name} name
58
+ EOS
59
+ end
60
+
61
+ def add_options!(opts)
62
+ opts.separator ''
63
+ opts.separator 'Options:'
64
+ # For each option below, place the default
65
+ # at the top of the file next to "default_options"
66
+ # opts.on("-a", "--author=\"Your Name\"", String,
67
+ # "Some comment about this option",
68
+ # "Default: none") { |options[:author]| }
69
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
70
+ end
71
+
72
+ def extract_options
73
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
74
+ # Templates can access these value via the attr_reader-generated methods, but not the
75
+ # raw instance variable value.
76
+ # @author = options[:author]
77
+ end
78
+
79
+ # Installation skeleton. Intermediate directories are automatically
80
+ # created so don't sweat their absence here.
81
+ BASEDIRS = %w(
82
+ lib
83
+ script
84
+ spec
85
+ rails
86
+ spec/xml
87
+ config
88
+ )
89
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 YOUR NAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ == <%= name %>
2
+
3
+ A gem that provides...
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+ require 'date'
5
+ require 'spec/rake/spectask'
6
+
7
+ GEM = "<%= name %>"
8
+ GEM_VERSION = "0.0.1"
9
+ AUTHOR = "Your Name"
10
+ EMAIL = "Your Email"
11
+ HOMEPAGE = "http://example.com"
12
+ SUMMARY = "A gem that provides..."
13
+
14
+ spec = Gem::Specification.new do |s|
15
+ s.name = GEM
16
+ s.version = GEM_VERSION
17
+ s.platform = Gem::Platform::RUBY
18
+ s.has_rdoc = true
19
+ s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
20
+ s.summary = SUMMARY
21
+ s.description = s.summary
22
+ s.author = AUTHOR
23
+ s.email = EMAIL
24
+ s.homepage = HOMEPAGE
25
+
26
+ # Uncomment this to add a dependency
27
+ # s.add_dependency "foo"
28
+
29
+ s.require_path = 'lib'
30
+ s.autorequire = GEM
31
+ s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
32
+ end
33
+
34
+ task :default => :spec
35
+
36
+ desc "Run specs"
37
+ Spec::Rake::SpecTask.new do |t|
38
+ t.spec_files = FileList['spec/**/*_spec.rb']
39
+ t.spec_opts = %w(-fs --color)
40
+ end
41
+
42
+
43
+ Rake::GemPackageTask.new(spec) do |pkg|
44
+ pkg.gem_spec = spec
45
+ end
46
+
47
+ desc "install the gem locally"
48
+ task :install => [:package] do
49
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
50
+ end
51
+
52
+ desc "create a gemspec file"
53
+ task :make_spec do
54
+ File.open("#{GEM}.gemspec", "w") do |file|
55
+ file.puts spec.to_ruby
56
+ end
57
+ end
@@ -0,0 +1,4 @@
1
+ TODO:
2
+ Fix LICENSE with your name
3
+ Fix Rakefile with your name and contact info
4
+ Add your code to lib/<%= name %>.rb
@@ -0,0 +1,2 @@
1
+ # You should set up your SCM to ignore this, and copy a version to
2
+ # <%= name %>.yml.sample sans sensitive data.
@@ -0,0 +1 @@
1
+ # Check this in to version control with sensitive data as dummy values
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'consumer'
3
+
4
+ module <%= name.camelcase %>;end
5
+
6
+ Dir.glob(File.join(File.dirname(__FILE__), '<%= name %>/**/*.rb')).each {|f| require f}
@@ -0,0 +1 @@
1
+ require '<%= name %>'
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:newgem_simple, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:newgem_simple, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,11 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require '<%= name %>'
5
+ include <%= name.camelcase %>
6
+
7
+ class Object
8
+ def blank?
9
+ self.nil? || self.empty?
10
+ end
11
+ end
data/bin/consumer ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rubigen'
5
+
6
+ if %w(-v --version).include? ARGV.first
7
+ require 'consumer/version'
8
+ puts "#{File.basename($0)} #{Consumer::VERSION}"
9
+ exit(0)
10
+ end
11
+
12
+ require 'rubigen/scripts/generate'
13
+ source = RubiGen::PathSource.new(:application,
14
+ File.join(File.dirname(__FILE__), "../app_generators"))
15
+ RubiGen::Base.reset_sources
16
+ RubiGen::Base.append_sources source
17
+ RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'consumer')
@@ -0,0 +1,2 @@
1
+ host: unknown@rubyforge.org
2
+ remote_dir: /var/www/gforge-projects/consumer
data/consumer.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = %q{consumer}
3
+ s.version = "0.8.1"
4
+
5
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
+ s.authors = ["Woody Peterson"]
7
+ s.date = %q{2009-01-29}
8
+ s.default_executable = %q{consumer}
9
+ s.description = %q{Consumer is a library for consuming xml resources via Builder, libxml, and some request sending / response marshaling glue. It comes with an app generator that creates an empty ready-for-rails gem that itself comes with a generator for making the request/response classes, config files, and specs (see script/generate after creating a new Consumer project).}
10
+ s.email = ["woody.peterson@gmail.com"]
11
+ s.executables = ["consumer"]
12
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "app_generators/consumer/templates/README.rdoc", "examples/active_record/README.txt", "website/index.txt"]
13
+ s.files = ["History.txt", "LICENSE", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "app_generators/consumer/USAGE", "app_generators/consumer/consumer_generator.rb", "app_generators/consumer/templates/LICENSE", "app_generators/consumer/templates/README.rdoc", "app_generators/consumer/templates/Rakefile", "app_generators/consumer/templates/TODO", "app_generators/consumer/templates/config/config.yml", "app_generators/consumer/templates/config/config.yml.sample", "app_generators/consumer/templates/lib/base.rb", "app_generators/consumer/templates/rails/init.rb", "app_generators/consumer/templates/script/destroy", "app_generators/consumer/templates/script/generate", "app_generators/consumer/templates/spec/spec_helper.rb", "bin/consumer", "config/website.yml.sample", "consumer.gemspec", "consumer_generators/request/USAGE", "consumer_generators/request/request_generator.rb", "consumer_generators/request/templates/lib/request.rb", "consumer_generators/request/templates/lib/response.rb", "consumer_generators/request/templates/spec/request_spec.rb", "consumer_generators/request/templates/spec/response_spec.rb", "consumer_generators/request/templates/spec/xml/response.xml", "examples/active_record/README.txt", "examples/active_record/ar_spec.rb", "examples/active_record/database.sqlite", "examples/active_record/environment.rb", "examples/active_record/migration.rb", "examples/active_record/models/book.rb", "examples/active_record/models/contributor.rb", "examples/active_record/xml/book.xml", "examples/active_record/xml/book_with_contributors.xml", "examples/active_record/xml/contributor.xml", "examples/active_record/xml/contributor_with_books.xml", "examples/shipping/environment.rb", "examples/shipping/rate.rb", "examples/shipping/shipping.yml.sample", "examples/shipping/shipping_spec.rb", "examples/shipping/ups_rate_request.rb", "examples/shipping/ups_rate_response.xml", "lib/consumer.rb", "lib/consumer/helper.rb", "lib/consumer/mapping.rb", "lib/consumer/request.rb", "rails_generators/request/USAGE", "rails_generators/request/request_generator.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "spec/helper_spec.rb", "spec/mapping_spec.rb", "spec/request_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/xml/rate_response.xml", "spec/xml/rate_response_error.xml", "tasks/rspec.rake", "test/test_consumer_generator.rb", "test/test_consumer_plugin_request_generator.rb", "test/test_generator_helper.rb", "test/test_rails_request_generator.rb", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.html.erb"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://consumer.rubyforge.org}
16
+ s.post_install_message = %q{PostInstall.txt}
17
+ s.rdoc_options = ["--main", "README.rdoc"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{consumer}
20
+ s.rubygems_version = %q{1.2.0}
21
+ s.summary = %q{Consumer is a library for consuming xml resources via Builder, libxml, and some request sending / response marshaling glue}
22
+ s.test_files = ["test/test_consumer_generator.rb", "test/test_consumer_plugin_request_generator.rb", "test/test_generator_helper.rb", "test/test_rails_request_generator.rb"]
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 2
27
+
28
+ if current_version >= 3 then
29
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.0.2"])
30
+ s.add_runtime_dependency(%q<libxml-ruby>, [">= 0.8.3"])
31
+ s.add_runtime_dependency(%q<builder>, [">= 2.1.2"])
32
+ s.add_development_dependency(%q<newgem>, [">= 1.0.7"])
33
+ s.add_development_dependency(%q<hoe>, [">= 1.8.0"])
34
+ else
35
+ s.add_dependency(%q<activesupport>, [">= 2.0.2"])
36
+ s.add_dependency(%q<libxml-ruby>, [">= 0.8.3"])
37
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
38
+ s.add_dependency(%q<newgem>, [">= 1.0.7"])
39
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
40
+ end
41
+ else
42
+ s.add_dependency(%q<activesupport>, [">= 2.0.2"])
43
+ s.add_dependency(%q<libxml-ruby>, [">= 0.8.3"])
44
+ s.add_dependency(%q<builder>, [">= 2.1.2"])
45
+ s.add_dependency(%q<newgem>, [">= 1.0.7"])
46
+ s.add_dependency(%q<hoe>, [">= 1.8.0"])
47
+ end
48
+ end
@@ -0,0 +1,25 @@
1
+ Description:
2
+
3
+ Creates request and response classes.
4
+
5
+ The first argument is the name of the request class *without* the word
6
+ "Request" at the end. This is added automatically. i.e. "UPSRate" would
7
+ generate the UPSRateRequest class.
8
+
9
+ The second (optional) argument is for the response class, and no name
10
+ trickery here - you get what you say. It defaults to the first argument,
11
+ so if that was "UPSRate", a UPSRate class would be created as the
12
+ response object (and UPSRateRequest would return UPSRate object(s)).
13
+
14
+ Usage:
15
+
16
+ script/generate request ShortRequestClass [ResponseClass=ShortRequestClass]
17
+
18
+ ex. script/generate request UPSRate Rate
19
+ => generates UPSRateRequest, which returns Rate objects, and generates
20
+ the Rate class and specs.
21
+
22
+ You should definitely look at the specs, and use DO_IT_LIVE (shown in specs) to
23
+ get started configuring the request. Once it gets back the kind of xml you want,
24
+ put it in the generated (empty) xml file and use that to configure the response
25
+ class with canned data. test one more time live, script/generate again, rinse, repeat.
@@ -0,0 +1,94 @@
1
+ require 'active_support'
2
+ require 'yaml'
3
+ class RequestGenerator < RubiGen::Base
4
+
5
+ default_options :author => nil
6
+
7
+ attr_reader :request_class, :response_class, :request_file, :response_file
8
+ attr_reader :response_xml, :request_base, :appname
9
+
10
+ def initialize(runtime_args, runtime_options = {})
11
+ super
12
+ usage if args.empty?
13
+ @request_base = args.shift
14
+ @request_class = @request_base + "Request"
15
+ @response_class = args.shift || @request_base
16
+ @request_file = @request_class.underscore
17
+ @response_file = @response_class.underscore
18
+ @response_xml = @request_base.underscore + "_response.xml"
19
+ @appname = APP_ROOT.split("/").last
20
+ extract_options
21
+ end
22
+
23
+ def manifest
24
+ record do |m|
25
+ # Ensure appropriate folder(s) exists
26
+ m.directory ''
27
+ m.directory 'lib'
28
+ m.directory "lib/#{@appname}"
29
+ m.directory 'spec'
30
+ m.directory 'spec/xml'
31
+
32
+ # 1 level of namespace support
33
+ if @request_file.include?("/")
34
+ namespace = @request_file.split("/")[0]
35
+ m.directory "lib/#{@appname}/#{namespace}"
36
+ m.directory "spec/#{namespace}"
37
+ m.directory "spec/xml/#{namespace}"
38
+ end
39
+
40
+ templates = [
41
+ ["lib/request.rb", "lib/#{@appname}/#{@request_file}.rb"],
42
+ ["lib/response.rb", "lib/#{@appname}/#{@response_file}.rb"],
43
+ ["spec/request_spec.rb", "spec/#{@request_file}_spec.rb"],
44
+ ["spec/response_spec.rb", "spec/#{@response_file}_spec.rb"],
45
+ ["spec/xml/response.xml", "spec/xml/#{@response_xml}"]
46
+ ]
47
+
48
+ templates.each {|args| m.template *args}
49
+
50
+ # put in a relevant example if the config is still empty
51
+ if File.exists?("config/#{@appname}.yml")
52
+ config = YAML.load(File.read("config/#{@appname}.yml"))
53
+ File.open("config/#{@appname}.yml", "a") do |file|
54
+ file << "all:\n global_default: Value\n#{@request_base.underscore}:\n request_default: Value"
55
+ end if !config
56
+ end
57
+
58
+ # Create stubs
59
+ # m.template "template.rb.erb", "some_file_after_erb.rb"
60
+ # m.template_copy_each ["template.rb", "template2.rb"]
61
+ # m.template_copy_each ["template.rb", "template2.rb"], "some/path"
62
+ # m.file "file", "some_file_copied"
63
+ # m.file_copy_each ["path/to/file", "path/to/file2"]
64
+ # m.file_copy_each ["path/to/file", "path/to/file2"], "some/path"
65
+ end
66
+ end
67
+
68
+ protected
69
+ def banner
70
+ <<-EOS
71
+ Creates request and response classes
72
+
73
+ USAGE: #{$0} #{spec.name} name
74
+ EOS
75
+ end
76
+
77
+ def add_options!(opts)
78
+ # opts.separator ''
79
+ # opts.separator 'Options:'
80
+ # For each option below, place the default
81
+ # at the top of the file next to "default_options"
82
+ # opts.on("-a", "--author=\"Your Name\"", String,
83
+ # "Some comment about this option",
84
+ # "Default: none") { |options[:author]| }
85
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
86
+ end
87
+
88
+ def extract_options
89
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
90
+ # Templates can access these value via the attr_reader-generated methods, but not the
91
+ # raw instance variable value.
92
+ # @author = options[:author]
93
+ end
94
+ end