icontact 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/config/test.yml.example +3 -0
- data/icontact.gemspec +29 -0
- data/lib/icontact/api/client_folders.rb +48 -0
- data/lib/icontact/api/contacts.rb +59 -0
- data/lib/icontact/api/custom_fields.rb +53 -0
- data/lib/icontact/api/lists.rb +53 -0
- data/lib/icontact/api/subscriptions.rb +48 -0
- data/lib/icontact/api/users.rb +48 -0
- data/lib/icontact/api.rb +75 -0
- data/lib/icontact/connection.rb +73 -0
- data/lib/icontact/errors.rb +58 -0
- data/lib/icontact/version.rb +3 -0
- data/lib/icontact.rb +7 -0
- data/spec/icontact/api/contacts_spec.rb +88 -0
- data/spec/icontact/api_spec.rb +33 -0
- data/spec/icontact_spec.rb +9 -0
- data/spec/spec_helper.rb +31 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cec9071cf8847d38d296c46cba772a56d724b290
|
4
|
+
data.tar.gz: db4bd7430726457a845e0747eb826fc570733ce2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 68cad6d28a5bc2a4886c043711694c6bd0e972f97284530441269168b5a30c1e8e9301b6d3d66414b70721dfaf563394bc46e5cf6f151da37aa3bfa19f0f43f4
|
7
|
+
data.tar.gz: 3499717bd093456ce4600472ed4c29479b0294fc7fed16086b06fec22144c58966c579574c40005e621584c8553cc807f75ec7d767cccced28db2f5eea070972
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
icontact (0.0.1)
|
5
|
+
faraday (~> 0.8)
|
6
|
+
oj (~> 2.11)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.3.6)
|
12
|
+
crack (0.4.2)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
diff-lcs (1.2.5)
|
15
|
+
faker (1.4.3)
|
16
|
+
i18n (~> 0.5)
|
17
|
+
faraday (0.9.0)
|
18
|
+
multipart-post (>= 1.2, < 3)
|
19
|
+
i18n (0.6.11)
|
20
|
+
multipart-post (2.0.0)
|
21
|
+
oj (2.11.0)
|
22
|
+
rake (10.3.2)
|
23
|
+
rspec (3.1.0)
|
24
|
+
rspec-core (~> 3.1.0)
|
25
|
+
rspec-expectations (~> 3.1.0)
|
26
|
+
rspec-mocks (~> 3.1.0)
|
27
|
+
rspec-core (3.1.7)
|
28
|
+
rspec-support (~> 3.1.0)
|
29
|
+
rspec-expectations (3.1.2)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.1.0)
|
32
|
+
rspec-mocks (3.1.3)
|
33
|
+
rspec-support (~> 3.1.0)
|
34
|
+
rspec-support (3.1.2)
|
35
|
+
safe_yaml (1.0.4)
|
36
|
+
vcr (2.9.3)
|
37
|
+
webmock (1.20.3)
|
38
|
+
addressable (>= 2.3.6)
|
39
|
+
crack (>= 0.3.2)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
bundler (~> 1.5)
|
46
|
+
faker (~> 1.4)
|
47
|
+
icontact!
|
48
|
+
rake (~> 10.3)
|
49
|
+
rspec (~> 3.0)
|
50
|
+
vcr (~> 2.9)
|
51
|
+
webmock (~> 1.18)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Devin Turner
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
[![Code Climate](https://codeclimate.com/github/L1h3r/icontact/badges/gpa.svg)](https://codeclimate.com/github/L1h3r/icontact)
|
2
|
+
|
3
|
+
Ruby Gem for iContact
|
4
|
+
---
|
5
|
+
|
6
|
+
For more details, read the iContact API documentation: http://www.icontact.com/developerportal/
|
7
|
+
|
8
|
+
Installation
|
9
|
+
---
|
10
|
+
|
11
|
+
TODO
|
12
|
+
|
13
|
+
Examples
|
14
|
+
---
|
15
|
+
|
16
|
+
Test connection to the API
|
17
|
+
```ruby
|
18
|
+
client = IContact::Api.new(username, api_password, app_id)
|
19
|
+
client.ping
|
20
|
+
```
|
21
|
+
|
22
|
+
Get all accounts
|
23
|
+
```ruby
|
24
|
+
client.get_accounts
|
25
|
+
```
|
26
|
+
|
27
|
+
Get all lists
|
28
|
+
```ruby
|
29
|
+
client.get_lists
|
30
|
+
```
|
31
|
+
|
32
|
+
Get a contact
|
33
|
+
```ruby
|
34
|
+
client.get_contact(contact_id)
|
35
|
+
```
|
36
|
+
|
37
|
+
Create a contact
|
38
|
+
```ruby
|
39
|
+
data = { email: 'user@example.com', firstName: 'John', lastName: 'Doe' }
|
40
|
+
client.create_contact(data)
|
41
|
+
```
|
42
|
+
|
43
|
+
Update a contact
|
44
|
+
```ruby
|
45
|
+
data = { firstName: 'Charlie', lastName: 'Brown', contactId: '8955' }
|
46
|
+
client.update_contact(contact_id, data)
|
47
|
+
```
|
48
|
+
|
49
|
+
Delete a contact
|
50
|
+
```ruby
|
51
|
+
client.delete_contact(contact_id)
|
52
|
+
```
|
53
|
+
|
54
|
+
Search for contacts
|
55
|
+
```ruby
|
56
|
+
client.find_contacts(firstName: 'John')
|
57
|
+
```
|
58
|
+
|
59
|
+
Create a subscription
|
60
|
+
```ruby
|
61
|
+
data = { listId: list_id, contactId: contact_id, status: 'normal' }
|
62
|
+
client.create_subscription(data)
|
63
|
+
```
|
64
|
+
|
65
|
+
Contributing
|
66
|
+
---
|
67
|
+
|
68
|
+
1. Fork it
|
69
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
70
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
71
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
72
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/icontact.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.expand_path('../lib/icontact/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.name = 'icontact'
|
6
|
+
gem.version = IContact::VERSION
|
7
|
+
gem.authors = ['Devin Turner']
|
8
|
+
gem.email = ['devin.turner09@gmail.com']
|
9
|
+
gem.summary = 'Ruby wrapper for the iContact API'
|
10
|
+
gem.homepage = 'https://github.com/l1h3r/icontact'
|
11
|
+
gem.license = 'MIT'
|
12
|
+
|
13
|
+
gem.files = `git ls-files`.split($/)
|
14
|
+
gem.executables = gem.files.grep(%r( ^bin/ )).map { |f| File.basename(f) }
|
15
|
+
gem.test_files = gem.files.grep(%r( ^(test|spec|features)/ ))
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
|
18
|
+
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
|
19
|
+
|
20
|
+
gem.add_runtime_dependency 'oj', '~> 2.11'
|
21
|
+
gem.add_runtime_dependency 'faraday', '~> 0.8'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'bundler', '~> 1.5'
|
24
|
+
gem.add_development_dependency 'rake', '~> 10.3'
|
25
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
gem.add_development_dependency 'vcr', '~> 2.9'
|
27
|
+
gem.add_development_dependency 'webmock', '~> 1.18'
|
28
|
+
gem.add_development_dependency 'faker', '~> 1.4'
|
29
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module IContact
|
2
|
+
class Api
|
3
|
+
module ClientFolders
|
4
|
+
|
5
|
+
def get_client_folder(id)
|
6
|
+
response = get(client_folders_path + id)
|
7
|
+
resource(response, 'clientfolder')
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_client_folders(limit = 10000)
|
11
|
+
response = get(client_folders_path + query(limit: limit))
|
12
|
+
resource(response, 'clientfolders')
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_client_folder(data)
|
16
|
+
response = post(client_folders_path, wrap(data))
|
17
|
+
resource(response, 'clientfolders', 0)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_client_folders(data)
|
21
|
+
response = post(client_folders_path, data)
|
22
|
+
resource(response, 'clientfolders')
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_client_folder(id, data)
|
26
|
+
response = post(client_folders_path + id, data)
|
27
|
+
resource(response, 'clientfolder')
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_client_folder!(id, data)
|
31
|
+
response = put(client_folders_path + id, data)
|
32
|
+
resource(response, 'clientfolder')
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_client_folders(data)
|
36
|
+
response = post(client_folders_path, data)
|
37
|
+
resource(response, 'clientfolders')
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def client_folders_path
|
43
|
+
"/icp/a/#{account_id}/c/"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module IContact
|
2
|
+
class Api
|
3
|
+
module Contacts
|
4
|
+
|
5
|
+
def get_contact(id)
|
6
|
+
response = get(contacts_path + id)
|
7
|
+
resource(response, 'contact')
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_contacts(limit = 10000)
|
11
|
+
response = get(contacts_path + query(limit: limit))
|
12
|
+
resource(response, 'contacts')
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_contact(data)
|
16
|
+
response = post(contacts_path, wrap(data))
|
17
|
+
resource(response, 'contacts', 0)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_contacts(data)
|
21
|
+
response = post(contacts_path, data)
|
22
|
+
resource(response, 'contacts')
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_contact(id, data)
|
26
|
+
response = post(contacts_path + id, data)
|
27
|
+
resource(response, 'contact')
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_contact!(id, data)
|
31
|
+
response = put(contacts_path + id, data)
|
32
|
+
resource(response, 'contact')
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_contacts(data)
|
36
|
+
response = post(contacts_path, data)
|
37
|
+
resource(response, 'contacts')
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_contact(id)
|
41
|
+
response = delete(contacts_path + id)
|
42
|
+
resource(response, 'status')
|
43
|
+
end
|
44
|
+
|
45
|
+
def find_contacts(data)
|
46
|
+
data.merge!(limit: 10000) unless data.has_key?(:limit)
|
47
|
+
response = get(contacts_path + query(data))
|
48
|
+
resource(response, 'contacts')
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def contacts_path
|
54
|
+
"/icp/a/#{account_id}/c/#{client_id}/contacts/"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module IContact
|
2
|
+
class Api
|
3
|
+
module CustomFields
|
4
|
+
|
5
|
+
def get_custom_field(id)
|
6
|
+
response = get(custom_fields_path + id)
|
7
|
+
resource(response, 'customfield')
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_custom_fields(limit = 10000)
|
11
|
+
response = get(custom_fields_path + query(limit: limit))
|
12
|
+
resource(response, 'customfields')
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_custom_field(data)
|
16
|
+
response = post(custom_fields_path, wrap(data))
|
17
|
+
resource(response, 'customfields', 0)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_custom_fields(data)
|
21
|
+
response = post(custom_fields_path, data)
|
22
|
+
resource(response, 'customfields')
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_custom_field(id, data)
|
26
|
+
response = post(custom_fields_path + id, data)
|
27
|
+
resource(response, 'customfield')
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_custom_field!(id, data)
|
31
|
+
response = put(custom_fields_path + id, data)
|
32
|
+
resource(response, 'customfield')
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_custom_fields(data)
|
36
|
+
response = post(custom_fields_path, data)
|
37
|
+
resource(response, 'customfields')
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_custom_field(id)
|
41
|
+
response = delete(custom_fields_path + id)
|
42
|
+
resource(response, 'status')
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def custom_fields_path
|
48
|
+
"/icp/a/#{account_id}/c/#{client_id}/customfields/"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module IContact
|
2
|
+
class Api
|
3
|
+
module Lists
|
4
|
+
|
5
|
+
def get_list(id)
|
6
|
+
response = get(lists_path + id)
|
7
|
+
resource(response, 'list')
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_lists(limit = 10000)
|
11
|
+
response = get(lists_path + query(limit: limit))
|
12
|
+
resource(response, 'lists')
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_list(data)
|
16
|
+
response = post(lists_path, wrap(data))
|
17
|
+
resource(response, 'lists', 0)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_lists(data)
|
21
|
+
response = post(lists_path, data)
|
22
|
+
resource(response, 'lists')
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_list(id, data)
|
26
|
+
response = post(lists_path + id, data)
|
27
|
+
resource(response, 'list')
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_list!(id, data)
|
31
|
+
response = put(lists_path + id, data)
|
32
|
+
resource(response, 'list')
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_lists(data)
|
36
|
+
response = post(lists_path, data)
|
37
|
+
resource(response, 'lists')
|
38
|
+
end
|
39
|
+
|
40
|
+
def delete_list(id)
|
41
|
+
response = delete(lists_path + id)
|
42
|
+
resource(response, 'status')
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def lists_path
|
48
|
+
"/icp/a/#{account_id}/c/#{client_id}/lists/"
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module IContact
|
2
|
+
class Api
|
3
|
+
module Subscriptions
|
4
|
+
|
5
|
+
def get_subscription(id)
|
6
|
+
response = get(subscriptions_path + id)
|
7
|
+
resource(response, 'subscription')
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_subscriptions(limit = 10000)
|
11
|
+
response = get(subscriptions_path + query(limit: limit))
|
12
|
+
resource(response, 'subscriptions')
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_subscription(data)
|
16
|
+
response = post(subscriptions_path, wrap(data))
|
17
|
+
resource(response, 'subscriptions', 0)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_subscriptions(data)
|
21
|
+
response = post(subscriptions_path, data)
|
22
|
+
resource(response, 'subscriptions')
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_subscription(id, data)
|
26
|
+
response = post(subscriptions_path + id, data)
|
27
|
+
resource(response, 'subscription')
|
28
|
+
end
|
29
|
+
|
30
|
+
def move_contact(id, data)
|
31
|
+
response = put(subscriptions_path + id, data)
|
32
|
+
resource(response, 'subscription')
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_subscriptions(data)
|
36
|
+
response = post(subscriptions_path, data)
|
37
|
+
resource(response, 'subscriptions')
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def subscriptions_path
|
43
|
+
"/icp/a/#{account_id}/c/#{client_id}/subscriptions/"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module IContact
|
2
|
+
class Api
|
3
|
+
module Users
|
4
|
+
|
5
|
+
def get_user(id)
|
6
|
+
response = get(users_path + id)
|
7
|
+
resource(response, 'user')
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_users(limit = 10000)
|
11
|
+
response = get(users_path + query(limit: limit))
|
12
|
+
resource(response, 'users')
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_user(data)
|
16
|
+
response = post(users_path, wrap(data))
|
17
|
+
resource(response, 'users', 0)
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_users(data)
|
21
|
+
response = post(users_path, data)
|
22
|
+
resource(response, 'users')
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_user(id, data)
|
26
|
+
response = post(users_path + id, data)
|
27
|
+
resource(response, 'user')
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_users(data)
|
31
|
+
response = post(users_path, data)
|
32
|
+
resource(response, 'users')
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete_user(id)
|
36
|
+
response = delete(users_path + id)
|
37
|
+
resource(response, 'status')
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def users_path
|
43
|
+
"/icp/a/#{account_id}/users/"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/icontact/api.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'oj'
|
3
|
+
|
4
|
+
require_relative 'connection'
|
5
|
+
require_relative 'api/client_folders'
|
6
|
+
require_relative 'api/contacts'
|
7
|
+
require_relative 'api/custom_fields'
|
8
|
+
require_relative 'api/lists'
|
9
|
+
require_relative 'api/subscriptions'
|
10
|
+
require_relative 'api/users'
|
11
|
+
|
12
|
+
module IContact
|
13
|
+
class Api
|
14
|
+
include Connection
|
15
|
+
include ClientFolders
|
16
|
+
include Contacts
|
17
|
+
include CustomFields
|
18
|
+
include Lists
|
19
|
+
include Subscriptions
|
20
|
+
include Users
|
21
|
+
|
22
|
+
attr_accessor :account_id, :client_id
|
23
|
+
attr_reader :app_id, :username, :password, :accounts, :clients
|
24
|
+
|
25
|
+
def initialize(username, password, app_id)
|
26
|
+
@app_id = app_id
|
27
|
+
@username = username
|
28
|
+
@password = password
|
29
|
+
@account_id = get_accounts.first['accountId']
|
30
|
+
@client_id = get_clients.first['clientFolderId']
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_accounts
|
34
|
+
response = get('/icp/a/')
|
35
|
+
@accounts = resource(response, 'accounts')
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_clients
|
39
|
+
response = get("/icp/a/#{account_id}/c")
|
40
|
+
@clients = resource(response, 'clientfolders')
|
41
|
+
end
|
42
|
+
|
43
|
+
def ping
|
44
|
+
return false if account_id.nil? || client_id.nil?
|
45
|
+
url = "#{BASE_URL}/icp/a/#{account_id}/c/#{client_id}/"
|
46
|
+
response = connection.run_request(:get, url, '', headers)
|
47
|
+
response.status.to_i == 200
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def query(data)
|
53
|
+
query = data.map do |key, value|
|
54
|
+
CGI.escape(key.to_s) + '=' + CGI.escape(value.to_s)
|
55
|
+
end.sort * '&'
|
56
|
+
"?#{query}"
|
57
|
+
end
|
58
|
+
|
59
|
+
def wrap(data)
|
60
|
+
return [] if data.nil?
|
61
|
+
data.respond_to?(:to_ary) ? data.to_ary : [data]
|
62
|
+
end
|
63
|
+
|
64
|
+
def resource(data, field, position = nil)
|
65
|
+
if data.empty? || data[field].nil?
|
66
|
+
[]
|
67
|
+
elsif position.nil?
|
68
|
+
data[field]
|
69
|
+
else
|
70
|
+
data[field][position]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module IContact
|
2
|
+
module Connection
|
3
|
+
BASE_URL = 'https://app.icontact.com'
|
4
|
+
|
5
|
+
DEFAULT_HEADERS = {
|
6
|
+
'API-Version' => '2.2',
|
7
|
+
'Accept' => 'application/json',
|
8
|
+
'Content-Type' => 'application/json'
|
9
|
+
}
|
10
|
+
|
11
|
+
def get(path)
|
12
|
+
request(:get, path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def post(path, data)
|
16
|
+
request(:post, path, data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def put(path, data)
|
20
|
+
request(:put, path, data)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(path)
|
24
|
+
request(:delete, path)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def connection
|
30
|
+
@connection ||= Faraday.new do |faraday|
|
31
|
+
# faraday.response :logger
|
32
|
+
faraday.request :url_encoded
|
33
|
+
faraday.adapter Faraday.default_adapter
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def headers
|
38
|
+
{
|
39
|
+
'API-Appid' => app_id,
|
40
|
+
'API-Username' => username,
|
41
|
+
'API-Password' => password
|
42
|
+
}.merge(DEFAULT_HEADERS)
|
43
|
+
end
|
44
|
+
|
45
|
+
def request(method, path, data = {})
|
46
|
+
request = data.empty? ? '' : Oj.dump(data, mode: :compat)
|
47
|
+
response = connection.run_request(method, BASE_URL + path, request, headers)
|
48
|
+
handle_response(response)
|
49
|
+
end
|
50
|
+
|
51
|
+
def handle_response(response)
|
52
|
+
case response.status.to_i
|
53
|
+
when 200..299
|
54
|
+
response_success(response)
|
55
|
+
when 404 # Return empty array instead of throwing an error
|
56
|
+
[]
|
57
|
+
else
|
58
|
+
IContact::ErrorHandler.new(response)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def response_success(response)
|
63
|
+
if response.env[:method] == :delete
|
64
|
+
{ 'status' => true }
|
65
|
+
elsif !response.body.strip.empty?
|
66
|
+
Oj.load(response.body, mode: :compat)
|
67
|
+
else
|
68
|
+
[]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class IContactError < StandardError
|
2
|
+
def initialize(message)
|
3
|
+
super(message)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
# http://www.icontact.com/developerportal/documentation/http-status-codes/
|
8
|
+
module IContact
|
9
|
+
class IContact::Forbidden < IContactError; end
|
10
|
+
|
11
|
+
class IContact::BadRequest < IContactError; end
|
12
|
+
|
13
|
+
class IContact::NotAcceptable < IContactError; end
|
14
|
+
|
15
|
+
class IContact::NotAuthorized < IContactError; end
|
16
|
+
|
17
|
+
class IContact::InternalServer < IContactError; end
|
18
|
+
|
19
|
+
class IContact::NotImplemented < IContactError; end
|
20
|
+
|
21
|
+
class IContact::PaymentRequest < IContactError; end
|
22
|
+
|
23
|
+
class IContact::MethodNotAllowed < IContactError; end
|
24
|
+
|
25
|
+
class IContact::InsufficientSpace < IContactError; end
|
26
|
+
|
27
|
+
class IContact::ServiceUnavailable < IContactError; end
|
28
|
+
|
29
|
+
class IContact::UnsupportedMediaType < IContactError; end
|
30
|
+
|
31
|
+
class ErrorHandler
|
32
|
+
ERRORS = {
|
33
|
+
400 => IContact::BadRequest,
|
34
|
+
401 => IContact::NotAuthorized,
|
35
|
+
402 => IContact::PaymentRequest,
|
36
|
+
403 => IContact::Forbidden,
|
37
|
+
405 => IContact::MethodNotAllowed,
|
38
|
+
406 => IContact::NotAcceptable,
|
39
|
+
415 => IContact::UnsupportedMediaType,
|
40
|
+
500 => IContact::InternalServer,
|
41
|
+
501 => IContact::NotImplemented,
|
42
|
+
503 => IContact::ServiceUnavailable,
|
43
|
+
507 => IContact::InsufficientSpace
|
44
|
+
}
|
45
|
+
|
46
|
+
def initialize(response)
|
47
|
+
error_class = ERRORS[response.status.to_i]
|
48
|
+
message = Oj.load(response.body)['errors']
|
49
|
+
|
50
|
+
if error_class
|
51
|
+
raise error_class.new(message)
|
52
|
+
else
|
53
|
+
raise IContactError.new("#{response.status}: #{message}")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
data/lib/icontact.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IContact::Api::Contacts do
|
4
|
+
|
5
|
+
let(:contact_id) { '9316234' }
|
6
|
+
|
7
|
+
describe '#get_contact' do
|
8
|
+
it 'returns a single contact' do
|
9
|
+
VCR.use_cassette('get_contact') do
|
10
|
+
contact = client.get_contact(contact_id)
|
11
|
+
expect(contact).to be_a(Hash)
|
12
|
+
expect(contact).not_to be_empty
|
13
|
+
expect(contact['contactId']).to eq(contact_id)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#get_contacts' do
|
19
|
+
it 'returns all contacts' do
|
20
|
+
VCR.use_cassette('get_contacts') do
|
21
|
+
contacts = client.get_contacts
|
22
|
+
expect(contacts).to be_a(Array)
|
23
|
+
expect(contacts).not_to be_empty
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#create_contact' do
|
29
|
+
it 'creates and returns a new contact' do
|
30
|
+
VCR.use_cassette('create_contact') do
|
31
|
+
data = {
|
32
|
+
firstName: Faker::Name.first_name,
|
33
|
+
lastName: Faker::Name.last_name,
|
34
|
+
email: Faker::Internet.email
|
35
|
+
}
|
36
|
+
contact = client.create_contact(data)
|
37
|
+
expect(contact).to be_a(Hash)
|
38
|
+
expect(contact).not_to be_empty
|
39
|
+
expect(contact['contactId']).not_to be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#create_contacts' do
|
45
|
+
it 'creats a returns a collection of new contacts' do
|
46
|
+
VCR.use_cassette('create_contacts') do
|
47
|
+
data = [{
|
48
|
+
firstName: Faker::Name.first_name,
|
49
|
+
lastName: Faker::Name.last_name,
|
50
|
+
email: Faker::Internet.email
|
51
|
+
},{
|
52
|
+
firstName: Faker::Name.first_name,
|
53
|
+
lastName: Faker::Name.last_name,
|
54
|
+
email: Faker::Internet.email
|
55
|
+
}]
|
56
|
+
contacts = client.create_contacts(data)
|
57
|
+
expect(contacts).to be_a(Array)
|
58
|
+
expect(contacts).not_to be_empty
|
59
|
+
expect(contacts.count).to eq(2)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#find_contacts' do
|
65
|
+
context 'when searching by first name' do
|
66
|
+
it 'returns all contacts that match the given params' do
|
67
|
+
VCR.use_cassette('find_contacts_first_name') do
|
68
|
+
contacts = client.find_contacts(firstName: 'Charlie')
|
69
|
+
expect(contacts).to be_a(Array)
|
70
|
+
expect(contacts).not_to be_empty
|
71
|
+
expect(contacts.first['firstName']).to eq('Charlie')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when searching by last name' do
|
77
|
+
it 'returns all contacts that match the given params' do
|
78
|
+
VCR.use_cassette('find_contacts_last_name') do
|
79
|
+
contacts = client.find_contacts(lastName: 'Br*')
|
80
|
+
expect(contacts).to be_a(Array)
|
81
|
+
expect(contacts).not_to be_empty
|
82
|
+
expect(contacts.first['lastName']).to start_with('Br')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IContact::Api do
|
4
|
+
|
5
|
+
describe '#get_accounts' do
|
6
|
+
it 'returns all accounts for the user' do
|
7
|
+
VCR.use_cassette('get_accounts') do
|
8
|
+
accounts = client.get_accounts
|
9
|
+
expect(accounts).to be_a(Array)
|
10
|
+
expect(accounts).not_to be_empty
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#get_clients' do
|
16
|
+
it 'returns all clients for the account' do
|
17
|
+
VCR.use_cassette('get_clients') do
|
18
|
+
clients = client.get_clients
|
19
|
+
expect(clients).to be_a(Array)
|
20
|
+
expect(clients).not_to be_empty
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#ping' do
|
26
|
+
it 'connects to iContact' do
|
27
|
+
VCR.use_cassette('ping') do
|
28
|
+
expect(client.ping).to eq(true)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
require 'faker'
|
3
|
+
require 'icontact'
|
4
|
+
require 'yaml'
|
5
|
+
require 'vcr'
|
6
|
+
|
7
|
+
def options
|
8
|
+
path = File.join(File.dirname(__FILE__), '../config/test.yml')
|
9
|
+
@options ||= YAML::load_file(File.expand_path(path))
|
10
|
+
end
|
11
|
+
|
12
|
+
def client
|
13
|
+
@client ||= IContact::Api.new(options['username'], options['password'], options['app_id'])
|
14
|
+
end
|
15
|
+
|
16
|
+
VCR.configure do |config|
|
17
|
+
config.default_cassette_options = { record: :new_episodes }
|
18
|
+
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
|
19
|
+
config.debug_logger = File.open('log/vcr.log', 'w')
|
20
|
+
config.hook_into :webmock
|
21
|
+
|
22
|
+
config.filter_sensitive_data('<-APP-ID->') { options['app_id'] }
|
23
|
+
config.filter_sensitive_data('<-API-USERNAME->') { options['username'] }
|
24
|
+
config.filter_sensitive_data('<-API-PASSWORD->') { options['password'] }
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.configure do |config|
|
28
|
+
config.expect_with :rspec do |c|
|
29
|
+
c.syntax = :expect
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: icontact
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Devin Turner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
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.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.18'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.18'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: faker
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.4'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.4'
|
125
|
+
description:
|
126
|
+
email:
|
127
|
+
- devin.turner09@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- Gemfile
|
135
|
+
- Gemfile.lock
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- config/test.yml.example
|
140
|
+
- icontact.gemspec
|
141
|
+
- lib/icontact.rb
|
142
|
+
- lib/icontact/api.rb
|
143
|
+
- lib/icontact/api/client_folders.rb
|
144
|
+
- lib/icontact/api/contacts.rb
|
145
|
+
- lib/icontact/api/custom_fields.rb
|
146
|
+
- lib/icontact/api/lists.rb
|
147
|
+
- lib/icontact/api/subscriptions.rb
|
148
|
+
- lib/icontact/api/users.rb
|
149
|
+
- lib/icontact/connection.rb
|
150
|
+
- lib/icontact/errors.rb
|
151
|
+
- lib/icontact/version.rb
|
152
|
+
- spec/icontact/api/contacts_spec.rb
|
153
|
+
- spec/icontact/api_spec.rb
|
154
|
+
- spec/icontact_spec.rb
|
155
|
+
- spec/spec_helper.rb
|
156
|
+
homepage: https://github.com/l1h3r/icontact
|
157
|
+
licenses:
|
158
|
+
- MIT
|
159
|
+
metadata: {}
|
160
|
+
post_install_message:
|
161
|
+
rdoc_options: []
|
162
|
+
require_paths:
|
163
|
+
- lib
|
164
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.3.6
|
174
|
+
requirements: []
|
175
|
+
rubyforge_project:
|
176
|
+
rubygems_version: 2.4.2
|
177
|
+
signing_key:
|
178
|
+
specification_version: 4
|
179
|
+
summary: Ruby wrapper for the iContact API
|
180
|
+
test_files: []
|