patch_retention 0.1.2 → 0.1.3

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: fadb1c62a03723e009e23b6e20980f4d1e345497c03f1bdceb327e589ffdac22
4
- data.tar.gz: 2667403dfe8ede9f30573e9384d42d2b5c89d51b69b9d851a6a87a9090cce8ed
3
+ metadata.gz: cf00b3a8f5069ab659bab2ca865777f408e86eaeca6335900d4be57b889b9c92
4
+ data.tar.gz: 925189b1b36aba6f33ae5f10f609c3471f49ceeb964dc748205ea8c71d1f5cfa
5
5
  SHA512:
6
- metadata.gz: 8b8b7f12cbcdc4b1ad2e2d9cc371ac6919b6430ee4b829a116ec6e1cba01e71919c5bd06e6fc78eca419c07c1378ef3c102f08871e41200725536bb5cdb32e67
7
- data.tar.gz: 8439450f9ee0fcb12daa2045acc6716c6f6e45cb2c4ce6ae7b2bfead467b6e044eb9a538dfb5d8a39c0e46329d432a8de914e40d5d85122f577ab8c41988e849
6
+ metadata.gz: d17b4a0602ba7463f3baaade37c65cc70774f18af352a89a171f5c0d4f6b7e0a7a2ed338a8711653969c8c5e33f1a35fae09fc470f512b8212082f25bb03ea57
7
+ data.tar.gz: c3f0012eb7e348acf60cecf0a997e05c812cdf5ad14aed02cfe2837f53bd7e4107c91e417d226403f79e7dc95dc01bca26bc562c990d7583e244d309e543d6ed
data/CHANGELOG.md CHANGED
@@ -4,6 +4,9 @@
4
4
 
5
5
  - Support proxying to a different host
6
6
  - Submit responses with JSON format and headers to preserve data types
7
+ - Add `reset_configuration` method to reset the configuration
8
+ - Fix `delete` method to return true when the response is 204
9
+ - Allow users to pass a config object for any request, and use the config object for the connection
7
10
 
8
11
  ## [0.1.0] - 2023-12-03
