rubspot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02b1708d1f815aecc6d92e1c77ee29aa3caf3af7
4
+ data.tar.gz: bf98cc9ab0ea930bfd3211237c6f7db5970ebd70
5
+ SHA512:
6
+ metadata.gz: 1044ef1dc92b8dbd408ebfe2a1f19054060ba29525b3041dd7a3477e1258b587f2a5bb3f4d5bbe0b16471112c89284128648b0c64a146355a25693d6c273a5cd
7
+ data.tar.gz: 2ac34bf455256308b6a633b809d65ca019d700b39ad984ff1216bc6dc89681cbd3c843b628b9195a27b3c2c25b8edbb48ca8ff7a52edbaad96c5793be4cfbeb0
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ lib/hubspot.yml
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubspot.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Paulo Diniz
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.
@@ -0,0 +1,29 @@
1
+ # Rubspot
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rubspot'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rubspot
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/rubspot/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.pattern = "test/*_test.rb"
8
+ end
@@ -0,0 +1,9 @@
1
+ require "rubspot/version"
2
+ require "rubspot/models/base"
3
+ require "rubspot/models/contact"
4
+ require "rubspot/models/deal"
5
+
6
+ module Rubspot
7
+ API_KEY = ENV["HUBSPOT_API_KEY"]
8
+ PORTAL_ID = ENV["HUBSPOT_PORTAL_ID"]
9
+ end
@@ -0,0 +1,20 @@
1
+ require 'httpclient'
2
+ require 'uri'
3
+
4
+ module Rubspot
5
+ class Base
6
+
7
+ def self.get(uri)
8
+ client = HTTPClient.new
9
+ client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
10
+ client.get(uri)
11
+ end
12
+
13
+ def self.post(uri, params = {})
14
+ client = HTTPClient.new
15
+ client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
16
+ client.post(uri, params, {'Content-Type' => 'application/json'} )
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,33 @@
1
+ require 'rubspot/representers/contact_representation'
2
+
3
+ module Rubspot
4
+ class Contact < Rubspot::Base
5
+
6
+ attr_accessor :vid, :email, :firstname
7
+
8
+ def initialize(opts = {})
9
+ opts.each do |opt|
10
+ instance_variable_set("@#{opt[0]}", opt[1])
11
+ end
12
+ end
13
+
14
+ def self.find_by_email(email)
15
+ response = Rubspot::Base::get("https://api.hubapi.com/contacts/v1/contact/email/#{email}/profile?hapikey=#{Rubspot::API_KEY}")
16
+ return nil unless response.ok?
17
+ Rubspot::ContactRepresentation.new(Rubspot::Contact.new).from_json response.body
18
+ end
19
+
20
+ def save
21
+ params = Rubspot::ContactRepresentation.new(self).to_json
22
+ response = Rubspot::Base::post("http://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/#{self.email}/?hapikey=#{Rubspot::API_KEY}&portalId=#{Rubspot::PORTAL_ID}", params)
23
+ return false unless response.ok?
24
+ populate_attributes_from response
25
+ true
26
+ end
27
+
28
+ private
29
+ def populate_attributes_from(response)
30
+ Rubspot::ContactRepresentation.new(self).from_json response.body
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ require 'json'
2
+ require 'rubspot/representers/deal_representation'
3
+
4
+ module Rubspot
5
+ class Deal < Rubspot::Base
6
+
7
+ attr_accessor :vids, :companies, :portal_id, :dealname, :id
8
+
9
+ def initialize(opts = {})
10
+ opts.each do |opt|
11
+ instance_variable_set("@#{opt[0]}", opt[1])
12
+ end
13
+ end
14
+
15
+ # def self.find(id)
16
+ # uri = "https://api.hubapi.com/deals/v1/deal/#{id}?hapikey=#{Rubspot::API_KEY}&portalId=#{Rubspot::PORTAL_ID}"
17
+ # response = Rubspot::Base::get uri
18
+ # return nil unless response.ok?
19
+ # end
20
+
21
+ def save
22
+ params = { 'associations' => {'associatedCompanyIds' => companies, 'associatedVids' => vids }, 'portalId' => portal_id, 'properties' => []}
23
+ uri = "https://api.hubapi.com/deals/v1/deal?hapikey=#{Rubspot::API_KEY}&portalId=#{Rubspot::PORTAL_ID}"
24
+ response = Rubspot::Base::post uri, params.to_json
25
+ return false unless response.ok?
26
+ populate_attributes_from response
27
+ true
28
+ end
29
+
30
+ private
31
+ def populate_attributes_from(response)
32
+ Rubspot::DealRepresentation.new(self).from_json response.body
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ require 'representable/json'
2
+
3
+ module Rubspot
4
+ class ContactRepresentation < Representable::Decorator
5
+ include Representable::JSON
6
+
7
+ property :vid
8
+ property :properties,
9
+ setter: lambda { |val, args|
10
+ self.email = val["email"]["value"] if val["email"]
11
+ self.firstname = val["firstname"]["value"] if val["firstname"]
12
+ },
13
+ getter: lambda { |_|
14
+ properties_array = []
15
+ [:email, :firstname].each { |field|
16
+ properties_array << {'property' => field, 'value' => instance_variable_get("@#{field}")}
17
+ }
18
+ return properties_array
19
+ }
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ require 'representable/json'
2
+
3
+ module Rubspot
4
+ class DealRepresentation < Representable::Decorator
5
+ include Representable::JSON
6
+
7
+ property :portal_id, as: :portalId
8
+ property :id, as: :dealId
9
+
10
+ nested :associations do
11
+ collection :companies, as: :associatedCompanyIds
12
+ collection :vids, as: :associatedVids
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Rubspot
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubspot/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubspot"
8
+ spec.version = Rubspot::VERSION
9
+ spec.authors = ["Paulo Diniz"]
10
+ spec.email = ["paulo.rc.diniz@gmail.com"]
11
+ spec.summary = %q{Hubspot wrapper.}
12
+ spec.description = %q{Hubspot wrapper for Contact an Deal.}
13
+ spec.homepage = "https://github.com/paulodiniz/rubspot"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "representable"
22
+ spec.add_dependency "httpclient"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "minitest"
27
+ spec.add_development_dependency "activesupport"
28
+ spec.add_development_dependency "pry"
29
+ end
@@ -0,0 +1,12 @@
1
+ require_relative './test_helper'
2
+ require 'json'
3
+
4
+ class ContactRepresentationTest < ActiveSupport::TestCase
5
+
6
+ test 'representing a contact to hubspot api' do
7
+ contact = Rubspot::Contact.new(email: 'teste@teste.com', firstname: 'Paulo')
8
+ json = JSON.parse(Rubspot::ContactRepresentation.new(contact).to_json)
9
+ assert_equal 'teste@teste.com', json["properties"][0]["value"]
10
+ assert_equal 'Paulo', json["properties"][1]["value"]
11
+ end
12
+ end
@@ -0,0 +1,35 @@
1
+ require_relative './test_helper'
2
+
3
+ class ContactTest < ActiveSupport::TestCase
4
+
5
+ setup do
6
+ Rubspot::API_KEY = "demo"
7
+ Rubspot::PORTAL_ID = 62515
8
+ end
9
+
10
+ test 'initialize' do
11
+ contact = Rubspot::Contact.new(email: 'teste@teste.com', firstname: 'Paulo')
12
+ assert_equal 'teste@teste.com', contact.email
13
+ assert_equal 'Paulo', contact.firstname
14
+ end
15
+
16
+ test 'finding by email' do
17
+ contact = Rubspot::Contact.find_by_email('testingapis@hubspot.com')
18
+ assert_equal 'testingapis@hubspot.com', contact.email
19
+ assert contact.vid
20
+ end
21
+
22
+ test 'not finding' do
23
+ contact = Rubspot::Contact.find_by_email('omg@becky.com')
24
+ refute contact
25
+ end
26
+
27
+ test 'saving a contact on hubspot' do
28
+ contact = Rubspot::Contact.new(email: 'paulo.rc.diniz@gmail.com', firstname: 'Modificado')
29
+ assert_equal 'paulo.rc.diniz@gmail.com', contact.email
30
+ assert_equal 'Modificado', contact.firstname
31
+ assert contact.save
32
+
33
+ assert contact.vid
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require_relative './test_helper'
2
+ require 'json'
3
+
4
+ class DealRepresentationTest < ActiveSupport::TestCase
5
+ test '' do
6
+ deal = Rubspot::Deal.new(companies: [8954037], vids: [27136], portal_id: 62515, dealname: 'OldNewDeal', id: 30)
7
+ hash = Rubspot::DealRepresentation.new(deal).to_hash
8
+
9
+ assert_equal 62515, hash['portalId']
10
+ assert_equal 30, hash['dealId']
11
+
12
+ assert_equal [8954037], hash['associations']['associatedCompanyIds']
13
+ assert_equal [27136], hash['associations']['associatedVids']
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ require_relative './test_helper'
2
+
3
+ class DealTest < ActiveSupport::TestCase
4
+
5
+ setup do
6
+ Rubspot::API_KEY = "demo"
7
+ Rubspot::PORTAL_ID = 62515
8
+ end
9
+
10
+ test 'initializing a deal' do
11
+ deal = Rubspot::Deal.new(companies: [8954037], vids: [27136], portal_id: 62515, dealname: 'OldNewDeal')
12
+
13
+ assert_equal 62515, deal.portal_id
14
+ assert_equal 'OldNewDeal', deal.dealname
15
+ assert_equal [8954037], deal.companies
16
+ assert_equal [27136], deal.vids
17
+ end
18
+
19
+ test 'creating a new deal' do
20
+ deal = Rubspot::Deal.new(companies: [8954037], vids: [27136], portal_id: 62515, dealname: 'OldNewDeal')
21
+ assert deal.save
22
+ assert deal.id
23
+ end
24
+
25
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubspot'
2
+ require 'minitest'
3
+
4
+ require 'minitest/unit'
5
+ require 'minitest/autorun'
6
+ require 'minitest/pride'
7
+
8
+ require 'active_support'
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubspot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paulo Diniz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: representable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: httpclient
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Hubspot wrapper for Contact an Deal.
112
+ email:
113
+ - paulo.rc.diniz@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - lib/rubspot.rb
124
+ - lib/rubspot/models/base.rb
125
+ - lib/rubspot/models/contact.rb
126
+ - lib/rubspot/models/deal.rb
127
+ - lib/rubspot/representers/contact_representation.rb
128
+ - lib/rubspot/representers/deal_representation.rb
129
+ - lib/rubspot/version.rb
130
+ - rubspot.gemspec
131
+ - test/contact_representation_test.rb
132
+ - test/contact_test.rb
133
+ - test/deal_representation_test.rb
134
+ - test/deal_test.rb
135
+ - test/test_helper.rb
136
+ homepage: https://github.com/paulodiniz/rubspot
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.4.1
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Hubspot wrapper.
160
+ test_files:
161
+ - test/contact_representation_test.rb
162
+ - test/contact_test.rb
163
+ - test/deal_representation_test.rb
164
+ - test/deal_test.rb
165
+ - test/test_helper.rb