patch_retention 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 39372fa6c5337b7ee0b824d3a9b717cf6f3b62486ed6da883feb7eb394e7e0ee
4
+ data.tar.gz: 4a91fb7072ef27462f7b191801aa2ca44150a41c4f750d7935f48645a40ef2ac
5
+ SHA512:
6
+ metadata.gz: a2d9e50653fa49e3a025825e79d6b7aea605489c512c4610a547a90c7d9ec692ce2ec18b9b220994de7cf8a072b779be5348edb158d7e6fad68fd1e65a19597a
7
+ data.tar.gz: 53d290e59bb4a343948d64b6b65e706f89b413868c787f73d2f35c843d57f50c143ac95eaf126e72a711badf604efb18d23542fb484c5a6867ba01f46e00dae8
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
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
+ Style/ClassAndModuleChildren:
13
+ EnforcedStyle: compact
14
+
15
+ Metrics/MethodLength:
16
+ Max: 30
17
+
18
+ Style/ModuleFunction:
19
+ Enabled: false
20
+
21
+ Metrics/AbcSize:
22
+ Max: 30
23
+
24
+ Layout/LineLength:
25
+ Max: 120
26
+
27
+ Style/Documentation:
28
+ Enabled: false
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.7.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-12-03
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 g3ortega@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,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in patch_retention.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "faraday"
11
+ gem "zeitwerk"
12
+
13
+ group :development do
14
+ gem "byebug"
15
+ gem "pry", require: true
16
+ gem "rspec", "~> 3.0"
17
+ gem "rubocop", "~> 1.21"
18
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,79 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ patch_retention (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ base64 (0.2.0)
11
+ byebug (11.1.3)
12
+ coderay (1.1.3)
13
+ diff-lcs (1.5.0)
14
+ faraday (2.7.12)
15
+ base64
16
+ faraday-net_http (>= 2.0, < 3.1)
17
+ ruby2_keywords (>= 0.0.4)
18
+ faraday-net_http (3.0.2)
19
+ json (2.7.0)
20
+ language_server-protocol (3.17.0.3)
21
+ method_source (1.0.0)
22
+ parallel (1.23.0)
23
+ parser (3.2.2.4)
24
+ ast (~> 2.4.1)
25
+ racc
26
+ pry (0.14.2)
27
+ coderay (~> 1.1)
28
+ method_source (~> 1.0)
29
+ racc (1.7.3)
30
+ rainbow (3.1.1)
31
+ rake (13.1.0)
32
+ regexp_parser (2.8.2)
33
+ rexml (3.2.6)
34
+ rspec (3.12.0)
35
+ rspec-core (~> 3.12.0)
36
+ rspec-expectations (~> 3.12.0)
37
+ rspec-mocks (~> 3.12.0)
38
+ rspec-core (3.12.2)
39
+ rspec-support (~> 3.12.0)
40
+ rspec-expectations (3.12.3)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.12.0)
43
+ rspec-mocks (3.12.6)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.12.0)
46
+ rspec-support (3.12.1)
47
+ rubocop (1.58.0)
48
+ json (~> 2.3)
49
+ language_server-protocol (>= 3.17.0)
50
+ parallel (~> 1.10)
51
+ parser (>= 3.2.2.4)
52
+ rainbow (>= 2.2.2, < 4.0)
53
+ regexp_parser (>= 1.8, < 3.0)
54
+ rexml (>= 3.2.5, < 4.0)
55
+ rubocop-ast (>= 1.30.0, < 2.0)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (>= 2.4.0, < 3.0)
58
+ rubocop-ast (1.30.0)
59
+ parser (>= 3.2.1.0)
60
+ ruby-progressbar (1.13.0)
61
+ ruby2_keywords (0.0.5)
62
+ unicode-display_width (2.5.0)
63
+ zeitwerk (2.6.0)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ byebug
70
+ faraday
71
+ patch_retention!
72
+ pry
73
+ rake (~> 13.0)
74
+ rspec (~> 3.0)
75
+ rubocop (~> 1.21)
76
+ zeitwerk
77
+
78
+ BUNDLED WITH
79
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Gerardo Ortega
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,141 @@
1
+ # Patch Retention API Wrapper
2
+
3
+ ## Installation
4
+
5
+ Install the gem and add to the application's Gemfile by executing:
6
+
7
+ $ bundle add patch_retention
8
+
9
+ If bundler is not being used to manage dependencies, install the gem by executing:
10
+
11
+ $ gem install patch_retention
12
+
13
+ ## Usage
14
+
15
+ ### Configuration
16
+
17
+ For local environment, you can set the following environment variables:
18
+
19
+ ```bash
20
+ PATCH_RETENTION_API_URL='your_custom_api_url' # Optional, by default is set to: https://api.patchretention.com/v2
21
+ PATCH_RETENTION_CLIENT_ID='your_client_id'
22
+ PATCH_RETENTION_CLIENT_SECRET='your_client_secret'
23
+ ```
24
+
25
+ Credentials might also be set in the initializer:
26
+
27
+ ```ruby
28
+ PatchRetention.configure do |config|
29
+ config.api_url = 'your_custom_api_url' # Optional, by default is set to: https://api.patchretention.com/v2
30
+ config.client_id = 'your_client_id'
31
+ config.client_secret = 'your_client_secret'
32
+ end
33
+ ```
34
+
35
+ ### Usage
36
+
37
+ First, you need to configure the gem with your API credentials.
38
+
39
+ Then, you can use the gem's methods to interact with the API. For example, to retrieve all contacts:
40
+
41
+ **Contacts:**
42
+
43
+ ```ruby
44
+ contacts = PatchRetention::Contacts.all
45
+ ```
46
+
47
+ To retrieve a single contact:
48
+
49
+ ```ruby
50
+ contact = PatchRetention::Contacts.find(1)
51
+ ```
52
+
53
+ To create a contact:
54
+
55
+ ```ruby
56
+ contact = PatchRetention::Contacts.find_or_create_by(
57
+ contact_params: {
58
+ first_name: 'John',
59
+ last_name: 'Doe',
60
+ email: 'john.doe@playbypoint.com',
61
+ phone: '1234567890',
62
+ address: '123 Main St',
63
+ city: 'New York',
64
+ state: 'NY',
65
+ zip: '10001',
66
+ country: 'US',
67
+ company: 'PlayByPoint',
68
+ job_title: 'Developer'
69
+ },
70
+ query_params: {
71
+ email: 'john.doe@playbypoint.com',
72
+ phone: '1234567890'
73
+ }
74
+ )
75
+ ```
76
+
77
+ **Events**
78
+
79
+ To retrieve all events:
80
+
81
+ ```ruby
82
+ events = PatchRetention::Events.all
83
+ ```
84
+
85
+ To retrieve a single event:
86
+
87
+ ```ruby
88
+ event = PatchRetention::Events.find(1)
89
+ ```
90
+
91
+ To create an event:
92
+
93
+ ```ruby
94
+ event = PatchRetention::Events.create(
95
+ event_type: 'order.finished',
96
+ primary_key_details: {
97
+ key: 'email',
98
+ value: 'john.doe@pbp.com'
99
+ },
100
+ data: {
101
+ "external_id": "1234567890",
102
+ "subtotal_amount": 3000,
103
+ "total_tax": 300,
104
+ "total_amount": 3300,
105
+ "total_discounts": 0,
106
+ "facility_id": 1,
107
+ },
108
+ contact_details: {
109
+ upsert: true,
110
+ params: {
111
+ # Optional, if upsert is true
112
+ first_name: 'John',
113
+ last_name: 'Doe',
114
+ email: 'john.doe@pbp.com',
115
+ phone: '1234567890',
116
+ address: '123 Main St',
117
+ city: 'New York'
118
+ }
119
+
120
+ },
121
+ at: Time.now,
122
+ )
123
+ ```
124
+
125
+ ## Development
126
+
127
+ 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.
128
+
129
+ 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).
130
+
131
+ ## Contributing
132
+
133
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/patch_retention. 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]/patch_retention/blob/main/CODE_OF_CONDUCT.md).
134
+
135
+ ## License
136
+
137
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
138
+
139
+ ## Code of Conduct
140
+
141
+ Everyone interacting in the PatchRetention project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/patch_retention/blob/main/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]
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PatchRetention # rubocop:disable Style/ClassAndModuleChildren
4
+ class Configuration
5
+ attr_accessor :api_url, :client_id, :client_secret
6
+
7
+ def initialize
8
+ @api_url = ENV.fetch("PATCH_RETENTION_API_URL", "https://api.patchretention.com/v2")
9
+ @client_id = ENV.fetch("PATCH_RETENTION_CLIENT_ID", nil)
10
+ @client_secret = ENV.fetch("PATCH_RETENTION_CLIENT_SECRET", nil)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PatchRetention::Contacts::Delete
4
+ include PatchRetention::Utils
5
+ extend self
6
+
7
+ def call(id)
8
+ raise_error_if_present do
9
+ PatchRetention.connection.delete("#{PatchRetention::Contacts::API_PATH}/#{id}")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The PatchRetention::Contacts::Find module provides methods to find contacts
4
+ # in the PatchRetention system. It includes methods to find a contact by ID
5
+ # and to retrieve all contacts with pagination.
6
+ #
7
+ # @example Finding a contact by ID
8
+ # PatchRetention::Contacts::Find.by_id(123)
9
+ #
10
+ # @example Retrieving all contacts with pagination
11
+ # PatchRetention::Contacts::Find.all(10, 0)
12
+ #
13
+ module PatchRetention::Contacts::Find
14
+ include PatchRetention::Util
15
+ extend self
16
+
17
+ # Finds a contact by its ID.
18
+ #
19
+ # @param id [Integer] The ID of the contact to find.
20
+ # @return [Object] The response from the PatchRetention API.
21
+ # @raise [PatchRetention::Error] If the API returns a status other than 200.
22
+ def by_id(id)
23
+ raise_error_if_present do
24
+ PatchRetention.connection.get("#{PatchRetention::Contacts::API_PATH}/#{id}")
25
+ end
26
+ end
27
+
28
+ # Retrieves all contacts with pagination.
29
+ #
30
+ # @param limit [Integer] The number of contacts to retrieve per page.
31
+ # @param offset [Integer] The number of contacts to skip before starting to collect the result set.
32
+ # @return [Object] The response from the PatchRetention API.
33
+ # @raise [PatchRetention::Error] If the API returns a status other than 200.
34
+ def all(limit, offset)
35
+ raise_error_if_present do
36
+ PatchRetention.connection.get(PatchRetention::Contacts::API_PATH) do |req|
37
+ req.params["limit"] = limit
38
+ req.params["offset"] = offset
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PatchRetention::Contacts::FindOrCreate
4
+ include PatchRetention::Util
5
+ extend self
6
+
7
+ ALLOWED_CONTACT_PARAMS = %i[
8
+ first_name
9
+ last_name
10
+ email
11
+ phone
12
+ sms_on
13
+ email_on
14
+ ].freeze
15
+
16
+ def call(contact_params:, query_params:)
17
+ contact_params = contact_params.slice(*ALLOWED_CONTACT_PARAMS)
18
+
19
+ raise_error_if_present do
20
+ PatchRetention.connection.patch(PatchRetention::Contacts::API_PATH) do |req|
21
+ req.params["search"] = build_search_string(query_params)
22
+ req.body = contact_params
23
+ end
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def build_search_string(query_params)
30
+ query_params = query_params.slice(:email, :phone).compact.map do |key, value|
31
+ { "search:#{key}" => value }
32
+ end.reduce(&:merge)
33
+
34
+ URI.encode_www_form(query_params)
35
+ end
36
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PatchRetention::Contacts::Update
4
+ include PatchRetention::Util
5
+ extend self
6
+
7
+ def call(id, contact_params)
8
+ raise_error_if_present do
9
+ PatchRetention.connection.put("#{PatchRetention::Contacts::API_PATH}/#{id}") do |req|
10
+ req.body = contact_params.to_json
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PatchRetention::Contacts
4
+ API_PATH = "contacts"
5
+
6
+ class << self
7
+ def find(id)
8
+ Find.by_id(id)
9
+ end
10
+
11
+ def all(limit: 30, offset: 0)
12
+ Find.all(limit, offset)
13
+ end
14
+
15
+ def find_or_create_by(contact_params:, query_params: {})
16
+ FindOrCreate.call(
17
+ contact_params: contact_params,
18
+ query_params: query_params
19
+ )
20
+ end
21
+
22
+ def update(id, attributes = {})
23
+ Update.call!(id, attributes)
24
+ end
25
+
26
+ def delete(id)
27
+ Delete.call(id)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PatchRetention::Events::Create
4
+ include PatchRetention::Util
5
+ extend self
6
+
7
+ def call(event_type:, primary_key_details:, data:, at:, contact_details:)
8
+ contact_upsert = contact_details[:upsert] || false
9
+
10
+ params = {
11
+ event: event_type,
12
+ primary_key: primary_key_details[:key],
13
+ primary_key_value: primary_key_details[:value],
14
+ data: data,
15
+ contact_upsert: contact_upsert
16
+ }.compact
17
+
18
+ params.merge!(at: format_datetime(at)) unless at.nil?
19
+ params.merge!(contact: contact_details[:params]) if contact_upsert && contact_details.key?(:params)
20
+
21
+ send_request(params)
22
+ end
23
+
24
+ private
25
+
26
+ def send_request(params)
27
+ raise_error_if_present do
28
+ PatchRetention.connection.post(PatchRetention::Events::API_PATH) do |req|
29
+ req.body = params
30
+ end
31
+ end
32
+ end
33
+
34
+ def format_datetime(datetime)
35
+ return unless datetime
36
+
37
+ datetime.to_time.utc.strftime("%Y-%m-%dT%H:%M:%S%z")
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PatchRetention::Events::Find
4
+ include PatchRetention::Util
5
+ extend self
6
+
7
+ def by_id(id)
8
+ raise_error_if_present do
9
+ PatchRetention.connection.get("#{PatchRetention::Events::API_PATH}/#{id}")
10
+ end
11
+ end
12
+
13
+ def all(limit, offset)
14
+ raise_error_if_present do
15
+ PatchRetention.connection.get(PatchRetention::Events::API_PATH) do |req|
16
+ req.params["limit"] = limit
17
+ req.params["offset"] = offset
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ class PatchRetention::Events
4
+ API_PATH = "events"
5
+
6
+ class << self
7
+ def find(id)
8
+ Find.by_id(id)
9
+ end
10
+
11
+ def all(limit: 30, offset: 0)
12
+ Find.all(limit, offset)
13
+ end
14
+
15
+ def create(event_type:, primary_key_details:, data:, at: nil, contact_details: {})
16
+ Create.call(
17
+ event_type: event_type,
18
+ primary_key_details: primary_key_details,
19
+ data: data,
20
+ at: at,
21
+ contact_details: contact_details
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PatchRetention # rubocop:disable Style/ClassAndModuleChildren
4
+ # The Util module provides utility methods used across the PatchRetention library.
5
+ # These methods are designed to handle common tasks such as error handling and response parsing.
6
+ module Util
7
+ # Raises a PatchRetention::Error if the yielded block's response status is not 200.
8
+ # @yield [response] The block to execute, which should return a response.
9
+ # @return [response] The response from the yielded block if no error is raised.
10
+ def raise_error_if_present
11
+ response = yield
12
+ raise PatchRetention::Error, parse_error_message(response) unless response.status.between?(200, 206)
13
+
14
+ JSON.parse(response.body)
15
+ end
16
+
17
+ # Parses the error message from the response.
18
+ # Raises a PatchRetention::Error if the response status is 502 and the body is blank.
19
+ # @param response [Object] The response to parse the error message from.
20
+ # @return [String] The error message parsed from the response body.
21
+ def parse_error_message(response)
22
+ if response.status == 502 && response.body.blank?
23
+ raise PatchRetention::Error,
24
+ "Internal Server Error: Patch API"
25
+ end
26
+
27
+ JSON.parse(response.body)["error"]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PatchRetention
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "faraday"
4
+ require "json"
5
+
6
+ require "zeitwerk"
7
+ loader = Zeitwerk::Loader.for_gem
8
+ loader.setup # ready!
9
+
10
+ require_relative "patch_retention/version"
11
+
12
+ module PatchRetention
13
+ class Error < StandardError; end
14
+
15
+ class << self
16
+ def configuration
17
+ @configuration ||= Configuration.new
18
+ end
19
+
20
+ def configure
21
+ yield(configuration)
22
+ end
23
+
24
+ def connection
25
+ Faraday.new(
26
+ url: configuration.api_url,
27
+ headers: {
28
+ "Authorization" => "Bearer #{configuration.client_secret}",
29
+ "X-Account-Id" => configuration.client_id
30
+ }
31
+ )
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,4 @@
1
+ module PatchRetention
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: patch_retention
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Playbypoint
8
+ - Gerardo Ortega
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2023-12-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Patch Retention API wrapper.
15
+ email:
16
+ - webmaster@playbypoint.com
17
+ - g3ortega@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - ".tool-versions"
25
+ - CHANGELOG.md
26
+ - CODE_OF_CONDUCT.md
27
+ - Gemfile
28
+ - Gemfile.lock
29
+ - LICENSE.txt
30
+ - README.md
31
+ - Rakefile
32
+ - lib/patch_retention.rb
33
+ - lib/patch_retention/configuration.rb
34
+ - lib/patch_retention/contacts.rb
35
+ - lib/patch_retention/contacts/delete.rb
36
+ - lib/patch_retention/contacts/find.rb
37
+ - lib/patch_retention/contacts/find_or_create.rb
38
+ - lib/patch_retention/contacts/update.rb
39
+ - lib/patch_retention/events.rb
40
+ - lib/patch_retention/events/create.rb
41
+ - lib/patch_retention/events/find.rb
42
+ - lib/patch_retention/util.rb
43
+ - lib/patch_retention/version.rb
44
+ - sig/patch_retention.rbs
45
+ homepage: https://playbypoint.com
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ homepage_uri: https://playbypoint.com
50
+ source_code_uri: https://playbypoint.com
51
+ changelog_uri: https://playbypoint.com
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.6.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.1.4
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Patch Retention API wrapper.
71
+ test_files: []