9
12
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patch_retention (0.1.0)
4
+ patch_retention (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -4,11 +4,15 @@
4
4
 
5
5
  Install the gem and add to the application's Gemfile by executing:
6
6
 
7
- $ bundle add patch_retention
7
+ ```bash
8
+ $ bundle add patch_retention
9
+ ```
8
10
 
9
11
  If bundler is not being used to manage dependencies, install the gem by executing:
10
12
 
11
- $ gem install patch_retention
13
+ ```bash
14
+ $ gem install patch_retention
15
+ ```
12
16
 
13
17
  ## Usage
14
18
 
@@ -20,6 +24,7 @@ For local environment, you can set the following environment variables:
20
24
  PATCH_RETENTION_API_URL='your_custom_api_url' # Optional, by default is set to: https://api.patchretention.com/v2
21
25
  PATCH_RETENTION_CLIENT_ID='your_client_id'
22
26
  PATCH_RETENTION_CLIENT_SECRET='your_client_secret'
27
+ PATCH_RETENTION_PROXY_URL='your_proxy_url' # Optional, for routing requests through a proxy
23
28
  ```
24
29
 
25
30
  Credentials might also be set in the initializer:
@@ -29,6 +34,7 @@ PatchRetention.configure do |config|
29
34
  config.api_url = 'your_custom_api_url' # Optional, by default is set to: https://api.patchretention.com/v2
30
35
  config.client_id = 'your_client_id'
31
36
  config.client_secret = 'your_client_secret'
37
+ config.proxy_url = 'your_proxy_url' # Optional, for routing requests through a proxy
32
38
  end
33
39
  ```
34
40
 
@@ -36,10 +42,12 @@ end
36
42
 
37
43
  First, you need to configure the gem with your API credentials.
38
44
 
39
- Then, you can use the gem's methods to interact with the API. For example, to retrieve all contacts:
45
+ Then, you can use the gem's methods to interact with the API.
40
46
 
41
47
  **Contacts:**
42
48
 
49
+ To retrieve all contacts:
50
+
43
51
  ```ruby
44
52
  contacts = PatchRetention::Contacts.all
45
53
  ```
@@ -54,24 +62,43 @@ To create a contact:
54
62
 
55
63
  ```ruby
56
64
  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
- )
65
+ contact_params: {
66
+ first_name: 'John',
67
+ last_name: 'Doe',
68
+ email: 'john.doe@playbypoint.com',
69
+ phone: '1234567890',
70
+ address: '123 Main St',
71
+ city: 'New York',
72
+ state: 'NY',
73
+ zip: '10001',
74
+ country: 'US',
75
+ company: 'PlayByPoint',
76
+ job_title: 'Developer'
77
+ },
78
+ query_params: {
79
+ email: 'john.doe@playbypoint.com',
80
+ phone: '1234567890'
81
+ }
82
+ )
83
+ ```
84
+
85
+ To update a contact:
86
+
87
+ ```ruby
88
+ contact = PatchRetention::Contacts.update(1, {
89
+ first_name: 'John',
90
+ last_name: 'Doe',
91
+ email: 'john.doe@example.com',
92
+ phone: '1234567890',
93
+ sms_on: true,
94
+ email_on: true
95
+ })
96
+ ```
97
+
98
+ To delete a contact:
99
+
100
+ ```ruby
101
+ PatchRetention::Contacts.delete(1)
75
102
  ```
76
103
 
77
104
  **Events**
@@ -92,34 +119,33 @@ To create an event:
92
119
 
93
120
  ```ruby
94
121
  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
- )
122
+ event_type: 'order.finished',
123
+ primary_key_details: {
124
+ key: 'email',
125
+ value: 'john.doe@pbp.com'
126
+ },
127
+ data: {
128
+ "external_id": "1234567890",
129
+ "subtotal_amount": 3000,
130
+ "total_tax": 300,
131
+ "total_amount": 3300,
132
+ "total_discounts": 0,
133
+ "facility_id": 1,
134
+ },
135
+ contact_details: {
136
+ upsert: true,
137
+ params: {
138
+ # Optional, if upsert is true
139
+ first_name: 'John',
140
+ last_name: 'Doe',
141
+ email: 'john.doe@pbp.com',
142
+ phone: '1234567890',
143
+ address: '123 Main St',
144
+ city: 'New York'
145
+ }
146
+ },
147
+ at: Time.now,
148
+ )
123
149
  ```
124
150
 
125
151
  ## Development
@@ -4,9 +4,9 @@ module PatchRetention::Contacts::Delete
4
4
  include PatchRetention::Util
5
5
  extend self
6
6
 
7
- def call(id)
7
+ def call(id, config = nil)
8
8
  raise_error_if_present do
9
- PatchRetention.connection.delete("#{PatchRetention::Contacts::API_PATH}/#{id}")
9
+ PatchRetention.connection(config).delete("#{PatchRetention::Contacts::API_PATH}/#{id}")
10
10
  end
11
11
  end
12
12
  end
@@ -19,9 +19,9 @@ module PatchRetention::Contacts::Find
19
19
  # @param id [Integer] The ID of the contact to find.
20
20
  # @return [Object] The response from the PatchRetention API.
21
21
  # @raise [PatchRetention::Error] If the API returns a status other than 200.
22
- def by_id(id)
22
+ def by_id(id, config = nil)
23
23
  raise_error_if_present do
24
- PatchRetention.connection.get("#{PatchRetention::Contacts::API_PATH}/#{id}")
24
+ PatchRetention.connection(config).get("#{PatchRetention::Contacts::API_PATH}/#{id}")
25
25
  end
26
26
  end
27
27
 
@@ -31,9 +31,9 @@ module PatchRetention::Contacts::Find
31
31
  # @param offset [Integer] The number of contacts to skip before starting to collect the result set.
32
32
  # @return [Object] The response from the PatchRetention API.
33
33
  # @raise [PatchRetention::Error] If the API returns a status other than 200.
34
- def all(limit, offset)
34
+ def all(limit, offset, config = nil)
35
35
  raise_error_if_present do
36
- PatchRetention.connection.get(PatchRetention::Contacts::API_PATH) do |req|
36
+ PatchRetention.connection(config).get(PatchRetention::Contacts::API_PATH) do |req|
37
37
  req.params["limit"] = limit
38
38
  req.params["offset"] = offset
39
39
  end
@@ -13,11 +13,11 @@ module PatchRetention::Contacts::FindOrCreate
13
13
  email_on
14
14
  ].freeze
