Skip to content
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

Add support for event http api #119

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions lib/hubspot-ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require 'hubspot/contact'
require 'hubspot/contact_properties'
require 'hubspot/contact_list'
require 'hubspot/event'
require 'hubspot/form'
require 'hubspot/blog'
require 'hubspot/topic'
Expand Down
7 changes: 7 additions & 0 deletions lib/hubspot/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,11 @@ def self.submit(path, opts)
post(url, body: opts[:body], headers: { 'Content-Type' => 'application/x-www-form-urlencoded' })
end
end

class EventConnection < Connection
def self.complete(path, opts)
url = generate_url(path, opts[:params], { base_url: 'https://track.hubspot.com', hapikey: false })
get(url, body: opts[:body], headers: opts[:headers])
end
end
end
21 changes: 21 additions & 0 deletions lib/hubspot/event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'hubspot/utils'

module Hubspot
#
# HubSpot Events HTTP API
#
# {https://developers.hubspot.com/docs/methods/enterprise_events/http_api}
#
class Event
POST_EVENT_PATH = '/v1/event'

class << self
def complete(event_id, email, options = {})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think trigger would be a better word here (and in EventConnection) that more closely aligns with the documentation and intent of the API. The documentation refers to this endpoint as:

Trigger a custom HubSpot event using an HTTP GET call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do!

default_params = { _n: event_id, _a: Hubspot::Config.portal_id, email: email }
options[:params] = default_params.merge(options[:params] || {})

Hubspot::EventConnection.complete(POST_EVENT_PATH, options).success?
end
end
end
end
190 changes: 189 additions & 1 deletion spec/fixtures/vcr_cassettes/contact_create_or_update.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading