Skip to content

Instantly share code, notes, and snippets.

@timurvafin
Created August 31, 2012 11:12
Show Gist options
  • Save timurvafin/3551542 to your computer and use it in GitHub Desktop.
Save timurvafin/3551542 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require 'highrise'
module HighriseContactCreator
class Contact
end
class Note
end
end
module HighriseContactCreator
def self.setup!(site, user)
Highrise::Base.site = site
Highrise::Base.user = user
Highrise::Base.format = :xml
end
def self.process
contact = Contact.new(email).find_or_create
Note.new(contact).create_all
end
end
HighriseContactCreator.setup!(site, user)
HighriseContactCreator.process(email)
class People
def add_new(email)
@contact = Highrise::Person.new(:first_name => email, :contact_data => {})
@contact.contact_data = {"email-addresses" => {"email-address" => {"address" => email, "location" => "work"}}}
@contact.save
return self
end
def initialize()
@contact = ""
end
def link(email)
@contact = Highrise::Person.search(:email => email)[0]
return self
end
def notes()
@contact.notes
end
def notes?()
[email protected]?
end
def note_add(note)
new_note = @contact.add_note
new_note.body = note
new_note.save
end
def note_exist?(note)
@contact.notes.each do |n|
return true if n.body == note
end
return false
end
end
def contact_exist(email)
Highrise::Person.search(:email => email)==[] ? false : true
end
NOTES = ['note1', 'note2']
email="[email protected]"
new_contact = People.new()
if contact_exist(email)
new_contact.link(email)
puts "Find contact!"
else
new_contact.add_new(email)
puts "Contact is new"
end
NOTES.each do |note|
unless new_contact.note_exist?(note)
new_contact.note_add(note)
puts "#{note} -- Note added"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment