hatchbuck 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 +7 -0
- data/lib/hatchbuck.rb +6 -0
- data/lib/helpers.rb +19 -0
- data/lib/objects/contact.rb +80 -0
- data/lib/objects/tag.rb +24 -0
- metadata +47 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 56ccc1cda10d10005f9003c5be82a15cd374c324
|
|
4
|
+
data.tar.gz: 6dbbe37205e1fa9d0814ea72b65b5f71c70013e8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bfc2c8249b83906f2bb5b82b94847ffd96157a16d24f760d621c15c508d334d87596935f9fc7da323dba9c55429dab780b454a793bd54566d8bd3109097112e2
|
|
7
|
+
data.tar.gz: 66f80a561011e00d939a421f6f32d2660071ed14411f6a5d12bec904c563f8d94e8272a12adeab6867b5b72bf73fc8132ba22f0a1f16d69b99e1ae486d899d3f
|
data/lib/hatchbuck.rb
ADDED
data/lib/helpers.rb
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Hatchbuck
|
|
2
|
+
module Key
|
|
3
|
+
def self.set(key)
|
|
4
|
+
@api_key = key
|
|
5
|
+
end
|
|
6
|
+
def self.get
|
|
7
|
+
return @api_key
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module URLifier
|
|
12
|
+
def self.build(object, action)
|
|
13
|
+
base_path = 'https://api.hatchbuck.com/api/v1/'
|
|
14
|
+
key = Key.get
|
|
15
|
+
return "#{base_path}#{object}#{action}?api_key=#{key}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module Hatchbuck
|
|
2
|
+
class Contact
|
|
3
|
+
@object_path = 'contact'
|
|
4
|
+
|
|
5
|
+
# accepts either an email address or contact id as a search term
|
|
6
|
+
def self.search(term)
|
|
7
|
+
endpoint = Hatchbuck::URLifier.build(@object_path, '/search')
|
|
8
|
+
if term =~ /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
|
|
9
|
+
search_json = '{ "emails":[{"address": "' + term + '"}] }'
|
|
10
|
+
else
|
|
11
|
+
search_json = '{ "contactId": "' + term + '" }'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
conn = Faraday.new
|
|
15
|
+
result = conn.post do |req|
|
|
16
|
+
req.url endpoint
|
|
17
|
+
req.headers['Content-Type'] = 'application/json'
|
|
18
|
+
req.body = search_json
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# handling response
|
|
22
|
+
if result.status == 400
|
|
23
|
+
return 'not found'
|
|
24
|
+
elsif result.status == 200
|
|
25
|
+
return result.body
|
|
26
|
+
else
|
|
27
|
+
return false
|
|
28
|
+
puts "Error!"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# creates the contact; returns false if it exists already
|
|
33
|
+
# use search first and capture the response to update contacts
|
|
34
|
+
def self.create(contact)
|
|
35
|
+
firstname = contact['firstname']
|
|
36
|
+
lastname = contact['lastname']
|
|
37
|
+
email = contact['email']
|
|
38
|
+
email_type = contact['email_type_id']
|
|
39
|
+
status = contact['status_id']
|
|
40
|
+
|
|
41
|
+
endpoint = Hatchbuck::URLifier.build(@object_path, '')
|
|
42
|
+
conn = Faraday.new
|
|
43
|
+
result = conn.post do |req|
|
|
44
|
+
req.url endpoint
|
|
45
|
+
req.headers['Content-Type'] = 'application/json'
|
|
46
|
+
req.body = '{
|
|
47
|
+
"firstName": "' + firstname + '",
|
|
48
|
+
"lastName": "' + lastname + '",
|
|
49
|
+
"emails": [{
|
|
50
|
+
"address": "' + email + '",
|
|
51
|
+
"typeId": "' + email_type + '"
|
|
52
|
+
}],
|
|
53
|
+
"status": {
|
|
54
|
+
"id": "' + status + '"
|
|
55
|
+
}
|
|
56
|
+
}'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# handling response
|
|
60
|
+
if result.status == 400
|
|
61
|
+
puts 'Contact already exists.'
|
|
62
|
+
return false
|
|
63
|
+
elsif result.status == 200
|
|
64
|
+
return result.body
|
|
65
|
+
else
|
|
66
|
+
puts "Error!"
|
|
67
|
+
return false
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# TODO
|
|
72
|
+
# accepts either contact id or email address
|
|
73
|
+
# responds false if contact isn't found
|
|
74
|
+
def self.update
|
|
75
|
+
# PUT api call here
|
|
76
|
+
return json_response
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
data/lib/objects/tag.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Hatchbuck
|
|
2
|
+
class Tag
|
|
3
|
+
@object_path = 'contact'
|
|
4
|
+
def self.create(term, tag)
|
|
5
|
+
endpoint = Hatchbuck::URLifier.build(@object_path, "/#{term}/tags")
|
|
6
|
+
|
|
7
|
+
conn = Faraday.new
|
|
8
|
+
result = conn.post do |req|
|
|
9
|
+
req.url endpoint
|
|
10
|
+
req.headers['Content-Type'] = 'application/json'
|
|
11
|
+
req.body = '[{ "id": "' + tag + '" }]'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# handling response
|
|
15
|
+
if result.status == 201
|
|
16
|
+
return result.body
|
|
17
|
+
else
|
|
18
|
+
return false
|
|
19
|
+
puts "Error!"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
metadata
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: hatchbuck
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sam Schirmer
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-01-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email: sschirmer@hatchbuck.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/hatchbuck.rb
|
|
20
|
+
- lib/helpers.rb
|
|
21
|
+
- lib/objects/contact.rb
|
|
22
|
+
- lib/objects/tag.rb
|
|
23
|
+
homepage: https://github.com/samschirmer/hatchbuck-ruby
|
|
24
|
+
licenses:
|
|
25
|
+
- GPL-3.0
|
|
26
|
+
metadata: {}
|
|
27
|
+
post_install_message:
|
|
28
|
+
rdoc_options: []
|
|
29
|
+
require_paths:
|
|
30
|
+
- lib
|
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
32
|
+
requirements:
|
|
33
|
+
- - ">="
|
|
34
|
+
- !ruby/object:Gem::Version
|
|
35
|
+
version: '1.9'
|
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
requirements: []
|
|
42
|
+
rubyforge_project:
|
|
43
|
+
rubygems_version: 2.2.2
|
|
44
|
+
signing_key:
|
|
45
|
+
specification_version: 4
|
|
46
|
+
summary: Simple library for Hatchbuck API
|
|
47
|
+
test_files: []
|