simplyq 0.8.0rc

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: f624f3db18fcc8a5a0ec534582e2cdd4044d3fe33e5bfb4f1401fccb93c5f10f
4
+ data.tar.gz: 3461b9748e3f8700cb7dd87e25d218b6b433242e2efc6cca6bc5f0ef5925c244
5
+ SHA512:
6
+ metadata.gz: 0164ce8d36157c90aa8784d4ec204897bffde1052f5c0ab86c28439d66623cd7bd88e1e577545d1168b9afac78a953bd2ec0403ac2f02a4bc266adec47451319
7
+ data.tar.gz: a5d76f618b5f0c13c432e9eff6c33ad41251ca78729f205336ca6b1654cdf8dc79444782a1b22045db0b742d8d2bed462c9f16383b993b171de02bb2e170ecba
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,58 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ require: rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.7
7
+ NewCops: enable
8
+ SuggestExtensions: false
9
+
10
+ Style/StringLiterals:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Style/StringLiteralsInInterpolation:
15
+ Enabled: true
16
+ EnforcedStyle: double_quotes
17
+
18
+ Layout/LineLength:
19
+ Max: 120
20
+ Exclude:
21
+ - 'spec/**/*'
22
+ - 'lib/simplyq/configuration.rb'
23
+ - 'lib/simplyq/models/delivery_attempt.rb'
24
+ - 'lib/simplyq/models/event.rb'
25
+ - 'lib/simplyq/models/event.rb'
26
+
27
+ Style/AccessModifierDeclarations:
28
+ EnforcedStyle: inline
29
+
30
+ Style/FrozenStringLiteralComment:
31
+ EnforcedStyle: always
32
+
33
+ Style/AccessorGrouping:
34
+ EnforcedStyle: separated
35
+
36
+ RSpec/ExampleLength:
37
+ Enabled: false
38
+
39
+ RSpec/MultipleExpectations:
40
+ Enabled: false
41
+
42
+ RSpec/MessageSpies:
43
+ Enabled: false
44
+
45
+ Style/MultilineBlockChain:
46
+ Enabled: false
47
+
48
+ Metrics/MethodLength:
49
+ Enabled: false
50
+
51
+ Metrics/BlockLength:
52
+ Enabled: false
53
+
54
+ Metrics/ClassLength:
55
+ Enabled: false
56
+
57
+ Style/Documentation:
58
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,156 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2022-10-31 12:57:18 UTC using RuboCop version 1.37.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Configuration parameters: AutoCorrect, EnforcedStyle.
11
+ # SupportedStyles: leading, trailing
12
+ Layout/LineContinuationLeadingSpace:
13
+ Exclude:
14
+ - 'lib/simplyq/configuration.rb'
15
+
16
+ # Offense count: 4
17
+ # This cop supports safe autocorrection (--autocorrect).
18
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns.
19
+ # URISchemes: http, https
20
+ Layout/LineLength:
21
+ Max: 227
22
+
23
+ # Offense count: 1
24
+ Lint/MissingSuper:
25
+ Exclude:
26
+ - 'lib/simplyq/errors.rb'
27
+
28
+ # Offense count: 1
29
+ Lint/ShadowingOuterLocalVariable:
30
+ Exclude:
31
+ - 'spec/simplyq/client_spec.rb'
32
+
33
+ # Offense count: 1
34
+ # This cop supports safe autocorrection (--autocorrect).
35
+ # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
36
+ Lint/UnusedMethodArgument:
37
+ Exclude:
38
+ - 'lib/simplyq/errors.rb'
39
+
40
+ # Offense count: 45
41
+ Lint/UselessAssignment:
42
+ Exclude:
43
+ - 'lib/simplyq/api/application_api.rb'
44
+ - 'lib/simplyq/api/endpoint_api.rb'
45
+ - 'lib/simplyq/api/event_api.rb'
46
+ - 'spec/simplyq/client_spec.rb'
47
+
48
+ # Offense count: 14
49
+ # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods, CountRepeatedAttributes.
50
+ Metrics/AbcSize:
51
+ Max: 42
52
+
53
+ # Offense count: 3
54
+ # Configuration parameters: CountComments, CountAsOne.
55
+ Metrics/ClassLength:
56
+ Max: 213
57
+
58
+ # Offense count: 10
59
+ # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
60
+ Metrics/CyclomaticComplexity:
61
+ Max: 17
62
+
63
+ # Offense count: 3
64
+ # Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
65
+ Metrics/ParameterLists:
66
+ Max: 8
67
+
68
+ # Offense count: 8
69
+ # Configuration parameters: AllowedMethods, AllowedPatterns, IgnoredMethods.
70
+ Metrics/PerceivedComplexity:
71
+ Max: 17
72
+
73
+ # Offense count: 1
74
+ # Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
75
+ # NamePrefix: is_, has_, have_
76
+ # ForbiddenPrefixes: is_, has_, have_
77
+ # AllowedMethods: is_a?
78
+ # MethodDefinitionMacros: define_method, define_singleton_method
79
+ Naming/PredicateName:
80
+ Exclude:
81
+ - 'spec/**/*'
82
+ - 'lib/simplyq/models/endpoint.rb'
83
+
84
+ # Offense count: 2
85
+ # Configuration parameters: Prefixes, AllowedPatterns.
86
+ # Prefixes: when, with, without
87
+ RSpec/ContextWording:
88
+ Exclude:
89
+ - 'spec/simplyq/client_spec.rb'
90
+
91
+ # Offense count: 3
92
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
93
+ # Include: **/*_spec*rb*, **/spec/**/*
94
+ RSpec/FilePath:
95
+ Exclude:
96
+ - 'spec/simplyq/models/application_spec.rb'
97
+ - 'spec/simplyq/models/endpoint_spec.rb'
98
+ - 'spec/simplyq/models/list_spec.rb'
99
+
100
+ # Offense count: 1
101
+ RSpec/IdenticalEqualityAssertion:
102
+ Exclude:
103
+ - 'spec/simplyq/models/list_spec.rb'
104
+
105
+ # Offense count: 13
106
+ # Configuration parameters: AllowSubject.
107
+ RSpec/MultipleMemoizedHelpers:
108
+ Max: 7
109
+
110
+ # Offense count: 1
111
+ # Configuration parameters: IgnoreSharedExamples.
112
+ RSpec/NamedSubject:
113
+ Exclude:
114
+ - 'spec/simplyq/client_spec.rb'
115
+
116
+ # Offense count: 1
117
+ # Configuration parameters: AllowedPatterns.
118
+ # AllowedPatterns: ^expect_, ^assert_
119
+ RSpec/NoExpectationExample:
120
+ Exclude:
121
+ - 'spec/simplyq/api/event_api_spec.rb'
122
+
123
+ # Offense count: 4
124
+ RSpec/RepeatedExampleGroupBody:
125
+ Exclude:
126
+ - 'spec/simplyq/models/application_spec.rb'
127
+
128
+ # Offense count: 14
129
+ # Configuration parameters: AllowedConstants.
130
+ Style/Documentation:
131
+ Exclude:
132
+ - 'spec/**/*'
133
+ - 'test/**/*'
134
+ - 'lib/simplyq.rb'
135
+ - 'lib/simplyq/api/application_api.rb'
136
+ - 'lib/simplyq/api/endpoint_api.rb'
137
+ - 'lib/simplyq/api/event_api.rb'
138
+ - 'lib/simplyq/client.rb'
139
+ - 'lib/simplyq/configuration.rb'
140
+ - 'lib/simplyq/errors.rb'
141
+ - 'lib/simplyq/models/application.rb'
142
+ - 'lib/simplyq/models/delivery_attempt.rb'
143
+ - 'lib/simplyq/models/endpoint.rb'
144
+ - 'lib/simplyq/models/event.rb'
145
+ - 'lib/simplyq/models/list.rb'
146
+
147
+ # Offense count: 3
148
+ # Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
149
+ Style/GuardClause:
150
+ Exclude:
151
+ - 'lib/simplyq/client.rb'
152
+ - 'lib/simplyq/configuration.rb'
153
+
154
+ Gemspec/RequireMFA:
155
+ Exclude:
156
+ - 'simplyq.gemspec'
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.7.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-09-20
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 ivan@simplyq.io. 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,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec
6
+
7
+ group :development do
8
+ gem "rake"
9
+
10
+ gem "rspec"
11
+
12
+ gem "rubocop-rspec"
13
+
14
+ gem "rubocop", "~> 1.36"
15
+
16
+ gem "yard", "~> 0.9.28"
17
+
18
+ gem "webmock", "~> 3.13"
19
+
20
+ gem "openapi3_parser", "~> 0.9.2"
21
+
22
+ platforms :mri do
23
+ gem "byebug"
24
+ gem "pry"
25
+ gem "pry-byebug"
26
+ end
27
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 simplyq-dxtimer
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,37 @@
1
+ # Simplyq
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/simplyq`. 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
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add simplyq
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install simplyq
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ 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.
24
+
25
+ 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).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/simplyq. 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]/simplyq/blob/main/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the Simplyq project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/simplyq/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[rubocop spec]
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Simplyq
4
+ module API
5
+ class ApplicationAPI
6
+ attr_reader :client
7
+
8
+ API_PATH = "/v1/application"
9
+ API_PARAM_PATH = "/v1/application/{app_id}"
10
+
11
+ # Initializes a new API object.
12
+ #
13
+ # @param client [Simplyq::Client] the client object that will be used to
14
+ # make HTTP requests.
15
+ def initialize(client)
16
+ @client = client
17
+ end
18
+
19
+ def retrieve(application_id)
20
+ path = API_PARAM_PATH.gsub("{app_id}", application_id.to_s)
21
+
22
+ data, status, headers = client.call_api(:get, path)
23
+ decerialize(data)
24
+ end
25
+
26
+ def list(params = {})
27
+ data, status, headers = client.call_api(:get, API_PATH, { query_params: params })
28
+ decerialize_list(data, params: params)
29
+ end
30
+
31
+ def create(application)
32
+ data, status, headers = client.call_api(:post, API_PATH, { body: build_model(application).to_h })
33
+ decerialize(data)
34
+ end
35
+
36
+ def update(application_id, application)
37
+ path = API_PARAM_PATH.gsub("{app_id}", application_id.to_s)
38
+
39
+ data, status, headers = client.call_api(:put, path, { body: build_model(application).to_h })
40
+ decerialize(data)
41
+ end
42
+
43
+ def delete(application_id)
44
+ path = API_PARAM_PATH.gsub("{app_id}", application_id.to_s)
45
+
46
+ data, status, headers = client.call_api(:delete, path)
47
+ status == 204
48
+ end
49
+
50
+ def build_model(data)
51
+ return data if data.is_a?(Simplyq::Model::Application)
52
+ raise ArgumentError, "Invalid data must be a Simplyq::Model::Application or Hash" unless data.is_a?(Hash)
53
+
54
+ Simplyq::Model::Application.from_hash(data)
55
+ end
56
+
57
+ def decerialize(json_data)
58
+ data = body_to_json(json_data)
59
+
60
+ Simplyq::Model::Application.from_hash(data)
61
+ end
62
+
63
+ def decerialize_list(json_data, params: {})
64
+ data = body_to_json(json_data)
65
+
66
+ Simplyq::Model::List.new(
67
+ Simplyq::Model::Application, data,
68
+ api_method: :list,
69
+ filters: params, api: self
70
+ )
71
+ end
72
+
73
+ def body_to_json(body)
74
+ return if body.nil?
75
+
76
+ JSON.parse(body, symbolize_names: true)
77
+ rescue JSON::ParserError
78
+ raise Simplyq::APIError.new("Invalid JSON in response body.", http_body: body)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,178 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "time"
5
+
6
+ module Simplyq
7
+ module API
8
+ class EndpointAPI
9
+ attr_reader :client
10
+
11
+ API_PATH = "/v1/application/{app_id}/endpoint"
12
+ API_PARAM_PATH = "/v1/application/{app_id}/endpoint/{endpoint_id}"
13
+ API_RECOVER_PATH = "/v1/application/{app_id}/endpoint/{endpoint_id}/recover"
14
+ API_SECRET_PATH = "/v1/application/{app_id}/endpoint/{endpoint_id}/secret"
15
+ API_ATTEMPTED_EVENTS_PATH = "/v1/application/{app_id}/endpoint/{endpoint_id}/event"
16
+ API_DELIVERY_ATTEMPTS_PATH = "/v1/application/{app_id}/endpoint/{endpoint_id}/delivery_attempt"
17
+
18
+ # Initializes a new API object.
19
+ #
20
+ # @param client [Simplyq::Client] the client object that will be used to
21
+ # make HTTP requests.
22
+ def initialize(client)
23
+ @client = client
24
+ end
25
+
26
+ def retrieve(application_id, endpoint_id)
27
+ path = API_PARAM_PATH.gsub("{app_id}", application_id.to_s).gsub("{endpoint_id}", endpoint_id.to_s)
28
+
29
+ data, status, headers = client.call_api(:get, path)
30
+ decerialize(data)
31
+ end
32
+
33
+ def list(application_id, params = {})
34
+ path = API_PATH.gsub("{app_id}", application_id.to_s)
35
+
36
+ data, status, headers = client.call_api(:get, path, { query_params: params })
37
+ decerialize_list(data, params: params, list_args: [application_id])
38
+ end
39
+
40
+ def create(application_id, endpoint)
41
+ path = API_PATH.gsub("{app_id}", application_id.to_s)
42
+
43
+ data, status, headers = client.call_api(:post, path, { body: build_model(endpoint).to_h })
44
+ decerialize(data)
45
+ end
46
+
47
+ def update(application_id, endpoint_id, endpoint)
48
+ path = API_PARAM_PATH.gsub("{app_id}", application_id.to_s).gsub("{endpoint_id}", endpoint_id.to_s)
49
+
50
+ data, status, headers = client.call_api(:put, path, { body: build_model(endpoint).to_h })
51
+ decerialize(data)
52
+ end
53
+
54
+ def delete(application_id, endpoint_id)
55
+ path = API_PARAM_PATH.gsub("{app_id}", application_id.to_s).gsub("{endpoint_id}", endpoint_id.to_s)
56
+
57
+ data, status, headers = client.call_api(:delete, path)
58
+ status == 204
59
+ end
60
+
61
+ def recover(application_id, endpoint_id, since:)
62
+ path = API_RECOVER_PATH.gsub("{app_id}", application_id.to_s).gsub("{endpoint_id}", endpoint_id.to_s)
63
+
64
+ data, status, headers = client.call_api(:post, path, { body: { since: _to_rfc3339(since) } })
65
+ status == 202
66
+ end
67
+
68
+ def retrieve_secret(application_id, endpoint_id)
69
+ path = API_SECRET_PATH.gsub("{app_id}", application_id.to_s).gsub("{endpoint_id}", endpoint_id.to_s)
70
+
71
+ data, status, headers = client.call_api(:get, path)
72
+ decerialize_secret(data)
73
+ end
74
+
75
+ def rotate_secret(application_id, endpoint_id, secret: nil)
76
+ path = API_SECRET_PATH.gsub("{app_id}", application_id.to_s).gsub("{endpoint_id}", endpoint_id.to_s)
77
+
78
+ data, status, headers = client.call_api(:post, path, { body: { key: secret } })
79
+ status == 204
80
+ end
81
+
82
+ def retrieve_attempted_events(application_id, endpoint_id, params = {})
83
+ path = API_ATTEMPTED_EVENTS_PATH.gsub("{app_id}", application_id.to_s).gsub("{endpoint_id}", endpoint_id.to_s)
84
+
85
+ data, status, headers = client.call_api(:get, path, { query_params: params })
86
+ decerialize_events_list(data, params: params, list_args: [application_id, endpoint_id])
87
+ end
88
+
89
+ def retrieve_delivery_attempts(application_id, endpoint_id, params = {})
90
+ path = API_DELIVERY_ATTEMPTS_PATH.gsub("{app_id}", application_id.to_s).gsub("{endpoint_id}", endpoint_id.to_s)
91
+
92
+ data, status, headers = client.call_api(:get, path, { query_params: params })
93
+ decerialize_attempts_list(data, params: params, list_args: [application_id, endpoint_id])
94
+ end
95
+
96
+ def build_model(data)
97
+ return data if data.is_a?(Simplyq::Model::Endpoint)
98
+ raise ArgumentError, "Invalid data must be a Simplyq::Model::Endpoint or Hash" unless data.is_a?(Hash)
99
+
100
+ Simplyq::Model::Endpoint.from_hash(data)
101
+ end
102
+
103
+ def decerialize(json_data)
104
+ data = body_to_json(json_data)
105
+
106
+ Simplyq::Model::Endpoint.from_hash(data)
107
+ end
108
+
109
+ def decerialize_secret(json_data)
110
+ data = body_to_json(json_data)
111
+
112
+ data[:key]
113
+ end
114
+
115
+ def decerialize_list(json_data, params: {}, list_args: [])
116
+ data = body_to_json(json_data)
117
+
118
+ Simplyq::Model::List.new(
119
+ Simplyq::Model::Endpoint,
120
+ data,
121
+ api_method: :list,
122
+ list_args: list_args,
123
+ filters: params, api: self
124
+ )
125
+ end
126
+
127
+ def decerialize_events_list(json_data, params: {}, list_args: [])
128
+ data = body_to_json(json_data)
129
+
130
+ Simplyq::Model::List.new(
131
+ Simplyq::Model::Event, data,
132
+ api_method: :retrieve_attempted_events,
133
+ list_args: list_args,
134
+ filters: params, api: self
135
+ )
136
+ end
137
+
138
+ def decerialize_attempts_list(json_data, params: {}, list_args: [])
139
+ data = body_to_json(json_data)
140
+
141
+ Simplyq::Model::List.new(
142
+ Simplyq::Model::DeliveryAttempt, data,
143
+ api_method: :retrieve_delivery_attempts,
144
+ list_args: list_args,
145
+ filters: params, api: self
146
+ )
147
+ end
148
+
149
+ def body_to_json(body)
150
+ return if body.nil?
151
+
152
+ JSON.parse(body, symbolize_names: true)
153
+ rescue JSON::ParserError
154
+ raise Simplyq::APIError.new("Invalid JSON in response body.", http_body: body)
155
+ end
156
+
157
+ def _to_rfc3339(time)
158
+ _to_utc(time).iso8601(0)
159
+ end
160
+
161
+ def _to_utc(time)
162
+ unless time.is_a?(Time) || time.is_a?(String) || time.is_a?(DateTime)
163
+ raise ArgumentError,
164
+ "Invalid time must be a Time, DateTime, String"
165
+ end
166
+
167
+ case time
168
+ when Time
169
+ time.utc
170
+ when DateTime
171
+ time.to_time.utc
172
+ else
173
+ Time.parse(time).utc
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end