Class: SocialProfile::People::Album

Inherits:
Object
  • Object
show all
Defined in:
lib/social_profile/people/vkontakte.rb

Instance Method Summary collapse

Constructor Details

#initialize(response, target) ⇒ Album

Returns a new instance of Album.



232
233
234
235
# File 'lib/social_profile/people/vkontakte.rb', line 232

def initialize(response, target)
  @hash = normalize_hash(response)
  @target = target
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



270
271
272
273
274
275
276
# File 'lib/social_profile/people/vkontakte.rb', line 270

def method_missing(method_name, *args, &block)
  if @hash.has_key?(method_name.to_s)
    @hash[method_name.to_s]
  else
    super
  end
end

Instance Method Details

#http_clientObject



237
238
239
# File 'lib/social_profile/people/vkontakte.rb', line 237

def http_client
  @http_client ||= ::HTTPClient.new(:agent_name => 'SocialProfile robot/0.1')
end

#identifierObject

Get album id



242
243
244
# File 'lib/social_profile/people/vkontakte.rb', line 242

def identifier
  @hash['aid']
end

#photo!(options) ⇒ Object



255
256
257
258
259
260
261
262
263
264
# File 'lib/social_profile/people/vkontakte.rb', line 255

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) ⇒ Boolean

Returns:

  • (Boolean)


266
267
268
# File 'lib/social_profile/people/vkontakte.rb', line 266

def respond_to?(method_name)
  @hash.has_key?(method_name.to_s) ? true : super
end