r_hapi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +16 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +53 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/lib/r_hapi/configuration.rb +30 -0
- data/lib/r_hapi/lead.rb +76 -0
- data/lib/r_hapi/r_hapi_exception.rb +28 -0
- data/lib/r_hapi.rb +9 -0
- data/spec/config.yml.sample +2 -0
- data/spec/configuration_spec.rb +36 -0
- data/spec/fixtures/error.html +1 -0
- data/spec/fixtures/lead.json +1 -0
- data/spec/fixtures/leads.json +1 -0
- data/spec/lead_spec.rb +122 -0
- data/spec/r_hapi_spec.rb +5 -0
- data/spec/spec_helper.rb +60 -0
- metadata +241 -0
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem "curb", "~> 0.7.12"
|
6
|
+
gem "json", '~> 1.5.1'
|
7
|
+
gem "activesupport", '>= 0'
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "rspec", "~> 2.5.0"
|
13
|
+
gem "bundler", "~> 1.0.0"
|
14
|
+
gem "jeweler", "~> 1.5.2"
|
15
|
+
gem "rcov", ">= 0"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.0.5)
|
5
|
+
curb (0.7.12)
|
6
|
+
diff-lcs (1.1.2)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.5.2)
|
9
|
+
bundler (~> 1.0.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
json (1.5.1)
|
13
|
+
rake (0.8.7)
|
14
|
+
rcov (0.9.9)
|
15
|
+
rspec (2.5.0)
|
16
|
+
rspec-core (~> 2.5.0)
|
17
|
+
rspec-expectations (~> 2.5.0)
|
18
|
+
rspec-mocks (~> 2.5.0)
|
19
|
+
rspec-core (2.5.1)
|
20
|
+
rspec-expectations (2.5.0)
|
21
|
+
diff-lcs (~> 1.1.2)
|
22
|
+
rspec-mocks (2.5.0)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
activesupport
|
29
|
+
bundler (~> 1.0.0)
|
30
|
+
curb (~> 0.7.12)
|
31
|
+
jeweler (~> 1.5.2)
|
32
|
+
json (~> 1.5.1)
|
33
|
+
rcov
|
34
|
+
rspec (~> 2.5.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Tim Stephenson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
= RHapi (Ruby HubSpot API Wrapper)
|
2
|
+
|
3
|
+
RHapi is a Ruby wrapper for the HubSpot API (HAPI).
|
4
|
+
|
5
|
+
== To do:
|
6
|
+
|
7
|
+
* Add method to create new leads.
|
8
|
+
* Build out methods for Blogs API.
|
9
|
+
* Write documentation.
|
10
|
+
|
11
|
+
== Using RHapi
|
12
|
+
|
13
|
+
First configure RHapi to work with your Hubspot API Key.
|
14
|
+
|
15
|
+
RHapi.configure do |config|
|
16
|
+
config.api_key = "YOUR_API_KEY"
|
17
|
+
end
|
18
|
+
|
19
|
+
Then to get a list of leads.
|
20
|
+
leads = RHapi::Lead.find
|
21
|
+
leads.each do |lead|
|
22
|
+
puts lead.first_name
|
23
|
+
puts lead.last_name
|
24
|
+
puts lead.city
|
25
|
+
puts lead.state
|
26
|
+
puts lead.guid
|
27
|
+
end
|
28
|
+
|
29
|
+
To find leads named Barny.
|
30
|
+
leads = RHapi::Lead.find("Barny")
|
31
|
+
|
32
|
+
To update a lead.
|
33
|
+
lead = leads.fist
|
34
|
+
lead.first_name = "Fred"
|
35
|
+
lead.last_name = "Flintsone"
|
36
|
+
lead.update
|
37
|
+
|
38
|
+
To get a single lead with a guid. Assumes the guid has be saved from a previous search.
|
39
|
+
lead = RHapi::Lead.find_by_guid(lead.guid)
|
40
|
+
|
41
|
+
== Contributing to r_hapi
|
42
|
+
|
43
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
44
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
45
|
+
* Fork the project
|
46
|
+
* Start a feature/bugfix branch
|
47
|
+
* Commit and push until you are happy with your contribution
|
48
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
49
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
50
|
+
|
51
|
+
== Copyright
|
52
|
+
|
53
|
+
Copyright (c) 2011 Tim Stephenson. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "r_hapi"
|
16
|
+
gem.homepage = "http://github.com/timstephenson/rHAPI"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{A ruby wrapper for the HubSpot API (HAPI).}
|
19
|
+
gem.description = %Q{Makes it easy to use the HubSpot API in a Ruby application.}
|
20
|
+
gem.email = "tim@raddonline.com"
|
21
|
+
gem.authors = ["Tim Stephenson of RaddOnline"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
gem.add_runtime_dependency 'curb', '~> 0.7.12'
|
27
|
+
gem.add_runtime_dependency 'json', '~> 1.5.1'
|
28
|
+
gem.add_runtime_dependency 'activesupport', '>= 0'
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rspec/core'
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
35
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.rcov = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "r_hapi #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RHapi
|
2
|
+
module Configuration
|
3
|
+
VALID_OPTIONS_KEYS = [:api_key, :end_point, :hub_spot_site, :version]
|
4
|
+
DEFAULT_API_KEY = nil
|
5
|
+
DEFAULT_END_POINT = "https://hubapi.com"
|
6
|
+
DEFAULT_VERSION = "v1"
|
7
|
+
DEFAULT_HUB_SPOT_SITE = nil
|
8
|
+
|
9
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
10
|
+
|
11
|
+
def configure
|
12
|
+
yield self
|
13
|
+
end
|
14
|
+
|
15
|
+
# Create a hash of options and their values
|
16
|
+
def options
|
17
|
+
Hash[VALID_OPTIONS_KEYS.map {|key| [key, send(key)] }]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Reset all configuration options to defaults
|
21
|
+
def reset
|
22
|
+
self.api_key = DEFAULT_API_KEY
|
23
|
+
self.end_point = DEFAULT_END_POINT
|
24
|
+
self.hub_spot_site = DEFAULT_HUB_SPOT_SITE
|
25
|
+
self.version = DEFAULT_VERSION
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
data/lib/r_hapi/lead.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_support/inflector/inflections'
|
4
|
+
module RHapi
|
5
|
+
|
6
|
+
class Lead
|
7
|
+
|
8
|
+
attr_accessor :attributes, :changed_attributes
|
9
|
+
|
10
|
+
def initialize(data)
|
11
|
+
self.attributes = data
|
12
|
+
self.changed_attributes = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
# Class methods ----------------------------------------------------------
|
16
|
+
|
17
|
+
# Finds leads and returns an array of leads.
|
18
|
+
# An optional string value that is used to search several basic lead fields: first name, last name, email address,
|
19
|
+
# and company name. According to HubSpot docs, a more advanced search is coming in the future.
|
20
|
+
# The default value for is nil, meaning return all leads.
|
21
|
+
def self.find(search=nil)
|
22
|
+
url = "#{RHapi.options[:end_point]}/leads/#{RHapi.options[:version]}/list?hapikey=#{RHapi.options[:api_key]}&search=#{search}"
|
23
|
+
data = Curl::Easy.perform(url)
|
24
|
+
RHapi::RHapiException.raise_error(data.body_str) if data.body_str =~ /Error/i
|
25
|
+
lead_data = JSON.parse(data.body_str)
|
26
|
+
leads = []
|
27
|
+
lead_data.each do |data|
|
28
|
+
lead = Lead.new(data)
|
29
|
+
leads << lead
|
30
|
+
end
|
31
|
+
leads
|
32
|
+
end
|
33
|
+
|
34
|
+
# Finds specified lead by the guid.
|
35
|
+
def self.find_by_guid(guid)
|
36
|
+
url = "#{RHapi.options[:end_point]}/leads/#{RHapi.options[:version]}/lead/#{guid}?hapikey=#{RHapi.options[:api_key]}"
|
37
|
+
c = Curl::Easy.perform(url)
|
38
|
+
RHapi::RHapiException.raise_error(c.body_str) if c.body_str =~ /Error/i
|
39
|
+
lead_data = JSON.parse(c.body_str)
|
40
|
+
Lead.new(lead_data)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Instance methods -------------------------------------------------------
|
44
|
+
def update
|
45
|
+
url = "#{RHapi.options[:end_point]}/leads/#{RHapi.options[:version]}/lead/#{self.guid}?hapikey=#{RHapi.options[:api_key]}"
|
46
|
+
data = self.changed_attributes.to_json
|
47
|
+
c = Curl::Easy.http_put(url, data) do |curl|
|
48
|
+
curl.headers["Content-Type"] = "application/json"
|
49
|
+
curl.header_in_body = true
|
50
|
+
end
|
51
|
+
RHapi::RHapiException.raise_error(c.body_str) unless c.body_str =~ /200/i
|
52
|
+
true
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# Work with data in the data hash
|
58
|
+
def method_missing(method, *args, &block)
|
59
|
+
|
60
|
+
attribute = ActiveSupport::Inflector.camelize(method.to_s, false)
|
61
|
+
|
62
|
+
if attribute =~ /=$/
|
63
|
+
attribute = attribute.chop
|
64
|
+
return super unless self.attributes.include?(attribute)
|
65
|
+
self.changed_attributes[attribute] = args[0]
|
66
|
+
self.attributes[attribute] = args[0]
|
67
|
+
else
|
68
|
+
return super unless self.attributes.include?(attribute)
|
69
|
+
self.attributes[attribute]
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module RHapi
|
2
|
+
class RHapiException < RuntimeError
|
3
|
+
attr :error_string
|
4
|
+
|
5
|
+
def initialize(error_string)
|
6
|
+
@error_string = error_string
|
7
|
+
end
|
8
|
+
|
9
|
+
def message
|
10
|
+
if @error_string =~ /401/
|
11
|
+
"HubSopt returned a 401 error. Make sure your API key is correct."
|
12
|
+
elsif @error_string =~ /404/
|
13
|
+
"HubSopt returned a 404 error. Check the end point or the guid to make sure it is valid."
|
14
|
+
elsif @error_string =~ /500/
|
15
|
+
"HubSopt returned a 500 error."
|
16
|
+
else
|
17
|
+
# else send back the whole message.
|
18
|
+
@error_string
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.raise_error(error_response)
|
23
|
+
exception = RHapi::RHapiException.new(error_response)
|
24
|
+
raise(exception, exception.message)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
data/lib/r_hapi.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Configuration" do
|
4
|
+
before do
|
5
|
+
RHapi.configure do |config|
|
6
|
+
config.api_key = "123"
|
7
|
+
config.end_point = "https://mysite.com"
|
8
|
+
config.hub_spot_site = "http://mysite.hubspot.com"
|
9
|
+
config.version = "v2"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sets the api key" do
|
14
|
+
RHapi.options[:api_key].should == "123"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets the endpoint" do
|
18
|
+
RHapi.options[:end_point].should == "https://mysite.com"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets the hub_spot_site" do
|
22
|
+
RHapi.options[:hub_spot_site].should == "http://mysite.hubspot.com"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "sets the version" do
|
26
|
+
RHapi.options[:version].should == "v2"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "resets to the default values" do
|
30
|
+
RHapi.reset
|
31
|
+
RHapi.options[:api_key].should == nil
|
32
|
+
RHapi.options[:end_point].should == "https://hubapi.com"
|
33
|
+
RHapi.options[:hub_spot_site].should == nil
|
34
|
+
RHapi.options[:version].should == "v1"
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<html><head><title>Apache Tomcat/6.0.16 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 401 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>This request requires HTTP authentication ().</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0.16</h3></body></html>
|
@@ -0,0 +1 @@
|
|
1
|
+
{"address":"","analyticsDetails":{"allViewsImported":true,"countsModifiedAt":1298732627000,"firstVisitAt":1298721462000,"id":"8a401EXAMPLE","lastPageViewAt":1298721462000,"lastVisitAt":1298721462000,"leadGuid":"8a401EXAMPLE","leadId":1100000,"pageViewCount":2,"portalId":93000,"userToken":"c99abEXAMPLE","visitCount":1},"city":"Bedrock","closedAt":0,"company":"Slate Rock Gravel Company","country":"USA","crmDetails":{"annualRevenue":0,"closeProbability":0,"crmType":1,"estimatedRevenue":0,"id":"8a40135EXAMPLE","nextAction":"","nextActionAssignedTo":0,"nextActionAssignedToEmail":"","nextActionDue":0,"numEmployees":0,"status":""},"customerStatusModifiedAt":0,"eligibleForEmail":true,"email":"fred@example.com","emailBounced":false,"emailOptOut":false,"fax":"","firstCampaign":"","firstName":"Fred","firstRefDomain":"","firstReferrer":"http://www.hubspot.com/","firstURL":"http://lumenistics.com/","firstVisitSetAt":1298728717682,"foundVia":"Referrals","fullFoundViaString":"Referrals - hubspot.com","guid":"8a401EXAMPLE","id":"8a4013EXAMPLE","imported":false,"industry":"","insertedAt":1298728717682,"ipAddress":"50.16.145.55","isCustomer":false,"isDeleted":false,"jobTitle":"Stone Cutter","lastConvertedAt":1298728666000,"lastModifiedAt":1298729412821,"lastName":"Flintstone","leadConversionEvents":[{"convertDate":1298728666000,"formGuid":"3e48d8eEXAMPLE","formId":31000,"formName":"Contact Us","formSubmissionValues":[{"conversionGuid":"504feEXAMPLE","convertDate":1298728666000,"fieldLabel":"First Name","fieldName":"FirstName","fieldValue":"Fred","formGuid":"","formId":31000,"formName":"Contact Us","id":1000050000,"leadGuid":"8a4013EXAMPLE","portalId":93950},{"conversionGuid":"504febbEXAMPLE","convertDate":1298728666000,"fieldLabel":"Last Name","fieldName":"LastName","fieldValue":"Flintstone","formGuid":"","formId":31000,"formName":"Contact Us","id":1000008000,"leadGuid":"8a401352EXAMPLE","portalId":93000},{"conversionGuid":"504febbEXAMPLE","convertDate":1298728666000,"fieldLabel":"Email (we will keep your email completely private)","fieldName":"Email","fieldValue":"fred@example.com","formGuid":"","formId":30001,"formName":"Contact Us","id":180000000,"leadGuid":"8a401EXAMPLE","portalId":93000},{"conversionGuid":"504febbEXAMPLE","convertDate":1298728666000,"fieldLabel":"Message","fieldName":"Message","fieldValue":"This is a sample lead.","formGuid":"","formId":31000,"formName":"Contact Us","id":1810000000,"leadGuid":"8a401EXAMPLE","portalId":93000}],"guid":"504febbEXAMPLE","id":"504febbEXAMPLE","leadGuid":"8a401352EXAMPLE","pageName":"Landing Pages","pageType":"Form","pageUrl":"http://lumenistics.web9.hubspot.com/landing-pages/Default.aspx?RewriteStatus=1","portalId":93000}],"leadCustomerStatusModifyLogs":[],"leadDeleteLogs":[],"leadId":1100000,"leadJsonLink":"https://hubapi.com/leads/v1/lead/8z401EXAMPLE","leadLink":"https://app.hubspot.com/leads/app/lead?portalId=YOURID&guid=8aEXAMPLE","leadNurturingActive":true,"leadNurturingCampaignId":-1,"message":"This is a sample lead.","numConversionEvents":1,"phone":"5551212","portalId":90500,"publicLeadLink":"https://app.hubspot.com/leads/public/leadDetails?portalId=EXAMPLE&leadToken=EXAMPLE","rawScore":110,"salutation":"","score":100,"sourceId":2,"sourceValue1":"hubspot.com","sourceValue2":"","sourceValueModifiedAt":1298728905366,"state":"CA","twitterHandle":"","userToken":"c99abEXAMPLE","website":"","zip":""}
|
@@ -0,0 +1 @@
|
|
1
|
+
[{"address":"","analyticsDetails":{"allViewsImported":true,"countsModifiedAt":1298732627000,"firstVisitAt":1298721462000,"id":"8a401EXAMPLE","lastPageViewAt":1298721462000,"lastVisitAt":1298721462000,"leadGuid":"8a401EXAMPLE","leadId":1100000,"pageViewCount":2,"portalId":93000,"userToken":"c99abEXAMPLE","visitCount":1},"city":"Bedrock","closedAt":0,"company":"Slate Rock Gravel Company","country":"USA","crmDetails":{"annualRevenue":0,"closeProbability":0,"crmType":1,"estimatedRevenue":0,"id":"8a40135EXAMPLE","nextAction":"","nextActionAssignedTo":0,"nextActionAssignedToEmail":"","nextActionDue":0,"numEmployees":0,"status":""},"customerStatusModifiedAt":0,"eligibleForEmail":true,"email":"fred@example.com","emailBounced":false,"emailOptOut":false,"fax":"","firstCampaign":"","firstName":"Fred","firstRefDomain":"","firstReferrer":"http://www.hubspot.com/","firstURL":"http://lumenistics.com/","firstVisitSetAt":1298728717682,"foundVia":"Referrals","fullFoundViaString":"Referrals - hubspot.com","guid":"8a401EXAMPLE","id":"8a4013EXAMPLE","imported":false,"industry":"","insertedAt":1298728717682,"ipAddress":"50.16.145.55","isCustomer":false,"isDeleted":false,"jobTitle":"Stone Cutter","lastConvertedAt":1298728666000,"lastModifiedAt":1298729412821,"lastName":"Flintstone","leadConversionEvents":[{"convertDate":1298728666000,"formGuid":"3e48d8eEXAMPLE","formId":31000,"formName":"Contact Us","formSubmissionValues":[{"conversionGuid":"504feEXAMPLE","convertDate":1298728666000,"fieldLabel":"First Name","fieldName":"FirstName","fieldValue":"Fred","formGuid":"","formId":31000,"formName":"Contact Us","id":1000050000,"leadGuid":"8a4013EXAMPLE","portalId":93950},{"conversionGuid":"504febbEXAMPLE","convertDate":1298728666000,"fieldLabel":"Last Name","fieldName":"LastName","fieldValue":"Flintstone","formGuid":"","formId":31000,"formName":"Contact Us","id":1000008000,"leadGuid":"8a401352EXAMPLE","portalId":93000},{"conversionGuid":"504febbEXAMPLE","convertDate":1298728666000,"fieldLabel":"Email (we will keep your email completely private)","fieldName":"Email","fieldValue":"fred@example.com","formGuid":"","formId":30001,"formName":"Contact Us","id":180000000,"leadGuid":"8a401EXAMPLE","portalId":93000},{"conversionGuid":"504febbEXAMPLE","convertDate":1298728666000,"fieldLabel":"Message","fieldName":"Message","fieldValue":"This is a sample lead.","formGuid":"","formId":31000,"formName":"Contact Us","id":1810000000,"leadGuid":"8a401EXAMPLE","portalId":93000}],"guid":"504febbEXAMPLE","id":"504febbEXAMPLE","leadGuid":"8a401352EXAMPLE","pageName":"Landing Pages","pageType":"Form","pageUrl":"http://lumenistics.web9.hubspot.com/landing-pages/Default.aspx?RewriteStatus=1","portalId":93000}],"leadCustomerStatusModifyLogs":[],"leadDeleteLogs":[],"leadId":1100000,"leadJsonLink":"https://hubapi.com/leads/v1/lead/8z401EXAMPLE","leadLink":"https://app.hubspot.com/leads/app/lead?portalId=YOURID&guid=8aEXAMPLE","leadNurturingActive":true,"leadNurturingCampaignId":-1,"message":"This is a sample lead.","numConversionEvents":1,"phone":"5551212","portalId":90500,"publicLeadLink":"https://app.hubspot.com/leads/public/leadDetails?portalId=EXAMPLE&leadToken=EXAMPLE","rawScore":110,"salutation":"","score":100,"sourceId":2,"sourceValue1":"hubspot.com","sourceValue2":"","sourceValueModifiedAt":1298728905366,"state":"CA","twitterHandle":"","userToken":"c99abEXAMPLE","website":"","zip":""}]
|
data/spec/lead_spec.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "RHapi::Lead" do
|
4
|
+
|
5
|
+
context "when searching for leads" do
|
6
|
+
before do
|
7
|
+
RHapi.configure do |config|
|
8
|
+
config.api_key = test_config["api_key"]
|
9
|
+
config.hub_spot_site = "http://mysite.hubspot.com"
|
10
|
+
end
|
11
|
+
stub_leads_search
|
12
|
+
end
|
13
|
+
|
14
|
+
# Most of the actual connections are mocked to spped tests.
|
15
|
+
it "should return all leads with no search params" do
|
16
|
+
leads = RHapi::Lead.find
|
17
|
+
leads.length.should >= 1
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a first_name attribute" do
|
21
|
+
leads = RHapi::Lead.find
|
22
|
+
leads.first.first_name.should == "Fred"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should set the value for a first name" do
|
26
|
+
leads = RHapi::Lead.find
|
27
|
+
lead = leads.first
|
28
|
+
lead.first_name = "Barny"
|
29
|
+
lead.first_name.should == "Barny"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should have analytics details" do
|
33
|
+
# Not sure yet how these will be used. I may want to make
|
34
|
+
# attributes that are hashes or arrays seem more like lead attributes.
|
35
|
+
leads = RHapi::Lead.find
|
36
|
+
lead = leads.first
|
37
|
+
lead.analytics_details.length.should == 12
|
38
|
+
lead.analytics_details["allViewsImported"].should == true
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
context "updating a lead" do
|
45
|
+
|
46
|
+
before do
|
47
|
+
RHapi.configure do |config|
|
48
|
+
config.api_key = test_config["api_key"]
|
49
|
+
config.hub_spot_site = "http://mysite.hubspot.com"
|
50
|
+
end
|
51
|
+
stub_leads_search
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should have a list of changed attributes" do
|
55
|
+
leads = RHapi::Lead.find
|
56
|
+
lead = leads.first
|
57
|
+
lead.first_name = "Barny"
|
58
|
+
lead.last_name = "Rubble"
|
59
|
+
lead.changed_attributes.length.should == 2
|
60
|
+
lead.changed_attributes["firstName"].should == "Barny"
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should update a lead" do
|
64
|
+
stub_lead_update
|
65
|
+
leads = RHapi::Lead.find
|
66
|
+
lead = leads.first
|
67
|
+
lead.first_name = "Barny"
|
68
|
+
lead.last_name = "Rubble"
|
69
|
+
lead.update.should == true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should raise an error if 200 is not returned" do
|
73
|
+
stub_lead_update_error
|
74
|
+
leads = RHapi::Lead.find
|
75
|
+
lead = leads.first
|
76
|
+
lead.first_name = "Barny"
|
77
|
+
lead.last_name = "Rubble"
|
78
|
+
lambda {lead.update}.should raise_error(RHapi::RHapiException)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
context "get lead information with guid" do
|
84
|
+
before do
|
85
|
+
RHapi.configure do |config|
|
86
|
+
config.api_key = test_config["api_key"]
|
87
|
+
config.hub_spot_site = "http://mysite.hubspot.com"
|
88
|
+
end
|
89
|
+
stub_leads_search
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should return a lead" do
|
93
|
+
leads = RHapi::Lead.find
|
94
|
+
stub_leads_find_by_guid
|
95
|
+
lead = RHapi::Lead.find_by_guid(leads.first.guid)
|
96
|
+
lead.first_name.should == "Fred"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should raise an error if an error string is returned" do
|
100
|
+
leads = RHapi::Lead.find
|
101
|
+
stub_leads_error
|
102
|
+
lambda {RHapi::Lead.find_by_guid(leads.first.guid)}.should raise_error(RHapi::RHapiException)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
context "accessing leads with incorrect API key" do
|
108
|
+
before do
|
109
|
+
RHapi.configure do |config|
|
110
|
+
config.api_key = "badapikey"
|
111
|
+
config.hub_spot_site = "http://mysite.hubspot.com"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should raise an exception" do
|
116
|
+
stub_leads_error
|
117
|
+
lambda {RHapi::Lead.find}.should raise_error(RHapi::RHapiException)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
end
|
data/spec/r_hapi_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'r_hapi'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_config
|
16
|
+
YAML::load( File.open( 'spec/config.yml' ) )
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_leads
|
20
|
+
IO.read( 'spec/fixtures/leads.json' )
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_lead
|
24
|
+
IO.read( 'spec/fixtures/lead.json' )
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_error
|
28
|
+
IO.read( 'spec/fixtures/error.html' )
|
29
|
+
end
|
30
|
+
|
31
|
+
def stub_leads_search
|
32
|
+
@data = mock("data")
|
33
|
+
@data.stub!(:body_str).and_return(test_leads)
|
34
|
+
Curl::Easy.stub!(:perform).and_return(@data)
|
35
|
+
end
|
36
|
+
|
37
|
+
def stub_leads_find_by_guid
|
38
|
+
@data = mock("data")
|
39
|
+
@data.stub!(:body_str).and_return(test_lead)
|
40
|
+
Curl::Easy.stub!(:perform).and_return(@data)
|
41
|
+
end
|
42
|
+
|
43
|
+
def stub_leads_error
|
44
|
+
@data = mock("data")
|
45
|
+
@data.stub!(:body_str).and_return(test_error)
|
46
|
+
Curl::Easy.stub!(:perform).and_return(@data)
|
47
|
+
end
|
48
|
+
|
49
|
+
def stub_lead_update
|
50
|
+
@response_mock = mock("data")
|
51
|
+
@response_mock.stub!(:body_str).and_return("200 OK")
|
52
|
+
Curl::Easy.stub!(:http_put).and_return(@response_mock)
|
53
|
+
end
|
54
|
+
|
55
|
+
def stub_lead_update_error
|
56
|
+
@response_mock = mock("data")
|
57
|
+
@response_mock.stub!(:body_str).and_return("Error: 500 internal server error.")
|
58
|
+
Curl::Easy.stub!(:http_put).and_return(@response_mock)
|
59
|
+
end
|
60
|
+
|
metadata
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: r_hapi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Tim Stephenson of RaddOnline
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-18 00:00:00 -07:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
prerelease: false
|
23
|
+
type: :runtime
|
24
|
+
name: curb
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 27
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
- 7
|
34
|
+
- 12
|
35
|
+
version: 0.7.12
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
prerelease: false
|
39
|
+
type: :runtime
|
40
|
+
name: json
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 1
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 5
|
50
|
+
- 1
|
51
|
+
version: 1.5.1
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
prerelease: false
|
55
|
+
type: :runtime
|
56
|
+
name: activesupport
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirement: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
prerelease: false
|
69
|
+
type: :development
|
70
|
+
name: rspec
|
71
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 27
|
77
|
+
segments:
|
78
|
+
- 2
|
79
|
+
- 5
|
80
|
+
- 0
|
81
|
+
version: 2.5.0
|
82
|
+
requirement: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
prerelease: false
|
85
|
+
type: :development
|
86
|
+
name: bundler
|
87
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ~>
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 23
|
93
|
+
segments:
|
94
|
+
- 1
|
95
|
+
- 0
|
96
|
+
- 0
|
97
|
+
version: 1.0.0
|
98
|
+
requirement: *id005
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
prerelease: false
|
101
|
+
type: :development
|
102
|
+
name: jeweler
|
103
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ~>
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
hash: 7
|
109
|
+
segments:
|
110
|
+
- 1
|
111
|
+
- 5
|
112
|
+
- 2
|
113
|
+
version: 1.5.2
|
114
|
+
requirement: *id006
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
prerelease: false
|
117
|
+
type: :development
|
118
|
+
name: rcov
|
119
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
version: "0"
|
128
|
+
requirement: *id007
|
129
|
+
- !ruby/object:Gem::Dependency
|
130
|
+
prerelease: false
|
131
|
+
type: :runtime
|
132
|
+
name: curb
|
133
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
134
|
+
none: false
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
hash: 27
|
139
|
+
segments:
|
140
|
+
- 0
|
141
|
+
- 7
|
142
|
+
- 12
|
143
|
+
version: 0.7.12
|
144
|
+
requirement: *id008
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
prerelease: false
|
147
|
+
type: :runtime
|
148
|
+
name: json
|
149
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ~>
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
hash: 1
|
155
|
+
segments:
|
156
|
+
- 1
|
157
|
+
- 5
|
158
|
+
- 1
|
159
|
+
version: 1.5.1
|
160
|
+
requirement: *id009
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
prerelease: false
|
163
|
+
type: :runtime
|
164
|
+
name: activesupport
|
165
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
166
|
+
none: false
|
167
|
+
requirements:
|
168
|
+
- - ">="
|
169
|
+
- !ruby/object:Gem::Version
|
170
|
+
hash: 3
|
171
|
+
segments:
|
172
|
+
- 0
|
173
|
+
version: "0"
|
174
|
+
requirement: *id010
|
175
|
+
description: Makes it easy to use the HubSpot API in a Ruby application.
|
176
|
+
email: tim@raddonline.com
|
177
|
+
executables: []
|
178
|
+
|
179
|
+
extensions: []
|
180
|
+
|
181
|
+
extra_rdoc_files:
|
182
|
+
- LICENSE.txt
|
183
|
+
- README.rdoc
|
184
|
+
files:
|
185
|
+
- Gemfile
|
186
|
+
- Gemfile.lock
|
187
|
+
- LICENSE.txt
|
188
|
+
- README.rdoc
|
189
|
+
- Rakefile
|
190
|
+
- VERSION
|
191
|
+
- lib/r_hapi.rb
|
192
|
+
- lib/r_hapi/configuration.rb
|
193
|
+
- lib/r_hapi/lead.rb
|
194
|
+
- lib/r_hapi/r_hapi_exception.rb
|
195
|
+
- spec/config.yml.sample
|
196
|
+
- spec/configuration_spec.rb
|
197
|
+
- spec/fixtures/error.html
|
198
|
+
- spec/fixtures/lead.json
|
199
|
+
- spec/fixtures/leads.json
|
200
|
+
- spec/lead_spec.rb
|
201
|
+
- spec/r_hapi_spec.rb
|
202
|
+
- spec/spec_helper.rb
|
203
|
+
has_rdoc: true
|
204
|
+
homepage: http://github.com/timstephenson/rHAPI
|
205
|
+
licenses:
|
206
|
+
- MIT
|
207
|
+
post_install_message:
|
208
|
+
rdoc_options: []
|
209
|
+
|
210
|
+
require_paths:
|
211
|
+
- lib
|
212
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
213
|
+
none: false
|
214
|
+
requirements:
|
215
|
+
- - ">="
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
hash: 3
|
218
|
+
segments:
|
219
|
+
- 0
|
220
|
+
version: "0"
|
221
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
222
|
+
none: false
|
223
|
+
requirements:
|
224
|
+
- - ">="
|
225
|
+
- !ruby/object:Gem::Version
|
226
|
+
hash: 3
|
227
|
+
segments:
|
228
|
+
- 0
|
229
|
+
version: "0"
|
230
|
+
requirements: []
|
231
|
+
|
232
|
+
rubyforge_project:
|
233
|
+
rubygems_version: 1.3.7
|
234
|
+
signing_key:
|
235
|
+
specification_version: 3
|
236
|
+
summary: A ruby wrapper for the HubSpot API (HAPI).
|
237
|
+
test_files:
|
238
|
+
- spec/configuration_spec.rb
|
239
|
+
- spec/lead_spec.rb
|
240
|
+
- spec/r_hapi_spec.rb
|
241
|
+
- spec/spec_helper.rb
|