itunes-search 0.2.6 → 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/.gitignore +21 -0
- data/VERSION +1 -1
- data/itunes-search.gemspec +23 -17
- data/lib/itunes-search.rb +1 -6
- data/lib/itunes-search/base.rb +13 -3
- data/lib/itunes-search/search.rb +18 -31
- metadata +22 -12
- data/lib/itunes-search/result.rb +0 -20
data/.gitignore
ADDED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.3.0
|
data/itunes-search.gemspec
CHANGED
|
@@ -1,44 +1,50 @@
|
|
|
1
1
|
# Generated by jeweler
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{itunes-search}
|
|
8
|
-
s.version = "0.
|
|
8
|
+
s.version = "0.3.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{
|
|
12
|
+
s.date = %q{2013-01-08}
|
|
13
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",
|
|
17
|
-
|
|
17
|
+
"README.rdoc"
|
|
18
18
|
]
|
|
19
19
|
s.files = [
|
|
20
20
|
".document",
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
".gitignore",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.rdoc",
|
|
24
|
+
"Rakefile",
|
|
25
|
+
"VERSION",
|
|
26
|
+
"itunes-search.gemspec",
|
|
27
|
+
"lib/itunes-search.rb",
|
|
28
|
+
"lib/itunes-search/base.rb",
|
|
29
|
+
"lib/itunes-search/search.rb",
|
|
30
|
+
"test/helper.rb",
|
|
31
|
+
"test/test_itunes-search.rb"
|
|
32
32
|
]
|
|
33
33
|
s.homepage = %q{http://github.com/johnnyiller/itunes-search}
|
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
34
35
|
s.require_paths = ["lib"]
|
|
35
|
-
s.rubygems_version = %q{1.
|
|
36
|
+
s.rubygems_version = %q{1.3.6}
|
|
36
37
|
s.summary = %q{Itunes Search}
|
|
38
|
+
s.test_files = [
|
|
39
|
+
"test/helper.rb",
|
|
40
|
+
"test/test_itunes-search.rb"
|
|
41
|
+
]
|
|
37
42
|
|
|
38
43
|
if s.respond_to? :specification_version then
|
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
39
45
|
s.specification_version = 3
|
|
40
46
|
|
|
41
|
-
if Gem::Version.new(Gem::
|
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
42
48
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
|
43
49
|
else
|
|
44
50
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
data/lib/itunes-search.rb
CHANGED
|
@@ -7,11 +7,7 @@ require "cgi"
|
|
|
7
7
|
|
|
8
8
|
class Hash
|
|
9
9
|
def to_url_params
|
|
10
|
-
|
|
11
|
-
keys.size.times do |i|
|
|
12
|
-
elements << "#{CGI::escape(keys[i])}=#{CGI::escape(values[i])}"
|
|
13
|
-
end
|
|
14
|
-
elements.join('&')
|
|
10
|
+
collect { |key,value| "#{CGI::escape(key)}=#{CGI::escape(value)}" }.join('&')
|
|
15
11
|
end
|
|
16
12
|
end
|
|
17
13
|
|
|
@@ -19,4 +15,3 @@ end
|
|
|
19
15
|
directory = File.expand_path(File.dirname(__FILE__))
|
|
20
16
|
require File.join(directory,"itunes-search", "base")
|
|
21
17
|
require File.join(directory,"itunes-search","search")
|
|
22
|
-
require File.join(directory,"itunes-search","result")
|
data/lib/itunes-search/base.rb
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
module ItunesSearch
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
|
|
4
|
+
@endpoint = "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsSearch"
|
|
5
|
+
|
|
6
|
+
def self.endpoint=(ep)
|
|
7
|
+
@endpoint = ep
|
|
8
|
+
end
|
|
9
|
+
def self.endpoint
|
|
10
|
+
@endpoint
|
|
11
|
+
end
|
|
12
|
+
|
|
5
13
|
class Base
|
|
6
14
|
|
|
7
15
|
def search(*args)
|
|
8
16
|
return ItunesSearch::Search.new(*args)
|
|
9
17
|
end
|
|
18
|
+
|
|
10
19
|
end
|
|
11
|
-
|
|
20
|
+
|
|
21
|
+
end
|
data/lib/itunes-search/search.rb
CHANGED
|
@@ -1,46 +1,33 @@
|
|
|
1
|
+
require 'ostruct'
|
|
1
2
|
module ItunesSearch
|
|
2
3
|
|
|
3
4
|
class Search
|
|
4
5
|
attr_accessor :options, :result_hash, :json
|
|
5
|
-
alias :original_method_missing :method_missing
|
|
6
6
|
|
|
7
7
|
def initialize(*args)
|
|
8
|
-
|
|
9
|
-
args.each do |arg|
|
|
10
|
-
self.options.merge!(arg)
|
|
11
|
-
end
|
|
8
|
+
@options = args.inject({}) { |result, element| element.merge(result); element }
|
|
12
9
|
end
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
10
|
+
|
|
11
|
+
def results
|
|
12
|
+
ra = []
|
|
13
|
+
ra = to_hash["results"].collect {|r| OpenStruct.new(r) } unless to_hash["results"].empty?
|
|
14
|
+
return ra
|
|
23
15
|
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
24
18
|
def fetch
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
resp = Net::HTTP.start(uri.host,uri.port) do |http|
|
|
19
|
+
uri = URI.parse("#{itunes_endpoint}?#{options.to_url_params}")
|
|
20
|
+
@json ||= Net::HTTP.start(uri.host,uri.port) do |http|
|
|
28
21
|
http.open_timeout=5
|
|
29
22
|
http.read_timeout=5
|
|
30
|
-
http.get("#{uri.path}?#{
|
|
31
|
-
end
|
|
32
|
-
self.json=resp.body
|
|
23
|
+
http.get("#{uri.path}?#{options.to_url_params}")
|
|
24
|
+
end.body
|
|
33
25
|
end
|
|
34
|
-
def results
|
|
35
|
-
ra = []
|
|
36
|
-
ra = self.to_hash["results"].collect {|r| ItunesSearch::Result.new(r)} unless self.to_hash["results"].empty?
|
|
37
|
-
puts ra.inspect
|
|
38
|
-
return ra
|
|
39
|
-
end
|
|
40
|
-
|
|
41
26
|
def to_hash
|
|
42
|
-
|
|
27
|
+
@result_hash ||= JSON.parse(fetch)
|
|
28
|
+
end
|
|
29
|
+
def itunes_endpoint
|
|
30
|
+
ItunesSearch.endpoint
|
|
43
31
|
end
|
|
44
|
-
|
|
45
32
|
end
|
|
46
|
-
end
|
|
33
|
+
end
|
metadata
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: itunes-search
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
prerelease:
|
|
5
|
-
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 3
|
|
8
|
+
- 0
|
|
9
|
+
version: 0.3.0
|
|
6
10
|
platform: ruby
|
|
7
11
|
authors:
|
|
8
12
|
- jeff durand
|
|
@@ -10,16 +14,18 @@ autorequire:
|
|
|
10
14
|
bindir: bin
|
|
11
15
|
cert_chain: []
|
|
12
16
|
|
|
13
|
-
date:
|
|
17
|
+
date: 2013-01-08 00:00:00 -05:00
|
|
18
|
+
default_executable:
|
|
14
19
|
dependencies:
|
|
15
20
|
- !ruby/object:Gem::Dependency
|
|
16
21
|
name: shoulda
|
|
17
22
|
prerelease: false
|
|
18
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
|
19
|
-
none: false
|
|
20
24
|
requirements:
|
|
21
25
|
- - ">="
|
|
22
26
|
- !ruby/object:Gem::Version
|
|
27
|
+
segments:
|
|
28
|
+
- 0
|
|
23
29
|
version: "0"
|
|
24
30
|
type: :development
|
|
25
31
|
version_requirements: *id001
|
|
@@ -34,6 +40,7 @@ extra_rdoc_files:
|
|
|
34
40
|
- README.rdoc
|
|
35
41
|
files:
|
|
36
42
|
- .document
|
|
43
|
+
- .gitignore
|
|
37
44
|
- LICENSE
|
|
38
45
|
- README.rdoc
|
|
39
46
|
- Rakefile
|
|
@@ -41,36 +48,39 @@ files:
|
|
|
41
48
|
- itunes-search.gemspec
|
|
42
49
|
- lib/itunes-search.rb
|
|
43
50
|
- lib/itunes-search/base.rb
|
|
44
|
-
- lib/itunes-search/result.rb
|
|
45
51
|
- lib/itunes-search/search.rb
|
|
46
52
|
- test/helper.rb
|
|
47
53
|
- test/test_itunes-search.rb
|
|
54
|
+
has_rdoc: true
|
|
48
55
|
homepage: http://github.com/johnnyiller/itunes-search
|
|
49
56
|
licenses: []
|
|
50
57
|
|
|
51
58
|
post_install_message:
|
|
52
|
-
rdoc_options:
|
|
53
|
-
|
|
59
|
+
rdoc_options:
|
|
60
|
+
- --charset=UTF-8
|
|
54
61
|
require_paths:
|
|
55
62
|
- lib
|
|
56
63
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
|
-
none: false
|
|
58
64
|
requirements:
|
|
59
65
|
- - ">="
|
|
60
66
|
- !ruby/object:Gem::Version
|
|
67
|
+
segments:
|
|
68
|
+
- 0
|
|
61
69
|
version: "0"
|
|
62
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
|
-
none: false
|
|
64
71
|
requirements:
|
|
65
72
|
- - ">="
|
|
66
73
|
- !ruby/object:Gem::Version
|
|
74
|
+
segments:
|
|
75
|
+
- 0
|
|
67
76
|
version: "0"
|
|
68
77
|
requirements: []
|
|
69
78
|
|
|
70
79
|
rubyforge_project:
|
|
71
|
-
rubygems_version: 1.
|
|
80
|
+
rubygems_version: 1.3.6
|
|
72
81
|
signing_key:
|
|
73
82
|
specification_version: 3
|
|
74
83
|
summary: Itunes Search
|
|
75
|
-
test_files:
|
|
76
|
-
|
|
84
|
+
test_files:
|
|
85
|
+
- test/helper.rb
|
|
86
|
+
- test/test_itunes-search.rb
|
data/lib/itunes-search/result.rb
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
|