Class: ItunesIcons
- Inherits:
-
Object
- Object
- ItunesIcons
- Defined in:
- lib/TokiServer/itunesicons.rb
Instance Method Summary collapse
- #download(url, path) ⇒ Object
- #find_icon(terms) ⇒ Object
- #grab(*args) ⇒ Object
- #grab_big(*args) ⇒ Object
- #grab_small(*args) ⇒ Object
-
#initialize(fileops) ⇒ ItunesIcons
constructor
A new instance of ItunesIcons.
Constructor Details
#initialize(fileops) ⇒ ItunesIcons
Returns a new instance of ItunesIcons.
12 13 14 |
# File 'lib/TokiServer/itunesicons.rb', line 12 def initialize(fileops) @fileops = fileops end |
Instance Method Details
#download(url, path) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/TokiServer/itunesicons.rb', line 49 def download url, path begin open(url) do |f| File.open(path,'w+') do |file| file.puts(f.read) end end true rescue false end end |
#find_icon(terms) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/TokiServer/itunesicons.rb', line 38 def find_icon(terms) url = URI.parse("http://itunes.apple.com/search?term=#{CGI.escape(terms)}&entity=#{@entity}") res = Net::HTTP.get_response(url).body match = res.match(/"#{@icon_size}":"(.*?)",/) unless match.nil? return match[1] else return false end end |
#grab(*args) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/TokiServer/itunesicons.rb', line 28 def grab(*args) terms = args.join(" ") icon_url = find_icon(terms) if icon_url URI.parse(icon_url) else '' end end |
#grab_big(*args) ⇒ Object
22 23 24 25 26 |
# File 'lib/TokiServer/itunesicons.rb', line 22 def grab_big(*args) @entity = "macSoftware" @icon_size = "artworkUrl100" grab(args) end |
#grab_small(*args) ⇒ Object
16 17 18 19 20 |
# File 'lib/TokiServer/itunesicons.rb', line 16 def grab_small(*args) @entity = "macSoftware" @icon_size = "artworkUrl60" grab(args) end |