icontact 0.0.3 → 0.0.4
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/Gemfile.lock +1 -1
- data/icontact.gemspec +1 -1
- data/lib/icontact/api/accounts.rb +2 -2
- data/lib/icontact/api/client_folders.rb +4 -4
- data/lib/icontact/api/contacts.rb +6 -6
- data/lib/icontact/api/custom_fields.rb +5 -5
- data/lib/icontact/api/lists.rb +5 -5
- data/lib/icontact/api/subscriptions.rb +4 -4
- data/lib/icontact/api/users.rb +4 -4
- data/lib/icontact/api.rb +5 -5
- data/lib/icontact/connection.rb +12 -6
- data/lib/icontact/errors.rb +6 -5
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f572c6471d13d68cbe4ba58806245804f45d5a66
|
4
|
+
data.tar.gz: 20e10242041a60effef3af1e78fa74e82d08633a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcc7988eda595f77b7e559b81f354cffcb1d926c7e8cac578d84c10b398cf89c997b87674b7e13033afbade4b03d9deaff88cfe91aad31f0ebf392b6aeac7baf
|
7
|
+
data.tar.gz: 0624508f859b3a0a1b5556510a47429a0fde3c28cefdc7bc8a8d15a9f81936cb894e8b221338f8217d4b7f4f888ffe5f94459205b5248f15693fdc47085a7de4
|
data/Gemfile.lock
CHANGED
data/icontact.gemspec
CHANGED
@@ -3,7 +3,7 @@ module IContact
|
|
3
3
|
module Accounts
|
4
4
|
|
5
5
|
def get_account(id)
|
6
|
-
|
6
|
+
ensure_valid_id(id)
|
7
7
|
response = get(accounts_path + id)
|
8
8
|
resource(response, 'account')
|
9
9
|
end
|
@@ -14,7 +14,7 @@ module IContact
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def update_account(id, data)
|
17
|
-
|
17
|
+
ensure_valid_id(id)
|
18
18
|
response = post(accounts_path + id, data)
|
19
19
|
resource(response, 'account')
|
20
20
|
end
|
@@ -3,7 +3,7 @@ module IContact
|
|
3
3
|
module ClientFolders
|
4
4
|
|
5
5
|
def get_client_folder(id)
|
6
|
-
|
6
|
+
ensure_valid_id(id)
|
7
7
|
response = get(client_folders_path + id)
|
8
8
|
resource(response, 'clientfolder')
|
9
9
|
end
|
@@ -15,7 +15,7 @@ module IContact
|
|
15
15
|
|
16
16
|
def create_client_folder(data)
|
17
17
|
response = post(client_folders_path, wrap(data))
|
18
|
-
resource(response, 'clientfolders',
|
18
|
+
resource(response, 'clientfolders', true)
|
19
19
|
end
|
20
20
|
|
21
21
|
def create_client_folders(data)
|
@@ -24,13 +24,13 @@ module IContact
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def update_client_folder(id, data)
|
27
|
-
|
27
|
+
ensure_valid_id(id)
|
28
28
|
response = post(client_folders_path + id, data)
|
29
29
|
resource(response, 'clientfolder')
|
30
30
|
end
|
31
31
|
|
32
32
|
def update_client_folder!(id, data)
|
33
|
-
|
33
|
+
ensure_valid_id(id)
|
34
34
|
response = put(client_folders_path + id, data)
|
35
35
|
resource(response, 'clientfolder')
|
36
36
|
end
|
@@ -3,7 +3,7 @@ module IContact
|
|
3
3
|
module Contacts
|
4
4
|
|
5
5
|
def get_contact(id)
|
6
|
-
|
6
|
+
ensure_valid_id(id)
|
7
7
|
response = get(contacts_path + id)
|
8
8
|
resource(response, 'contact')
|
9
9
|
end
|
@@ -15,7 +15,7 @@ module IContact
|
|
15
15
|
|
16
16
|
def create_contact(data)
|
17
17
|
response = post(contacts_path, wrap(data))
|
18
|
-
resource(response, 'contacts',
|
18
|
+
resource(response, 'contacts', true)
|
19
19
|
end
|
20
20
|
|
21
21
|
def create_contacts(data)
|
@@ -24,13 +24,13 @@ module IContact
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def update_contact(id, data)
|
27
|
-
|
27
|
+
ensure_valid_id(id)
|
28
28
|
response = post(contacts_path + id, data)
|
29
29
|
resource(response, 'contact')
|
30
30
|
end
|
31
31
|
|
32
32
|
def update_contact!(id, data)
|
33
|
-
|
33
|
+
ensure_valid_id(id)
|
34
34
|
response = put(contacts_path + id, data)
|
35
35
|
resource(response, 'contact')
|
36
36
|
end
|
@@ -41,13 +41,13 @@ module IContact
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def delete_contact(id)
|
44
|
-
|
44
|
+
ensure_valid_id(id)
|
45
45
|
response = delete(contacts_path + id)
|
46
46
|
resource(response, 'status')
|
47
47
|
end
|
48
48
|
|
49
49
|
def find_contacts(data)
|
50
|
-
|
50
|
+
ensure_valid_data(data)
|
51
51
|
data.merge!(limit: 10000) unless data.has_key?(:limit)
|
52
52
|
response = get(contacts_path + query(data))
|
53
53
|
resource(response, 'contacts')
|
@@ -3,7 +3,7 @@ module IContact
|
|
3
3
|
module CustomFields
|
4
4
|
|
5
5
|
def get_custom_field(id)
|
6
|
-
|
6
|
+
ensure_valid_id(id)
|
7
7
|
response = get(custom_fields_path + id)
|
8
8
|
resource(response, 'customfield')
|
9
9
|
end
|
@@ -15,7 +15,7 @@ module IContact
|
|
15
15
|
|
16
16
|
def create_custom_field(data)
|
17
17
|
response = post(custom_fields_path, wrap(data))
|
18
|
-
resource(response, 'customfields',
|
18
|
+
resource(response, 'customfields', true)
|
19
19
|
end
|
20
20
|
|
21
21
|
def create_custom_fields(data)
|
@@ -24,13 +24,13 @@ module IContact
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def update_custom_field(id, data)
|
27
|
-
|
27
|
+
ensure_valid_id(id)
|
28
28
|
response = post(custom_fields_path + id, data)
|
29
29
|
resource(response, 'customfield')
|
30
30
|
end
|
31
31
|
|
32
32
|
def update_custom_field!(id, data)
|
33
|
-
|
33
|
+
ensure_valid_id(id)
|
34
34
|
response = put(custom_fields_path + id, data)
|
35
35
|
resource(response, 'customfield')
|
36
36
|
end
|
@@ -41,7 +41,7 @@ module IContact
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def delete_custom_field(id)
|
44
|
-
|
44
|
+
ensure_valid_id(id)
|
45
45
|
response = delete(custom_fields_path + id)
|
46
46
|
resource(response, 'status')
|
47
47
|
end
|
data/lib/icontact/api/lists.rb
CHANGED
@@ -3,7 +3,7 @@ module IContact
|
|
3
3
|
module Lists
|
4
4
|
|
5
5
|
def get_list(id)
|
6
|
-
|
6
|
+
ensure_valid_id(id)
|
7
7
|
response = get(lists_path + id)
|
8
8
|
resource(response, 'list')
|
9
9
|
end
|
@@ -15,7 +15,7 @@ module IContact
|
|
15
15
|
|
16
16
|
def create_list(data)
|
17
17
|
response = post(lists_path, wrap(data))
|
18
|
-
resource(response, 'lists',
|
18
|
+
resource(response, 'lists', true)
|
19
19
|
end
|
20
20
|
|
21
21
|
def create_lists(data)
|
@@ -24,13 +24,13 @@ module IContact
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def update_list(id, data)
|
27
|
-
|
27
|
+
ensure_valid_id(id)
|
28
28
|
response = post(lists_path + id, data)
|
29
29
|
resource(response, 'list')
|
30
30
|
end
|
31
31
|
|
32
32
|
def update_list!(id, data)
|
33
|
-
|
33
|
+
ensure_valid_id(id)
|
34
34
|
response = put(lists_path + id, data)
|
35
35
|
resource(response, 'list')
|
36
36
|
end
|
@@ -41,7 +41,7 @@ module IContact
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def delete_list(id)
|
44
|
-
|
44
|
+
ensure_valid_id(id)
|
45
45
|
response = delete(lists_path + id)
|
46
46
|
resource(response, 'status')
|
47
47
|
end
|
@@ -3,7 +3,7 @@ module IContact
|
|
3
3
|
module Subscriptions
|
4
4
|
|
5
5
|
def get_subscription(id)
|
6
|
-
|
6
|
+
ensure_valid_id(id)
|
7
7
|
response = get(subscriptions_path + id)
|
8
8
|
resource(response, 'subscription')
|
9
9
|
end
|
@@ -15,7 +15,7 @@ module IContact
|
|
15
15
|
|
16
16
|
def create_subscription(data)
|
17
17
|
response = post(subscriptions_path, wrap(data))
|
18
|
-
resource(response, 'subscriptions',
|
18
|
+
resource(response, 'subscriptions', true)
|
19
19
|
end
|
20
20
|
|
21
21
|
def create_subscriptions(data)
|
@@ -24,13 +24,13 @@ module IContact
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def update_subscription(id, data)
|
27
|
-
|
27
|
+
ensure_valid_id(id)
|
28
28
|
response = post(subscriptions_path + id, data)
|
29
29
|
resource(response, 'subscription')
|
30
30
|
end
|
31
31
|
|
32
32
|
def move_contact(id, data)
|
33
|
-
|
33
|
+
ensure_valid_id(id)
|
34
34
|
response = put(subscriptions_path + id, data)
|
35
35
|
resource(response, 'subscription')
|
36
36
|
end
|
data/lib/icontact/api/users.rb
CHANGED
@@ -3,7 +3,7 @@ module IContact
|
|
3
3
|
module Users
|
4
4
|
|
5
5
|
def get_user(id)
|
6
|
-
|
6
|
+
ensure_valid_id(id)
|
7
7
|
response = get(users_path + id)
|
8
8
|
resource(response, 'user')
|
9
9
|
end
|
@@ -15,7 +15,7 @@ module IContact
|
|
15
15
|
|
16
16
|
def create_user(data)
|
17
17
|
response = post(users_path, wrap(data))
|
18
|
-
resource(response, 'users',
|
18
|
+
resource(response, 'users', true)
|
19
19
|
end
|
20
20
|
|
21
21
|
def create_users(data)
|
@@ -24,7 +24,7 @@ module IContact
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def update_user(id, data)
|
27
|
-
|
27
|
+
ensure_valid_id(id)
|
28
28
|
response = post(users_path + id, data)
|
29
29
|
resource(response, 'user')
|
30
30
|
end
|
@@ -35,7 +35,7 @@ module IContact
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def delete_user(id)
|
38
|
-
|
38
|
+
ensure_valid_id(id)
|
39
39
|
response = delete(users_path + id)
|
40
40
|
resource(response, 'status')
|
41
41
|
end
|
data/lib/icontact/api.rb
CHANGED
@@ -53,13 +53,13 @@ module IContact
|
|
53
53
|
data.respond_to?(:to_ary) ? data.to_ary : [data]
|
54
54
|
end
|
55
55
|
|
56
|
-
def resource(data,
|
57
|
-
if data.empty? || data[
|
56
|
+
def resource(data, collection, first = false)
|
57
|
+
if data.empty? || data[collection].nil?
|
58
58
|
[]
|
59
|
-
elsif
|
60
|
-
data[
|
59
|
+
elsif first
|
60
|
+
data[collection].first
|
61
61
|
else
|
62
|
-
data[
|
62
|
+
data[collection]
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
data/lib/icontact/connection.rb
CHANGED
@@ -13,12 +13,12 @@ module IContact
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def post(path, data)
|
16
|
-
|
16
|
+
ensure_valid(data)
|
17
17
|
request(:post, path, data)
|
18
18
|
end
|
19
19
|
|
20
20
|
def put(path, data)
|
21
|
-
|
21
|
+
ensure_valid_data(data)
|
22
22
|
request(:put, path, data)
|
23
23
|
end
|
24
24
|
|
@@ -45,7 +45,7 @@ module IContact
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def request(method, path, data = {})
|
48
|
-
request =
|
48
|
+
request = Oj.dump((data || {}), mode: :compat)
|
49
49
|
response = connection.run_request(method, BASE_URL + path, request, headers)
|
50
50
|
handle_response(response)
|
51
51
|
end
|
@@ -62,12 +62,18 @@ module IContact
|
|
62
62
|
def response_success(response)
|
63
63
|
if response.env[:method] == :delete
|
64
64
|
{ 'status' => true }
|
65
|
-
elsif !response.body.nil? && !response.body.strip.empty?
|
66
|
-
Oj.load(response.body, mode: :compat)
|
67
65
|
else
|
68
|
-
|
66
|
+
Oj.load((response.body || {}), mode: :compat)
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
70
|
+
def ensure_valid_id(id)
|
71
|
+
raise ArgumentError, 'ID cannot be nil' if id.nil?
|
72
|
+
end
|
73
|
+
|
74
|
+
def ensure_valid_data(data)
|
75
|
+
raise ArgumentError, 'Data cannot be empty' if data.nil? || data.empty?
|
76
|
+
end
|
77
|
+
|
72
78
|
end
|
73
79
|
end
|
data/lib/icontact/errors.rb
CHANGED
@@ -28,7 +28,7 @@ module IContact
|
|
28
28
|
class IContact::UnsupportedMediaType < IContactError; end
|
29
29
|
|
30
30
|
class ErrorHandler
|
31
|
-
|
31
|
+
MAPPED_ERRORS = {
|
32
32
|
400 => IContact::BadRequest,
|
33
33
|
401 => IContact::NotAuthorized,
|
34
34
|
402 => IContact::PaymentRequest,
|
@@ -44,11 +44,12 @@ module IContact
|
|
44
44
|
}
|
45
45
|
|
46
46
|
def initialize(response)
|
47
|
-
|
48
|
-
|
47
|
+
klass = MAPPED_ERRORS[response.status.to_i]
|
48
|
+
parsed = Oj.load(response.body || '')
|
49
|
+
message = parsed.nil? ? '' : parsed['errors']
|
49
50
|
|
50
|
-
if
|
51
|
-
raise
|
51
|
+
if klass
|
52
|
+
raise klass.new(message)
|
52
53
|
else
|
53
54
|
raise IContactError.new("#{response.status}: #{message}")
|
54
55
|
end
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
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.4
|
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
|
+
date: 2014-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2.11'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.11'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0.8'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.8'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.5'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '10.3'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '3.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.0'
|
83
83
|
description:
|
@@ -87,8 +87,8 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
-
|
91
|
-
-
|
90
|
+
- .gitignore
|
91
|
+
- .rspec
|
92
92
|
- Gemfile
|
93
93
|
- Gemfile.lock
|
94
94
|
- LICENSE.txt
|
@@ -118,12 +118,12 @@ require_paths:
|
|
118
118
|
- lib
|
119
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- -
|
121
|
+
- - '>='
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
125
|
requirements:
|
126
|
-
- -
|
126
|
+
- - '>='
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: 1.3.6
|
129
129
|
requirements: []
|