acw 1.1.2 → 1.3.3

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: dda66f075833c1878fa3bd2f35a27d92eaf0a9290ee519b131997b90fd00bc29
4
- data.tar.gz: 445c24100e91284c7bb62be7a66b8a8040f9f99c6c565d4e743e08f49229d781
3
+ metadata.gz: 5056bbd39cf081f2341a38dd4468f6679d4d519e98aba42d11408ec8913dcb66
4
+ data.tar.gz: 4edc0ad34248773e7c1820c8d6022780a517b4995cb4fa5787a4ca3ddcb4ba40
5
5
  SHA512:
6
- metadata.gz: 1b793e49061b1dd95860830c270a9d91ba22c8a14a3e976b3c36904d37516054feee0ef47378ad6f6cd58f1604ef3f9f8087d6a817cb603b16606ad1a2deda98
7
- data.tar.gz: 52c0e6116c71b98fbefea9be9da18a9baf75f8bba7b104a7239cd92f3e739f2898edd08d4dbf0351bb447deedb37385d96b81b6c9378c9cd9ff7cc1a3f20e8ed
6
+ metadata.gz: 999c8b63d60bd4918fada14a8a75135c5e9a152a61faa4a68c06da850b4d168fa8d618e80332ab90e72413b199de81d36ed61938734a51deef075776e2d539e9
7
+ data.tar.gz: 745760bf88da723f83e72736cbe9946d316ca01f0f2b48778ec43f04167d2240b54f79fc577ea8ecabad4fcd262b0a02b7d62156be0e28f47aecf1f0a3f78f0b
@@ -0,0 +1,2 @@
1
+ Style/Documentation:
2
+ Enabled: false
@@ -1,24 +1,46 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acw (1.1.2)
5
- faraday (>= 1.0)
4
+ acw (1.3.3)
5
+ excon (>= 0.73.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  addressable (2.7.0)
11
11
  public_suffix (>= 2.0.2, < 5.0)
12
+ ast (2.4.1)
13
+ backport (1.1.2)
14
+ benchmark (0.1.1)
15
+ coderay (1.1.3)
12
16
  crack (0.4.3)
13
17
  safe_yaml (~> 1.0.0)
14
18
  diff-lcs (1.3)
15
- faraday (1.2.0)
16
- multipart-post (>= 1.2, < 3)
17
- ruby2_keywords
19
+ e2mmap (0.1.0)
20
+ excon (0.78.1)
18
21
  hashdiff (1.0.1)
19
- multipart-post (2.1.1)
22
+ jaro_winkler (1.5.4)
23
+ kramdown (2.3.0)
24
+ rexml
25
+ kramdown-parser-gfm (1.1.0)
26
+ kramdown (~> 2.0)
27
+ method_source (1.0.0)
28
+ mini_portile2 (2.4.0)
29
+ nokogiri (1.10.10)
30
+ mini_portile2 (~> 2.4.0)
31
+ parallel (1.20.1)
32
+ parser (2.7.2.0)
33
+ ast (~> 2.4.1)
34
+ pry (0.13.1)
35
+ coderay (~> 1.1)
36
+ method_source (~> 1.0)
20
37
  public_suffix (4.0.4)
38
+ rainbow (3.0.0)
21
39
  rake (12.3.3)
40
+ regexp_parser (2.0.3)
41
+ reverse_markdown (2.0.0)
42
+ nokogiri
43
+ rexml (3.2.4)
22
44
  rspec (3.9.0)
23
45
  rspec-core (~> 3.9.0)
24
46
  rspec-expectations (~> 3.9.0)
@@ -32,13 +54,42 @@ GEM
32
54
  diff-lcs (>= 1.2.0, < 2.0)
33
55
  rspec-support (~> 3.9.0)
34
56
  rspec-support (3.9.2)
35
- ruby2_keywords (0.0.2)
57
+ rubocop (1.7.0)
58
+ parallel (~> 1.10)
59
+ parser (>= 2.7.1.5)
60
+ rainbow (>= 2.2.2, < 4.0)
61
+ regexp_parser (>= 1.8, < 3.0)
62
+ rexml
63
+ rubocop-ast (>= 1.2.0, < 2.0)
64
+ ruby-progressbar (~> 1.7)
65
+ unicode-display_width (>= 1.4.0, < 2.0)
66
+ rubocop-ast (1.3.0)
67
+ parser (>= 2.7.1.5)
68
+ ruby-progressbar (1.10.1)
36
69
  safe_yaml (1.0.5)
70
+ solargraph (0.40.1)
71
+ backport (~> 1.1)
72
+ benchmark
73
+ bundler (>= 1.17.2)
74
+ e2mmap
75
+ jaro_winkler (~> 1.5)
76
+ kramdown (~> 2.3)
77
+ kramdown-parser-gfm (~> 1.1)
78
+ parser (~> 2.3)
79
+ reverse_markdown (>= 1.0.5, < 3)
80
+ rubocop (>= 0.52)
81
+ thor (~> 1.0)
82
+ tilt (~> 2.0)
83
+ yard (~> 0.9, >= 0.9.24)
84
+ thor (1.0.1)
85
+ tilt (2.0.10)
86
+ unicode-display_width (1.7.0)
37
87
  vcr (5.1.0)
38
88
  webmock (3.8.3)
39
89
  addressable (>= 2.3.6)
40
90
  crack (>= 0.3.2)
41
91
  hashdiff (>= 0.4.0, < 2.0.0)
92
+ yard (0.9.26)
42
93
 
43
94
  PLATFORMS
44
95
  ruby
@@ -46,8 +97,11 @@ PLATFORMS
46
97
  DEPENDENCIES
47
98
  acw!
48
99
  bundler (~> 2.0)
100
+ pry (~> 0.13.1)
49
101
  rake (~> 12.3.3)
50
102
  rspec (~> 3.0)
103
+ rubocop (~> 1.7)
104
+ solargraph (~> 0.40)
51
105
  vcr (~> 5.1)
52
106
  webmock (~> 3.8)
53
107
 
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
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)
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
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
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
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
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
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,6 +115,44 @@ 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
 
