itunes-search-rb 0.3
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.
- data/.document +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +34 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/itunes-search.gemspec +50 -0
- data/lib/itunes-search/base.rb +12 -0
- data/lib/itunes-search/result.rb +20 -0
- data/lib/itunes-search/search.rb +31 -0
- data/lib/itunes-search.rb +10 -0
- data/test/helper.rb +10 -0
- data/test/test_itunes-search.rb +35 -0
- metadata +91 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Caleb Adam Haye
|
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/README.rdoc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
= itunes-search-rb
|
2
|
+
|
3
|
+
This project allows you to search iTunes using Ruby
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
gem install itunes-search-rb
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
base = ItunesSearch::Base.new
|
12
|
+
search_object = base.search("term", "The Killers")
|
13
|
+
|
14
|
+
# get an array of the search_objects
|
15
|
+
results = search_object.results
|
16
|
+
results.each do |result|
|
17
|
+
puts result.trackViewUrl
|
18
|
+
end
|
19
|
+
|
20
|
+
puts result.attributes
|
21
|
+
|
22
|
+
== Note on Patches/Pull Requests
|
23
|
+
|
24
|
+
* Fork the project.
|
25
|
+
* Make your feature addition or bug fix.
|
26
|
+
* Add tests for it. This is important so I don't break it in a
|
27
|
+
future version unintentionally.
|
28
|
+
* Commit, do not mess with rakefile, version, or history.
|
29
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
30
|
+
* Send me a pull request. Bonus points for topic branches.
|
31
|
+
|
32
|
+
== Copyright
|
33
|
+
|
34
|
+
Copyright (c) 2012 Caleb Adam Haye. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "itunes-search-rb"
|
8
|
+
gem.summary = %Q{Itunes Search}
|
9
|
+
gem.description = %Q{This project allows you to search iTunes using Ruby}
|
10
|
+
gem.email = "caleb@fire.coop"
|
11
|
+
gem.homepage = "http://github.com/calebhaye/itunes-search"
|
12
|
+
gem.authors = ["Caleb Adam Haye"]
|
13
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "itunes-search #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{itunes-search-rb}
|
8
|
+
s.version = "0.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Caleb Adam Haye"]
|
12
|
+
s.date = %q{2012-05-22}
|
13
|
+
s.description = %q{This project allows you to search iTunes using Ruby}
|
14
|
+
s.email = %q{caleb@fire.coop}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"itunes-search.gemspec",
|
26
|
+
"lib/itunes-search.rb",
|
27
|
+
"lib/itunes-search/base.rb",
|
28
|
+
"lib/itunes-search/result.rb",
|
29
|
+
"lib/itunes-search/search.rb",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/test_itunes-search.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/calebhaye/itunes-search}
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.7.2}
|
36
|
+
s.summary = %q{Itunes Search}
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
s.specification_version = 3
|
40
|
+
|
41
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
42
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
43
|
+
else
|
44
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
45
|
+
end
|
46
|
+
else
|
47
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module ItunesSearch
|
2
|
+
|
3
|
+
ENDPOINT = "http://itunes.apple.com/search" #"http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsSearch"
|
4
|
+
|
5
|
+
class Base
|
6
|
+
attr_accessor :search_type
|
7
|
+
|
8
|
+
def search(search_type, query)
|
9
|
+
return ItunesSearch::Search.new(search_type, CGI::escape(query))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -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
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ItunesSearch
|
2
|
+
|
3
|
+
class Search
|
4
|
+
attr_accessor :query, :result_hash, :json, :search_type
|
5
|
+
alias :original_method_missing :method_missing
|
6
|
+
|
7
|
+
def initialize(search_type, query)
|
8
|
+
self.search_type = search_type
|
9
|
+
self.query = query
|
10
|
+
end
|
11
|
+
def fetch
|
12
|
+
itunes_search_url = "#{ItunesSearch::ENDPOINT}/?#{self.search_type}=#{self.query}"
|
13
|
+
puts "itunes_search_url: #{itunes_search_url}"
|
14
|
+
self.json = RestClient.get(itunes_search_url)
|
15
|
+
puts self.json
|
16
|
+
self.json
|
17
|
+
end
|
18
|
+
def results
|
19
|
+
ra = []
|
20
|
+
ra = self.to_hash["results"].collect {|r| ItunesSearch::Result.new(r)} unless self.to_hash["results"].empty?
|
21
|
+
puts "result"
|
22
|
+
puts ra.inspect
|
23
|
+
return ra
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_hash
|
27
|
+
self.result_hash ||= JSON.parse(fetch)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/http'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
require "cgi"
|
6
|
+
|
7
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
8
|
+
require File.join(directory,"itunes-search", "base")
|
9
|
+
require File.join(directory,"itunes-search","search")
|
10
|
+
require File.join(directory,"itunes-search","result")
|
data/test/helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'itunes-search'
|
3
|
+
|
4
|
+
class TestItunesSearch < Test::Unit::TestCase
|
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
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: itunes-search-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 13
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: "0.3"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Caleb Adam Haye
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2012-05-22 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: This project allows you to search iTunes using Ruby
|
35
|
+
email: caleb@fire.coop
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files:
|
41
|
+
- LICENSE
|
42
|
+
- README.rdoc
|
43
|
+
files:
|
44
|
+
- .document
|
45
|
+
- LICENSE
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- VERSION
|
49
|
+
- itunes-search.gemspec
|
50
|
+
- lib/itunes-search.rb
|
51
|
+
- lib/itunes-search/base.rb
|
52
|
+
- lib/itunes-search/result.rb
|
53
|
+
- lib/itunes-search/search.rb
|
54
|
+
- test/helper.rb
|
55
|
+
- test/test_itunes-search.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://github.com/calebhaye/itunes-search
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.6.2
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Itunes Search
|
90
|
+
test_files: []
|
91
|
+
|