Skip to content

Instantly share code, notes, and snippets.

@criess
Last active February 2, 2021 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save criess/7d897ca4e5f823806416f55a6aca5f96 to your computer and use it in GitHub Desktop.
Save criess/7d897ca4e5f823806416f55a6aca5f96 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
PROJECT_ID_KEY = 'respectiveproject_custom_project'.freeze
USER_ID_KEY = 'sender_user'.freeze
MESSAGETYPE_MATCHER = lambda { |k, entry| entry['messagetype_text'] == 'RequestProjectData' }
# message downloader extending from
module Imports
module BubbleApi
class Message < Record
def parse_results(data)
data.map do |entry|
[entry.delete('_id'), entry]
end.to_h
end
def action
"/obj/message?cursor=#{objects_cache.size}"
end
def data
process_all! if objects_cache.empty?
objects_cache
end
end
end
end
Imports::BubbleApi::Message.new.data.select(&MESSAGETYPE_MATCHER).each do |k, row|
user = User.find_by(
bubble_id: row[USER_ID_KEY]
) if row[USER_ID_KEY].present?
selling_profile = SellingProfile.platform_deal.find_by(
external_id: row[PROJECT_ID_KEY]
) if row[PROJECT_ID_KEY].present?
interest = SellingProfileUserInterest.find_or_create_by(user: user, selling_profile: selling_profile)
if interest.valid? && interest.interested?
puts("resolved to interest ##{interest.id}")
else
puts("unable to resolve message ##{k} from: #{row['Created Date']} User: #{user&.id || '<nil>'} SellingProfile: #{selling_profile&.id || '<nil>'}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment