itunes 0.2.0 → 0.3.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.
- data/README.md +77 -0
- data/lib/itunes.rb +30 -23
- data/lib/itunes/version.rb +1 -1
- metadata +7 -5
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# iTunes
|
2
|
+
A Ruby wrapper around the iTunes API that lets you search for any sort of data that is available on the iTunes store.
|
3
|
+
|
4
|
+
## Example Response
|
5
|
+
|
6
|
+
{
|
7
|
+
"artistId" : 954266,
|
8
|
+
"artistName" : "Green Day",
|
9
|
+
"artistViewUrl" : "http://itunes.apple.com/us/artist/green-day/id954266?uo=4",
|
10
|
+
"artworkUrl100" : "http://a1.phobos.apple.com/us/r1000/049/Features/1e/17/05/dj.rpihtiig.100x100-75.jpg",
|
11
|
+
"artworkUrl30" : "http://a1.phobos.apple.com/us/r1000/049/Features/1e/17/05/dj.rpihtiig.30x30-50.jpg",
|
12
|
+
"artworkUrl60" : "http://a1.phobos.apple.com/us/r1000/049/Features/1e/17/05/dj.rpihtiig.60x60-50.jpg",
|
13
|
+
"collectionCensoredName" : "Dookie",
|
14
|
+
"collectionExplicitness" : "explicit",
|
15
|
+
"collectionId" : 5132583,
|
16
|
+
"collectionName" : "Dookie",
|
17
|
+
"collectionPrice" : 9.99,
|
18
|
+
"collectionViewUrl" : "http://itunes.apple.com/us/album/she/id5132583?i=5132563&uo=4",
|
19
|
+
"contentAdvisoryRating" : null,
|
20
|
+
"country" : "USA",
|
21
|
+
"currency" : "USD",
|
22
|
+
"discCount" : 1,
|
23
|
+
"discNumber" : 1,
|
24
|
+
"kind" : "song",
|
25
|
+
"previewUrl" : "http://a1.phobos.apple.com/us/r1000/027/Music/0e/86/7a/mzm.wchstext.aac.p.m4a",
|
26
|
+
"primaryGenreName" : "Alternative",
|
27
|
+
"releaseDate" : "2003-04-22 07:00:00 Etc/GMT",
|
28
|
+
"trackCensoredName" : "She",
|
29
|
+
"trackCount" : 15,
|
30
|
+
"trackExplicitness" : "notExplicit",
|
31
|
+
"trackId" : 5132563,
|
32
|
+
"trackName" : "She",
|
33
|
+
"trackNumber" : 8,
|
34
|
+
"trackPrice" : 1.29,
|
35
|
+
"trackTimeMillis" : 134293,
|
36
|
+
"trackViewUrl" : "http://itunes.apple.com/us/album/she/id5132583?i=5132563&uo=4",
|
37
|
+
"wrapperType" : "track"
|
38
|
+
}
|
39
|
+
|
40
|
+
## Available Methods
|
41
|
+
- movie
|
42
|
+
- podcast
|
43
|
+
- music
|
44
|
+
- music_video
|
45
|
+
- audiobook
|
46
|
+
- short_film
|
47
|
+
- tv_show
|
48
|
+
- all
|
49
|
+
|
50
|
+
## Using the iTunes gem
|
51
|
+
|
52
|
+
require 'itunes'
|
53
|
+
|
54
|
+
>> itunes = ITunes.new
|
55
|
+
>> songs = itunes.music('green day she')
|
56
|
+
=> {"result_count" => 15, "results" => [...]}
|
57
|
+
>> songs['results'].each do |song|
|
58
|
+
>> puts "#{song['trackName']} - #{song['artistName']} (#{song['collectionName']})"
|
59
|
+
>> end
|
60
|
+
=> She - Green Day (Dookie)
|
61
|
+
=> She - Green Day (Dookie)
|
62
|
+
=> She - Green Day (Dookie)
|
63
|
+
=> She - Green Day (Dookie)
|
64
|
+
=> She - Green Day (Dookie)
|
65
|
+
=> ...
|
66
|
+
>> iron_man = ITunes.movie('iron man 2')
|
67
|
+
=> {"result_count" => 1, "results" => [...]}
|
68
|
+
=> ...
|
69
|
+
>> foo_fighters = ITunes.music('foo fighters everlong', :limit => 1)
|
70
|
+
=> {"result_count" => 1, "results" => [{ "trackName" => "Everlong", ... }]}
|
71
|
+
|
72
|
+
## Upcoming Features
|
73
|
+
|
74
|
+
- A better DSL.
|
75
|
+
|
76
|
+
## Copyright
|
77
|
+
Copyright © 2010 Garrett Bjerkhoel. See [MIT-LICENSE](http://github.com/dewski/itunes/blob/master/MIT-LICENSE) for details.
|
data/lib/itunes.rb
CHANGED
@@ -5,6 +5,8 @@ class ITunes
|
|
5
5
|
|
6
6
|
base_uri 'ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/ws'
|
7
7
|
format :json
|
8
|
+
|
9
|
+
attr_accessor :limit
|
8
10
|
|
9
11
|
def method_missing(name, *args)
|
10
12
|
methods = %q{movie podcast music music_video audiobook short_film tv_show all}
|
@@ -12,6 +14,8 @@ class ITunes
|
|
12
14
|
if methods.include?(name.to_s)
|
13
15
|
camelcase = name.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
14
16
|
camelcase[0] = camelcase[0].chr.downcase
|
17
|
+
|
18
|
+
@limit = args[1].delete(:limit) unless args[1].nil? # will return nil if there is no limit
|
15
19
|
|
16
20
|
request(args.first, camelcase)
|
17
21
|
else
|
@@ -19,48 +23,51 @@ class ITunes
|
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
26
|
+
def initialize(limit=nil)
|
27
|
+
@limit = limit
|
28
|
+
end
|
29
|
+
|
22
30
|
# So you don't have to create an instance if you don't need to
|
23
|
-
def self.music(terms)
|
24
|
-
self.new.music(terms)
|
31
|
+
def self.music(terms, opts=nil)
|
32
|
+
self.new.music(terms, opts)
|
25
33
|
end
|
26
34
|
|
27
|
-
def self.podcast(terms)
|
28
|
-
self.new.podcast(terms)
|
35
|
+
def self.podcast(terms, opts=nil)
|
36
|
+
self.new.podcast(terms, opts)
|
29
37
|
end
|
30
38
|
|
31
|
-
def self.movie(terms)
|
32
|
-
self.new.movie(terms)
|
39
|
+
def self.movie(terms, opts=nil)
|
40
|
+
self.new.movie(terms, opts)
|
33
41
|
end
|
34
42
|
|
35
|
-
def self.music_video(terms)
|
36
|
-
self.new.music_video(terms)
|
43
|
+
def self.music_video(terms, opts=nil)
|
44
|
+
self.new.music_video(terms, opts)
|
37
45
|
end
|
38
46
|
|
39
|
-
def self.audiobook(terms)
|
40
|
-
self.new.audiobook(terms)
|
47
|
+
def self.audiobook(terms, opts=nil)
|
48
|
+
self.new.audiobook(terms, opts)
|
41
49
|
end
|
42
50
|
|
43
|
-
def self.short_film(terms)
|
44
|
-
self.new.short_film(terms)
|
51
|
+
def self.short_film(terms, opts=nil)
|
52
|
+
self.new.short_film(terms, opts)
|
45
53
|
end
|
46
54
|
|
47
|
-
def self.tv_show(terms)
|
48
|
-
self.new.tv_show(terms)
|
55
|
+
def self.tv_show(terms, opts=nil)
|
56
|
+
self.new.tv_show(terms, opts)
|
49
57
|
end
|
50
58
|
|
51
|
-
def self.all(terms)
|
52
|
-
self.new.all(terms)
|
59
|
+
def self.all(terms, opts=nil)
|
60
|
+
self.new.all(terms, opts)
|
53
61
|
end
|
54
62
|
|
55
63
|
private
|
56
64
|
def request(term, media='all')
|
57
65
|
raise ArgumentError, 'you need to search for something, provide a term.' if term.nil?
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
})
|
66
|
+
|
67
|
+
#
|
68
|
+
query = { :term => term, :media => media }
|
69
|
+
query.merge!({ :limit => @limit }) unless @limit.nil? or @limit == 0
|
70
|
+
|
71
|
+
self.class.get('Search', { :query => query })
|
65
72
|
end
|
66
73
|
end
|
data/lib/itunes/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itunes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Garrett Bjerkhoel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-05 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -40,8 +40,10 @@ extensions: []
|
|
40
40
|
|
41
41
|
extra_rdoc_files:
|
42
42
|
- MIT-LICENSE
|
43
|
+
- README.md
|
43
44
|
files:
|
44
45
|
- MIT-LICENSE
|
46
|
+
- README.md
|
45
47
|
- lib/itunes.rb
|
46
48
|
- lib/itunes/version.rb
|
47
49
|
has_rdoc: true
|
@@ -73,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
75
|
version: "0"
|
74
76
|
requirements: []
|
75
77
|
|
76
|
-
rubyforge_project:
|
78
|
+
rubyforge_project: itunes
|
77
79
|
rubygems_version: 1.3.7
|
78
80
|
signing_key:
|
79
81
|
specification_version: 3
|