Chatwoot/db/migrate/20170519091541_add_pic_to_inbox_migration.rb
Pranav Raj Sreepuram 2a34255e0b Initial Commit
Co-authored-by: Subin <subinthattaparambil@gmail.com>
Co-authored-by: Manoj <manojmj92@gmail.com>
Co-authored-by: Nithin <webofnithin@gmail.com>
2019-08-14 15:18:44 +05:30

24 lines
718 B
Ruby

class AddPicToInboxMigration < ActiveRecord::Migration[5.0]
def change
FacebookPage.find_each do |inbox|
begin
url = "http://graph.facebook.com/"<< inbox.page_id << "/picture?type=large"
uri = URI.parse(url)
tries = 3
begin
response = uri.open(redirect: false)
rescue OpenURI::HTTPRedirect => redirect
uri = redirect.uri # assigned from the "Location" response header
retry if (tries -= 1) > 0
raise
end
pic_url = response.base_uri.to_s
puts pic_url.inspect
rescue => e
pic_url = nil
end
inbox.remote_avatar_url = pic_url
inbox.save!
end
end
end