envoy-hooks 0.3.0

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: 9652ef54ad9d10e92e4d1953316b4422fecfcc56ff5215eda8d6e692487f4088
4
+ data.tar.gz: c97991170af52414d7b4cdfb248b26afcc2eddf3e5c7bce6df61c3082d8ced94
5
+ SHA512:
6
+ metadata.gz: 2d28d4b89bfe107a2e3a6f35c5d138d5d151e49c476bef94ef3d037895fc3abb8c8a1e8f6a4660ce39680d5a00e98c0564a35b0cc8f0befae89a628c86ca8158
7
+ data.tar.gz: e6c1c6f9bf722a11b7686fa266b0a99264fca88d6088470e317364f9f6a912bbec5dcd63460c267ebe62d405b6ac48771a6ed13539b99fd0a75fcdeed718e08d
@@ -0,0 +1,13 @@
1
+ version: 2.1
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: ruby:3.0.0
6
+ steps:
7
+ - checkout
8
+ - run:
9
+ name: Run the default task
10
+ command: |
11
+ gem install bundler -v 2.2.3
12
+ bundle install
13
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,63 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.6
7
+ Exclude:
8
+ - 'bin/*'
9
+ - 'db/**/*'
10
+ - 'doc/**/*'
11
+ - 'log/**/*'
12
+ - 'script/**/*'
13
+ - 'tmp/**/*'
14
+ - 'vendor/**/*'
15
+ CacheRootDirectory: "tmp/cache"
16
+
17
+ Rails:
18
+ Enabled: true
19
+
20
+ Layout/LineLength:
21
+ Max: 150
22
+
23
+ Metrics/BlockLength:
24
+ Enabled: false
25
+
26
+ Metrics/ClassLength:
27
+ Max: 150
28
+
29
+ Metrics/MethodLength:
30
+ Enabled: true
31
+ Severity: warning
32
+ Max: 50
33
+
34
+ Metrics/ParameterLists:
35
+ Enabled: false
36
+
37
+ Naming/BlockParameterName:
38
+ Enabled: false
39
+
40
+ Naming/MethodName:
41
+ Enabled: false
42
+
43
+ Naming/MethodParameterName:
44
+ Enabled: false
45
+
46
+ Naming/VariableName:
47
+ Enabled: false
48
+ EnforcedStyle: "camelCase"
49
+
50
+ RSpec/ExampleLength:
51
+ Max: 30
52
+
53
+ RSpec/ContextWording:
54
+ Enabled: false
55
+
56
+ RSpec/MultipleExpectations:
57
+ Enabled: false
58
+
59
+ Style/Documentation:
60
+ Enabled: false
61
+
62
+ Style/IfUnlessModifier:
63
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.8
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in envoy-hooks.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'rspec', '~> 3.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ envoy-hooks (0.3.0)
5
+ faraday (~> 0.15.4)
6
+ faraday-net_http (~> 1.0)
7
+ faraday_middleware (~> 0.12.2)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ diff-lcs (1.5.0)
13
+ faraday (0.15.4)
14
+ multipart-post (>= 1.2, < 3)
15
+ faraday-net_http (1.0.1)
16
+ faraday_middleware (0.12.2)
17
+ faraday (>= 0.7.4, < 1.0)
18
+ multipart-post (2.1.1)
19
+ rake (13.0.6)
20
+ rspec (3.10.0)
21
+ rspec-core (~> 3.10.0)
22
+ rspec-expectations (~> 3.10.0)
23
+ rspec-mocks (~> 3.10.0)
24
+ rspec-core (3.10.1)
25
+ rspec-support (~> 3.10.0)
26
+ rspec-expectations (3.10.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-mocks (3.10.2)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-support (3.10.3)
33
+
34
+ PLATFORMS
35
+ x86_64-darwin-18
36
+ x86_64-darwin-19
37
+ x86_64-darwin-20
38
+
39
+ DEPENDENCIES
40
+ envoy-hooks!
41
+ rake (~> 13.0)
42
+ rspec (~> 3.0)
43
+
44
+ BUNDLED WITH
45
+ 2.3.5
data/README.md ADDED
@@ -0,0 +1,284 @@
1
+ # Envoy::Hooks
2
+
3
+ > Note: this Readme is currently written as if the API is completed. This is so that we can get the desired interface and work backwards to create it.
4
+ >
5
+ > Once everything is implemented, this note will be removed.
6
+
7
+ This is a Ruby wrapper for [the Envoy Hooks service](https://github.com/envoy/hooks).
8
+
9
+ It has the following three API methods regarding UI Hooks and their subscriptions:
10
+
11
+ * `upsertSubscription`
12
+ * `triggerUIHooks`
13
+ * `subscribedUIHooks`
14
+
15
+ These are the methods listed in [the Jira ticket](https://envoycom.atlassian.net/jira/software/c/projects/DEVP/boards/131?modal=detail&selectedIssue=DEVP-829) describing what's required for the email customization screen and the dynamic email sender.
16
+
17
+ The following method is used for syncing the clientConfig -- that is, the configuration for the app/integration.
18
+
19
+ * `syncClientConfig`
20
+
21
+ That covers all the endpoints that are currently available on the Hooks Service. The number of endpoints, however, will likely grow.
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'envoy-hooks'
29
+ ```
30
+
31
+ And then execute:
32
+
33
+ $ bundle install
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install envoy-hooks
38
+
39
+ # Usage
40
+
41
+ ## Setting up JWT
42
+
43
+ Before we can initialize the hooks service, we need to get a valid JWT token.
44
+
45
+ > These instructions will be focused on envoy-web for now. When we want to use this elsewhere, we can update them to be more generic.
46
+
47
+ ### 1. Set up RSA key in hooks service
48
+
49
+ * Grab RSA key from `dev.pub.pem` in `envoy-web`
50
+ * Replace newlines with \n, so it's all on one line
51
+ * Surround with quotes
52
+ * Put in `ENVOY_PUBLIC_KEY` for hooks service's `.env` file ()
53
+
54
+ ### 2. Get a valid JWT
55
+
56
+ In `envoy-web`, use `rails c` and run the following commands to generate a client record for the Hooks service, and to get a valid JWT.
57
+
58
+ ```rb
59
+ > client = Client.create(name: "Envoy Hooks", permitted_scopes: ["client.privileged", "first-party"])
60
+ > subject = Envoy::Auth::Subject.new(client)
61
+ > jwt_data = Envoy::Auth::TokenGenerator.new(client.id, subject, client.permitted_scopes).generate
62
+ > jwt_token = jwt_data[:access_token]
63
+ ```
64
+
65
+ You'll use this JWT token when initializing the hooks service.
66
+
67
+ ## Initalizing the Hooks Service
68
+
69
+ You must initialize the Hooks service before calling any methods.
70
+
71
+ ```rb
72
+ hooksService = Envoy::Hooks.new(
73
+ # REQUIRED
74
+ jwtToken: "2c3671da-ad83-44a5-9798-cdbc0ee946b6", # what you generated in the previous section
75
+ baseUrl: "http://localhost:9000", # should differ based on env
76
+
77
+ # OPTIONAL
78
+ adapter: Faraday.default_adapter, # You probably won't need to mess with this in typical usage. But if you do, a list is here: https://github.com/lostisland/awesome-faraday/#adapters
79
+ stubs: [], # These are only used during testing
80
+ )
81
+ ```
82
+
83
+ We'll use the `hooksService` variable defined here in the rest of the documentation.
84
+
85
+ ## UI Hooks and Subscriptions
86
+
87
+ ### **`subscribedUIHooks`**
88
+
89
+ This returns a list of UI Hooks that your location is connected to, optionally filtered by trigger name (extension point). This will pull in hooks from company-level subscriptions as well.
90
+
91
+ ```rb
92
+ hooksService.subscribedUIHooks(
93
+ # REQUIRED
94
+ locationID: 3,
95
+
96
+ # OPTIONAL
97
+ triggerName: "welcome_email", # which "extension point" we're fetching hooks for. If left empty, we won't filter by triggerName.
98
+ includeHidden: true, # include hooks that have been hidden. Defaults to false.
99
+ )
100
+ ```
101
+
102
+ The return value will be an array of the subscribed UI Hooks.
103
+
104
+ They'll look like this:
105
+
106
+ ```rb
107
+ {
108
+ uiHookId: 3581
109
+ # 'client' is the app you're calling this from
110
+ clientId: 28567
111
+ clientName: "Cool Envoy Customer #28567"
112
+ triggerName: "welcome_email"
113
+ invocationType: "HTML"
114
+ label: "Parking QR Code" # the display name of the UI Hook
115
+ isHidden: false
116
+ icon: "https://envoy.com/images/logo-new.svg" # The app-level icon - determined per integration, not per hook
117
+ }
118
+ ```
119
+ ### **`upsertSubscription`**
120
+
121
+ Create or update a subscription.
122
+
123
+ A subscription is when a location is associated with an integration - typically when they install the integration. This method will also be called when they perform the setup steps, and when they disable the integration.
124
+
125
+ Keep in mind that "updated" subscriptions completely replace the previous subscription, meaning a null value in the new subscription data will be a null value in the database, not the old value for that field.
126
+
127
+ ```rb
128
+ hooksService.upsertSubscription(
129
+ # REQUIRED
130
+ subscriptionScope: {
131
+ type: "LOCATION", # or COMPANY or USER
132
+ id: 52952 # the ID of the location or company
133
+ },
134
+ clientId: 39581, # the ID of the integration
135
+ status: "ENABLED", # could also be DISABLED or PENDING
136
+
137
+ # OPTIONAL
138
+ config: {}, # TODO - what can go in here?
139
+ externalId: 20958, # Application-specific ID, e.g. an app install ID
140
+ creatorUserId: 9824, # ID of the Envoy user that made the subscription, if any
141
+ authorizedScopes: [], # The scopes that the creator authorized this client to have, if any.
142
+ )
143
+ ```
144
+
145
+ When you send a valid upsert, an updated subscription object will be returned.
146
+
147
+ The subscription object is the same as the arguments to `upsertSubscription` with two differences:
148
+
149
+ * there's an ID field
150
+ * `subscriptionScope` object is split into `scopeType` and `scopeId`, which are directly on the subscription object.
151
+
152
+ ### **`triggerUIHooks`**
153
+
154
+ This is how we fetch custom UI. The name "trigger UI Hooks" comes from the fact that we are getting the custom UI from potentially multiple UI Hooks, and we "trigger" them in order to fetch the data.
155
+
156
+ This will act to fetch the custom UI, which we will receive in the response.
157
+
158
+ ```rb
159
+ hooksService.triggerUIHooks(
160
+ # REQUIRED
161
+ locationId: 3,
162
+ triggerName: "welcome_email", # which "extension point" the UI will be showing up at.
163
+ responseType: "JSON", # only other option is HTML. Determines whether you get Component JSON or prerendered HTML.
164
+ resourceId: 341153, # the ID of the resource ( entry or invite ) we are working with, only required if previewMode = false
165
+
166
+ # OPTIONAL
167
+ previewMode: false, # Whether or not to run in preview mode. Preview mode makes it so you do not need to send in a resourceId
168
+ accentColor: "#123DEF", # Override the default Envoy accent color on applicable UI components. Currently only in emails, but that could change.
169
+ uiHookIds: [2954, 8271], # The specific UI hooks to invoke. If you don't include it, _all_ UI Hook subscriptions that match the locationId and triggerName will trigger.
170
+ )
171
+ ```
172
+
173
+ The return value will be an array of objects. Each object will contain a lot of information, but the most important part is `response` - that will contain the HTML or JSON from the UI Hooks, which will then be used to create the UI.
174
+ ## Client Config
175
+
176
+ ### Client Config object
177
+
178
+ All of the Client Config related methods return a Client Config object - aka, the configuration of your integration/app.
179
+
180
+ Here's an example Client Config object:
181
+
182
+ ```rb
183
+ {
184
+ clientId: "87305", # UUID for this record
185
+ clientSecret: "ac33c458-25ee-45e1-ac19-cd8e55e4261c", # used to sign invocations
186
+ clientName: "Parking Services Inc.",
187
+ clientType: "APP", # Other option is PRODUCT
188
+ clientIcon: "https://envoy.com/images/logo-new.svg", # The app-level icon - determined per integration, not per hook
189
+ version: "1.8.2", # Application-specific version. The hooks service does not store all versions, just the one you've given us.
190
+ subscriptionEnabledInvocationURL: "https://myapp.thirdparty.com/webhooks/subscription-status/subscribed", # Invoked when a client is subscribed to a location.
191
+ subscriptionDisabledInvocationURL: "https://myapp.thirdparty.com/webhooks/subscription-status/unsubscribed", # Invoked when a client is unsubscribed from a location.
192
+ externalId: "8739534", # Application-specific ID, e.g. an app id.
193
+ isDisabled: false, # Disabling the integration hides it from your company. Enabling it shares it with your company.
194
+
195
+ eventHooks: [{
196
+ id: "9896886",
197
+ triggerName: "visitor_sign_in", # Must be a valid event hook name
198
+ invocationURL: "https://www.my-app.com/webhooks/envoy/visitor-sign-in", # The URL to invoke when this hook is triggered.
199
+ invocationFormatVersion: "V2", # Currently only V1 and V2. Allows app developers to migrate from the old format to the new one, and help us introduce new formats in the future if needed.
200
+
201
+ }], # 0 to N hooks allowed
202
+ featureHooks: [], # 0 to N hooks allowed. Feature hooks format is exact same as event hooks format, except that the triggerName must be a valid feature hook instead of an event hook, so left it off to save room
203
+ uiHooks: [{
204
+ id: "198968",
205
+ triggerName: "welcome_email", # which "extension point" the UI will be showing up at.
206
+ invocationType: "DYNAMIC_CONTENT", # Currently can be DYNAMIC_CONTENT or STATIC_CONTENT. List will be expanded in Q1 2022.
207
+ invocationURL: "https://www.my-app.com/webhooks/envoy/visitor-invite-email-content", # The URL where we get
208
+ invocationFormatVersion: "V2", # Currently only V1 and V2. Allows app developers to migrate from the old format to the new one, and help us introduce new formats in the future if needed.
209
+ staticContent: nil, # Component JSON, only returned if invocationType is STATIC_CONTENT.
210
+ label: "Parking Pass - QR Code",
211
+
212
+ }], # once again, 0 to N hooks allowed. Note that this shares some fields with the event hooks and feature hooks but also has additional fields
213
+ }
214
+ ```
215
+
216
+ ### **`syncClientConfig`**
217
+
218
+ Update the Client Config - or, if none exists with that clientId, create a new one.
219
+
220
+ Note that the update is a complete replacement - so if you have a value in the existing config, and you put a nil value here, then the value in the existing config will be overwritten with nil.
221
+
222
+ The arguments are the same properties as the return value, so I will remove the comments in the example.
223
+
224
+ ```rb
225
+ hooksService.syncClientConfig(
226
+ # REQUIRED
227
+ clientId: "87305",
228
+ clientSecret: "ac33c458-25ee-45e1-ac19-cd8e55e4261c",
229
+ clientName: "Parking Services Inc.",
230
+ clientType: "APP",
231
+ clientIcon: "https://envoy.com/images/logo-new.svg",
232
+ version: "1.8.2",
233
+ isDisabled: false,
234
+
235
+ # OPTIONAL
236
+ subscriptionEnabledInvocationURL: "https://myapp.thirdparty.com/webhooks/subscription-status/subscribed",
237
+ subscriptionDisabledInvocationURL: "https://myapp.thirdparty.com/webhooks/subscription-status/unsubscribed",
238
+ externalId: "8739534",
239
+
240
+ eventHooks: [{
241
+ id: "9896886",
242
+ triggerName: "visitor_sign_in",
243
+ invocationURL: "https://www.my-app.com/webhooks/envoy/visitor-sign-in",
244
+ invocationFormatVersion: "V2",
245
+ }],
246
+ featureHooks: [],
247
+ uiHooks: [{
248
+ id: "198968",
249
+ triggerName: "welcome_email",
250
+ invocationType: "DYNAMIC_CONTENT",
251
+ invocationURL: "https://www.my-app.com/webhooks/envoy/visitor-invite-email-content",
252
+ invocationFormatVersion: "V2",
253
+ staticContent: nil,
254
+ label: "Parking Pass - QR Code",
255
+ }],
256
+ )
257
+ ```
258
+
259
+ The return value is the newly created or updated Client Config.
260
+
261
+
262
+ ## Timeouts
263
+
264
+ The default timeout is 25 seconds. This is because the Heroku timeout is at 30 seconds, and a Heroku timeout error will give us less information than if we can trace the timeout to a method on this gem.
265
+
266
+ If you wish to change the timeout length, that is an option when initializing `Envoy::Hooks`.
267
+
268
+ ```rb
269
+ Envoy::Hooks.new(timeout: 3).triggerUIHooks(/*...*/)
270
+ ```
271
+
272
+ The units are in seconds.
273
+
274
+ ## Development
275
+
276
+ > This was autogenerated, so I assume it's correct. If it's not, please make a PR fixing it or at tell me or least create a Github issue.
277
+
278
+ 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.
279
+
280
+ 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).
281
+
282
+ ## Future of this gem
283
+
284
+ Right now this is a handcrafted gem. In the future we hope to autogenerate it, so that it's automatically kept up to date and can be easily generated in other languages and for other codebases. If we switch to the autogenerated gem, we intend to keep the API changes minimal.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
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
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'envoy/hooks'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
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,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/envoy/hooks/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'envoy-hooks'
7
+ spec.version = Envoy::Hooks::VERSION
8
+ spec.authors = ['Jeffrey-Biles-Envoy']
9
+ spec.email = ['jeffrey@envoy.com']
10
+
11
+ spec.summary = 'Ruby wrapper for envoy/hooks'
12
+ # spec.description = "TODO: Write a longer description or delete this line."
13
+ spec.homepage = 'https://github.com/envoy/envoy-hooks-ruby'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/envoy/envoy-hooks-ruby'
20
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ['lib']
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+ spec.add_dependency 'faraday', '~> 0.15.4'
34
+ spec.add_dependency 'faraday-net_http', '~> 1.0'
35
+ spec.add_dependency 'faraday_middleware', '~> 0.12.2'
36
+
37
+ # For more information and examples about making a new gem, checkout our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Envoy
4
+ class Hooks
5
+ VERSION = "0.3.0"
6
+ end
7
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'hooks/version'
4
+ require 'faraday'
5
+ require 'faraday_middleware'
6
+
7
+ module Envoy
8
+ class Hooks
9
+ class Error < StandardError; end
10
+
11
+ attr_reader :jwtToken, :baseUrl, :adapter
12
+ def initialize(jwtToken:, baseUrl:, adapter: Faraday.default_adapter, stubs: nil, timeout: 25)
13
+ @jwtToken = jwtToken
14
+ @baseUrl = baseUrl
15
+ @adapter = adapter
16
+ @stubs = stubs
17
+ @timeout = timeout
18
+ end
19
+
20
+ def faraday
21
+ @faraday ||= Faraday.new do |conn|
22
+ conn.url_prefix = @baseUrl
23
+ conn.request :authorization, 'Bearer', @jwtToken
24
+ conn.request :json
25
+ conn.response :json, content_type: 'application/json'
26
+ conn.adapter @adapter, @stubs
27
+ conn.options.timeout = @timeout
28
+ conn.proxy ENV.fetch('http_proxy', nil)
29
+ end
30
+ end
31
+
32
+ # Should we require all these, or can we get some from the environment?
33
+ def upsertSubscription(subscriptionScope:, clientId:, status:, config: {}, externalId: nil, creatorUserId: nil, authorizedScopes: [])
34
+ # NOTE - should we be doing these checks in here, or let the API handle it?
35
+ if !subscriptionScope || !subscriptionScope[:type] || !subscriptionScope[:id]
36
+ raise(Error, 'Must fully define a subscriptionScope for `upsertSubscription`')
37
+ end
38
+ validateEnum("subscriptionScope.type", subscriptionScope[:type], %w[LOCATION COMPANY USER])
39
+ validateEnum("status", status, %w[ENABLED DISABLED PENDING])
40
+
41
+ faraday.post('/rest/v1/subscriptions', {
42
+ subscriptionScope: subscriptionScope,
43
+ clientId: clientId,
44
+ status: status,
45
+ config: config,
46
+ externalId: externalId,
47
+ creatorUserId: creatorUserId,
48
+ authorizedScopes: authorizedScopes
49
+ })
50
+ end
51
+
52
+
53
+ def triggerUIHooks(locationId:, triggerName:, responseType:, resourceId: nil, accentColor: nil, uiHooks: [], previewMode: false)
54
+ validateEnum('responseType', responseType, %w[HTML JSON])
55
+
56
+ faraday.post("/rest/v1/locations/#{locationId}/hooks/ui/trigger", {
57
+ locationId: locationId,
58
+ triggerName: triggerName,
59
+ responseType: responseType,
60
+ resourceId: resourceId,
61
+ accentColor: accentColor,
62
+ previewMode: previewMode,
63
+ uiHooks: uiHooks
64
+ })
65
+ end
66
+
67
+ def subscribedUIHooks(locationId:, triggerName: nil, includeHidden: false)
68
+ faraday.get("/rest/v1/locations/#{locationId}/hooks/ui", {
69
+ locationId: locationId,
70
+ triggerName: triggerName,
71
+ includeHidden: includeHidden
72
+ })
73
+ end
74
+
75
+ def syncClientConfig(
76
+ clientId:,
77
+ clientSecret:,
78
+ clientName:,
79
+ clientType:,
80
+ clientIcon:,
81
+ version:,
82
+ isDisabled:,
83
+ eventHooks: [],
84
+ featureHooks: [],
85
+ uiHooks: [],
86
+ subscriptionEnabledInvocationURL: nil,
87
+ subscriptionDisabledInvocationURL: nil,
88
+ externalId: nil
89
+ )
90
+ validateEnum('clientType', clientType, %w[APP PRODUCT])
91
+ uiHooks.each do |uiHook|
92
+ if uiHook[:invocationType] != 'STATIC_CONTENT'
93
+ uiHook[:staticContent] = nil
94
+ end
95
+ if uiHook[:invocationType] != 'DYNAMIC_CONTENT'
96
+ uiHook[:invocationURL] = nil
97
+ end
98
+ end
99
+ faraday.post("/rest/v1/clients/#{clientId}/config", {
100
+ clientId: clientId,
101
+ clientSecret: clientSecret,
102
+ clientName: clientName,
103
+ clientType: clientType,
104
+ clientIcon: clientIcon,
105
+ version: version,
106
+ isDisabled: isDisabled,
107
+ eventHooks: eventHooks,
108
+ featureHooks: featureHooks,
109
+ uiHooks: uiHooks,
110
+ subscriptionEnabledInvocationURL: subscriptionEnabledInvocationURL,
111
+ subscriptionDisabledInvocationURL: subscriptionDisabledInvocationURL,
112
+ externalId: externalId
113
+ })
114
+ end
115
+
116
+ def validateEnum(optionName, testOption, validOptions)
117
+ raise(Error, "#{optionName} must be one of the allowed options: #{validOptions.join(', ')}") unless validOptions.include?(testOption)
118
+ end
119
+ end
120
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: envoy-hooks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeffrey-Biles-Envoy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-06-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.15.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.15.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-net_http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday_middleware
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.12.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.12.2
55
+ description:
56
+ email:
57
+ - jeffrey@envoy.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".circleci/config.yml"
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".rubocop.yml"
66
+ - ".ruby-version"
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - envoy-hooks.gemspec
74
+ - lib/envoy/hooks.rb
75
+ - lib/envoy/hooks/version.rb
76
+ homepage: https://github.com/envoy/envoy-hooks-ruby
77
+ licenses: []
78
+ metadata:
79
+ homepage_uri: https://github.com/envoy/envoy-hooks-ruby
80
+ source_code_uri: https://github.com/envoy/envoy-hooks-ruby
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.3.0
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubygems_version: 3.0.9
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Ruby wrapper for envoy/hooks
100
+ test_files: []