diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..34d6733 Binary files /dev/null and b/.DS_Store differ diff --git a/app/.DS_Store b/app/.DS_Store new file mode 100644 index 0000000..1255a6a Binary files /dev/null and b/app/.DS_Store differ diff --git a/app/models/.DS_Store b/app/models/.DS_Store new file mode 100644 index 0000000..5847eb2 Binary files /dev/null and b/app/models/.DS_Store differ diff --git a/app/models/hubspot/.DS_Store b/app/models/hubspot/.DS_Store new file mode 100644 index 0000000..983cfbe Binary files /dev/null and b/app/models/hubspot/.DS_Store differ diff --git a/app/models/hubspot/connection.rb b/app/models/hubspot/connection.rb index b8e0eea..2beaf1d 100644 --- a/app/models/hubspot/connection.rb +++ b/app/models/hubspot/connection.rb @@ -29,17 +29,21 @@ def configure_http(http) # Makes a request to the remote service and appends the default parameters def request(method, path, *arguments) uri = URI.parse(path) - + puts "URI: #{uri}" unless arguments.last.is_a?(Hash) && arguments.last.delete('skip_default_parameters') + puts "Args: #{arguments}" Hubspot::Connection.default_parameters.to_param.tap do |default_parameters| if uri.query.present? uri.query += '&' + default_parameters else uri.query = default_parameters end + puts "Query: #{uri.query}" end end + puts "Method: #{method}" + puts "uri.to_s: #{uri.to_s}" super(method, uri.to_s, *arguments) end diff --git a/app/models/hubspot/contact.rb b/app/models/hubspot/contact.rb new file mode 100644 index 0000000..b28fe84 --- /dev/null +++ b/app/models/hubspot/contact.rb @@ -0,0 +1,103 @@ +module Hubspot + + # Finds blogs + # + # Finds: + # Hubspot::Blog.find :all, :params => { :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.