hubspot_informer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +9 -0
- data/hubspot_informer.gemspec +28 -0
- data/lib/hubspot_informer/version.rb +3 -0
- data/lib/hubspot_informer.rb +49 -0
- data/spec/fixtures/vcr/add_subscriber.yml +34 -0
- data/spec/fixtures/vcr/raise_exception.yml +48 -0
- data/spec/hubspot_informer_spec.rb +39 -0
- data/spec/support/vcr.rb +7 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ODkzODI2NzZjNGZmOTE1ZjQ5ZTM1MTI0NGIwMjAxZDA1MDhhMmIzYw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTYwZmJlYTFjNjYzMTQ5YTUxMmIyZGUzZGJiZDM3NDkyZGY5MGU2Nw==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
N2NjNTZiZDNiZGMwOTFmYTkyNTJiNDA0YjhkY2Q1OGU4YzcwMDg4MmY0ZmZm
|
10
|
+
MTA2OWZjNGY4MWNjNzQyYTM0MjQ1NWRiYzI1OTVjYzJmMzFkNWE2ZjA5ZWU4
|
11
|
+
OTZjNTQzYjUyMDFhYjYzYTY4YzRiOThlZDY1ODFlNTE0NmYyYzc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDA2YjMwNjI1Mzg1YzNhZGE3N2FlNDg4ZGM5ZGExYWIzYWE4M2I1Y2JlYzUy
|
14
|
+
NjhkODE5YWFmMmJmMjVmZDliYWVhNmUwNTI4OTYxNWJhYzFjMjQ1ZjYyZmRh
|
15
|
+
Yzk4MWIzYjk3MzUxYTdkNGQyNzdkOGRkNWFhZjZkNjY5NTdlY2I=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Henrik Sjökvist
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# HubSpot Informer for Ruby
|
2
|
+
|
3
|
+
A simple API wrapper for HubSpot form submission API.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
### In Rails
|
8
|
+
|
9
|
+
hubspot = HubspotInformer.new(
|
10
|
+
# These are mandatory
|
11
|
+
portal_id: 1234,
|
12
|
+
form_guid: 567890,
|
13
|
+
# These are optional
|
14
|
+
request_ip: request.remote_ip,
|
15
|
+
hutk: cookies[:hutk],
|
16
|
+
page_url: "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
|
17
|
+
page_title: @title
|
18
|
+
)
|
19
|
+
hubspot.submit params
|
20
|
+
|
21
|
+
## Contributing
|
22
|
+
|
23
|
+
1. Fork it
|
24
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
25
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
26
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
27
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hubspot_informer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "hubspot_informer"
|
8
|
+
gem.version = HubspotInformer::VERSION
|
9
|
+
gem.authors = ["Henrik Sjökvist"]
|
10
|
+
gem.email = ["henrik.sjokvist@gmail.com"]
|
11
|
+
gem.description = %q{A simple API wrapper for the HubSpot form submission API.}
|
12
|
+
gem.summary = %q{A simple API wrapper for the HubSpot form submission API.
|
13
|
+
A typical use case is adding subcribers to a mailing list.}
|
14
|
+
gem.homepage = "http://github.com/kollegorna/hubspot_informer"
|
15
|
+
gem.license = 'MIT'
|
16
|
+
|
17
|
+
gem.files = `git ls-files`.split($/)
|
18
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
19
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
|
22
|
+
gem.rubyforge_project = "hubspot_informer"
|
23
|
+
|
24
|
+
# Dependencies
|
25
|
+
gem.add_development_dependency "rspec"
|
26
|
+
gem.add_development_dependency "vcr"
|
27
|
+
gem.add_runtime_dependency "faraday"
|
28
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'hubspot_informer/version'
|
2
|
+
require 'faraday'
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class HubspotInformer
|
7
|
+
HubspotInformerError = Class.new(StandardError)
|
8
|
+
def initialize args
|
9
|
+
args.each do |k,v|
|
10
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
11
|
+
end
|
12
|
+
@page_url ||= ''
|
13
|
+
@request_ip ||= ''
|
14
|
+
@hutk ||= ''
|
15
|
+
@page_title ||= ''
|
16
|
+
|
17
|
+
raise HubspotInformerError.new(
|
18
|
+
"HubspotInformer API Error: Missing portal_id and/or form_guid"
|
19
|
+
) unless @portal_id && @form_guid
|
20
|
+
|
21
|
+
base_url = "https://forms.hubspot.com/"
|
22
|
+
@conn = Faraday.new(
|
23
|
+
url: base_url,
|
24
|
+
ssl: { verify: false },
|
25
|
+
headers: { accept: 'application/json' })
|
26
|
+
end
|
27
|
+
|
28
|
+
def submit params
|
29
|
+
params[:hs_context] = hs_context
|
30
|
+
response = @conn.post do |req|
|
31
|
+
req.url "uploads/form/v2/#{@portal_id}/#{@form_guid}"
|
32
|
+
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
33
|
+
req.body = URI.encode_www_form params
|
34
|
+
end
|
35
|
+
unless response.status == 204
|
36
|
+
raise HubspotInformerError.new("HubspotInformer API Error: #{response.body} (status code #{response.status})")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def hs_context
|
41
|
+
values = {
|
42
|
+
'hutk' => @hutk,
|
43
|
+
'ipAddress' => @request_ip,
|
44
|
+
'pageUrl' => @page_url,
|
45
|
+
'pageTitle' => @page_title
|
46
|
+
}
|
47
|
+
values.to_json
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://forms.hubspot.com/uploads/form/v2/<PORTAL_ID>/<FORM_GUID>
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: firstname=John&lastname=Doe&email=john.doe%40example.com&hs_context=%7B%22hutk%22%3A%22%22%2C%22ipAddress%22%3A%22%22%2C%22pageUrl%22%3A%22%22%2C%22pageTitle%22%3A%22%22%7D
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- Faraday v0.8.6
|
14
|
+
Content-Type:
|
15
|
+
- application/x-www-form-urlencoded
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 204
|
19
|
+
message:
|
20
|
+
headers:
|
21
|
+
access-control-allow-credentials:
|
22
|
+
- 'false'
|
23
|
+
date:
|
24
|
+
- Wed, 10 Apr 2013 13:33:48 GMT
|
25
|
+
server:
|
26
|
+
- Apache-Coyote/1.1
|
27
|
+
connection:
|
28
|
+
- Close
|
29
|
+
body:
|
30
|
+
encoding: US-ASCII
|
31
|
+
string: ''
|
32
|
+
http_version:
|
33
|
+
recorded_at: Wed, 10 Apr 2013 13:33:42 GMT
|
34
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://forms.hubspot.com/uploads/form/v2/<PORTAL_ID>/thisisnogood
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: firstname=John&lastname=Doe&email=john.doe%40example.com&hs_context=%7B%22hutk%22%3A%22%22%2C%22ipAddress%22%3A%22%22%2C%22pageUrl%22%3A%22%22%2C%22pageTitle%22%3A%22%22%7D
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/json
|
12
|
+
User-Agent:
|
13
|
+
- Faraday v0.8.6
|
14
|
+
Content-Type:
|
15
|
+
- application/x-www-form-urlencoded
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 404
|
19
|
+
message:
|
20
|
+
headers:
|
21
|
+
access-control-allow-credentials:
|
22
|
+
- 'false'
|
23
|
+
content-type:
|
24
|
+
- text/html;charset=utf-8
|
25
|
+
date:
|
26
|
+
- Wed, 10 Apr 2013 11:55:33 GMT
|
27
|
+
server:
|
28
|
+
- Apache-Coyote/1.1
|
29
|
+
content-length:
|
30
|
+
- '952'
|
31
|
+
connection:
|
32
|
+
- Close
|
33
|
+
body:
|
34
|
+
encoding: US-ASCII
|
35
|
+
string: ! '<html><head><title>Apache Tomcat/6.0.30 - Error report</title><style><!--H1
|
36
|
+
{font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;}
|
37
|
+
H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;}
|
38
|
+
H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;}
|
39
|
+
BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;}
|
40
|
+
B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;}
|
41
|
+
P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A
|
42
|
+
{color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP
|
43
|
+
Status 404 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b>
|
44
|
+
<u></u></p><p><b>description</b> <u>The requested resource () is not available.</u></p><HR
|
45
|
+
size="1" noshade="noshade"><h3>Apache Tomcat/6.0.30</h3></body></html>'
|
46
|
+
http_version:
|
47
|
+
recorded_at: Wed, 10 Apr 2013 11:55:30 GMT
|
48
|
+
recorded_with: VCR 2.4.0
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
require 'faraday'
|
3
|
+
require_relative 'support/vcr'
|
4
|
+
require_relative '../lib/hubspot_informer.rb'
|
5
|
+
|
6
|
+
|
7
|
+
unless ENV['HUBSPOT_TEST_PORTAL_ID'] && ENV['HUBSPOT_TEST_FORM_GUID']
|
8
|
+
warn ["WARNING: You need to set the HUBSPOT_TEST_PORTAL_ID and HUBSPOT_TEST_FORM_GUID",
|
9
|
+
"environment variables or the calls to the HubSpot API will be invalid."].join("\n")
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "HubspotInformer" do
|
13
|
+
it "adds a subscriber to a list" do
|
14
|
+
VCR.use_cassette('add_subscriber') do
|
15
|
+
portal_id = ENV['HUBSPOT_TEST_PORTAL_ID']
|
16
|
+
form_guid = ENV['HUBSPOT_TEST_FORM_GUID']
|
17
|
+
hubspot = HubspotInformer.new(
|
18
|
+
portal_id: portal_id,
|
19
|
+
form_guid: form_guid,
|
20
|
+
)
|
21
|
+
params = { firstname: 'John', lastname: 'Doe', email: 'john.doe@example.com' }
|
22
|
+
response = hubspot.submit params
|
23
|
+
response.should eql nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it "raises an exception when an error HTTP status code is returned" do
|
28
|
+
VCR.use_cassette('raise_exception') do
|
29
|
+
portal_id = ENV['HUBSPOT_TEST_PORTAL_ID']
|
30
|
+
form_guid = 'thisisnogood'
|
31
|
+
hubspot = HubspotInformer.new(
|
32
|
+
portal_id: portal_id,
|
33
|
+
form_guid: form_guid,
|
34
|
+
)
|
35
|
+
params = { firstname: 'John', lastname: 'Doe', email: 'john.doe@example.com' }
|
36
|
+
lambda { hubspot.submit params }.should raise_error(HubspotInformer::HubspotInformerError)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/support/vcr.rb
ADDED
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hubspot_informer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Henrik Sjökvist
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: vcr
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: A simple API wrapper for the HubSpot form submission API.
|
56
|
+
email:
|
57
|
+
- henrik.sjokvist@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- hubspot_informer.gemspec
|
68
|
+
- lib/hubspot_informer.rb
|
69
|
+
- lib/hubspot_informer/version.rb
|
70
|
+
- spec/fixtures/vcr/add_subscriber.yml
|
71
|
+
- spec/fixtures/vcr/raise_exception.yml
|
72
|
+
- spec/hubspot_informer_spec.rb
|
73
|
+
- spec/support/vcr.rb
|
74
|
+
homepage: http://github.com/kollegorna/hubspot_informer
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project: hubspot_informer
|
94
|
+
rubygems_version: 2.0.3
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: A simple API wrapper for the HubSpot form submission API. A typical use
|
98
|
+
case is adding subcribers to a mailing list.
|
99
|
+
test_files:
|
100
|
+
- spec/fixtures/vcr/add_subscriber.yml
|
101
|
+
- spec/fixtures/vcr/raise_exception.yml
|
102
|
+
- spec/hubspot_informer_spec.rb
|
103
|
+
- spec/support/vcr.rb
|