lib/itunes.rb in itunes-0.3.0 vs lib/itunes.rb in itunes-0.4.0
- old
+ new
@@ -1,73 +1,26 @@
-require 'httparty'
+require 'faraday_middleware'
+require 'faraday/rashify'
+require 'itunes/configuration'
+require 'itunes/client'
-class ITunes
- include HTTParty
+module ITunes
+ extend Configuration
- base_uri 'ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/ws'
- format :json
-
- attr_accessor :limit
+ # Alias for ITunes::Client.new
+ #
+ # @return [ITunes::Client]
+ def self.client(options={})
+ ITunes::Client.new(options)
+ end
- 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
-
- @limit = args[1].delete(:limit) unless args[1].nil? # will return nil if there is no limit
-
- request(args.first, camelcase)
- else
- super(name, *args)
- end
+ # Delegate to ITunes::Client
+ def self.method_missing(method, *args, &block)
+ return super unless client.respond_to?(method)
+ client.send(method, *args, &block)
end
-
- def initialize(limit=nil)
- @limit = limit
- end
-
- # So you don't have to create an instance if you don't need to
- def self.music(terms, opts=nil)
- self.new.music(terms, opts)
- end
-
- def self.podcast(terms, opts=nil)
- self.new.podcast(terms, opts)
- end
-
- def self.movie(terms, opts=nil)
- self.new.movie(terms, opts)
- end
-
- def self.music_video(terms, opts=nil)
- self.new.music_video(terms, opts)
- end
-
- def self.audiobook(terms, opts=nil)
- self.new.audiobook(terms, opts)
- end
-
- def self.short_film(terms, opts=nil)
- self.new.short_film(terms, opts)
- end
-
- def self.tv_show(terms, opts=nil)
- self.new.tv_show(terms, opts)
- end
-
- def self.all(terms, opts=nil)
- self.new.all(terms, opts)
- end
- private
- def request(term, media='all')
- raise ArgumentError, 'you need to search for something, provide a term.' if term.nil?
-
- #
- query = { :term => term, :media => media }
- query.merge!({ :limit => @limit }) unless @limit.nil? or @limit == 0
-
- self.class.get('Search', { :query => query })
- end
+ # Delegate to ITunes::Client
+ def self.respond_to?(method)
+ return client.respond_to?(method) || super
+ end
end