acw 0.1.1 → 1.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f2ee9e81e82ddb38146867d27dd8f5536e17bb50811c6955fa8f2b0da4eae1d
4
- data.tar.gz: 1c040990f3a83a6cfc2d63cf122e7d0a64880768b3d058a77b0c6bf7261ee05e
3
+ metadata.gz: fe9d8bfedad891dc4c137426e6efa8eb9655e940b1709c071f81f89051b0821d
4
+ data.tar.gz: 781329947357dfb3db4cdf206646ab337af4b453ee88c952bf5ac6f1b8c23c8a
5
5
  SHA512:
6
- metadata.gz: 5fb18e9a0db08a17d4df577bc713e60e02bd39892d817f75a22c8256eca3bf2f2046fdb0d5a5854b9e0271c713d8957441ee8ce0441435369ee60db68af5bbc0
7
- data.tar.gz: 67279b26b380b148a5ca59a4cd4cb223defcef51c41da0d838077a61b512aa93aed51460d2bab148283d0a50227c14a9beed9f794c076f19261063f0a842b30a
6
+ metadata.gz: e7df0939dbf9d23df23d7b9e83f3c296776348981c11620e7b3105ce62304cab1f37009f17fc053b3ea9e827ea3bbaad207943ee65f29fa241dd9a4d68f5bd6f
7
+ data.tar.gz: 4a174ad13bdaa0b4e8dfc8c8a5ada3850ad0116f6ae039f8ce086c667e0a94c2d0a2cd6eeca1b0fa8a1d69807db83bed76a8667d31ec4522bf5e5f93f967d015
@@ -0,0 +1,2 @@
1
+ Style/Documentation:
2
+ Enabled: false
@@ -1,23 +1,46 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acw (0.1.1)
5
- faraday (>= 1.0, < 3.0)
4
+ acw (1.3.2)
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.0.1)
16
- multipart-post (>= 1.2, < 3)
19
+ e2mmap (0.1.0)
20
+ excon (0.78.1)
17
21
  hashdiff (1.0.1)
18
- 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)
19
37
  public_suffix (4.0.4)
20
- rake (10.5.0)
38
+ rainbow (3.0.0)
39
+ rake (12.3.3)
40
+ regexp_parser (2.0.3)
41
+ reverse_markdown (2.0.0)
42
+ nokogiri
43
+ rexml (3.2.4)
21
44
  rspec (3.9.0)
22
45
  rspec-core (~> 3.9.0)
23
46
  rspec-expectations (~> 3.9.0)
@@ -31,12 +54,42 @@ GEM
31
54
  diff-lcs (>= 1.2.0, < 2.0)
32
55
  rspec-support (~> 3.9.0)
33
56
  rspec-support (3.9.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)
34
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)
35
87
  vcr (5.1.0)
36
88
  webmock (3.8.3)
37
89
  addressable (>= 2.3.6)
38
90
  crack (>= 0.3.2)
39
91
  hashdiff (>= 0.4.0, < 2.0.0)
92
+ yard (0.9.26)
40
93
 
41
94
  PLATFORMS
42
95
  ruby
@@ -44,10 +97,13 @@ PLATFORMS
44
97
  DEPENDENCIES
45
98
  acw!
46
99
  bundler (~> 2.0)
47
- rake (~> 10.0)
100
+ pry (~> 0.13.1)
101
+ rake (~> 12.3.3)
48
102
  rspec (~> 3.0)
103
+ rubocop (~> 1.7)
104
+ solargraph (~> 0.40)
49
105
  vcr (~> 5.1)
50
106
  webmock (~> 3.8)
51
107
 
52
108
  BUNDLED WITH
53
- 2.0.2
109
+ 2.1.4
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,18 +29,13 @@ client = Acw::Client.new({
29
29
  })
30
30
  ```
31
31
 
32
- > ### Connection details
32
+ ### Connection details
33
33
 
34
34
  ```ruby
35
- client = Acw::Client.new({
36
- url: 'your-url',
37
- token: 'your-token'
38
- })
39
-
40
35
  client.connection
41
36
  ```
42
37
 
43
- > ### Create contact
38
+ ### Create contact - [Api Reference](https://developers.activecampaign.com/reference#create-a-contact-new)
44
39
 
45
40
  ```ruby
