class FroyoApi::Photo
Attributes
href[R]
type[R]
Public Class Methods
new()
click to toggle source
# File lib/froyo_api/photo.rb, line 7 def initialize @href = attributes['href'] @type = attributes['type'] end
Public Instance Methods
download(directory = '.')
click to toggle source
# File lib/froyo_api/photo.rb, line 19 def download(directory = '.') file = File.join(directory, filename) File.open(file, 'wb') do |out| process_response = lambda do |response| response.read_body do |chunk| out.write(chunk) end end options = { url: href, method: :get, block_response: process_response, headers: { accept: type } } RestClient::Request.execute(options) end end
filename()
click to toggle source
# File lib/froyo_api/photo.rb, line 12 def filename @filename ||= begin uri = URI.parse(href) File.basename(uri.path) end end
Private Instance Methods
attributes()
click to toggle source
# File lib/froyo_api/photo.rb, line 44 def attributes @attributes ||= fetch end
fetch()
click to toggle source
# File lib/froyo_api/photo.rb, line 54 def fetch request(path)['links']['enclosure'].first end
path()
click to toggle source
# File lib/froyo_api/photo.rb, line 50 def path "apod" end