Skip to content
This repository was archived by the owner on Feb 27, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions itunes.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ Gem::Specification.new do |s|
s.add_development_dependency('json', '~> 1.6')

s.add_runtime_dependency('rash', '~> 0.3')
s.add_runtime_dependency('faraday_middleware', '~> 0.7')
s.add_runtime_dependency('faraday_middleware', '~> 0.9')
s.add_runtime_dependency('multi_json', '~> 1.0')

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
Expand Down
1 change: 1 addition & 0 deletions lib/itunes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'faraday_middleware'
require 'nokogiri'
require 'itunes/configuration'
require 'itunes/client'

Expand Down
1 change: 1 addition & 0 deletions lib/itunes/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def initialize(options={})
include Request
include Search
include Lookup
include AdditionalMetadata

end
end
20 changes: 20 additions & 0 deletions lib/itunes/client/additional_metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module ITunes
module AdditionalMetadata
PEOPLE_TYPES=%w(Actor Director Artist Producer Screenwriter)
def read_people(people_type, html)
raise ArgumentError, "you must pass #{PEOPLE_TYPES.join('|')}" unless PEOPLE_TYPES.include?( people_type )
nodes = html.xpath("//div[starts-with(@metrics-loc,'Titledbox_#{people_type}')]")
nodes.map{|n|n.search('.//a').map{|a|a.text}}.flatten
end
def get_additional_metadata(result)
raise ArgumentError, 'you must pass in a single result object containing track_url' unless result && result.track_view_url
html = Nokogiri::HTML(Faraday.new.get(result.track_view_url.gsub(/\?.*/,'')).body)
additional_metadata = PEOPLE_TYPES.inject({}) do |hash, type|
hash["#{type}s"]=read_people(type, html)
hash
end
additional_metadata
end
end
end

2 changes: 1 addition & 1 deletion lib/itunes/client/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,4 @@ def search(term, media='all', options={})
end

end
end
end