acw 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +53 -0
- data/LICENSE.txt +21 -0
- data/README.md +113 -0
- data/Rakefile +6 -0
- data/acw.gemspec +38 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/acw/client.rb +95 -0
- data/lib/acw/version.rb +3 -0
- data/lib/acw.rb +14 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3fe596f7097c6a3355323c283784d3b2103314fee7084c87c83f21ea99976ddc
|
4
|
+
data.tar.gz: 0c0a32b7357d07c05814285bd69619a4492618eb7fd2634e0a18f9a76d8d243e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66457311e161a8a3256bf3c55948ad5fc531883309ba07e438c1139fe929306b1d7e72bed58066614fc993813930a1a3469b11b6b4be6a51098b3e01e1c3e926
|
7
|
+
data.tar.gz: 0f705d80498efc7e37c463874710e8d20d6c753150afda75a36e9de87e3e6cb4f2d0ce47a4aff8549d08f75465151df493ce914a3bf1cc8c47c2422862baea26
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
acw (0.1.0)
|
5
|
+
faraday (>= 1.0, < 3.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.7.0)
|
11
|
+
public_suffix (>= 2.0.2, < 5.0)
|
12
|
+
crack (0.4.3)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
faraday (1.0.1)
|
16
|
+
multipart-post (>= 1.2, < 3)
|
17
|
+
hashdiff (1.0.1)
|
18
|
+
multipart-post (2.1.1)
|
19
|
+
public_suffix (4.0.4)
|
20
|
+
rake (10.5.0)
|
21
|
+
rspec (3.9.0)
|
22
|
+
rspec-core (~> 3.9.0)
|
23
|
+
rspec-expectations (~> 3.9.0)
|
24
|
+
rspec-mocks (~> 3.9.0)
|
25
|
+
rspec-core (3.9.1)
|
26
|
+
rspec-support (~> 3.9.1)
|
27
|
+
rspec-expectations (3.9.1)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.9.0)
|
30
|
+
rspec-mocks (3.9.1)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.9.0)
|
33
|
+
rspec-support (3.9.2)
|
34
|
+
safe_yaml (1.0.5)
|
35
|
+
vcr (5.1.0)
|
36
|
+
webmock (3.8.3)
|
37
|
+
addressable (>= 2.3.6)
|
38
|
+
crack (>= 0.3.2)
|
39
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
40
|
+
|
41
|
+
PLATFORMS
|
42
|
+
ruby
|
43
|
+
|
44
|
+
DEPENDENCIES
|
45
|
+
acw!
|
46
|
+
bundler (~> 2.0)
|
47
|
+
rake (~> 10.0)
|
48
|
+
rspec (~> 3.0)
|
49
|
+
vcr (~> 5.1)
|
50
|
+
webmock (~> 3.8)
|
51
|
+
|
52
|
+
BUNDLED WITH
|
53
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Anchieta Júnior
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# Acw
|
2
|
+
|
3
|
+
This is a very simple wrapper of the Active Campaign Api.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'acw'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install acw
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
> ### Initialize client
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = Acw::Client.new({
|
27
|
+
url: 'your-url',
|
28
|
+
token: 'your-token'
|
29
|
+
})
|
30
|
+
```
|
31
|
+
|
32
|
+
> ### Connection details
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
client = Acw::Client.new({
|
36
|
+
url: 'your-url',
|
37
|
+
token: 'your-token'
|
38
|
+
})
|
39
|
+
|
40
|
+
client.connection
|
41
|
+
```
|
42
|
+
|
43
|
+
> ### Create contact
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
client.create_contact({
|
47
|
+
email: 'contact@email.com',
|
48
|
+
firstName: 'first',
|
49
|
+
lastName: 'last',
|
50
|
+
phone: '12312312'
|
51
|
+
})
|
52
|
+
```
|
53
|
+
|
54
|
+
> ### Sync contact (Create or Update)
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
client.sync_contact({
|
58
|
+
email: 'contact@email.com',
|
59
|
+
firstName: 'first',
|
60
|
+
lastName: 'last',
|
61
|
+
phone: '12312312'
|
62
|
+
})
|
63
|
+
```
|
64
|
+
|
65
|
+
> ### Retrieve contact
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
client.retrieve_contact("contact_id")
|
69
|
+
```
|
70
|
+
|
71
|
+
> ### Retrieve contact by email
|
72
|
+
|
73
|
+
This will return an array of contacts.
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
client.retrieve_contact_by_email("email")
|
77
|
+
```
|
78
|
+
|
79
|
+
> ### Retrieve lists
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
client.retrieve_lists
|
83
|
+
```
|
84
|
+
|
85
|
+
> ### Create tag
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
client.create_tag({
|
89
|
+
tag: "tag_name", tagType: "tag_type"
|
90
|
+
})
|
91
|
+
```
|
92
|
+
|
93
|
+
> ### Add a tag to contact
|
94
|
+
|
95
|
+
It generates a relationship called contactTag containing an id.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
client.add_contact_tag({
|
99
|
+
contact: "contact_id", tag: "tag_id"
|
100
|
+
})
|
101
|
+
```
|
102
|
+
|
103
|
+
> ### Remove a tag to contact
|
104
|
+
|
105
|
+
To remove a tag from contact just remove the relationship between them.
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
client.remove_contact_tag("contact_tag_id)
|
109
|
+
```
|
110
|
+
|
111
|
+
## License
|
112
|
+
|
113
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/acw.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "acw/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "acw"
|
7
|
+
spec.version = Acw::VERSION
|
8
|
+
spec.authors = ["Anchieta Júnior"]
|
9
|
+
spec.email = ["santosjr87@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Active Campaign Wrapper.}
|
12
|
+
spec.description = %q{Active Campaign Wrapper.}
|
13
|
+
spec.homepage = "https://github.com/anchietajunior.com/acw"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/anchietajunior.com/acw"
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/anchietajunior.com/acw"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_dependency 'faraday', '>= 1.0', '< 3.0'
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "vcr", "~> 5.1"
|
37
|
+
spec.add_development_dependency "webmock", "~> 3.8"
|
38
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "acw"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/acw/client.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'cgi'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Acw
|
6
|
+
class Client
|
7
|
+
|
8
|
+
Result = Struct.new(:success?, :error, :value)
|
9
|
+
|
10
|
+
def initialize(configs = {})
|
11
|
+
@config = configs
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :config
|
15
|
+
|
16
|
+
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
|
23
|
+
end
|
24
|
+
|
25
|
+
#CONTACTS
|
26
|
+
def create_contact(args={})
|
27
|
+
safe_http_call do
|
28
|
+
params = { contact: args }
|
29
|
+
connection.post("contacts", params.to_json)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def sync_contact(args={})
|
34
|
+
safe_http_call do
|
35
|
+
params = { contact: args }
|
36
|
+
connection.post("contact/sync", params.to_json)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def retrieve_contact(id)
|
41
|
+
safe_http_call do
|
42
|
+
connection.get("contacts/#{id}")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def retrieve_contact_by_email(email)
|
47
|
+
safe_http_call do
|
48
|
+
uemail = CGI.escape email
|
49
|
+
connection.get("contacts?search=#{uemail}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#LISTS
|
54
|
+
def retrieve_lists
|
55
|
+
safe_http_call do
|
56
|
+
connection.get("lists")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
#TAGS
|
61
|
+
def create_tag(args={})
|
62
|
+
safe_http_call do
|
63
|
+
params = {"tag": args}
|
64
|
+
connection.post("tags", params.to_json)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def add_contact_tag(args={})
|
69
|
+
safe_http_call do
|
70
|
+
params = {"contactTag": args}
|
71
|
+
connection.post("contactTags", params.to_json)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def remove_contact_tag(id)
|
76
|
+
safe_http_call do
|
77
|
+
connection.delete("contactTags/#{id}")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def safe_http_call
|
84
|
+
response = yield
|
85
|
+
raise response.body unless success_http_status(response.status)
|
86
|
+
Result.new(true, nil, JSON.parse(response.body))
|
87
|
+
rescue StandardError => e
|
88
|
+
Result.new(false, e.message, nil)
|
89
|
+
end
|
90
|
+
|
91
|
+
def success_http_status(status)
|
92
|
+
status == 200 || status == 201
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/acw/version.rb
ADDED
data/lib/acw.rb
ADDED
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: acw
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Anchieta Júnior
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '3.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '3.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: vcr
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '5.1'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '5.1'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: webmock
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.8'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.8'
|
103
|
+
description: Active Campaign Wrapper.
|
104
|
+
email:
|
105
|
+
- santosjr87@gmail.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".gitignore"
|
111
|
+
- ".rspec"
|
112
|
+
- ".travis.yml"
|
113
|
+
- Gemfile
|
114
|
+
- Gemfile.lock
|
115
|
+
- LICENSE.txt
|
116
|
+
- README.md
|
117
|
+
- Rakefile
|
118
|
+
- acw.gemspec
|
119
|
+
- bin/console
|
120
|
+
- bin/setup
|
121
|
+
- lib/acw.rb
|
122
|
+
- lib/acw/client.rb
|
123
|
+
- lib/acw/version.rb
|
124
|
+
homepage: https://github.com/anchietajunior.com/acw
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata:
|
128
|
+
allowed_push_host: https://rubygems.org
|
129
|
+
homepage_uri: https://github.com/anchietajunior.com/acw
|
130
|
+
source_code_uri: https://github.com/anchietajunior.com/acw
|
131
|
+
changelog_uri: https://github.com/anchietajunior.com/acw
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubygems_version: 3.0.6
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: Active Campaign Wrapper.
|
151
|
+
test_files: []
|