acw 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6f83ffb21109941cf55bca7475d4efcea6864dba7e5f60e7db3b00cea5fe935
4
- data.tar.gz: 26469ac00550599f941d1b33c7365d46e21c7a520c248e52ebb91896ee436e76
3
+ metadata.gz: c19f8b720097ef991c9c849fbb801c8d54eaf3b4b1a26129506481bc1a94c902
4
+ data.tar.gz: 6803935f1441129dfb7f48600d7627b0f42c665d9e48da72b83f959410cfde89
5
5
  SHA512:
6
- metadata.gz: f4b5556926b458da090b34b9dec09bd4516a26bdaf0810f5956d8358c3105d9ccd5789e4cfab73436791acb4d59db16d161461886ce9fa7d5da9e55ef3c1d621
7
- data.tar.gz: b2691fc0ca83aa1ecb76d5a2f98142027a505dac183536e45c7c96797b4a9cf70cf8aba331b66fc5ab1de334a47cb7c373581ab4d0b5894b918a459e25a9cab6
6
+ metadata.gz: 610c728226bfb1ed0caaf403e1e369faa4c6d4325fb375cf3cbcd3f5caa629a715eb65619d4bcd2b0f947499f4734c3e93b6739d4d4de8eb7bd2bc74e9654389
7
+ data.tar.gz: a84c1ef728d660d40062bd12260dd6ef261fa34d1e62275b315b1b50db6ab789968072c74cdea01cd6f8a79ebd9128b3a6ed5d55f0ce4430dcb80570e94c0baf
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acw (1.3.0)
4
+ acw (1.3.1)
5
5
  excon (>= 0.73.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -20,7 +20,7 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- > ### Initialize client
23
+ ### Initialize client
24
24
 
25
25
  ```ruby
26
26
  client = Acw::Client.new({
@@ -29,13 +29,13 @@ client = Acw::Client.new({
29
29
  })
30
30
  ```
31
31
 
32
- > ### Connection details
32
+ ### Connection details
33
33
 
34
34
  ```ruby
35
35
  client.connection
36
36
  ```
37
37
 
38
- > ### Create contact - [Api Reference](https://developers.activecampaign.com/reference#create-a-contact-new)
38
+ ### Create contact - [Api Reference](https://developers.activecampaign.com/reference#create-a-contact-new)
39
39
 
40
40
  ```ruby
41
41
  client.create_contact({
@@ -46,24 +46,36 @@ client.create_contact({
46
46
  })
47
47
  ```
48
48
 
49
- > ### Sync contact (Create or Update) - [Api Reference](https://developers.activecampaign.com/reference#create-or-update-contact-new)
49
+ ### Sync contact (Create or Update) - [Api Reference](https://developers.activecampaign.com/reference#create-or-update-contact-new)
50
50
 
51
51
  ```ruby
52
52
  client.sync_contact({
53
+ contact: {
53
54
  email: 'contact@email.com',
54
55
  firstName: 'first',
55
56
  lastName: 'last',
56
- phone: '12312312'
57
+ phone: '12312312',
58
+ fieldValues: [
59
+ {
60
+ field: '1',
61
+ value: 'My Value'
62
+ },
63
+ {
64
+ field: '2',
65
+ value: 'My second value'
66
+ }
67
+ ]
68
+ }
57
69
  })
58
70
  ```
59
71
 
60
- > ### Retrieve contact - [Api Reference](https://developers.activecampaign.com/reference#get-contact)
72
+ ### Retrieve contact - [Api Reference](https://developers.activecampaign.com/reference#get-contact)
61
73
 
62
74
  ```ruby
63
75
  client.retrieve_contact("contact_id")
64
76
  ```
65
77
 
66
- > ### Retrieve contact by email
78
+ ### Retrieve contact by email
67
79
 
68
80
  This will return an array of contacts.
69
81
 
@@ -71,13 +83,13 @@ This will return an array of contacts.
71
83
  client.retrieve_contact_by_email("email")
72
84
  ```
73
85
 
74
- > ### Retrieve lists - [Api Reference](https://developers.activecampaign.com/reference#retrieve-all-lists)
86
+ ### Retrieve lists - [Api Reference](https://developers.activecampaign.com/reference#retrieve-all-lists)
75
87
 
76
88
  ```ruby
77
89
  client.retrieve_lists
78
90
  ```
79
91
 
80
- > ### Create tag - [Api Reference](https://developers.activecampaign.com/reference#tags)
92
+ ### Create tag - [Api Reference](https://developers.activecampaign.com/reference#tags)
81
93
 
82
94
  ```ruby
83
95
  client.create_tag({
@@ -85,7 +97,7 @@ client.create_tag({
85
97
  })
86
98
  ```
87
99
 
88
- > ### Add a tag to contact - [Api Reference](https://developers.activecampaign.com/reference#create-contact-tag)
100
+ ### Add a tag to contact - [Api Reference](https://developers.activecampaign.com/reference#create-contact-tag)
89
101
 
90
102
  It generates a relationship called contactTag containing an id.
91
103
 
@@ -95,7 +107,7 @@ client.add_contact_tag({
95
107
  })
96
108
  ```
97
109
 
98
- > ### Remove a tag to contact - [Api Reference](https://developers.activecampaign.com/reference#delete-contact-tag)
110
+ ### Remove a tag to contact - [Api Reference](https://developers.activecampaign.com/reference#delete-contact-tag)
99
111
 
100
112
  To remove a tag from contact just remove the relationship between them.
101
113
 
@@ -103,7 +115,7 @@ To remove a tag from contact just remove the relationship between them.
103
115
  client.remove_contact_tag("contact_tag_id)
104
116
  ```
105
117
 
106
- > ### Create field value - [Api Reference](https://developers.activecampaign.com/reference#create-fieldvalue)
118
+ ### Create field value - [Api Reference](https://developers.activecampaign.com/reference#create-fieldvalue)
107
119
 
108
120
  It generates a relationship called fieldVaalue containing an id.
109
121
 
@@ -117,7 +129,7 @@ client.create_field_value(
117
129
  )
118
130
  ```
119
131
 
120
- > ### Update a field value - [Api Reference](https://developers.activecampaign.com/reference#update-a-custom-field-value-for-contact)
132
+ ### Update a field value - [Api Reference](https://developers.activecampaign.com/reference#update-a-custom-field-value-for-contact)
121
133
 
122
134
  It updates a relationship called fieldVaalue containing an id.
123
135
 
@@ -3,11 +3,13 @@
3
3
  require 'excon'
4
4
  require 'cgi'
5
5
  require 'json'
6
+ require './lib/acw/helpers'
6
7
 
7
8
  module Acw
8
9
  class Client
10
+ include Acw::Helpers
11
+
9
12
  API_VERSION = 3
10
- Result = Struct.new(:success?, :error, :value)
11
13
 
12
14
  def initialize(configs = {})
13
15
  @config = configs
@@ -19,24 +21,22 @@ module Acw
19
21
  @connection ||= Excon.new(config[:url])
20
22
  end
21
23
 
22
- # CONTACTS
23
24
  def create_contact(args = {})
24
25
  safe_http_call do
25
26
  params = { contact: args }
26
27
  connection.post(
27
28
  path: "/api/#{API_VERSION}/contacts",
28
- headers: headers,
29
+ headers: headers(config[:token]),
29
30
  body: params.to_json
30
31
  )
31
32
  end
32
33
  end
33
34
 
34
- def sync_contact(args = {})
35
+ def sync_contact(params)
35
36
  safe_http_call do
36
- params = { contact: args }
37
37
  connection.post(
38
38
  path: "/api/#{API_VERSION}/contact/sync",
39
- headers: headers,
39
+ headers: headers(config[:token]),
40
40
  body: params.to_json
41
41
  )
42
42
  end
@@ -44,31 +44,38 @@ module Acw
44
44
 
45
45
  def retrieve_contact(id)
46
46
  safe_http_call do
47
- connection.get(path: "/api/#{API_VERSION}/contacts/#{id}", headers: headers)
47
+ connection.get(
48
+ path: "/api/#{API_VERSION}/contacts/#{id}",
49
+ headers: headers(config[:token])
50
+ )
48
51
  end
49
52
  end
50
53
 
51
54
  def retrieve_contact_by_email(email)
52
55
  safe_http_call do
53
56
  uemail = CGI.escape email
54
- connection.get(path: "/api/#{API_VERSION}/contacts?search=#{uemail}", headers: headers)
57
+ connection.get(
58
+ path: "/api/#{API_VERSION}/contacts?search=#{uemail}",
59
+ headers: headers(config[:token])
60
+ )
55
61
  end
56
62
  end
57
63
 
58
- # LISTS
59
64
  def retrieve_lists
60
65
  safe_http_call do
61
- connection.get(path: "/api/#{API_VERSION}/lists", headers: headers)
66
+ connection.get(
67
+ path: "/api/#{API_VERSION}/lists",
68
+ headers: headers(config[:token])
69
+ )
62
70
  end
63
71
  end
64
72
 
65
- # TAGS
66
73
  def create_tag(args = {})
67
74
  safe_http_call do
68
75
  params = { tag: args }
69
76
  connection.post(
70
77
  path: "/api/#{API_VERSION}/tags",
71
- headers: headers,
78
+ headers: headers(config[:token]),
72
79
  body: params.to_json
73
80
  )
74
81
  end
@@ -79,7 +86,7 @@ module Acw
79
86
  params = { 'contactTag': args }
80
87
  connection.post(
81
88
  path: "/api/#{API_VERSION}/contactTags",
82
- headers: headers,
89
+ headers: headers(config[:token]),
83
90
  body: params.to_json
84
91
  )
85
92
  end
@@ -87,17 +94,19 @@ module Acw
87
94
 
88
95
  def remove_contact_tag(id)
89
96
  safe_http_call do
90
- connection.delete(path: "/api/#{API_VERSION}/contactTags/#{id}", headers: headers)
97
+ connection.delete(
98
+ path: "/api/#{API_VERSION}/contactTags/#{id}",
99
+ headers: headers(config[:token])
100
+ )
91
101
  end
92
102
  end
93
103
 
94
- # FIELD_VALUES
95
104
  def create_field_value(args = {})
96
105
  safe_http_call do
97
106
  params = { 'fieldValue': args }
98
107
  connection.post(
99
108
  path: "/api/#{API_VERSION}/fieldValues",
100
- headers: headers,
109
+ headers: headers(config[:token]),
101
110
  body: params.to_json
102
111
  )
103
112
  end
@@ -108,7 +117,7 @@ module Acw
108
117
  params = { 'fieldValue': args }
109
118
  connection.put(
110
119
  path: "/api/#{API_VERSION}/fieldValues/#{id}",
111
- headers: headers,
120
+ headers: headers(config[:token]),
112
121
  body: params.to_json
113
122
  )
114
123
  end
@@ -116,21 +125,13 @@ module Acw
116
125
 
117
126
  private
118
127
 
119
- def headers
120
- {
121
- 'Accept': 'application/json',
122
- 'Content-Type': 'application/json',
123
- 'Api-Token': config[:token]
124
- }
125
- end
126
-
127
128
  def safe_http_call
128
129
  response = yield
129
130
  raise response.body unless success_http_status(response.status)
130
131
 
131
- Result.new(true, nil, JSON.parse(response.body))
132
+ result(true, nil, JSON.parse(response.body))
132
133
  rescue StandardError => e
133
- Result.new(false, e.message, nil)
134
+ result(false, e.message, nil)
134
135
  end
135
136
 
136
137
  def success_http_status(status)
@@ -0,0 +1,17 @@
1
+ module Acw
2
+ module Helpers
3
+ Result = Struct.new(:success?, :error, :value)
4
+
5
+ def headers(token)
6
+ @headers ||= {
7
+ 'Accept': 'application/json',
8
+ 'Content-Type': 'application/json',
9
+ 'Api-Token': token
10
+ }
11
+ end
12
+
13
+ def result(success, error, value)
14
+ Result.new(success, error, value)
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Acw
4
- VERSION = '1.3.0'
4
+ VERSION = '1.3.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acw
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anchieta Júnior
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2021-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon
@@ -157,6 +157,7 @@ files:
157
157
  - bin/setup
158
158
  - lib/acw.rb
159
159
  - lib/acw/client.rb
160
+ - lib/acw/helpers.rb
160
161
  - lib/acw/version.rb
161
162
  homepage: https://github.com/anchietajunior.com/acw
162
163
  licenses: