I would like to ask if there is any way how to update database from external source to my Rails DB constantly (every 1 hour)...
I was trying to do that but when i do that my DB is duplicated + added new files so is there any
class Bitbucket < ActiveRecord::Base
bitbucket = BitBucket.new login:'...', password:'...'
repo = bitbucket.repos.commits.list '...', '...'
repo["values"].each do |r|
So, If I understand it right you want to pull data from bitbucket every 1 hour, and update your database only with new 'values'. In that case the question how to know if you have an entry in the database already or not is up to you.
For instance you could ask:
author_name = r["author"]["user"]["display_name"] message = r["message"] date = r["date"] unless exists?(name: author_name, message: message, date: date) create(name: author_name, message: message, data: date) end
Doku for 'exists?': http://apidock.com/rails/ActiveRecord/Base/exists%3F/class
Alternatively you could use 'first_or_create':