118
+ ### Create field value - [Api Reference](https://developers.activecampaign.com/reference#create-fieldvalue)
119
+
120
+ It generates a relationship called fieldVaalue containing an id.
121
+
122
+ ```ruby
123
+ client.create_field_value(
124
+ {
125
+ contact: 572218,
126
+ field: 2,
127
+ value: 'field_value'
128
+ }
129
+ )
130
+ ```
131
+
132
+ ### Update a field value - [Api Reference](https://developers.activecampaign.com/reference#update-a-custom-field-value-for-contact)
133
+
134
+ It updates a relationship called fieldVaalue containing an id.
135
+
136
+ ```ruby
137
+ client.update_field_value(
138
+ 803_383,
139
+ {
140
+ contact: 572218,
141
+ field: 2,
142
+ value: 'new_field_value_put'
143
+ }
144
+ )
145
+ ```
146
+
147
+ ## Testing with your Api-Token
148
+
149
+ You can disable vcr in specs with these commands in your tests and create a new context for you.
150
+
151
+ ```
152
+ WebMock.allow_net_connect!
153
+ VCR.turn_off!
154
+ ```
155
+
106
156
  ## License
107
157
 
108
158
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -28,11 +28,15 @@ Gem::Specification.new do |spec|
28
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
29
  spec.require_paths = ["lib"]
30
30
 
31
- spec.add_dependency 'faraday', '>= 1.0'
31
+ # spec.add_dependency 'faraday', '>= 1.0'
32
+ spec.add_dependency 'excon', '>= 0.73.0'
32
33
 
33
34
  spec.add_development_dependency "bundler", "~> 2.0"
