Skip to content

Attempting to add support for new Contacts API #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added app/.DS_Store
Binary file not shown.
Binary file added app/models/.DS_Store
Binary file not shown.
Binary file added app/models/hubspot/.DS_Store
Binary file not shown.
6 changes: 5 additions & 1 deletion app/models/hubspot/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
103 changes: 103 additions & 0 deletions app/models/hubspot/contact.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module Hubspot

# Finds blogs
#
# Finds:
# Hubspot::Blog.find :all, :params => { :max => 10 }
# Hubspot::Blog.find <GUID>
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
7 changes: 7 additions & 0 deletions app/models/hubspot/contacts/form_submission.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Hubspot
module Contacts
class FormSubmission < Hubspot::Contacts

end
end
end
7 changes: 7 additions & 0 deletions app/models/hubspot/contacts/identity_profile.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Hubspot
module Contacts
class IdentityProfile < Hubspot::Contacts

end
end
end
7 changes: 7 additions & 0 deletions app/models/hubspot/contacts/list_membership.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Hubspot
module Contacts
class ListMembership < Hubspot::Contacts

end
end
end
2 changes: 1 addition & 1 deletion app/models/hubspot/performable/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down