Class: FroyoApi::Photo
Instance Attribute Summary collapse
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #download(directory = '.') ⇒ Object
- #filename ⇒ Object
-
#initialize ⇒ Photo
constructor
A new instance of Photo.
Methods inherited from Client
Constructor Details
#initialize ⇒ Photo
Returns a new instance of Photo.
7 8 9 10 |
# File 'lib/froyo_api/photo.rb', line 7 def initialize @href = attributes['href'] @type = attributes['type'] end |
Instance Attribute Details
#href ⇒ Object (readonly)
Returns the value of attribute href.
5 6 7 |
# File 'lib/froyo_api/photo.rb', line 5 def href @href end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/froyo_api/photo.rb', line 5 def type @type end |
Instance Method Details
#download(directory = '.') ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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 = { url: href, method: :get, block_response: process_response, headers: { accept: type } } RestClient::Request.execute() end end |
#filename ⇒ Object
12 13 14 15 16 17 |
# File 'lib/froyo_api/photo.rb', line 12 def filename @filename ||= begin uri = URI.parse(href) File.basename(uri.path) end end |