itunes-search 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.3.0
@@ -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 'rake gemspec'
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.2.6"
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{2011-06-15}
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
- "README.rdoc"
17
+ "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
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"
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.7.2}
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::VERSION) >= Gem::Version.new('1.2.0') then
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
- elements = []
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")
@@ -1,11 +1,21 @@
1
1
  module ItunesSearch
2
2
 
3
- ENDPOINT = "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/wsSearch"
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
- end
20
+
21
+ end
@@ -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
- self.options={}
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
- 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
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
- #puts "#{ItunesSearch::ENDPOINT}?#{self.options.to_url_params}"
26
- uri = URI.parse("#{ItunesSearch::ENDPOINT}?#{self.options.to_url_params}")
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}?#{self.options.to_url_params}")
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
- self.result_hash ||= JSON.parse(fetch)
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
- version: 0.2.6
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: 2011-06-15 00:00:00 Z
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.7.2
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
@@ -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