rails koala gem - get API url request

144 views Asked by At

I'm working on rails 4, with the Koala gem to retrieve users pictures from Graph API.

I can receive the gem to receive the pictures:

picture, picture_medium, picture_small = graph.batch do |batch_api|
  batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_LARGE, 'height' => PIC_SIZE_LARGE}, 'return_ssl_resources' => '0')
  batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_MED, 'height' => PIC_SIZE_MED}, 'return_ssl_resources' => '0')
  batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_SMALL, 'height' => PIC_SIZE_SMALL}, 'return_ssl_resources' => '0')
end

but I would like to save the url the Koala is using (I preffer the user will call the url, instead of me). I assumes that the gem calls: https://graph.facebook.com/facebook_id/picture

but I don't want it to be hard-coded. Is there a way extracting the url from the gem? thanks

1

There are 1 answers

0
MilesStanfield On

Change this

picture, picture_medium, picture_small = graph.batch do |batch_api|
  batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_LARGE, 'height' => PIC_SIZE_LARGE}, 'return_ssl_resources' => '0')
  batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_MED, 'height' => PIC_SIZE_MED}, 'return_ssl_resources' => '0')
  batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_SMALL, 'height' => PIC_SIZE_SMALL}, 'return_ssl_resources' => '0')
end

to this

@graph = Koala::Facebook::API.new(oauth_access_token)

@graph.batch do |batch_api|
  @large_pic = batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_LARGE, 'height' => PIC_SIZE_LARGE}, 'return_ssl_resources' => '0')
  @med_pic = batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_MED, 'height' => PIC_SIZE_MED}, 'return_ssl_resources' => '0')
  @small_pic = batch_api.get_picture(facebook_id, {'width' => PIC_SIZE_SMALL, 'height' => PIC_SIZE_SMALL}, 'return_ssl_resources' => '0')
end

And then the pics in your views without saving them to the db

= image_tag @large_pic