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.



253
254
255
256
# File 'lib/social_profile/people/vkontakte.rb', line 253

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



291
292
293
294
295
296
297
# 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

Instance Method Details

#http_clientObject



258
259
260
# File 'lib/social_profile/people/vkontakte.rb', line 258

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

#identifierObject

Get album id



263
264
265
# File 'lib/social_profile/people/vkontakte.rb', line 263

def identifier
  @hash['aid']
end

#photo!(options) ⇒ Object



276
277
278
279
280
281
282
283
284
285
# 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) ⇒ Boolean

Returns:

  • (Boolean)


287
288
289
# File 'lib/social_profile/people/vkontakte.rb', line 287

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