hatchbuck 0.0.1 → 0.0.2
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 +4 -4
- data/lib/helpers.rb +10 -0
- data/lib/objects/contact.rb +65 -6
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 40149dba5bdb01e5dd43ead99aa7194ce02fe0ed
|
|
4
|
+
data.tar.gz: 83981202f12b08e1059d6d2aeffe69d73a8932d4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ee2e2b3dca9fd7f1c4ed246f9376931abf44364a2d4bc8b52a5e858a6282d22e688d2580bc9ae56fcfe2ff38c165081391e6e4ebf3158b053f6e92c5d8ce723
|
|
7
|
+
data.tar.gz: 39e3ef459183850a435c4b939333b515c54cb37e1e50fb1dd855bf52496bdd4238c37089dd8655b931d3ce401b00c6006bef87bb058115b5fd351d2590916480
|
data/lib/helpers.rb
CHANGED
|
@@ -15,5 +15,15 @@ module Hatchbuck
|
|
|
15
15
|
return "#{base_path}#{object}#{action}?api_key=#{key}"
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
|
+
|
|
19
|
+
module TermDeterminer
|
|
20
|
+
def self.determine(term)
|
|
21
|
+
if term =~ /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
|
|
22
|
+
return 'email'
|
|
23
|
+
else
|
|
24
|
+
return 'contactid'
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
18
28
|
end
|
|
19
29
|
|
data/lib/objects/contact.rb
CHANGED
|
@@ -5,7 +5,9 @@ module Hatchbuck
|
|
|
5
5
|
# accepts either an email address or contact id as a search term
|
|
6
6
|
def self.search(term)
|
|
7
7
|
endpoint = Hatchbuck::URLifier.build(@object_path, '/search')
|
|
8
|
-
|
|
8
|
+
|
|
9
|
+
determination = Hatchbuck::TermDeterminer.determine(term)
|
|
10
|
+
if determination == 'email'
|
|
9
11
|
search_json = '{ "emails":[{"address": "' + term + '"}] }'
|
|
10
12
|
else
|
|
11
13
|
search_json = '{ "contactId": "' + term + '" }'
|
|
@@ -32,13 +34,15 @@ module Hatchbuck
|
|
|
32
34
|
# creates the contact; returns false if it exists already
|
|
33
35
|
# use search first and capture the response to update contacts
|
|
34
36
|
def self.create(contact)
|
|
37
|
+
endpoint = Hatchbuck::URLifier.build(@object_path, '')
|
|
38
|
+
|
|
35
39
|
firstname = contact['firstname']
|
|
36
40
|
lastname = contact['lastname']
|
|
37
41
|
email = contact['email']
|
|
42
|
+
company = contact['company']
|
|
38
43
|
email_type = contact['email_type_id']
|
|
39
44
|
status = contact['status_id']
|
|
40
45
|
|
|
41
|
-
endpoint = Hatchbuck::URLifier.build(@object_path, '')
|
|
42
46
|
conn = Faraday.new
|
|
43
47
|
result = conn.post do |req|
|
|
44
48
|
req.url endpoint
|
|
@@ -46,6 +50,7 @@ module Hatchbuck
|
|
|
46
50
|
req.body = '{
|
|
47
51
|
"firstName": "' + firstname + '",
|
|
48
52
|
"lastName": "' + lastname + '",
|
|
53
|
+
"company": "' + company + '",
|
|
49
54
|
"emails": [{
|
|
50
55
|
"address": "' + email + '",
|
|
51
56
|
"typeId": "' + email_type + '"
|
|
@@ -68,11 +73,65 @@ module Hatchbuck
|
|
|
68
73
|
end
|
|
69
74
|
end
|
|
70
75
|
|
|
71
|
-
#
|
|
72
|
-
# accepts either contact id or email address
|
|
76
|
+
# accepts either contact id or email address as search term
|
|
73
77
|
# responds false if contact isn't found
|
|
74
|
-
def self.update
|
|
75
|
-
|
|
78
|
+
def self.update(term, contact)
|
|
79
|
+
endpoint = Hatchbuck::URLifier.build(@object_path, '')
|
|
80
|
+
|
|
81
|
+
firstname = contact['firstname']
|
|
82
|
+
lastname = contact['lastname']
|
|
83
|
+
email = contact['email']
|
|
84
|
+
company = contact['company']
|
|
85
|
+
email_type = contact['email_type_id']
|
|
86
|
+
status = contact['status_id']
|
|
87
|
+
|
|
88
|
+
determination = Hatchbuck::TermDeterminer.determine(term)
|
|
89
|
+
if determination == 'email'
|
|
90
|
+
search_json = ' {
|
|
91
|
+
"emails": [{
|
|
92
|
+
"address": "' + email + '",
|
|
93
|
+
"typeId": "' + email_type + '"
|
|
94
|
+
}]
|
|
95
|
+
}'
|
|
96
|
+
else
|
|
97
|
+
search_json = ' {
|
|
98
|
+
"contactId": "' + term + '",
|
|
99
|
+
"emails": [{
|
|
100
|
+
"address": "' + email + '",
|
|
101
|
+
"typeId": :' + email_type + '"
|
|
102
|
+
}]
|
|
103
|
+
}'
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
conn = Faraday.new
|
|
107
|
+
result = conn.put do |req|
|
|
108
|
+
req.url endpoint
|
|
109
|
+
req.headers['Content-Type'] = 'application/json'
|
|
110
|
+
req.body = '{
|
|
111
|
+
"firstName": "' + firstname + '",
|
|
112
|
+
"lastName": "' + lastname + '",
|
|
113
|
+
"company": "' + company + '",
|
|
114
|
+
"emails": [{
|
|
115
|
+
"address": "' + email + '",
|
|
116
|
+
"typeId": "' + email_type + '"
|
|
117
|
+
}],
|
|
118
|
+
"status": {
|
|
119
|
+
"id": "' + status + '"
|
|
120
|
+
}
|
|
121
|
+
}'
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
puts result.status
|
|
125
|
+
# handling response
|
|
126
|
+
if result.status == 400
|
|
127
|
+
puts 'Contact already exists.'
|
|
128
|
+
return false
|
|
129
|
+
elsif result.status == 200
|
|
130
|
+
return result.body
|
|
131
|
+
else
|
|
132
|
+
puts "Error!"
|
|
133
|
+
return false
|
|
134
|
+
end
|
|
76
135
|
return json_response
|
|
77
136
|
end
|
|
78
137
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hatchbuck
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sam Schirmer
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-01-
|
|
11
|
+
date: 2017-01-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email: sschirmer@hatchbuck.com
|
|
@@ -32,7 +32,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
32
32
|
requirements:
|
|
33
33
|
- - ">="
|
|
34
34
|
- !ruby/object:Gem::Version
|
|
35
|
-
version: '1
|
|
35
|
+
version: '2.1'
|
|
36
36
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - ">="
|