34
35
  spec.add_development_dependency "rake", "~> 12.3.3"
35
36
  spec.add_development_dependency "rspec", "~> 3.0"
36
37
  spec.add_development_dependency "vcr", "~> 5.1"
37
38
  spec.add_development_dependency "webmock", "~> 3.8"
39
+ spec.add_development_dependency 'pry', '~> 0.13.1'
40
+ spec.add_development_dependency 'solargraph', '~> 0.40'
41
+ spec.add_development_dependency 'rubocop', '~> 1.7'
38
42
  end
data/lib/acw.rb CHANGED
@@ -1,5 +1,8 @@
1
- require "acw/version"
2
- require "acw/client"
1
+ # frozen_string_literal: true
2
+
3
+ require 'acw/version'
4
+ require 'acw/helpers'
5
+ require 'acw/client'
3
6
 
4
7
  module Acw
5
8
  module_function
@@ -1,12 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'faraday'
3
+ require 'excon'
4
4
  require 'cgi'
5
5
  require 'json'
6
6
 
7
7
  module Acw
8
8
  class Client
9
- Result = Struct.new(:success?, :error, :value)
9
+ include Acw::Helpers
10
+
11
+ API_VERSION = 3
10
12
 
11
13
  def initialize(configs = {})
12
14
  @config = configs
@@ -15,67 +17,120 @@ module Acw
15
17
  attr_reader :config
16
18
 
17
19
  def connection
18
- @connection ||= Faraday.new(url: config[:url]) do |faraday|
19
- faraday.headers['Accept'] = 'application/json'
20
- faraday.headers['Content-Type'] = 'application/json'
21
- faraday.headers['Api-Token'] = config[:token]
22
- faraday
23
- end
20
+ @connection ||= Excon.new(config[:url])
24
21
  end
25
22
 
26
- # CONTACTS
27
- def create_contact(args={})
23
+ def create_contact(args = {})
28
24
  safe_http_call do
29
25
  params = { contact: args }
30
- connection.post('contacts', params.to_json)
26
+ connection.post(
27
+ path: "/api/#{API_VERSION}/contacts",
28
+ headers: headers(config[:token]),
29
+ body: params.to_json
30
+ )
31
31
  end
32
32
  end
33
33
 
34
- def sync_contact(args = {})
34
+ def sync_contact(params)
35
35
  safe_http_call do
36
- params = { contact: args }
37
- connection.post('contact/sync', params.to_json)
36
+ connection.post(
37
+ path: "/api/#{API_VERSION}/contact/sync",
38
+ headers: headers(config[:token]),
39
+ body: params.to_json
40
+ )
38
41
  end
39
42
  end
40
43
 
41
44
  def retrieve_contact(id)
42
45
  safe_http_call do
43
- connection.get("contacts/#{id}")
46
+ connection.get(
47
+ path: "/api/#{API_VERSION}/contacts/#{id}",
48
+ headers: headers(config[:token])
49
+ )
44
50
  end
45
51
  end
46
52
 
47
53
  def retrieve_contact_by_email(email)
48
54
  safe_http_call do
49
55
  uemail = CGI.escape email
50
- connection.get("contacts?search=#{uemail}")
56
+ connection.get(
57
+ path: "/api/#{API_VERSION}/contacts?search=#{uemail}",
58
+ headers: headers(config[:token])
59
+ )
51
60
  end
52
61
  end
53
62
 
54
- # LISTS
55
63
  def retrieve_lists
56
64
  safe_http_call do
57
- connection.get('lists')
65
+ connection.get(
66
+ path: "/api/#{API_VERSION}/lists",
67
+ headers: headers(config[:token])
68
+ )
69
+ end
70
+ end
71
+
72
+ def contact_list_subscription(args = {})
73
+ safe_http_call do
74
+ args[:status] = (args[:status] == 'subscribe' ? 1 : 2)
75
+ params = { contactList: args }
76
+ connection.post(
77
+ path: "/api/#{API_VERSION}/contactLists",
78
+ headers: headers(config[:token]),
79
+ body: params.to_json
80
+ )
58
81
  end