15
15
 
16
- def call(contact_params:, query_params:)
16
+ def call(contact_params:, query_params:, config: nil)
17
17
  contact_params = contact_params.slice(*ALLOWED_CONTACT_PARAMS)
18
18
 
19
19
  raise_error_if_present do
20
- PatchRetention.connection.patch(PatchRetention::Contacts::API_PATH) do |req|
20
+ PatchRetention.connection(config).patch(PatchRetention::Contacts::API_PATH) do |req|
21
21
  req.params["search"] = build_search_string(query_params)
22
22
  req.body = contact_params
23
23
  end
@@ -4,9 +4,9 @@ module PatchRetention::Contacts::Update
4
4
  include PatchRetention::Util
5
5
  extend self
6
6
 
7
- def call(id, contact_params)
7
+ def call(id, contact_params, config = nil)
8
8
  raise_error_if_present do
9
- PatchRetention.connection.put("#{PatchRetention::Contacts::API_PATH}/#{id}") do |req|
9
+ PatchRetention.connection(config).put("#{PatchRetention::Contacts::API_PATH}/#{id}") do |req|
10
10
  req.body = contact_params.to_json
11
11
  end
12
12
  end
@@ -4,27 +4,28 @@ class PatchRetention::Contacts
4
4
  API_PATH = "contacts"
5
5
 
6
6
  class << self
7
- def find(id)
8
- Find.by_id(id)
7
+ def find(id, config = nil)
8
+ Find.by_id(id, config)
9
9
  end
10
10
 
11
- def all(limit: 30, offset: 0)
12
- Find.all(limit, offset)
11
+ def all(limit = 30, offset = 0, config = nil)
12
+ Find.all(limit, offset, config)
13
13
  end
14
14
 
15
- def find_or_create_by(contact_params:, query_params: {})
15
+ def find_or_create_by(contact_params:, query_params: {}, config: nil)
16
16
  FindOrCreate.call(
17
17
  contact_params: contact_params,
18
- query_params: query_params
18
+ query_params: query_params,
19
+ config: config
19
20
  )
20
21
  end
21
22
 
22
- def update(id, attributes = {})
23
- Update.call!(id, attributes)
23
+ def update(id, attributes = {}, config = nil)
24
+ Update.call!(id, attributes, config)
24
25
  end
25
26
 
26
- def delete(id)
27
- Delete.call(id)
27
+ def delete(id, config = nil)
28
+ Delete.call(id, config)
28
29
  end
29
30
  end
30
31
  end
@@ -4,7 +4,7 @@ module PatchRetention::Events::Create
4
4
  include PatchRetention::Util
5
5
  extend self
6
6
 
7
- def call(event_type:, primary_key_details:, data:, at:, contact_details:)
7
+ def call(event_type:, primary_key_details:, data:, at:, contact_details:, config: nil)
8
8
  contact_upsert = contact_details[:upsert] || false
9
9
 