46
41
  client.create_contact({
@@ -51,24 +46,36 @@ client.create_contact({
51
46
  })
52
47
  ```
53
48
 
54
- > ### Sync contact (Create or Update)
49
+ ### Sync contact (Create or Update) - [Api Reference](https://developers.activecampaign.com/reference#create-or-update-contact-new)
55
50
 
56
51
  ```ruby
57
52
  client.sync_contact({
53
+ contact: {
58
54
  email: 'contact@email.com',
59
55
  firstName: 'first',
60
56
  lastName: 'last',
61
- 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
+ }
62
69
  })
63
70
  ```
64
71
 
65
- > ### Retrieve contact
72
+ ### Retrieve contact - [Api Reference](https://developers.activecampaign.com/reference#get-contact)
66
73
 
67
74
  ```ruby
68
75
  client.retrieve_contact("contact_id")
69
76
  ```
70
77
 
71
- > ### Retrieve contact by email
78
+ ### Retrieve contact by email
72
79
 
73
80
  This will return an array of contacts.
74
81
 
@@ -76,13 +83,13 @@ This will return an array of contacts.
76
83
  client.retrieve_contact_by_email("email")
77
84
  ```
78
85
 
79
- > ### Retrieve lists
86
+ ### Retrieve lists - [Api Reference](https://developers.activecampaign.com/reference#retrieve-all-lists)
80
87
 
81
88
  ```ruby
82
89
  client.retrieve_lists
83
90
  ```
84
91
 
85
- > ### Create tag
92
+ ### Create tag - [Api Reference](https://developers.activecampaign.com/reference#tags)
86
93
 
87
94
  ```ruby
88
95
  client.create_tag({
@@ -90,7 +97,7 @@ client.create_tag({
90
97
  })
91
98
  ```
92
99
 
93
- > ### Add a tag to contact
100
+ ### Add a tag to contact - [Api Reference](https://developers.activecampaign.com/reference#create-contact-tag)
94
101
 
95
102
  It generates a relationship called contactTag containing an id.
96
103
 
@@ -100,7 +107,7 @@ client.add_contact_tag({
100
107
  })
101
108
  ```
102
109
 
103
- > ### Remove a tag to contact
110
+ ### Remove a tag to contact - [Api Reference](https://developers.activecampaign.com/reference#delete-contact-tag)
104
111
 
105
112
  To remove a tag from contact just remove the relationship between them.
106
113
 
@@ -108,6 +115,44 @@ To remove a tag from contact just remove the relationship between them.
108
115
  client.remove_contact_tag("contact_tag_id)
109
116
  ```
110
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
+
111
156
  ## License
112
157
 
113
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', '< 3.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
- spec.add_development_dependency "rake", "~> 10.0"
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,11 +1,14 @@
1
- require 'faraday'
1
+ # frozen_string_literal: true
2
+
3
+ require 'excon'
2
4
  require 'cgi'
3
5
  require 'json'
4
6
 
5
7
  module Acw
6
8
  class Client
9
+ include Acw::Helpers
7
10
 
8
- Result = Struct.new(:success?, :error, :value)
11
+ API_VERSION = 3
9
12
 
10
13
  def initialize(configs = {})
11
14
  @config = configs
@@ -14,67 +17,108 @@ module Acw
14
17
  attr_reader :config
15
18
 
16
19
  def connection
17
- @connection ||= Faraday.new(url: config[:url]) do |faraday|
18
- faraday.headers["Accept"] = 'application/json'
19
- faraday.headers['Content-Type'] = 'application/json'
20
- faraday.headers['Api-Token'] = config[:token]
21
- faraday
22
- end
20
+ @connection ||= Excon.new(config[:url])
23
21
  end
24
22
 
25
- #CONTACTS
26
- def create_contact(args={})
23
+ def create_contact(args = {})
27
24
  safe_http_call do
28
25
  params = { contact: args }
29
- 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
+ )
30
31
  end
31
32
  end
32
33
 
33
- def sync_contact(args={})
34
+ def sync_contact(params)
34
35
  safe_http_call do
35
- params = { contact: args }
36
- 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
+ )
37
41
  end
38
42
  end
39
43
 
40
44
  def retrieve_contact(id)
41
45
  safe_http_call do
42
- connection.get("contacts/#{id}")
46
+ connection.get(
47
+ path: "/api/#{API_VERSION}/contacts/#{id}",
48
+ headers: headers(config[:token])
49
+ )
43
50
  end
44
51
  end
45
52
 
46
53
  def retrieve_contact_by_email(email)
47
54
  safe_http_call do
48
55
  uemail = CGI.escape email
49
- connection.get("contacts?search=#{uemail}")
56
+ connection.get(
57
+ path: "/api/#{API_VERSION}/contacts?search=#{uemail}",
58
+ headers: headers(config[:token])
59
+ )
50
60
  end
51
61
  end
52
62
 
53
- #LISTS
54
63
  def retrieve_lists
55
64
  safe_http_call do
56
- connection.get("lists")
65
+ connection.get(
66
+ path: "/api/#{API_VERSION}/lists",
67
+ headers: headers(config[:token])
68
+ )
57
69
  end
58
70
  end
59
71
 
60
- #TAGS
61
- def create_tag(args={})
72
+ def create_tag(args = {})
62
73
  safe_http_call do
