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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/helpers.rb +10 -0
  3. data/lib/objects/contact.rb +65 -6
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56ccc1cda10d10005f9003c5be82a15cd374c324
4
- data.tar.gz: 6dbbe37205e1fa9d0814ea72b65b5f71c70013e8
3
+ metadata.gz: 40149dba5bdb01e5dd43ead99aa7194ce02fe0ed
4
+ data.tar.gz: 83981202f12b08e1059d6d2aeffe69d73a8932d4
5
5
  SHA512:
6
- metadata.gz: bfc2c8249b83906f2bb5b82b94847ffd96157a16d24f760d621c15c508d334d87596935f9fc7da323dba9c55429dab780b454a793bd54566d8bd3109097112e2
7
- data.tar.gz: 66f80a561011e00d939a421f6f32d2660071ed14411f6a5d12bec904c563f8d94e8272a12adeab6867b5b72bf73fc8132ba22f0a1f16d69b99e1ae486d899d3f
6
+ metadata.gz: 0ee2e2b3dca9fd7f1c4ed246f9376931abf44364a2d4bc8b52a5e858a6282d22e688d2580bc9ae56fcfe2ff38c165081391e6e4ebf3158b053f6e92c5d8ce723
7
+ data.tar.gz: 39e3ef459183850a435c4b939333b515c54cb37e1e50fb1dd855bf52496bdd4238c37089dd8655b931d3ce401b00c6006bef87bb058115b5fd351d2590916480
@@ -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
 
@@ -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
- if term =~ /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
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
- # TODO
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
- # PUT api call here
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.1
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-20 00:00:00.000000000 Z
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.9'
35
+ version: '2.1'
36
36
  required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="