Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 40bf18cb70cb948744d5b49a6d0a2465e8354ecf dewski committed Oct 2, 2010
Showing with 115 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +20 −0 MIT-LICENSE
  3. +57 −0 Rakefile
  4. +33 −0 lib/itunes.rb
  5. +3 −0 lib/itunes/version.rb
@@ -0,0 +1,2 @@
+itunes.gemspec
+pkg/*
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Garrett Bjerkhoel
+
+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.
@@ -0,0 +1,57 @@
+require 'rubygems'
+require File.join(File.dirname(__FILE__), 'lib', 'itunes', 'version')
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |s|
+ root_files = FileList["README.md", "MIT-LICENSE"]
+ s.name = 'itunes'
+ s.version = JSONBuilder::VERSION.dup
+ s.summary = 'iTunes'
+ s.email = 'me@garrettbjerkhoel.com'
+ s.homepage = 'http://github.com/dewski/itunes'
+ s.description = 'iTunes API'
+ s.authors = ['Garrett Bjerkhoel']
+ s.files = root_files + FileList['{lib}/**/*']
+ s.extra_rdoc_files = root_files
+ s.add_dependency('httparty')
+ end
+
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: gem install jeweler"
+end
+
+def gemspec
+ @gemspec ||= begin
+ gemspec_file = File.expand_path('../json_builder.gemspec', __FILE__)
+ gemspec = eval(File.read(gemspec_file), binding, gemspec_file)
+ end
+end
+
+desc 'Removes trailing whitespace'
+task :whitespace do
+ sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
+end
+
+namespace :release do
+ task :tag do
+ release_tag = "v#{gemspec.version}"
+ sh "git tag -a #{release_tag} -m 'Tagging #{release_tag}'"
+ sh "git push origin #{release_tag}"
+ end
+
+ task :gem => :build do
+ sh "gem push pkg/#{gemspec.file_name}"
+ end
+end
+
+desc "Release the current branch to GitHub and Gemcutter"
+task :release => %w(release:tag release:gem)
+
+namespace :gemspec do
+ desc 'Validate the gemspec'
+ task :validate do
+ gemspec.validate
+ end
+end
@@ -0,0 +1,33 @@
+require 'httparty'
+
+class ITunes
+ include HTTParty
+
+ base_uri 'ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/ws'
+ format :json
+
+ def method_missing(name, *args)
+ methods = %q{movie podcast music music_video audiobook short_film tv_show all}
+
+ if methods.include?(name.to_s)
+ camelcase = name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
+ camelcase[0] = camelcase[0].chr.downcase
+
+ request(args.first, camelcase)
+ else
+ super(name, *args)
+ end
+ end
+
+ private
+ def request(term, media='all')
+ raise ArgumentError, 'you need to search for something, provide a term.' if term.nil?
+
+ self.class.get('Search', {
+ :query => {
+ :term => term,
+ :media => media
+ }
+ })
+ end
+end
@@ -0,0 +1,3 @@
+class ITunes
+ VERSION = '0.1.0'.freeze
+end

0 comments on commit 40bf18c

Please sign in to comment.