59
82
  end
60
83
 
61
- # TAGS
62
84
  def create_tag(args = {})
63
85
  safe_http_call do
64
- params = { 'tag': args }
65
- connection.post('tags', params.to_json)
86
+ params = { tag: args }
87
+ connection.post(
88
+ path: "/api/#{API_VERSION}/tags",
89
+ headers: headers(config[:token]),
90
+ body: params.to_json
91
+ )
66
92
  end
67
93
  end
68
94
 
69
95
  def add_contact_tag(args = {})
70
96
  safe_http_call do
71
97
  params = { 'contactTag': args }
72
- connection.post('contactTags', params.to_json)
98
+ connection.post(
99
+ path: "/api/#{API_VERSION}/contactTags",
100
+ headers: headers(config[:token]),
101
+ body: params.to_json
102
+ )
73
103
  end
74
104
  end
75
105
 
76
106
  def remove_contact_tag(id)
77
107
  safe_http_call do
78
- connection.delete("contactTags/#{id}")
108
+ connection.delete(
109
+ path: "/api/#{API_VERSION}/contactTags/#{id}",
110
+ headers: headers(config[:token])
111
+ )
112
+ end
113
+ end
114
+
115
+ def create_field_value(args = {})
116
+ safe_http_call do
117
+ params = { 'fieldValue': args }
118
+ connection.post(
119
+ path: "/api/#{API_VERSION}/fieldValues",
120
+ headers: headers(config[:token]),
121
+ body: params.to_json
122
+ )
123
+ end
124
+ end
125
+
126
+ def update_field_value(id, args = {})
127
+ safe_http_call do
128
+ params = { 'fieldValue': args }
129
+ connection.put(
130
+ path: "/api/#{API_VERSION}/fieldValues/#{id}",
131
+ headers: headers(config[:token]),
132
+ body: params.to_json
133
+ )
79
134
  end
80
135
  end
81
136
 
@@ -85,13 +140,13 @@ module Acw
85
140
  response = yield
86
141
  raise response.body unless success_http_status(response.status)
87
142
 
88
- Result.new(true, nil, JSON.parse(response.body))
143
+ result(true, nil, JSON.parse(response.body))
89
144
  rescue StandardError => e
90
- Result.new(false, e.message, nil)
145
+ result(false, e.message, nil)
91
146
  end
92
147
 
93
148
  def success_http_status(status)
94
- [200, 201].include?(status)
149
+ [200, 201, 202].include?(status)
95
150
  end
96
151
  end
97
152
  end
@@ -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.1.2'
4
+ VERSION = '1.3.3'
5
5
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acw
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.3.3
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-24 00:00:00.000000000 Z
11
+ date: 2021-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: faraday
14
+ name: excon
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: 0.73.0
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
- version: '1.0'
26
+ version: 0.73.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,48 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.8'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.13.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.13.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: solargraph
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.40'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.40'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.7'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.7'
97
139
  description: Active Campaign Wrapper.
98
140
  email:
99
141
  - santosjr87@gmail.com
@@ -104,6 +146,7 @@ files:
104
146
  - ".github/workflows/ci.yml"
105
147
  - ".gitignore"
106
148
  - ".rspec"
149
+ - ".rubocop.yml"
107
150
  - Gemfile
108
151
  - Gemfile.lock
109
152
  - LICENSE.txt
@@ -114,6 +157,7 @@ files:
114
157
  - bin/setup
115
158
  - lib/acw.rb
116
159
  - lib/acw/client.rb
160
+ - lib/acw/helpers.rb
117
161
  - lib/acw/version.rb
118
162
  homepage: https://github.com/anchietajunior.com/acw
119
163
  licenses: