itunes-search 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,27 @@
1
1
  = itunes-search
2
2
 
3
- Description goes here.
3
+ This was created for use on musicxray.com if you think you can do better send your resume to jeff at musicxray.com
4
+
5
+ == Installation
6
+
7
+ gem install itunes-search
8
+
9
+ == Usage
10
+
11
+ base = Itunes::Base.new
12
+
13
+ search_object = base.search("term"=>"The Killers")
14
+
15
+ # get an array of the search_objects
16
+
17
+ results = search_object.results
18
+
19
+ results.each do |result|
20
+ puts result.trackViewUrl
21
+ end
22
+
23
+ puts result.attributes
24
+
4
25
 
5
26
  == Note on Patches/Pull Requests
6
27
 
data/Rakefile CHANGED
@@ -6,11 +6,11 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "itunes-search"
8
8
  gem.summary = %Q{Itunes Search}
9
- gem.description = %Q{Pretty simple interface for the itunes search api}
9
+ gem.description = %Q{Pretty simple interface for the itunes search api will return results as array of results objects and offer reasonable accessor methods variables}
10
10
  gem.email = "jeff.durand@gmail.com"
11
11
  gem.homepage = "http://github.com/johnnyiller/itunes-search"
12
12
  gem.authors = ["jeff durand"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
13
+ gem.add_development_dependency "shoulda", ">= 0"
14
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
15
  end
16
16
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{itunes-search}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jeff durand"]
12
- s.date = %q{2010-04-15}
13
- s.description = %q{Pretty simple interface for the itunes search api}
12
+ s.date = %q{2010-04-16}
13
+ s.description = %q{Pretty simple interface for the itunes search api will return results as array of results objects and offer reasonable accessor methods variables}
14
14
  s.email = %q{jeff.durand@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -24,7 +24,10 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "itunes-search.gemspec",
27
+ "lib/hash_extension.rb",
27
28
  "lib/itunes-search.rb",
29
+ "lib/result.rb",
30
+ "lib/search.rb",
28
31
  "test/helper.rb",
29
32
  "test/test_itunes-search.rb"
30
33
  ]
@@ -43,12 +46,12 @@ Gem::Specification.new do |s|
43
46
  s.specification_version = 3
44
47
 
45
48
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
49
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
47
50
  else
48
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ s.add_dependency(%q<shoulda>, [">= 0"])
49
52
  end
50
53
  else
51
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
54
+ s.add_dependency(%q<shoulda>, [">= 0"])
52
55
  end
53
56
  end
54
57
 
@@ -0,0 +1,12 @@
1
+ require "cgi"
2
+ require 'rubygems'
3
+
4
+ class Hash
5
+ def to_url_params
6
+ elements = []
7
+ keys.size.times do |i|
8
+ elements << "#{CGI::escape(keys[i])}=#{CGI::escape(values[i])}"
9
+ end
10
+ elements.join('&')
11
+ end
12
+ end
data/lib/itunes-search.rb CHANGED
@@ -0,0 +1,24 @@
1
+ module ItunesSearch
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+
6
+ # require '*'
7
+ require 'hash_extension'
8
+ require 'net/http'
9
+ require 'uri'
10
+ require 'json'
11
+ require 'search'
12
+ require 'result'
13
+
14
+ ENDPOINT = "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsSearch"
15
+
16
+ class Base
17
+
18
+
19
+ def search(*args)
20
+ return Search.new(*args)
21
+ end
22
+
23
+ end
24
+ end
data/lib/result.rb ADDED
@@ -0,0 +1,20 @@
1
+ module ItunesSearch
2
+
3
+ class Result
4
+ attr_accessor :attributes
5
+ alias :original_method_missing :method_missing
6
+ def initialize(hash)
7
+ self.attributes = {}
8
+ self.attributes.merge!(hash)
9
+ end
10
+
11
+ def method_missing(method_name,*args)
12
+ if self.attributes.keys.include?(method_name.to_s)
13
+ return self.attributes["#{method_name.to_s}"]
14
+ else
15
+ original_method_missing method_name, args
16
+ end
17
+ end
18
+ end
19
+
20
+ end
data/lib/search.rb ADDED
@@ -0,0 +1,39 @@
1
+ module ItunesSearch
2
+
3
+ class Search
4
+ attr_accessor :options, :result_hash, :json
5
+ alias :original_method_missing :method_missing
6
+
7
+ def initialize(*args)
8
+ self.options={}
9
+ args.each do |arg|
10
+ self.options.merge!(arg)
11
+ end
12
+ end
13
+ def method_missing(method_name,*args)
14
+ if args.size == 1
15
+ self.options.merge!({"#{method_name.to_s.gsub("=","")}"=>args.first.to_s})
16
+ return self.options["#{method_name.to_s.gsub("=","")}"]
17
+ elsif args.size == 0
18
+ if self.options.keys.include?(method_name.to_s)
19
+ return self.options["#{method_name.to_s.gsub("=","")}"]
20
+ end
21
+ end
22
+ original_method_missing method_name, args
23
+ end
24
+ def fetch
25
+ puts "#{ItunesSearch::ENDPOINT}?#{self.options.to_url_params}"
26
+ self.json = Net::HTTP.get(URI.parse("#{ItunesSearch::ENDPOINT}?#{self.options.to_url_params}")).to_s
27
+ end
28
+ def results
29
+ ra = []
30
+ ra = self.to_hash["results"].collect {|r| Result.new(r)} unless self.to_hash["results"].empty?
31
+ return ra
32
+ end
33
+
34
+ def to_hash
35
+ self.result_hash ||= JSON.parse(fetch)
36
+ end
37
+
38
+ end
39
+ end
@@ -1,7 +1,35 @@
1
1
  require 'helper'
2
+ require 'itunes-search'
2
3
 
3
4
  class TestItunesSearch < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- flunk "hey buddy, you should probably rename this file and start testing for real"
5
+
6
+ include ItunesSearch
7
+
8
+ context "Search working" do
9
+ setup do
10
+ @base = Base.new()
11
+ end
12
+ context "Band exists on itunes" do
13
+ setup do
14
+ @so = @base.search("term"=>"The Killers")
15
+ end
16
+ should "have result set" do
17
+ assert @so.results.size>0
18
+ end
19
+ should "be able to get first url" do
20
+ assert !@so.results.first.trackViewUrl!=""
21
+ end
22
+ should "not be empty" do
23
+ assert !@so.results.empty?
24
+ end
25
+ end
26
+ context "Band does not exist on itunes" do
27
+ setup do
28
+ @so = @base.search("term"=>"dsafjlkdsajflkjdsa")
29
+ end
30
+ should "have empty result set" do
31
+ assert @so.results.empty?
32
+ end
33
+ end
6
34
  end
7
35
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - jeff durand
@@ -14,11 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-15 00:00:00 -04:00
17
+ date: 2010-04-16 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: thoughtbot-shoulda
21
+ name: shoulda
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: "0"
30
30
  type: :development
31
31
  version_requirements: *id001
32
- description: Pretty simple interface for the itunes search api
32
+ description: Pretty simple interface for the itunes search api will return results as array of results objects and offer reasonable accessor methods variables
33
33
  email: jeff.durand@gmail.com
34
34
  executables: []
35
35
 
@@ -46,7 +46,10 @@ files:
46
46
  - Rakefile
47
47
  - VERSION
48
48
  - itunes-search.gemspec
49
+ - lib/hash_extension.rb
49
50
  - lib/itunes-search.rb
51
+ - lib/result.rb
52
+ - lib/search.rb
50
53
  - test/helper.rb
51
54
  - test/test_itunes-search.rb
52
55
  has_rdoc: true