10
10
  params = {
@@ -18,14 +18,14 @@ module PatchRetention::Events::Create
18
18
  params.merge!(at: format_datetime(at)) unless at.nil?
19
19
  params.merge!(contact: contact_details[:params]) if contact_upsert && contact_details.key?(:params)
20
20
 
21
- send_request(params)
21
+ send_request(params, config)
22
22
  end
23
23
 
24
24
  private
25
25
 
26
- def send_request(params)
26
+ def send_request(params, config)
27
27
  raise_error_if_present do
28
- PatchRetention.connection.post(PatchRetention::Events::API_PATH) do |req|
28
+ PatchRetention.connection(config).post(PatchRetention::Events::API_PATH) do |req|
29
29
  req.body = params
30
30
  end
31
31
  end
@@ -4,15 +4,15 @@ module PatchRetention::Events::Find
4
4
  include PatchRetention::Util
5
5
  extend self
6
6
 
7
- def by_id(id)
7
+ def by_id(id, config = nil)
8
8
  raise_error_if_present do
9
- PatchRetention.connection.get("#{PatchRetention::Events::API_PATH}/#{id}")
9
+ PatchRetention.connection(config).get("#{PatchRetention::Events::API_PATH}/#{id}")
10
10
  end
11
11
  end
12
12
 
13
- def all(limit, offset)
13
+ def all(limit, offset, config = nil)
14
14
  raise_error_if_present do
15
- PatchRetention.connection.get(PatchRetention::Events::API_PATH) do |req|
15
+ PatchRetention.connection(config).get(PatchRetention::Events::API_PATH) do |req|
16
16
  req.params["limit"] = limit
17
17
  req.params["offset"] = offset
18
18
  end
@@ -4,21 +4,22 @@ class PatchRetention::Events
4
4
  API_PATH = "events"
5
5
 
6
6
  class << self
7
- def find(id)
8
- Find.by_id(id)
7
+ def find(id, config: nil)
8
+ Find.by_id(id, config)
9
9
  end
10
10
 
11
- def all(limit: 30, offset: 0)
12
- Find.all(limit, offset)
11
+ def all(limit: 30, offset: 0, config: nil)
12
+ Find.all(limit, offset, config)
13
13
  end
14
14
 
15
- def create(event_type:, primary_key_details:, data:, at: nil, contact_details: {})
15
+ def create(event_type:, primary_key_details:, data:, at: nil, contact_details: {}, config: nil)
16
16
  Create.call(
17
17
  event_type: event_type,
18
18
  primary_key_details: primary_key_details,
19
19
  data: data,
20
20
  at: at,
21
- contact_details: contact_details
21
+ contact_details: contact_details,
22
+ config: config
22
23
  )
23
24
  end
24
25
  end
@@ -11,7 +11,11 @@ module PatchRetention # rubocop:disable Style/ClassAndModuleChildren
11
11
  response = yield
12
12
  raise PatchRetention::Error, parse_error_message(response) unless response.status.between?(200, 206)
13
13
 
14
- JSON.parse(response.body)
14
+ begin
15
+ JSON.parse(response.body)
16
+ rescue JSON::ParserError
17
+ true
18
+ end
15
19
  end
16
20
 
17
21
  # Parses the error message from the response.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PatchRetention
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -21,13 +21,19 @@ module PatchRetention
21
21
  yield(configuration)
22
22
  end
23
23
 
24
- def connection
24
+ def reset_configuration
25
+ @configuration = nil
26
+ end
27
+
28
+ def connection(config = nil)
29
+ config = config || configuration
30
+
25
31
  Faraday.new(
26
- url: configuration.api_url,
27
- proxy: configuration.proxy_url,
32
+ url: config.api_url,
33
+ proxy: config.proxy_url,
28
34
  headers: {
29
- "Authorization" => "Bearer #{configuration.client_secret}",
30
- "X-Account-Id" => configuration.client_id
35
+ "Authorization" => "Bearer #{config.client_secret}",
36
+ "X-Account-Id" => config.client_id
31
37
  }
32
38
  ) do |builder|
33
39
  builder.request :json
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/patch_retention/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "patch_retention"
7
+ spec.version = PatchRetention::VERSION
8
+ spec.authors = ["Playbypoint", "Gerardo Ortega"]
9
+ spec.email = ["webmaster@playbypoint.com", "g3ortega@gmail.com"]
10
+
11
+ spec.summary = "Patch Retention API wrapper."
12
+ spec.description = "Patch Retention API wrapper."
13
+ spec.homepage = "https://playbypoint.com"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://playbypoint.com"
21
+ spec.metadata["changelog_uri"] = "https://playbypoint.com"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patch_retention
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Playbypoint
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-02-05 00:00:00.000000000 Z
12
+ date: 2024-12-16 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Patch Retention API wrapper.
15
15
  email:
@@ -41,6 +41,7 @@ files:
41
41
  - lib/patch_retention/events/find.rb
42
42
  - lib/patch_retention/util.rb
43
43
  - lib/patch_retention/version.rb
44
+ - patch_retention.gemspec
44
45
  - sig/patch_retention.rbs
45
46
  homepage: https://playbypoint.com
46
47
  licenses: