From 37d67984167f9746f25b856ef1ba9ec952d9d78a Mon Sep 17 00:00:00 2001 From: marclipovsky Date: Fri, 13 Jul 2012 12:26:47 -0400 Subject: [PATCH] Attempting add support for new Contacts API. Close but not there yet.. --- .DS_Store | Bin 0 -> 6148 bytes app/.DS_Store | Bin 0 -> 6148 bytes app/models/.DS_Store | Bin 0 -> 12292 bytes app/models/hubspot/.DS_Store | Bin 0 -> 6148 bytes app/models/hubspot/connection.rb | 6 +- app/models/hubspot/contact.rb | 103 ++++++++++++++++++ .../hubspot/contacts/form_submission.rb | 7 ++ .../hubspot/contacts/identity_profile.rb | 7 ++ .../hubspot/contacts/list_membership.rb | 7 ++ app/models/hubspot/performable/event.rb | 2 +- 10 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 .DS_Store create mode 100644 app/.DS_Store create mode 100644 app/models/.DS_Store create mode 100644 app/models/hubspot/.DS_Store create mode 100644 app/models/hubspot/contact.rb create mode 100644 app/models/hubspot/contacts/form_submission.rb create mode 100644 app/models/hubspot/contacts/identity_profile.rb create mode 100644 app/models/hubspot/contacts/list_membership.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..34d67332d04699b1f03c56a558957974a311d0ed GIT binary patch literal 6148 zcmeH~%}T>S5XX1hs;M84i_qiZxk#jz_TV9e3Lb?NdQj1Xhz*3KG^st*Xz(q33g5=( zab|Y{R(lqaS=jy0?#%9He~|qULP&2Bod{tIAuPzK5{(TBn>V@|6pSiyjC>X*SqQcF za7MnrF8J+D5r~N&%*t5$=7(^aRvVOh4@ zR@;8F4v&t{F2=!A`TSBDiV`5}bU<3mD;TthM}M9sS^5Aib#xuY$^@7I6JP>NKog(? z!rEgVOn?b6fo}wGe^8K7UDC>^-a4Sb>ofXWsF=XUw*;ypbxA9u;DIDfS5VVc(i20P z?$E9%&Lypkn(jjCnPD87xqiGzJv+239WJD6luIVS1l9>OP1VNp{~UgqjgS2GE?i>* zOyHjpkgbtF@?cSPw*FWip0x_{9b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)$!sg-RTb^M0wuPpP$;L;5J@b7BWh)Ta931OwH*W~kM{H`idIep^XS0+6s;guDLT|}G}fpn{0`RVgo9#3iXcW7Rb_to&R3 zMP2J2M#iQuuD4y^GVlU-=3!Q602s7D7UZ2^cgE~`+NUP5A`VQx4iq=gbvC^3ZwYcWC!=Xx~1+;B*k z!V#?b2=?aB<|XLcnLnyKLY~lPXTTZQXFz&i%3SXMD}FMQO}@JL { :max => 10 } + # Hubspot::Blog.find + class Contact < Hubspot::Base + self.site = 'https://api.hubapi.com/contacts/v1' + + schema do + string 'vid' + end + + alias_attribute :id, :vid + + # ==== ActiveResource Overrides ==== + + def self.element_path(id, prefix_options = {}, query_options = nil) + prefix_options, query_options = split_options(prefix_options) if query_options.nil? + "#{prefix(prefix_options)}#{collection_name.singularize}/vid/#{URI.escape id.to_s}/profile.#{format.extension}#{query_string(query_options)}" + end + + + def self.collection_path(prefix_options = {}, query_options = nil) + puts "#### self.collection_path" + puts "prefix_options: #{prefix_options}" + puts "query_options: #{query_options}" + prefix_options, query_options = split_options(prefix_options) if query_options.nil? + "#{prefix(prefix_options)}lists/all/contacts/all.#{format.extension}#{query_string(query_options)}" + end + + class << self + def instantiate_collection(collection, prefix_options = {}) + collection = collection['contacts'] if collection.is_a?(Hash) + # collection.collect! { |record| record } + collection.collect! { |record| instantiate_record(record, prefix_options) } + end + + def instantiate_record(record, prefix_options = {}) + puts "#### self.collection_path" + puts "record: #{record}" + new(record, true).tap do |resource| + puts "resource: #{resource}" + puts "resource.prefix_options: #{resource.prefix_options}" + resource.prefix_options = prefix_options + end + end + end + + def find_or_create_resource_for(name) + puts "#### find_or_create_resource_for(name)" + puts "name: #{name}" + + resource_name = name.to_s.gsub('-','_').camelize + puts "resource_name #{resource_name}" + + const_args = RUBY_VERSION < "1.9" ? [resource_name] : [resource_name, false] + if self.class.const_defined?(*const_args) + self.class.const_get(*const_args) + else + ancestors = self.class.name.split("::") + if ancestors.size > 1 + asdf = find_or_create_resource_in_modules(resource_name, ancestors) + else + if Object.const_defined?(*const_args) + Object.const_get(*const_args) + else + create_resource_for(resource_name) + end + end + end + end + + def update + connection.post(element_path(prefix_options), encode, self.class.headers).tap do |response| + load_attributes_from_response(response) + end + end + + + # # TODO Change - to _ + # def method_missing(method_symbol, *arguments) #:nodoc: + # puts method_symbol + # puts arguments + # method_name = method_symbol.to_s + # + # if method_name =~ /(=|\?)$/ + # case $1 + # when "=" + # attributes[$`] = arguments.first + # when "?" + # attributes[$`] + # end + # else + # return attributes[method_name] if attributes.include?(method_name) + # # not set right now but we know about it + # return nil if known_attributes.include?(method_name) + # super + # end + # end + end +end \ No newline at end of file diff --git a/app/models/hubspot/contacts/form_submission.rb b/app/models/hubspot/contacts/form_submission.rb new file mode 100644 index 0000000..413be46 --- /dev/null +++ b/app/models/hubspot/contacts/form_submission.rb @@ -0,0 +1,7 @@ +module Hubspot + module Contacts + class FormSubmission < Hubspot::Contacts + + end + end +end \ No newline at end of file diff --git a/app/models/hubspot/contacts/identity_profile.rb b/app/models/hubspot/contacts/identity_profile.rb new file mode 100644 index 0000000..0d1841d --- /dev/null +++ b/app/models/hubspot/contacts/identity_profile.rb @@ -0,0 +1,7 @@ +module Hubspot + module Contacts + class IdentityProfile < Hubspot::Contacts + + end + end +end \ No newline at end of file diff --git a/app/models/hubspot/contacts/list_membership.rb b/app/models/hubspot/contacts/list_membership.rb new file mode 100644 index 0000000..94df546 --- /dev/null +++ b/app/models/hubspot/contacts/list_membership.rb @@ -0,0 +1,7 @@ +module Hubspot + module Contacts + class ListMembership < Hubspot::Contacts + + end + end +end \ No newline at end of file diff --git a/app/models/hubspot/performable/event.rb b/app/models/hubspot/performable/event.rb index c816f0c..de56a10 100644 --- a/app/models/hubspot/performable/event.rb +++ b/app/models/hubspot/performable/event.rb @@ -16,7 +16,7 @@ class Event < Struct.new(:event_id, :performed_at, :completed_at, :url, :ip, :va # _n - The EVENT_ID of the event you want to record. You can get an event id in two ways: # Log into your Performable account, click Setup, and then click on the event that you wish to record. Finally, click the configuration link to bring up a dialog which shows you the event id. # Use your own unique label as the id, and Performable will automatically generate the corresponding event in your account. You can rename it from within the app later if you'd like. - # There are also optional parameters: + # There are walso optional parameters: # # _t - The timestamp of the event (in seconds as a UTC Unix epoch). By default this is ignored - it is used only to help make requests unique and the time that our servers receive the event is used for the timestamp of the event. # _d - If equal to the string true, implies that the timestamp sent with this event should be used as the time of completion for this event. The timestamp will be ignored if it represents a future date (within some reason), or is more than a few years old. Servers generating timestamps should use some mechanism (like NTP) for syncing clocks to a reasonable standard. The API expects timestamps are in seconds, but may detect timestamps in milliseconds and attempt to resolve them to seconds.