esod-client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. data/EXAMPLES +140 -0
  2. data/GEM_RELEASE +19 -0
  3. data/README +10 -0
  4. data/Rakefile +14 -0
  5. data/VERSION +1 -0
  6. data/esod-client.gemspec +118 -0
  7. data/esod-client.rb +35 -0
  8. data/lib/activesupport-2.2.2/CHANGELOG +1257 -0
  9. data/lib/activesupport-2.2.2/README +43 -0
  10. data/lib/activesupport-2.2.2/README.CFT +2 -0
  11. data/lib/activesupport-2.2.2/lib/active_support.rb +26 -0
  12. data/lib/activesupport-2.2.2/lib/active_support/base64.rb +33 -0
  13. data/lib/activesupport-2.2.2/lib/active_support/basic_object.rb +24 -0
  14. data/lib/activesupport-2.2.2/lib/active_support/buffered_logger.rb +122 -0
  15. data/lib/activesupport-2.2.2/lib/active_support/cache.rb +223 -0
  16. data/lib/activesupport-2.2.2/lib/active_support/cache/compressed_mem_cache_store.rb +20 -0
  17. data/lib/activesupport-2.2.2/lib/active_support/cache/drb_store.rb +15 -0
  18. data/lib/activesupport-2.2.2/lib/active_support/cache/file_store.rb +72 -0
  19. data/lib/activesupport-2.2.2/lib/active_support/cache/mem_cache_store.rb +127 -0
  20. data/lib/activesupport-2.2.2/lib/active_support/cache/memory_store.rb +52 -0
  21. data/lib/activesupport-2.2.2/lib/active_support/cache/synchronized_memory_store.rb +47 -0
  22. data/lib/activesupport-2.2.2/lib/active_support/callbacks.rb +280 -0
  23. data/lib/activesupport-2.2.2/lib/active_support/core_ext.rb +6 -0
  24. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash.rb +14 -0
  25. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/conversions.rb +259 -0
  26. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/deep_merge.rb +23 -0
  27. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/diff.rb +19 -0
  28. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/except.rb +25 -0
  29. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/indifferent_access.rb +137 -0
  30. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/keys.rb +52 -0
  31. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/reverse_merge.rb +35 -0
  32. data/lib/activesupport-2.2.2/lib/active_support/core_ext/hash/slice.rb +33 -0
  33. data/lib/activesupport-2.2.2/lib/active_support/vendor.rb +14 -0
  34. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/blankslate.rb +113 -0
  35. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder.rb +13 -0
  36. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +20 -0
  37. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/css.rb +250 -0
  38. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +115 -0
  39. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +139 -0
  40. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +63 -0
  41. data/lib/activesupport-2.2.2/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +328 -0
  42. data/lib/activesupport-2.2.2/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +1021 -0
  43. data/lib/activesupport-2.2.2/lib/activesupport.rb +1 -0
  44. data/lib/esodclient/esodclient.rb +22 -0
  45. data/lib/hash.rb +22 -0
  46. data/lib/mime-types-1.16/History.txt +107 -0
  47. data/lib/mime-types-1.16/Install.txt +17 -0
  48. data/lib/mime-types-1.16/Licence.txt +15 -0
  49. data/lib/mime-types-1.16/Manifest.txt +12 -0
  50. data/lib/mime-types-1.16/README.txt +28 -0
  51. data/lib/mime-types-1.16/Rakefile +316 -0
  52. data/lib/mime-types-1.16/lib/mime/types.rb +751 -0
  53. data/lib/mime-types-1.16/lib/mime/types.rb.data +1324 -0
  54. data/lib/mime-types-1.16/mime-types.gemspec +43 -0
  55. data/lib/mime-types-1.16/setup.rb +1585 -0
  56. data/lib/mime-types-1.16/test/test_mime_type.rb +356 -0
  57. data/lib/mime-types-1.16/test/test_mime_types.rb +122 -0
  58. data/lib/rest-client-1.2.0/README.rdoc +102 -0
  59. data/lib/rest-client-1.2.0/Rakefile +57 -0
  60. data/lib/rest-client-1.2.0/VERSION +1 -0
  61. data/lib/rest-client-1.2.0/bin/restclient +87 -0
  62. data/lib/rest-client-1.2.0/lib/rest_client.rb +2 -0
  63. data/lib/rest-client-1.2.0/lib/restclient.rb +108 -0
  64. data/lib/rest-client-1.2.0/lib/restclient/exceptions.rb +89 -0
  65. data/lib/rest-client-1.2.0/lib/restclient/mixin/response.rb +48 -0
  66. data/lib/rest-client-1.2.0/lib/restclient/net_http_ext.rb +21 -0
  67. data/lib/rest-client-1.2.0/lib/restclient/payload.rb +178 -0
  68. data/lib/rest-client-1.2.0/lib/restclient/raw_response.rb +30 -0
  69. data/lib/rest-client-1.2.0/lib/restclient/request.rb +287 -0
  70. data/lib/rest-client-1.2.0/lib/restclient/resource.rb +146 -0
  71. data/lib/rest-client-1.2.0/lib/restclient/response.rb +20 -0
  72. data/lib/rest-client-1.2.0/spec/base.rb +10 -0
  73. data/lib/rest-client-1.2.0/spec/exceptions_spec.rb +65 -0
  74. data/lib/rest-client-1.2.0/spec/master_shake.jpg +0 -0
  75. data/lib/rest-client-1.2.0/spec/mixin/response_spec.rb +46 -0
  76. data/lib/rest-client-1.2.0/spec/payload_spec.rb +131 -0
  77. data/lib/rest-client-1.2.0/spec/raw_response_spec.rb +17 -0
  78. data/lib/rest-client-1.2.0/spec/request_spec.rb +521 -0
  79. data/lib/rest-client-1.2.0/spec/resource_spec.rb +75 -0
  80. data/lib/rest-client-1.2.0/spec/response_spec.rb +21 -0
  81. data/lib/rest-client-1.2.0/spec/restclient_spec.rb +53 -0
  82. data/lib/trollop/trollop.rb +735 -0
  83. metadata +137 -0
