class SocialProfile::People::Album
Public Class Methods
new(response, target)
click to toggle source
# File lib/social_profile/people/vkontakte.rb, line 253 def initialize(response, target) @hash = normalize_hash(response) @target = target end
Public Instance Methods
http_client()
click to toggle source
# File lib/social_profile/people/vkontakte.rb, line 258 def http_client @http_client ||= ::HTTPClient.new(:agent_name => 'SocialProfile robot/0.1') end
identifier()
click to toggle source
Get album id
# File lib/social_profile/people/vkontakte.rb, line 263 def identifier @hash['aid'] end
method_missing(method_name, *args, &block)
click to toggle source
Calls superclass method
# File lib/social_profile/people/vkontakte.rb, line 291 def method_missing(method_name, *args, &block) if @hash.has_key?(method_name.to_s) @hash[method_name.to_s] else super end end
photo!(options)
click to toggle source
Upload photo to album
album.photo!(
:source => File.new('/path/to/image') :message => "some photo info"
)
# File lib/social_profile/people/vkontakte.rb, line 276 def photo!(options) return if identifier.nil? if upload_url = find_upload_url data = http_client.post(upload_url, 'file1' => options[:source]) parsed_response = MultiJson.decode(data.body) @target.photos.save(parsed_response.merge('caption' => options[:message])) end end
respond_to?(method_name)
click to toggle source
Calls superclass method
# File lib/social_profile/people/vkontakte.rb, line 287 def respond_to?(method_name) @hash.has_key?(method_name.to_s) ? true : super end
Protected Instance Methods
find_upload_url()
click to toggle source
# File lib/social_profile/people/vkontakte.rb, line 301 def find_upload_url server = @target.photos.getUploadServer(:aid => identifier) if server && server['upload_url'] server['upload_url'] elsif server && server['response'] server['response']['upload_url'] else nil end end
normalize_hash(hash)
click to toggle source
# File lib/social_profile/people/vkontakte.rb, line 313 def normalize_hash(hash) hash = hash["response"] if hash.is_a?(Hash) && hash["response"] response = Array.wrap(hash).first response || {} end