icontact 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/Gemfile.lock +1 -15
- data/icontact.gemspec +3 -9
- data/lib/icontact/api/accounts.rb +30 -0
- data/lib/icontact/api/client_folders.rb +3 -0
- data/lib/icontact/api/contacts.rb +6 -1
- data/lib/icontact/api/custom_fields.rb +5 -1
- data/lib/icontact/api/lists.rb +5 -1
- data/lib/icontact/api/subscriptions.rb +4 -1
- data/lib/icontact/api/users.rb +3 -0
- data/lib/icontact/api.rb +16 -24
- data/lib/icontact/connection.rb +2 -2
- data/lib/icontact/errors.rb +3 -3
- data/lib/icontact.rb +3 -2
- data/spec/icontact/icontact_spec.rb +75 -0
- data/spec/spec_helper.rb +8 -19
- metadata +4 -49
- data/config/test.yml.example +0 -3
- data/lib/icontact/version.rb +0 -3
- data/spec/icontact/api/contacts_spec.rb +0 -88
- data/spec/icontact/api_spec.rb +0 -33
- data/spec/icontact_spec.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3a505fef9d111e1ef537217756169f65c579596
|
4
|
+
data.tar.gz: 06965beb80528dd7cf36f572102d2e10b66552f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be07d42d4083962a9f58e951f22c3c6111113b9c4bdbd865b69c12794a76fc73dd166b8836521fb9ffe9c02f9fb1f9906b1a08ceaceda038e1c0fd4bf18720d8
|
7
|
+
data.tar.gz: 3d7d61dfb0e167e2333157d1c78d6f9c476bfb0c6b84034aef12f42ba1bfda4554d0f7233f8689cb453dd00ceb0ad68577df7ab9fb0619a10739ec49fcde49f3
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,16 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
icontact (0.0.
|
4
|
+
icontact (0.0.3)
|
5
5
|
faraday (~> 0.8)
|
6
6
|
oj (~> 2.11)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
addressable (2.3.6)
|
12
|
-
crack (0.4.2)
|
13
|
-
safe_yaml (~> 1.0.0)
|
14
11
|
diff-lcs (1.2.5)
|
15
|
-
faker (1.4.3)
|
16
|
-
i18n (~> 0.5)
|
17
12
|
faraday (0.9.0)
|
18
13
|
multipart-post (>= 1.2, < 3)
|
19
|
-
i18n (0.6.11)
|
20
14
|
multipart-post (2.0.0)
|
21
15
|
oj (2.11.1)
|
22
16
|
rake (10.3.2)
|
@@ -32,20 +26,12 @@ GEM
|
|
32
26
|
rspec-mocks (3.1.3)
|
33
27
|
rspec-support (~> 3.1.0)
|
34
28
|
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
29
|
|
41
30
|
PLATFORMS
|
42
31
|
ruby
|
43
32
|
|
44
33
|
DEPENDENCIES
|
45
34
|
bundler (~> 1.5)
|
46
|
-
faker (~> 1.4)
|
47
35
|
icontact!
|
48
36
|
rake (~> 10.3)
|
49
37
|
rspec (~> 3.0)
|
50
|
-
vcr (~> 2.9)
|
51
|
-
webmock (~> 1.18)
|
data/icontact.gemspec
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
require File.expand_path('../lib/icontact/version', __FILE__)
|
3
|
-
|
4
2
|
Gem::Specification.new do |gem|
|
5
3
|
gem.name = 'icontact'
|
6
|
-
gem.version =
|
4
|
+
gem.version = '0.0.3'
|
7
5
|
gem.authors = ['Devin Turner']
|
8
6
|
gem.email = ['devin.turner09@gmail.com']
|
9
7
|
gem.summary = 'Ruby wrapper for the iContact API'
|
@@ -17,13 +15,9 @@ Gem::Specification.new do |gem|
|
|
17
15
|
|
18
16
|
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
|
19
17
|
|
20
|
-
gem.add_runtime_dependency 'oj',
|
21
|
-
gem.add_runtime_dependency 'faraday',
|
22
|
-
|
18
|
+
gem.add_runtime_dependency 'oj', '~> 2.11'
|
19
|
+
gem.add_runtime_dependency 'faraday', '~> 0.8'
|
23
20
|
gem.add_development_dependency 'bundler', '~> 1.5'
|
24
21
|
gem.add_development_dependency 'rake', '~> 10.3'
|
25
22
|
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
23
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module IContact
|
2
|
+
class Api
|
3
|
+
module Accounts
|
4
|
+
|
5
|
+
def get_account(id)
|
6
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
7
|
+
response = get(accounts_path + id)
|
8
|
+
resource(response, 'account')
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_accounts
|
12
|
+
response = get(accounts_path)
|
13
|
+
resource(response, 'accounts')
|
14
|
+
end
|
15
|
+
|
16
|
+
def update_account(id, data)
|
17
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
18
|
+
response = post(accounts_path + id, data)
|
19
|
+
resource(response, 'account')
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def accounts_path
|
25
|
+
'/icp/a/'
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -3,6 +3,7 @@ module IContact
|
|
3
3
|
module ClientFolders
|
4
4
|
|
5
5
|
def get_client_folder(id)
|
6
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
6
7
|
response = get(client_folders_path + id)
|
7
8
|
resource(response, 'clientfolder')
|
8
9
|
end
|
@@ -23,11 +24,13 @@ module IContact
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def update_client_folder(id, data)
|
27
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
26
28
|
response = post(client_folders_path + id, data)
|
27
29
|
resource(response, 'clientfolder')
|
28
30
|
end
|
29
31
|
|
30
32
|
def update_client_folder!(id, data)
|
33
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
31
34
|
response = put(client_folders_path + id, data)
|
32
35
|
resource(response, 'clientfolder')
|
33
36
|
end
|
@@ -3,6 +3,7 @@ module IContact
|
|
3
3
|
module Contacts
|
4
4
|
|
5
5
|
def get_contact(id)
|
6
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
6
7
|
response = get(contacts_path + id)
|
7
8
|
resource(response, 'contact')
|
8
9
|
end
|
@@ -23,11 +24,13 @@ module IContact
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def update_contact(id, data)
|
27
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
26
28
|
response = post(contacts_path + id, data)
|
27
29
|
resource(response, 'contact')
|
28
30
|
end
|
29
31
|
|
30
32
|
def update_contact!(id, data)
|
33
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
31
34
|
response = put(contacts_path + id, data)
|
32
35
|
resource(response, 'contact')
|
33
36
|
end
|
@@ -38,11 +41,13 @@ module IContact
|
|
38
41
|
end
|
39
42
|
|
40
43
|
def delete_contact(id)
|
44
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
41
45
|
response = delete(contacts_path + id)
|
42
46
|
resource(response, 'status')
|
43
47
|
end
|
44
48
|
|
45
49
|
def find_contacts(data)
|
50
|
+
raise ArgumentError, 'Data cannot be empty' if data.nil? || data.empty?
|
46
51
|
data.merge!(limit: 10000) unless data.has_key?(:limit)
|
47
52
|
response = get(contacts_path + query(data))
|
48
53
|
resource(response, 'contacts')
|
@@ -51,7 +56,7 @@ module IContact
|
|
51
56
|
private
|
52
57
|
|
53
58
|
def contacts_path
|
54
|
-
"/icp/a/#{account_id}/c/#{
|
59
|
+
"/icp/a/#{account_id}/c/#{client_folder_id}/contacts/"
|
55
60
|
end
|
56
61
|
|
57
62
|
end
|
@@ -3,6 +3,7 @@ module IContact
|
|
3
3
|
module CustomFields
|
4
4
|
|
5
5
|
def get_custom_field(id)
|
6
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
6
7
|
response = get(custom_fields_path + id)
|
7
8
|
resource(response, 'customfield')
|
8
9
|
end
|
@@ -23,11 +24,13 @@ module IContact
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def update_custom_field(id, data)
|
27
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
26
28
|
response = post(custom_fields_path + id, data)
|
27
29
|
resource(response, 'customfield')
|
28
30
|
end
|
29
31
|
|
30
32
|
def update_custom_field!(id, data)
|
33
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
31
34
|
response = put(custom_fields_path + id, data)
|
32
35
|
resource(response, 'customfield')
|
33
36
|
end
|
@@ -38,6 +41,7 @@ module IContact
|
|
38
41
|
end
|
39
42
|
|
40
43
|
def delete_custom_field(id)
|
44
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
41
45
|
response = delete(custom_fields_path + id)
|
42
46
|
resource(response, 'status')
|
43
47
|
end
|
@@ -45,7 +49,7 @@ module IContact
|
|
45
49
|
private
|
46
50
|
|
47
51
|
def custom_fields_path
|
48
|
-
"/icp/a/#{account_id}/c/#{
|
52
|
+
"/icp/a/#{account_id}/c/#{client_folder_id}/customfields/"
|
49
53
|
end
|
50
54
|
|
51
55
|
end
|
data/lib/icontact/api/lists.rb
CHANGED
@@ -3,6 +3,7 @@ module IContact
|
|
3
3
|
module Lists
|
4
4
|
|
5
5
|
def get_list(id)
|
6
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
6
7
|
response = get(lists_path + id)
|
7
8
|
resource(response, 'list')
|
8
9
|
end
|
@@ -23,11 +24,13 @@ module IContact
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def update_list(id, data)
|
27
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
26
28
|
response = post(lists_path + id, data)
|
27
29
|
resource(response, 'list')
|
28
30
|
end
|
29
31
|
|
30
32
|
def update_list!(id, data)
|
33
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
31
34
|
response = put(lists_path + id, data)
|
32
35
|
resource(response, 'list')
|
33
36
|
end
|
@@ -38,6 +41,7 @@ module IContact
|
|
38
41
|
end
|
39
42
|
|
40
43
|
def delete_list(id)
|
44
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
41
45
|
response = delete(lists_path + id)
|
42
46
|
resource(response, 'status')
|
43
47
|
end
|
@@ -45,7 +49,7 @@ module IContact
|
|
45
49
|
private
|
46
50
|
|
47
51
|
def lists_path
|
48
|
-
"/icp/a/#{account_id}/c/#{
|
52
|
+
"/icp/a/#{account_id}/c/#{client_folder_id}/lists/"
|
49
53
|
end
|
50
54
|
|
51
55
|
end
|
@@ -3,6 +3,7 @@ module IContact
|
|
3
3
|
module Subscriptions
|
4
4
|
|
5
5
|
def get_subscription(id)
|
6
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
6
7
|
response = get(subscriptions_path + id)
|
7
8
|
resource(response, 'subscription')
|
8
9
|
end
|
@@ -23,11 +24,13 @@ module IContact
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def update_subscription(id, data)
|
27
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
26
28
|
response = post(subscriptions_path + id, data)
|
27
29
|
resource(response, 'subscription')
|
28
30
|
end
|
29
31
|
|
30
32
|
def move_contact(id, data)
|
33
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
31
34
|
response = put(subscriptions_path + id, data)
|
32
35
|
resource(response, 'subscription')
|
33
36
|
end
|
@@ -40,7 +43,7 @@ module IContact
|
|
40
43
|
private
|
41
44
|
|
42
45
|
def subscriptions_path
|
43
|
-
"/icp/a/#{account_id}/c/#{
|
46
|
+
"/icp/a/#{account_id}/c/#{client_folder_id}/subscriptions/"
|
44
47
|
end
|
45
48
|
|
46
49
|
end
|
data/lib/icontact/api/users.rb
CHANGED
@@ -3,6 +3,7 @@ module IContact
|
|
3
3
|
module Users
|
4
4
|
|
5
5
|
def get_user(id)
|
6
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
6
7
|
response = get(users_path + id)
|
7
8
|
resource(response, 'user')
|
8
9
|
end
|
@@ -23,6 +24,7 @@ module IContact
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def update_user(id, data)
|
27
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
26
28
|
response = post(users_path + id, data)
|
27
29
|
resource(response, 'user')
|
28
30
|
end
|
@@ -33,6 +35,7 @@ module IContact
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def delete_user(id)
|
38
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
36
39
|
response = delete(users_path + id)
|
37
40
|
resource(response, 'status')
|
38
41
|
end
|
data/lib/icontact/api.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'oj'
|
3
|
-
|
4
1
|
require_relative 'connection'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
require_relative 'api/subscriptions'
|
10
|
-
require_relative 'api/users'
|
2
|
+
|
3
|
+
Dir[File.dirname(__FILE__) + '/api/*'].each do |file|
|
4
|
+
require file
|
5
|
+
end
|
11
6
|
|
12
7
|
module IContact
|
13
8
|
class Api
|
14
9
|
include Connection
|
10
|
+
include Accounts
|
15
11
|
include ClientFolders
|
16
12
|
include Contacts
|
17
13
|
include CustomFields
|
@@ -19,30 +15,26 @@ module IContact
|
|
19
15
|
include Subscriptions
|
20
16
|
include Users
|
21
17
|
|
22
|
-
attr_accessor :account_id, :
|
23
|
-
attr_reader :app_id, :username, :password
|
18
|
+
attr_accessor :account_id, :client_folder_id
|
19
|
+
attr_reader :app_id, :username, :password
|
24
20
|
|
25
21
|
def initialize(username, password, app_id)
|
22
|
+
raise ArgumentError, 'Username cannot be nil' if username.nil?
|
23
|
+
raise ArgumentError, 'Password cannot be nil' if password.nil?
|
24
|
+
raise ArgumentError, 'App ID cannot be nil' if app_id.nil?
|
25
|
+
|
26
26
|
@app_id = app_id
|
27
27
|
@username = username
|
28
28
|
@password = password
|
29
29
|
@account_id = get_accounts.first['accountId']
|
30
|
-
|
31
|
-
|
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')
|
30
|
+
raise IContact::NotAuthorized, 'Unable to find account' if account_id.nil?
|
31
|
+
@client_folder_id = get_client_folders.first['clientFolderId']
|
32
|
+
raise IContact::NotAuthorized, 'Unable to find client folder' if client_folder_id.nil?
|
41
33
|
end
|
42
34
|
|
43
35
|
def ping
|
44
|
-
return false if account_id.nil? ||
|
45
|
-
url = "#{BASE_URL}/icp/a/#{account_id}/c/#{
|
36
|
+
return false if account_id.nil? || client_folder_id.nil?
|
37
|
+
url = "#{BASE_URL}/icp/a/#{account_id}/c/#{client_folder_id}/"
|
46
38
|
response = connection.run_request(:get, url, '', headers)
|
47
39
|
response.status.to_i == 200
|
48
40
|
end
|
data/lib/icontact/connection.rb
CHANGED
@@ -13,10 +13,12 @@ module IContact
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def post(path, data)
|
16
|
+
raise ArgumentError, 'Data cannot be empty' if data.nil? || data.empty?
|
16
17
|
request(:post, path, data)
|
17
18
|
end
|
18
19
|
|
19
20
|
def put(path, data)
|
21
|
+
raise ArgumentError, 'Data cannot be empty' if data.nil? || data.empty?
|
20
22
|
request(:put, path, data)
|
21
23
|
end
|
22
24
|
|
@@ -52,8 +54,6 @@ module IContact
|
|
52
54
|
case response.status.to_i
|
53
55
|
when 200..299
|
54
56
|
response_success(response)
|
55
|
-
when 404 # Return empty array instead of throwing an error
|
56
|
-
[]
|
57
57
|
else
|
58
58
|
IContact::ErrorHandler.new(response)
|
59
59
|
end
|
data/lib/icontact/errors.rb
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
class IContactError < StandardError
|
2
|
-
def initialize(message)
|
3
|
-
super(message)
|
4
|
-
end
|
5
2
|
end
|
6
3
|
|
7
4
|
# http://www.icontact.com/developerportal/documentation/http-status-codes/
|
@@ -20,6 +17,8 @@ module IContact
|
|
20
17
|
|
21
18
|
class IContact::PaymentRequest < IContactError; end
|
22
19
|
|
20
|
+
class IContact::ResourceNotFound < IContactError; end
|
21
|
+
|
23
22
|
class IContact::MethodNotAllowed < IContactError; end
|
24
23
|
|
25
24
|
class IContact::InsufficientSpace < IContactError; end
|
@@ -34,6 +33,7 @@ module IContact
|
|
34
33
|
401 => IContact::NotAuthorized,
|
35
34
|
402 => IContact::PaymentRequest,
|
36
35
|
403 => IContact::Forbidden,
|
36
|
+
404 => IContact::ResourceNotFound,
|
37
37
|
405 => IContact::MethodNotAllowed,
|
38
38
|
406 => IContact::NotAcceptable,
|
39
39
|
415 => IContact::UnsupportedMediaType,
|
data/lib/icontact.rb
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe IContact::Api do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@username = options['username']
|
7
|
+
@password = options['password']
|
8
|
+
@app_id = options['app_id']
|
9
|
+
@client = IContact::Api.new(@username, @password, @app_id)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#initialize' do
|
13
|
+
context 'with valid attributes' do
|
14
|
+
it 'sets a username' do
|
15
|
+
expect(@client.username).to eq(@username)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'sets a password' do
|
19
|
+
expect(@client.password).to eq(@password)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'sets an app id' do
|
23
|
+
expect(@client.app_id).to eq(@app_id)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'with invalid attributes' do
|
28
|
+
it 'raises an error when username is nil' do
|
29
|
+
expect { IContact::Api.new(nil, @password, @app_id) }.to raise_error(ArgumentError)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'raises an error when password is nil' do
|
33
|
+
expect { IContact::Api.new(@username, nil, @app_id) }.to raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'raises an error when app id is nil' do
|
37
|
+
expect { IContact::Api.new(@username, @password, nil) }.to raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#ping' do
|
43
|
+
context 'with valid account_id and client_folder_id' do
|
44
|
+
it 'connects to the icontact api' do
|
45
|
+
expect(@client.ping).to eq(true)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with invalid account_id or client_folder_id' do
|
50
|
+
it 'returns false with invalid account_id' do
|
51
|
+
@client.account_id = 'hello'
|
52
|
+
expect(@client.ping).to eq(false)
|
53
|
+
end
|
54
|
+
it 'returns false with invalid client_folder_id' do
|
55
|
+
@client.client_folder_id = 'tacos'
|
56
|
+
expect(@client.ping).to eq(false)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'attributes' do
|
62
|
+
it 'sets a new account id' do
|
63
|
+
account_id = @client.get_accounts.sample['accountId']
|
64
|
+
@client.account_id = account_id
|
65
|
+
expect(@client.account_id).to eq(account_id)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'sets a new client folder id' do
|
69
|
+
client_folder_id = @client.get_client_folders.sample['clientFolderId']
|
70
|
+
@client.client_folder_id = client_folder_id
|
71
|
+
expect(@client.client_folder_id).to eq(client_folder_id)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,27 +1,16 @@
|
|
1
|
-
require 'webmock/rspec'
|
2
|
-
require 'faker'
|
3
1
|
require 'icontact'
|
4
2
|
require 'yaml'
|
5
|
-
require 'vcr'
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
# Set your username, password, and app id in spec/config.yml
|
5
|
+
# EXAMPLE:
|
6
|
+
# username: 'user@example.com'
|
7
|
+
# password: 'your-api-password'
|
8
|
+
# app_id: 'your-app-id'
|
11
9
|
|
12
|
-
def client
|
13
|
-
@client ||= IContact::Api.new(options['username'], options['password'], options['app_id'])
|
14
|
-
end
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
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'] }
|
11
|
+
def options
|
12
|
+
path = File.join(File.dirname(__FILE__), 'config.yml')
|
13
|
+
@options ||= YAML::load_file(path)
|
25
14
|
end
|
26
15
|
|
27
16
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icontact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Devin Turner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -80,48 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
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
83
|
description:
|
126
84
|
email:
|
127
85
|
- devin.turner09@gmail.com
|
@@ -136,10 +94,10 @@ files:
|
|
136
94
|
- LICENSE.txt
|
137
95
|
- README.md
|
138
96
|
- Rakefile
|
139
|
-
- config/test.yml.example
|
140
97
|
- icontact.gemspec
|
141
98
|
- lib/icontact.rb
|
142
99
|
- lib/icontact/api.rb
|
100
|
+
- lib/icontact/api/accounts.rb
|
143
101
|
- lib/icontact/api/client_folders.rb
|
144
102
|
- lib/icontact/api/contacts.rb
|
145
103
|
- lib/icontact/api/custom_fields.rb
|
@@ -148,10 +106,7 @@ files:
|
|
148
106
|
- lib/icontact/api/users.rb
|
149
107
|
- lib/icontact/connection.rb
|
150
108
|
- lib/icontact/errors.rb
|
151
|
-
-
|
152
|
-
- spec/icontact/api/contacts_spec.rb
|
153
|
-
- spec/icontact/api_spec.rb
|
154
|
-
- spec/icontact_spec.rb
|
109
|
+
- spec/icontact/icontact_spec.rb
|
155
110
|
- spec/spec_helper.rb
|
156
111
|
homepage: https://github.com/l1h3r/icontact
|
157
112
|
licenses:
|
data/config/test.yml.example
DELETED
data/lib/icontact/version.rb
DELETED
@@ -1,88 +0,0 @@
|
|
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
|
data/spec/icontact/api_spec.rb
DELETED
@@ -1,33 +0,0 @@
|
|
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
|