@@ -0,0 +1 @@
1
+ require 'active_support'
@@ -0,0 +1,22 @@
1
+ require 'restclient'
2
+ require 'lib/hash' # Dotted notation for hash access
3
+ require 'benchmark'
4
+ require 'activesupport' # Hash.from_xml
5
+
6
+ class ESODClient
7
+ def initialize(url, api_token)
8
+ @url = url
9
+ @token = api_token
10
+ end
11
+
12
+ def server(id)
13
+ get("server/#{id}")
14
+ end
15
+
16
+ protected
17
+
18
+ def get(path)
19
+ response = RestClient.get("#{@url}/#{path}.xml?key=#{@token}").to_s
20
+ response_hash = Hash.from_xml(response)
21
+ end
22
+ end
data/lib/hash.rb ADDED
@@ -0,0 +1,22 @@
1
+ # turn hashes into openstruct-like objects with dotted access
2
+ class Hash
3
+ def method_missing(meth, *args, &block)
4
+ if args.size == 0
5
+ self[meth.to_s] || self[meth.to_sym]
6
+ end
7
+ end
8
+
9
+ # in: "foo.bar.baz"
10
+ # out: self.foo.bar.baz == ['foo']['bar']['baz']
11
+ def value_of_dotted_property(property)
12
+ methods = property.split('.')
13
+ # call each method in the dotted chain until we get to the result
14
+ hash = self
15
+ methods.each do |method|
16
+ hash = hash.send(method)
17
+ end
18
+ hash
19
+ end
20
+ end
21
+
22
+
@@ -0,0 +1,107 @@
1
+ == MIME::Types 1.16
2
+ * Made compatible with Ruby 1.8.6, 1.8.7, and 1.9.1.
3
+ * Switched to the 'hoe' gem system and added a lot of build-time tools.
4
+ * Updated the MIME types to the list based on the values in the Perl library
5
+ version 1.27. Also updated based on external source information and bug
6
+ reports.
7
+ * This is the last planned version of MIME::Types 1.x. Work will be
8
+ starting soon on MIME::Types 2.x with richer data querying mechanisms
9
+ and support for external data sources.
10
+
11
+ == MIME::Types 1.15
12
+ * Removed lib/mime/type.rb to form a single MIME::Types database source. It
13
+ is unlikely that one will ever need MIME::Type without MIME::Types.
14
+ * Re-synchronized the MIME type list with the sources, focusing primarily on
15
+ the IANA list.
16
+ * Added more detailed source information for MIME::Type objects.
17
+ * Changed MIME::Types from a module to a class with a default instance. There
18
+ should be no difference in usage.
19
+ * Removed MIME::Types::DATA_VERSION; it is now an attribute on the
20
+ MIME::Types instance.
21
+ * NOTE: Synchronization with the Perl version of MIME::Types is no longer a
22
+ priority as of this release. The data format and information has changed.
23
+ * Removed MIME::Types.by_suffix and MIME::Types.by_mediatype.
24
+
25
+ == MIME::Types 1.13.1
26
+ * Fixed a problem with the installer running tests. This now works.
27
+ * Improved the implementation of MIME::Type.signature?
28
+ * Moved code around to use the class << self idiom instead of always
29
+ prepending the module/class name.
30
+ * Added two new best-guess implementations of functions found in Perl's
31
+ MIME::Types implementation (1.13). Do not rely on these until the purpose
32
+ and implementation is stabilised.
33
+ * Updated the MIME list to reflect changes noted by
34
+ Ville Skyttä <ville.skytta@iki.fi>.
35
+ * Added a new constant to MIME::Types, DATA_VERSION. This will allow the Ruby
36
+ version number to be updated separately from the Perl version while keeping
37
+ the MIME Type list version in sync.
38
+
39
+ == MIME::Types 1.13
40
+ ! WARNING: This version changes the API of MIME::Types !
41
+ ! WARNING: This version is compatible with Ruby 1.8 and higher ONLY !
42
+ * Removed dependency on InstallPackage; offering 1.13 as either .tar.gz or
43
+ .gem.
44
+ * Split into two files, mime/type.rb and mime/types.rb. This will make
45
+ maintaining the list of changes easier.
46
+ * Changed the MIME::Type construction API. Accepts only a single String
47
+ argument (but does no named type-checking) and yields self.
48
+ * Removed private methods #init_extensions, #init_encoding, and #init_system
49
+ and replaced with #extensions=, #encoding=, and #system=.
50
+ * Added #default_encoding to return 'quoted-printable' or 'base64' depending
51
+ on the media type of the MIME type.
52
+ * Added #raw_media_type and #raw_sub_type to provide the non-simplified
53
+ versions of the media type and subtype.
54
+ * Alternative constructors MIME::Type.from_array, MIME::Type.from_hash, and
55
+ MIME::Type.from_mime_type added to compensate for the removal of named type
56
+ checking in the original constructor.
57
+ * Added #to_str, #to_a, and #to_hash methods. The latter two will provide
58
+ output suitable for use in #from_array and #from_hash.
59
+ * Removed "binary" encoding and enforced the use of a valid encoding string.
60
+ * Added #system? returning true if the MIME::Type is an OS-specific
61
+ MIME::Type.
62
+ * Added #platform? returning true if the MIME::Type is an OS-specific
63
+ MIME::Type for the current RUBY_PLATFORM.
64
+ * Added #like? returning true if the simplified type matches the other value
65
+ provided. #<'application/x-excel'>.like?('application/excel') is true.
66
+ * Added #complete? returning true if the MIME::Type specifies an extension
67
+ list.
68
+ * Updated the MIME type list to reflect additions by Mark Overmeer for Perl's
69
+ MIME::Types 1.12 and the official IANA list as of 2004.04.06. A number of
70
+ formerly "registered" MIME types are now no longer registered (e.g.,
71
+ application/excel is now application/x-excel). This ensures that the
72
+ simplified type still works with applications, but does not report an
73
+ unregistered type as registered.
74
+ * Restored MIME type list to Mark Overmeer's format to facilitate easy
75
+ exchange between the two projects.
76
+ * Added additional unit tests from Mark Overmeer's 1.12 version.
77
+
78
+ == MIME::Types 1.07
79
+ * Changed version numbering to match Perl MIME::Types 1.07.
80
+ * Re-synchronized with Mark Overmeer's list in Perl PMIME::Types 1.07.
81
+ * [NN Poster] updated the attributes for the PGP types.
82
+
83
+ == MIME::Types 1.005
84
+ * Changed to Phil Thomson's InstallPackage.
85
+ * Added several types from Perl MIME::Types 1.005.
86
+ * Cleaned up data format; some data formats will show up with proper data now.
87
+
88
+ == MIME::Types 1.004
89
+ * Updated to match Perl MIME::Types 1.004, links credited to Dan Puro. Adds
90
+ new reference list to http://www.indiana.edu/cgi-bin-local/mimetypes
91
+ * Removed InvalidType and replaced with TypeError.
92
+ * Changed instances of #type to #class.
93
+ * Cleaned up how simplified versions are created.
94
+
95
+ == MIME::Types 1.003
96
+ * Initial release based on Perl MIME::Types 1.003.
97
+
98
+ == Copyright
99
+ MIME::Types
100
+ A Ruby implementation of a MIME Types information library. Based in spirit
101
+ on the Perl MIME::Types information library by Mark Overmeer.
102
+ http://rubyforge.org/projects/mime-types/
103
+
104
+ Licensed under the Ruby disjunctive licence with the GNU GPL or the Perl
105
+ Artistic licence. See Licence.txt for more information.
106
+
107
+ Copyright 2003 - 2009 Austin Ziegler
@@ -0,0 +1,17 @@
1
+ Installing this package is as simple as:
2
+
3
+ % ruby setup.rb
4
+
5
+ Alternatively, you can use the Gem version of MIME::Types available as
6
+ mime-types-1.16.gem from the usual sources.
7
+
8
+ == Copyright
9
+ MIME::Types
10
+ A Ruby implementation of a MIME Types information library. Based in spirit
11
+ on the Perl MIME::Types information library by Mark Overmeer.
12
+ http://rubyforge.org/projects/mime-types/
13
+
14
+ Licensed under the Ruby disjunctive licence with the GNU GPL or the Perl
15
+ Artistic licence. See Licence.txt for more information.
16
+
17
+ Copyright 2003 - 2009 Austin Ziegler
@@ -0,0 +1,15 @@
1
+ = MIME::Types for Ruby
2
+ Homepage:: http://rubyforge.org/projects/mime-types/
3
+ Copyright:: Copyright (c) 2003 - 2006 Austin Ziegler.
4
+ Summary:: Ruby's licence, Perl Aristic Licence,
5
+ GNU GPL version 2 (or later)
6
+
7
+ The text of the Ruby licence can be found at:
8
+ http://www.ruby-lang.org/en/LICENSE.txt
9
+
10
+ The text of the Perl Artistic Licence can be found at:
11
+ http://www.perl.com/pub/a/language/misc/Artistic.html
12
+
13
+ The text of the GNU GPL can be found at: http://www.gnu.org/copyleft/gpl.html
14
+
15
+ If you do not accept one of these licences, you may not use this software.
@@ -0,0 +1,12 @@
1
+ History.txt
2
+ Install.txt
3
+ Licence.txt
4
+ Manifest.txt
5
+ README.txt
6
+ Rakefile
7
+ lib/mime/types.rb
8
+ lib/mime/types.rb.data
9
+ mime-types.gemspec
10
+ setup.rb
11
+ test/test_mime_type.rb
12
+ test/test_mime_types.rb
@@ -0,0 +1,28 @@
1
+ = README: Mime::Types for Ruby
2
+ This library allows for the identification of a file's likely MIME content
3
+ type. This is release 1.16. The identification of MIME content type is based
4
+ on a file's filename extensions.
5
+
6
+ MIME::Types for Ruby originally based on and synchronized with MIME::Types
7
+ for Perl by Mark Overmeer, copyright 2001 - 2009. As of version 1.15, the
8
+ data format for the MIME::Type list has changed and the synchronization will
9
+ no longer happen.
10
+
11
+ Homepage:: http://mime-types.rubyforge.org/
12
+ Copyright:: 2002 - 2009, Austin Ziegler
13
+ Based in part on prior work copyright Mark Overmeer
14
+
15
+ == Licensing
16
+ MIME::Types is available under three disjunctive licences, as detailed in the
17
+ Licence.txt file.
18
+
19
+ == Copyright
20
+ MIME::Types
21
+ A Ruby implementation of a MIME Types information library. Based in spirit
22
+ on the Perl MIME::Types information library by Mark Overmeer.
23
+ http://rubyforge.org/projects/mime-types/
24
+
25
+ Licensed under the Ruby disjunctive licence with the GNU GPL or the Perl
26
+ Artistic licence. See Licence.txt for more information.
27
+
28
+ Copyright 2003 - 2009 Austin Ziegler
@@ -0,0 +1,316 @@
1
+ #! /usr/bin/env rake
2
+ #--
3
+ # MIME::Types
4
+ # A Ruby implementation of a MIME Types information library. Based in spirit
5
+ # on the Perl MIME::Types information library by Mark Overmeer.
6
+ # http://rubyforge.org/projects/mime-types/
7
+ #
8
+ # Licensed under the Ruby disjunctive licence with the GNU GPL or the Perl
9
+ # Artistic licence. See Licence.txt for more information.
10
+ #
11
+ # Copyright 2003 - 2009 Austin Ziegler
12
+ #++
13
+
14
+ require 'rubygems'
15
+ require 'hoe'
16
+
17
+ $LOAD_PATH.unshift('lib')
18
+
19
+ require 'mime/types'
20
+
21
+ PKG_NAME = 'mime-types'
22
+ PKG_VERSION = MIME::Types::VERSION
23
+ PKG_DIST = "#{PKG_NAME}-#{PKG_VERSION}"
24
+ PKG_TAR = "pkg/#{PKG_DIST}.tar.gz"
25
+ MANIFEST = File.read("Manifest.txt").split
26
+
27
+ hoe = Hoe.new PKG_NAME, PKG_VERSION do |p|
28
+ p.rubyforge_name = PKG_NAME
29
+ # This is a lie because I will continue to use Archive::Tar::Minitar.
30
+ p.need_tar = false
31
+ # need_zip - Should package create a zipfile? [default: false]
32
+
33
+ p.author = [ "Austin Ziegler" ]
34
+ p.email = %W(austin@rubyforge.org)
35
+ p.url = "http://mime-types.rubyforge.org/"
36
+ p.summary = %q{Manages a MIME Content-Type database that will return the Content-Type for a given filename.}
37
+ p.changes = p.paragraphs_of("History.txt", 0..0).join("\n\n")
38
+ p.description = p.paragraphs_of("README.txt", 1..1).join("\n\n")
39
+
40
+ p.extra_dev_deps << %w(archive-tar-minitar ~>0.5)
41
+ p.extra_dev_deps << %w(nokogiri ~>1.2)
42
+ p.extra_dev_deps << %w(rcov ~>0.8)
43
+
44
+ p.clean_globs << "coverage"
45
+
46
+ p.spec_extras[:extra_rdoc_files] = MANIFEST.grep(/txt$/) - ["Manifest.txt"]
47
+ end
48
+
49
+ begin
50
+ require 'rcov/rcovtask'
51
+ Rcov::RcovTask.new do |t|
52
+ t.libs << 'test'
53
+ t.test_files = hoe.test_files
54
+ t.verbose = true
55
+ end
56
+ rescue LoadError
57
+ puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
58
+ end
59
+
60
+ =begin
61
+ require 'cucumber/rake/task'
62
+ Cucumber::Rake::Task.new(:features)
63
+ rescue LoadError
64
+ puts "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
65
+ =end
66
+
67
+ desc "Build a MIME::Types .tar.gz distribution."
68
+ task :tar => [ PKG_TAR ]
69
+ file PKG_TAR => [ :test ] do |t|
70
+ require 'archive/tar/minitar'
71
+ require 'zlib'
72
+ files = MANIFEST.map { |f|
73
+ fn = File.join(PKG_DIST, f)
74
+ tm = File.stat(f).mtime
75
+
76
+ if File.directory?(f)
77
+ { :name => fn, :mode => 0755, :dir => true, :mtime => tm }
78
+ else
79
+ mode = if f =~ %r{^bin}
80
+ 0755
81
+ else
82
+ 0644
83
+ end
84
+ data = File.read(f)
85
+ { :name => fn, :mode => mode, :data => data, :size => data.size,
86
+ :mtime => tm }
87
+ end
88
+ }
89
+
90
+ begin
91
+ unless File.directory?(File.dirname(t.name))
92
+ require 'fileutils'
93
+ FileUtils.mkdir_p File.dirname(t.name)
94
+ end
95
+ tf = File.open(t.name, 'wb')
96
+ gz = Zlib::GzipWriter.new(tf)
97
+ tw = Archive::Tar::Minitar::Writer.new(gz)
98
+
99
+ files.each do |entry|
100
+ if entry[:dir]
101
+ tw.mkdir(entry[:name], entry)
102
+ else
103
+ tw.add_file_simple(entry[:name], entry) { |os|
104
+ os.write(entry[:data])
105
+ }
106
+ end
107
+ end
108
+ ensure
109
+ tw.close if tw
110
+ gz.close if gz
111
+ end
112
+ end
113
+ task :package => [ PKG_TAR ]
114
+
115
+ desc "Build the manifest file from the current set of files."
116
+ task :build_manifest do |t|
117
+ require 'find'
118
+
119
+ hoerc = File.join(File.dirname(__FILE__), ".hoerc")
120
+ hoerc = File.open(hoerc, "rb") { |f| f.read }
121
+ hoerc = YAML::load(hoerc)
122
+
123
+ paths = []
124
+ Find.find(".") do |path|
125
+ next if File.directory?(path) || path =~ hoerc["exclude"]
126
+ paths << path.sub(%r{^\./}, '')
127
+ end
128
+
129
+ paths = paths.sort.join("\n")
130
+
131
+ File.open("Manifest.txt", "w") do |f|
132
+ f.puts paths
133
+ end
134
+
135
+ puts paths
136
+ end
137
+
138
+ desc "Download the current MIME type registrations from IANA."
139
+ task :iana, :save, :destination do |t, args|
140
+ save_type = args.save || :text
141
+ save_type = save_type.to_sym
142
+
143
+ case save_type
144
+ when :text, :both, :html
145
+ nil
146
+ else
147
+ raise "Unknown save type provided. Must be one of text, both, or html."
148
+ end
149
+
150
+ destination = args.destination || "type-lists"
151
+
152
+ require 'open-uri'
153
+ require 'nokogiri'
154
+ require 'cgi'
155
+
156
+ class IANAParser
157
+ include Comparable
158
+
159
+ INDEX = %q(http://www.iana.org/assignments/media-types/)
160
+ CONTACT_PEOPLE = %r{http://www.iana.org/assignments/contact-people.html?#(.*)}
161
+ RFC_EDITOR = %r{http://www.rfc-editor.org/rfc/rfc(\d+).txt}
162
+ IETF_RFC = %r{http://www.ietf.org/rfc/rfc(\d+).txt}
163
+ IETF_RFC_TOOLS = %r{http://tools.ietf.org/html/rfc(\d+)}
164
+
165
+ class << self
166
+ def load_index
167
+ @types ||= {}
168
+
169
+ Nokogiri::HTML(open(INDEX) { |f| f.read }).xpath('//p/a').each do |tag|
170
+ href_match = %r{^/assignments/media-types/(.+)/$}.match(tag['href'])
171
+ next if href_match.nil?
172
+ type = href_match.captures[0]
173
+ @types[tag.content] = IANAParser.new(tag.content, type)
174
+ end
175
+ end
176
+
177
+ attr_reader :types
178
+ end
179
+
180
+ def initialize(name, type)
181
+ @name = name
182
+ @type = type
183
+ @url = File.join(INDEX, @type)
184
+ end
185
+
186
+ attr_reader :name
187
+ attr_reader :type
188
+ attr_reader :url
189
+ attr_reader :html
190
+
191
+ def download(name = nil)
192
+ @html = Nokogiri::HTML(open(name || @url) { |f| f.read })
193
+ end
194
+
195
+ def save_html
196
+ File.open("#@name.html", "wb") { |w| w.write @html }
197
+ end
198
+
199
+ def <=>(o)
200
+ self.name <=> o.name
201
+ end
202
+
203
+ def parse
204
+ nodes = html.xpath("//table//table//tr")
205
+
206
+ # How many <td> children does the first node have?
207
+ node_count = nodes.first.children.select { |node| node.elem? }.size
208
+
209
+ @mime_types = nodes.map do |node|
210
+ next if node == nodes.first
211
+ elems = node.children.select { |n| n.elem? }
212
+ next if elems.size.zero?
213
+ raise "size mismatch #{elems.size} != #{node_count}" if node_count != elems.size
214
+
215
+ case elems.size
216
+ when 3
217
+ subtype_index = 1
218
+ refnode_index = 2
219
+ when 4
220
+ subtype_index = 1
221
+ refnode_index = 3
222
+ else
223
+ raise "Unknown element size."
224
+ end
225
+
226
+ subtype = elems[subtype_index].content.chomp.strip
227
+ refnodes = elems[refnode_index].children.select { |n| n.elem? }.map { |ref|
228
+ case ref['href']
229
+ when CONTACT_PEOPLE
230
+ tag = CGI::unescape($1).chomp.strip
231
+ if tag == ref.content
232
+ "[#{ref.content}]"
233
+ else
234
+ "[#{ref.content}=#{tag}]"
235
+ end
236
+ when RFC_EDITOR, IETF_RFC, IETF_RFC_TOOLS
237
+ "RFC#$1"
238
+ when %r{(https?://.*)}
239
+ "{#{ref.content}=#$1}"
240
+ else
241
+ ref
242
+ end
243
+ }
244
+ refs = refnodes.join(',')
245
+
246
+ "#@type/#{subtype} 'IANA,#{refs}"
247
+ end.compact
248
+
249
+ @mime_types
250
+ end
251
+
252
+ def save_text
253
+ File.open("#@name.txt", "wb") { |w| w.write @mime_types.join("\n") }
254
+ end
255
+ end
256
+
257
+ puts "Downloading index of MIME types from #{IANAParser::INDEX}."
258
+ IANAParser.load_index
259
+
260
+ require 'fileutils'
261
+ FileUtils.mkdir_p destination
262
+ Dir.chdir destination do
263
+ IANAParser.types.values.sort.each do |parser|
264
+ next if parser.name == "example" or parser.name == "mime"
265
+ puts "Downloading #{parser.name} from #{parser.url}"
266
+ parser.download
267
+
268
+ if :html == save_type || :both == save_type
269
+ puts "Saving #{parser.name}.html"
270
+ parser.save_html
271
+ end
272
+
273
+ puts "Parsing #{parser.name} HTML"
274
+ parser.parse
275
+
276
+ if :text == save_type || :both == save_type
277
+ puts "Saving #{parser.name}.txt"
278
+ parser.save_text
279
+ end
280
+ end
281
+ end
282
+ end
283
+
284
+ desc "Shows known MIME type sources."
285
+ task :mime_type_sources do
286
+ puts <<-EOS
287
+ http://www.ltsw.se/knbase/internet/mime.htp
288
+ http://www.webmaster-toolkit.com/mime-types.shtml
289
+ http://plugindoc.mozdev.org/winmime.php
290
+ http://standards.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html
291
+ http://www.feedforall.com/mime-types.htm
292
+ http://www.iana.org/assignments/media-types/
293
+ EOS
294
+ end
295
+
296
+ desc "Validate the RubyGem spec for GitHub."
297
+ task :github_validate_spec do |t|
298
+ require 'yaml'
299
+
300
+ require 'rubygems/specification'
301
+ data = File.read("#{PKG_NAME}.gemspec")
302
+ spec = nil
303
+
304
+ if data !~ %r{!ruby/object:Gem::Specification}
305
+ code = "$SAFE = 3\n#{data}"
306
+ p code.split($/)[44]
307
+ Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
308
+ else
309
+ spec = YAML.load(data)
310
+ end
311
+
312
+ spec.validate
313
+
314
+ puts spec
315
+ puts "OK"
316
+ end