ractive_campaign 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c6b7944a2753a3db0335c5c172ebeac9dfb33eb9a5f15071036b552bf555592a
4
+ data.tar.gz: 80048d41a31fe9286cd7aa78dbe9372909336b06b989d2148e42eb58ea39cf6f
5
+ SHA512:
6
+ metadata.gz: 2d4d9640752af2626483f7802d5e9236fe54d30a984d700f004424d459be67bc0f934ecbca0bb56df2c75a028b4be14dbd7a1b11ddc51f2c292ad9a8aa01958a
7
+ data.tar.gz: afce1288618683daab865e7dc89799c0a79ddece26a3563d8f3a6847053bbb109e6328deb2d73b995afbad8656bdc717ef477559725140555cc0d7899d212a02
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-11-10
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at wedson.sousa.lima@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in vindi.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ group :development do
11
+ gem "dotenv"
12
+ gem "httplog"
13
+ gem "pry-byebug"
14
+ gem "rubocop"
15
+ end
16
+
17
+ group :test do
18
+ gem "rspec"
19
+ gem "vcr"
20
+ gem "webmock"
21
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,132 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ractive_campaign (0.0.1)
5
+ activemodel (~> 6.1.4)
6
+ activesupport (~> 6.1.4)
7
+ dry-configurable (~> 0.7.0)
8
+ faraday (~> 1.8.0)
9
+ faraday_middleware (~> 1.2.0)
10
+ oj (>= 3.0, < 4.0)
11
+
12
+ GEM
13
+ remote: https://rubygems.org/
14
+ specs:
15
+ activemodel (6.1.4.1)
16
+ activesupport (= 6.1.4.1)
17
+ activesupport (6.1.4.1)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 1.6, < 2)
20
+ minitest (>= 5.1)
21
+ tzinfo (~> 2.0)
22
+ zeitwerk (~> 2.3)
23
+ addressable (2.8.0)
24
+ public_suffix (>= 2.0.2, < 5.0)
25
+ ast (2.4.2)
26
+ byebug (11.1.3)
27
+ coderay (1.1.3)
28
+ concurrent-ruby (1.1.9)
29
+ crack (0.4.5)
30
+ rexml
31
+ diff-lcs (1.4.4)
32
+ dotenv (2.7.6)
33
+ dry-configurable (0.7.0)
34
+ concurrent-ruby (~> 1.0)
35
+ faraday (1.8.0)
36
+ faraday-em_http (~> 1.0)
37
+ faraday-em_synchrony (~> 1.0)
38
+ faraday-excon (~> 1.1)
39
+ faraday-httpclient (~> 1.0.1)
40
+ faraday-net_http (~> 1.0)
41
+ faraday-net_http_persistent (~> 1.1)
42
+ faraday-patron (~> 1.0)
43
+ faraday-rack (~> 1.0)
44
+ multipart-post (>= 1.2, < 3)
45
+ ruby2_keywords (>= 0.0.4)
46
+ faraday-em_http (1.0.0)
47
+ faraday-em_synchrony (1.0.0)
48
+ faraday-excon (1.1.0)
49
+ faraday-httpclient (1.0.1)
50
+ faraday-net_http (1.0.1)
51
+ faraday-net_http_persistent (1.2.0)
52
+ faraday-patron (1.0.0)
53
+ faraday-rack (1.0.0)
54
+ faraday_middleware (1.2.0)
55
+ faraday (~> 1.0)
56
+ hashdiff (1.0.1)
57
+ httplog (1.5.0)
58
+ rack (>= 1.0)
59
+ rainbow (>= 2.0.0)
60
+ i18n (1.8.11)
61
+ concurrent-ruby (~> 1.0)
62
+ method_source (1.0.0)
63
+ minitest (5.14.4)
64
+ multipart-post (2.1.1)
65
+ oj (3.13.9)
66
+ parallel (1.21.0)
67
+ parser (3.0.2.0)
68
+ ast (~> 2.4.1)
69
+ pry (0.13.1)
70
+ coderay (~> 1.1)
71
+ method_source (~> 1.0)
72
+ pry-byebug (3.9.0)
73
+ byebug (~> 11.0)
74
+ pry (~> 0.13.0)
75
+ public_suffix (4.0.6)
76
+ rack (2.2.3)
77
+ rainbow (3.0.0)
78
+ rake (13.0.6)
79
+ regexp_parser (2.1.1)
80
+ rexml (3.2.5)
81
+ rspec (3.10.0)
82
+ rspec-core (~> 3.10.0)
83
+ rspec-expectations (~> 3.10.0)
84
+ rspec-mocks (~> 3.10.0)
85
+ rspec-core (3.10.1)
86
+ rspec-support (~> 3.10.0)
87
+ rspec-expectations (3.10.1)
88
+ diff-lcs (>= 1.2.0, < 2.0)
89
+ rspec-support (~> 3.10.0)
90
+ rspec-mocks (3.10.2)
91
+ diff-lcs (>= 1.2.0, < 2.0)
92
+ rspec-support (~> 3.10.0)
93
+ rspec-support (3.10.3)
94
+ rubocop (1.22.3)
95
+ parallel (~> 1.10)
96
+ parser (>= 3.0.0.0)
97
+ rainbow (>= 2.2.2, < 4.0)
98
+ regexp_parser (>= 1.8, < 3.0)
99
+ rexml
100
+ rubocop-ast (>= 1.12.0, < 2.0)
101
+ ruby-progressbar (~> 1.7)
102
+ unicode-display_width (>= 1.4.0, < 3.0)
103
+ rubocop-ast (1.13.0)
104
+ parser (>= 3.0.1.1)
105
+ ruby-progressbar (1.11.0)
106
+ ruby2_keywords (0.0.5)
107
+ tzinfo (2.0.4)
108
+ concurrent-ruby (~> 1.0)
109
+ unicode-display_width (2.1.0)
110
+ vcr (6.0.0)
111
+ webmock (3.14.0)
112
+ addressable (>= 2.8.0)
113
+ crack (>= 0.3.2)
114
+ hashdiff (>= 0.4.0, < 2.0.0)
115
+ zeitwerk (2.5.1)
116
+
117
+ PLATFORMS
118
+ x86_64-linux
119
+
120
+ DEPENDENCIES
121
+ dotenv
122
+ httplog
123
+ pry-byebug
124
+ ractive_campaign!
125
+ rake (~> 13.0)
126
+ rspec
127
+ rubocop
128
+ vcr
129
+ webmock
130
+
131
+ BUNDLED WITH
132
+ 2.2.31
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Wedson Lima
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,43 @@
1
+ # RactiveCampaign
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ractive_campaign`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ractive_campaign'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ractive_campaign
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ractive_campaign. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ractive_campaign/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the RactiveCampaign project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ractive_campaign/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "dotenv/load"
6
+ require "active_campaign"
7
+ require "httplog"
8
+ require "json"
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+
13
+ ActiveCampaign.configure do |config|
14
+ config.api_url = ENV["AC_API_URL"]
15
+ config.api_key = ENV["AC_API_KEY"]
16
+ end
17
+
18
+ HttpLog.configure do |config|
19
+ config.log_headers = true
20
+ end
21
+
22
+ require "pry"
23
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaign
4
+ class API # :nodoc:
5
+ attr_reader :connection
6
+
7
+ def initialize
8
+ setup
9
+ end
10
+
11
+ def setup
12
+ @connection = Faraday.new(::ActiveCampaign.config.api_url) do |f|
13
+ f.request :json
14
+ f.response :json, content_type: "application/json"
15
+
16
+ f.use ::ActiveCampaign::ResponseParser
17
+ f.use Faraday::Request::UrlEncoded
18
+
19
+ f.adapter Faraday.default_adapter
20
+ end
21
+
22
+ @connection.headers["Api-Token"] = ::ActiveCampaign.config.api_key
23
+ @connection.headers["User-Agent"] = "Ruby ActiveCampaign (ractive_campaign)"
24
+
25
+ self
26
+ end
27
+
28
+ # @private
29
+ def request(opts = {})
30
+ method = opts.delete(:_method)
31
+ path = opts.delete(:_path)
32
+ headers = opts.delete(:_headers)
33
+
34
+ opts.delete_if { |key, _| key.to_s =~ /^_/ } # Remove all internal parameters
35
+
36
+ response = @connection.send method do |request|
37
+ request.headers.merge!(headers) if headers
38
+
39
+ if method == :get
40
+ request.url path, opts
41
+ else
42
+ request.url path
43
+ request.body = opts
44
+ end
45
+ end
46
+
47
+ {
48
+ parsed_data: response.env[:parsed_data],
49
+ _response: response
50
+ }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,99 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaign
4
+ module Attributes # :nodoc:
5
+ extend ActiveSupport::Concern
6
+
7
+ attr_accessor :all_attrs
8
+
9
+ DEFAULT_ATTRS = %i[
10
+ id
11
+ cdate
12
+ created_timestamp
13
+ updated_timestamp
14
+ created_utc_timestamp
15
+ updated_utc_timestamp
16
+ created_by
17
+ updated_by
18
+ links
19
+ ].freeze
20
+
21
+ def only_changes_to_params
22
+ return nil unless changed?
23
+
24
+ root, root_params = to_params.first
25
+
26
+ {
27
+ root => root_params.slice(*changed)
28
+ }
29
+ end
30
+
31
+ def to_params
32
+ iv = instance_variables - DEFAULT_ATTRS.map { |da| :"@#{da}" } - %i[@mutations_from_database @mutations_before_last_save]
33
+
34
+ {
35
+ self.class.root_element => iv.map { |v| [v.to_s.delete("@"), instance_variable_get(v)] }.to_h
36
+ }
37
+ end
38
+
39
+ module ClassMethods # :nodoc:
40
+ def define_attributes(*attrs)
41
+ attrs.each do |attr|
42
+ define_attribute_methods attr
43
+
44
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
45
+ def #{attr}
46
+ @#{attr}
47
+ end
48
+
49
+ def #{attr}=(val)
50
+ #{attr}_will_change! unless val == @#{attr}
51
+ @#{attr} = val
52
+ end
53
+ RUBY
54
+ end
55
+ end
56
+
57
+ def new_records(data)
58
+ instantiate_records self, data
59
+ end
60
+
61
+ def new_record(data)
62
+ instantiate_record self, data
63
+ end
64
+
65
+ def instantiate_record(klass, data)
66
+ record = klass.new data
67
+ record.clear_changes_information
68
+ record
69
+ end
70
+
71
+ def instantiate_records(klass, records_data)
72
+ records_data.map do |record_data|
73
+ instantiate_record klass, record_data
74
+ end
75
+ end
76
+
77
+ def endpoint
78
+ name.demodulize.underscore.pluralize
79
+ end
80
+
81
+ def root_element
82
+ name.demodulize.underscore.to_sym
83
+ end
84
+
85
+ def root_elements
86
+ root_element.to_s.pluralize.to_sym
87
+ end
88
+ end
89
+
90
+ # def reload!
91
+ # # get the values from the persistence layer
92
+ # clear_changes_information
93
+ # end
94
+
95
+ def rollback!
96
+ restore_attributes
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaign
4
+ class Error < RuntimeError # :nodoc:
5
+ def initialize(response = nil, exception = nil)
6
+ super
7
+
8
+ self.response = response
9
+ @exception = exception
10
+ end
11
+
12
+ def message
13
+ if response.nil?
14
+ super
15
+ else
16
+ <<~MESSAGE
17
+ STATUS: #{response.status}
18
+ URL: #{env.url}
19
+ REQUEST HEADERS: #{env.request_headers}
20
+ RESPONSE_HEADERS: #{env.response_headers}
21
+ REQUEST_BODY: #{env.request_body}\n\n"
22
+ RESPONSE_BODY: #{response.body}\n\n"
23
+ MESSAGE
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def env
30
+ @env ||= response.env
31
+ end
32
+
33
+ attr_accessor :response
34
+ end
35
+
36
+ class ClientError < Error
37
+ end
38
+
39
+ class UnauthorizedError < ClientError
40
+ end
41
+
42
+ class ResourceNotFound < ClientError
43
+ end
44
+
45
+ class UnprocessableEntityError < ClientError
46
+ end
47
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaign
4
+ module ApiHttp # :nodoc:
5
+ extend ActiveSupport::Concern
6
+
7
+ HTTP_METHODS = %i[get post put delete].freeze
8
+
9
+ module ClassMethods # :nodoc:
10
+ HTTP_METHODS.each do |method|
11
+ class_eval <<-RUBY, __FILE__, __LINE__ + 1
12
+ def #{method}(path, params={})
13
+ send(:'#{method}_raw', path, params) do |parsed_data, response|
14
+ return {} unless [200, 201].include?(parsed_data[:status_code])
15
+ return {} unless parsed_data[:data].present?
16
+
17
+ data = parsed_data[:data].first.last
18
+
19
+ if data.is_a?(Array)
20
+ new_records data
21
+ else
22
+ new_record data
23
+ end
24
+ end
25
+ end
26
+
27
+ def #{method}_raw(path, params={}, &block)
28
+ request(params.merge(:_method => #{method.to_sym.inspect}, :_path => path), &block)
29
+ end
30
+ RUBY
31
+ end
32
+
33
+ def request(params = {})
34
+ api = ActiveCampaign::API.new
35
+ request = api.request params
36
+
37
+ if block_given?
38
+ yield request[:parsed_data], request[:_response]
39
+ else
40
+ request
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaign
4
+ class Contact < Model # :nodoc:
5
+ define_attributes :email,
6
+ :phone,
7
+ :firstName,
8
+ :lastName,
9
+ :orgid,
10
+ :orgname,
11
+ :segmentio_id,
12
+ :bounced_hard,
13
+ :bounced_soft,
14
+ :bounced_date,
15
+ :ip,
16
+ :ua,
17
+ :hash,
18
+ :socialdata_lastcheck,
19
+ :email_local,
20
+ :email_domain,
21
+ :sentcnt,
22
+ :rating_tstamp,
23
+ :gravatar,
24
+ :deleted,
25
+ :anonymized,
26
+ :adate,
27
+ :udate,
28
+ :edate,
29
+ :deleted_at,
30
+ :email_empty,
31
+ :mpp_tracking,
32
+ :scoreValues,
33
+ :accountContacts,
34
+ :organization
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaign
4
+ class ContactTag < Model # :nodoc:
5
+ define_attributes :tag_id, :contact_id
6
+ end
7
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaign
4
+ class Model # :nodoc:
5
+ include ActiveModel::Model
6
+ include ActiveModel::Dirty
7
+
8
+ include ActiveCampaign::ApiHttp
9
+ include ActiveCampaign::Attributes
10
+
11
+ define_attributes(*DEFAULT_ATTRS)
12
+
13
+ class << self
14
+ def all
15
+ get endpoint
16
+ end
17
+
18
+ def filter(args = {})
19
+ get "#{endpoint}?#{args}"
20
+ end
21
+
22
+ def find_by(args = {})
23
+ filter(args.to_query).last
24
+ end
25
+
26
+ def find(id)
27
+ get "#{endpoint}/#{id}"
28
+ end
29
+
30
+ def save(**args)
31
+ new(args).save
32
+ end
33
+
34
+ def create(**args)
35
+ new(args).create
36
+ end
37
+ end
38
+
39
+ def save
40
+ return update if id.present?
41
+
42
+ create
43
+ end
44
+
45
+ def update
46
+ return nil unless changed?
47
+
48
+ result = self.class.put "#{self.class.endpoint}/#{id}", only_changes_to_params
49
+
50
+ changes_applied
51
+
52
+ result
53
+ end
54
+
55
+ def create
56
+ result = self.class.post self.class.endpoint, to_params
57
+
58
+ changes_applied
59
+
60
+ result
61
+ end
62
+
63
+ def destroy
64
+ self.class.delete "#{self.class.endpoint}/#{id}"
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaign
4
+ class Tag < Model # :nodoc:
5
+ define_attributes :tagType, :tag, :description, :subscriber_count
6
+
7
+ class << self
8
+ def find_by(tag:)
9
+ filter({ tags: { tag: tag } }.to_query).last
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module ActiveCampaign
6
+ class ResponseParser < Faraday::Response::Middleware # :nodoc:
7
+ def on_complete(env)
8
+ parsed_data = JSON.parse(env[:body], symbolize_names: true)
9
+ metadata = parsed_data.delete(:meta) || []
10
+ errors = parsed_data.delete(:errors) || {}
11
+ score_values = parsed_data.delete(:scoreValues) || {}
12
+ status_code = env[:status]
13
+
14
+ env[:parsed_data] = {
15
+ status_code: status_code,
16
+ data: parsed_data,
17
+ errors: errors,
18
+ meta: metadata,
19
+ score_values: score_values
20
+ }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveCampaign
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-configurable"
4
+
5
+ require "faraday"
6
+ require "faraday_middleware"
7
+
8
+ require "active_model"
9
+ # require "active_support"
10
+ require "active_support/inflector"
11
+
12
+ require "active_campaign/version"
13
+ require "active_campaign/parser"
14
+ require "active_campaign/api_attributes"
15
+ require "active_campaign/api_errors"
16
+ require "active_campaign/api"
17
+ require "active_campaign/api_http"
18
+
19
+ module ActiveCampaign # :nodoc:
20
+ extend Dry::Configurable
21
+
22
+ RESOURCE_MODELS = Dir[File.expand_path("active_campaign/models/**/*.rb", File.dirname(__FILE__))].freeze
23
+
24
+ RESOURCE_MODELS.each do |f|
25
+ autoload File.basename(f, ".rb").camelcase.to_sym, f
26
+ end
27
+
28
+ setting :api_url
29
+ setting :api_key
30
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ractive_campaign
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Wedson Lima
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 6.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 6.1.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 6.1.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 6.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: dry-configurable
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.7.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.2.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: oj
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: '4.0'
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '3.0'
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: '4.0'
103
+ description: Active Campaign - API v3
104
+ email:
105
+ - wedson.sousa.lima@gmail.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - ".rspec"
111
+ - ".rubocop.yml"
112
+ - CHANGELOG.md
113
+ - CODE_OF_CONDUCT.md
114
+ - Gemfile
115
+ - Gemfile.lock
116
+ - LICENSE.txt
117
+ - README.md
118
+ - Rakefile
119
+ - bin/console
120
+ - bin/setup
121
+ - lib/active_campaign.rb
122
+ - lib/active_campaign/api.rb
123
+ - lib/active_campaign/api_attributes.rb
124
+ - lib/active_campaign/api_errors.rb
125
+ - lib/active_campaign/api_http.rb
126
+ - lib/active_campaign/models/contact.rb
127
+ - lib/active_campaign/models/contact_tag.rb
128
+ - lib/active_campaign/models/model.rb
129
+ - lib/active_campaign/models/tag.rb
130
+ - lib/active_campaign/parser.rb
131
+ - lib/active_campaign/version.rb
132
+ homepage: https://github.com/wedsonlima/ractive_campaign
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 2.6.0
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.0.3.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Active Campaign - API v3
155
+ test_files: []