63
- params = {"tag": args}
64
- connection.post("tags", params.to_json)
74
+ params = { tag: args }
75
+ connection.post(
76
+ path: "/api/#{API_VERSION}/tags",
77
+ headers: headers(config[:token]),
78
+ body: params.to_json
79
+ )
65
80
  end
66
81
  end
67
-
68
- def add_contact_tag(args={})
82
+
83
+ def add_contact_tag(args = {})
69
84
  safe_http_call do
70
- params = {"contactTag": args}
71
- connection.post("contactTags", params.to_json)
85
+ params = { 'contactTag': args }
86
+ connection.post(
87
+ path: "/api/#{API_VERSION}/contactTags",
88
+ headers: headers(config[:token]),
89
+ body: params.to_json
90
+ )
72
91
  end
73
92
  end
74
-
93
+
75
94
  def remove_contact_tag(id)
76
95
  safe_http_call do
77
- connection.delete("contactTags/#{id}")
96
+ connection.delete(
97
+ path: "/api/#{API_VERSION}/contactTags/#{id}",
98
+ headers: headers(config[:token])
99
+ )
100
+ end
101
+ end
102
+
103
+ def create_field_value(args = {})
104
+ safe_http_call do
105
+ params = { 'fieldValue': args }
106
+ connection.post(
107
+ path: "/api/#{API_VERSION}/fieldValues",
108
+ headers: headers(config[:token]),
109
+ body: params.to_json
110
+ )
111
+ end
112
+ end
113
+
114
+ def update_field_value(id, args = {})
115
+ safe_http_call do
116
+ params = { 'fieldValue': args }
117
+ connection.put(
118
+ path: "/api/#{API_VERSION}/fieldValues/#{id}",
119
+ headers: headers(config[:token]),
120
+ body: params.to_json
121
+ )
78
122
  end
79
123
  end
80
124
 
@@ -83,13 +127,14 @@ module Acw
83
127
  def safe_http_call
84
128
  response = yield
85
129
  raise response.body unless success_http_status(response.status)
86
- Result.new(true, nil, JSON.parse(response.body))
130
+
131
+ result(true, nil, JSON.parse(response.body))
87
132
  rescue StandardError => e
88
- Result.new(false, e.message, nil)
133
+ result(false, e.message, nil)
89
134
  end
90
135
 
91
136
  def success_http_status(status)
92
- status == 200 || status == 201
137
+ [200, 201, 202].include?(status)
93
138
  end
94
139
  end
95
- end
140
+ 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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Acw
2
- VERSION = "0.1.1"
4
+ VERSION = '1.3.2'
3
5
  end
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acw
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anchieta Júnior
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-04 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
- 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'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '3.0'
19
+ version: 0.73.0
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: '1.0'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '3.0'
26
+ version: 0.73.0
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: bundler
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,14 +44,14 @@ dependencies:
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '10.0'
47
+ version: 12.3.3
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: '10.0'
54
+ version: 12.3.3
61
55
  - !ruby/object:Gem::Dependency
62
56
  name: rspec
63
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +94,48 @@ dependencies:
100
94
  - - "~>"
101
95
  - !ruby/object:Gem::Version
102
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'
103
139
  description: Active Campaign Wrapper.
104
140
  email:
105
141
  - santosjr87@gmail.com
@@ -110,7 +146,7 @@ files:
110
146
  - ".github/workflows/ci.yml"
111
147
  - ".gitignore"
112
148
  - ".rspec"
113
- - ".travis.yml"
149
+ - ".rubocop.yml"
114
150
  - Gemfile
115
151
  - Gemfile.lock
116
152
  - LICENSE.txt
@@ -121,6 +157,7 @@ files:
121
157
  - bin/setup
122
158
  - lib/acw.rb
123
159
  - lib/acw/client.rb
160
+ - lib/acw/helpers.rb
124
161
  - lib/acw/version.rb
125
162
  homepage: https://github.com/anchietajunior.com/acw
126
163
  licenses:
@@ -130,7 +167,7 @@ metadata:
130
167
  homepage_uri: https://github.com/anchietajunior.com/acw
131
168
  source_code_uri: https://github.com/anchietajunior/acw
132
169
  changelog_uri: https://github.com/anchietajunior/acw
133
- post_install_message:
170
+ post_install_message:
134
171
  rdoc_options: []
135
172
  require_paths:
136
173
  - lib
@@ -145,8 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
182
  - !ruby/object:Gem::Version
146
183
  version: '0'
147
184
  requirements: []
148
- rubygems_version: 3.0.6
149
- signing_key:
185
+ rubygems_version: 3.0.8
186
+ signing_key:
150
187
  specification_version: 4
151
188
  summary: Active Campaign Wrapper.
152
189
  test_files: []
@@ -1,11 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.2
7
- before_install:
8
- - gem update --system
9
- - gem install bundler -v 2.0.2
10
- script:
11
- - bundle exec rspec