Class: Envoy::Hooks
- Inherits:
-
Object
- Object
- Envoy::Hooks
- Defined in:
- lib/envoy/hooks.rb,
lib/envoy/hooks/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
'0.9.6'
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#baseUrl ⇒ Object
readonly
Returns the value of attribute baseUrl.
-
#jwtToken ⇒ Object
readonly
Returns the value of attribute jwtToken.
Instance Method Summary collapse
- #faraday ⇒ Object
-
#initialize(jwtToken:, baseUrl:, adapter: Faraday.default_adapter, stubs: nil, timeout: 25) ⇒ Hooks
constructor
A new instance of Hooks.
- #subscribedUIHooks(locationId: nil, locationIds: [], triggerName: nil, triggerNames: [], includeHidden: false) ⇒ Object
- #subscribedZoneUIHooks(zoneIds: [], triggerNames: [], includeHidden: false) ⇒ Object
- #syncClientConfig(clientId:, clientSecret:, clientName:, clientType:, clientIcon:, version:, isDisabled:, eventHooks: [], featureHooks: [], uiHooks: [], subscriptionEnabledInvocationURL: nil, subscriptionDisabledInvocationURL: nil, externalId: nil) ⇒ Object
- #triggerEventHooks(locationId:, userEmail: nil, userEmails: [], triggerName: nil, triggerNames: [], resourceId: nil, eventHookIds: []) ⇒ Object
- #triggerUIHooks(locationId:, responseType:, triggerName: nil, triggerNames: [], resourceId: nil, accentColor: nil, uiHooks: [], previewMode: false, uiHookIds: [], resourceType: nil) ⇒ Object
- #triggerZoneUIHooks(responseType:, zoneIds:, triggerNames: [], resourceId: nil, resourceIds: [], resourceType: nil, accentColor: nil, previewMode: false, uiHookIds: []) ⇒ Object
-
#upsertSubscription(subscriptionScope:, clientId:, status:, config: {}, externalId: nil, creatorUserId: nil, authorizedScopes: []) ⇒ Object
Should we require all these, or can we get some from the environment?.
- #validateEnum(optionName, testOption, validOptions) ⇒ Object
Constructor Details
#initialize(jwtToken:, baseUrl:, adapter: Faraday.default_adapter, stubs: nil, timeout: 25) ⇒ Hooks
Returns a new instance of Hooks.
13 14 15 16 17 18 19 |
# File 'lib/envoy/hooks.rb', line 13 def initialize(jwtToken:, baseUrl:, adapter: Faraday.default_adapter, stubs: nil, timeout: 25) @jwtToken = jwtToken @baseUrl = baseUrl @adapter = adapter @stubs = stubs @timeout = timeout end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
11 12 13 |
# File 'lib/envoy/hooks.rb', line 11 def adapter @adapter end |
#baseUrl ⇒ Object (readonly)
Returns the value of attribute baseUrl.
11 12 13 |
# File 'lib/envoy/hooks.rb', line 11 def baseUrl @baseUrl end |
#jwtToken ⇒ Object (readonly)
Returns the value of attribute jwtToken.
11 12 13 |
# File 'lib/envoy/hooks.rb', line 11 def jwtToken @jwtToken end |
Instance Method Details
#faraday ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/envoy/hooks.rb', line 21 def faraday @faraday ||= Faraday.new do |conn| conn.url_prefix = @baseUrl conn.request :authorization, 'Bearer', @jwtToken conn.request :json conn.response :json, content_type: 'application/json' conn.adapter @adapter, @stubs conn..timeout = @timeout conn.proxy ENV.fetch('http_proxy', nil) end end |
#subscribedUIHooks(locationId: nil, locationIds: [], triggerName: nil, triggerNames: [], includeHidden: false) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/envoy/hooks.rb', line 95 def subscribedUIHooks(locationId: nil, locationIds: [], triggerName: nil, triggerNames: [], includeHidden: false) faraday.get('/rest/v1/locations/hooks/ui', { locationId: locationId, locationIds: locationIds, triggerName: triggerName, triggerNames: triggerNames, includeHidden: includeHidden }) end |
#subscribedZoneUIHooks(zoneIds: [], triggerNames: [], includeHidden: false) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/envoy/hooks.rb', line 105 def subscribedZoneUIHooks(zoneIds: [], triggerNames: [], includeHidden: false) faraday.get('/rest/v1/zones/hooks/ui', { zoneIds: zoneIds, triggerNames: triggerNames, includeHidden: includeHidden }) end |
#syncClientConfig(clientId:, clientSecret:, clientName:, clientType:, clientIcon:, version:, isDisabled:, eventHooks: [], featureHooks: [], uiHooks: [], subscriptionEnabledInvocationURL: nil, subscriptionDisabledInvocationURL: nil, externalId: nil) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/envoy/hooks.rb', line 126 def syncClientConfig( clientId:, clientSecret:, clientName:, clientType:, clientIcon:, version:, isDisabled:, eventHooks: [], featureHooks: [], uiHooks: [], subscriptionEnabledInvocationURL: nil, subscriptionDisabledInvocationURL: nil, externalId: nil ) validateEnum('clientType', clientType, %w[APP PRODUCT]) faraday.post("/rest/v1/clients/#{clientId}/config", { clientId: clientId, clientSecret: clientSecret, clientName: clientName, clientType: clientType, clientIcon: clientIcon, version: version, isDisabled: isDisabled, eventHooks: eventHooks, featureHooks: featureHooks, uiHooks: uiHooks, subscriptionEnabledInvocationURL: subscriptionEnabledInvocationURL, subscriptionDisabledInvocationURL: subscriptionDisabledInvocationURL, externalId: externalId }) end |
#triggerEventHooks(locationId:, userEmail: nil, userEmails: [], triggerName: nil, triggerNames: [], resourceId: nil, eventHookIds: []) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/envoy/hooks.rb', line 113 def triggerEventHooks(locationId:, userEmail: nil, userEmails: [], triggerName: nil, triggerNames: [], resourceId: nil, eventHookIds: []) faraday.post("/rest/v1/locations/#{locationId}/hooks/event/trigger", { locationId: locationId, userEmail: userEmail, userEmails: userEmails, triggerName: triggerName, triggerNames: triggerNames, resourceId: resourceId, eventHookIds: eventHookIds }) end |
#triggerUIHooks(locationId:, responseType:, triggerName: nil, triggerNames: [], resourceId: nil, accentColor: nil, uiHooks: [], previewMode: false, uiHookIds: [], resourceType: nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/envoy/hooks.rb', line 55 def triggerUIHooks(locationId:, responseType:, triggerName: nil, triggerNames: [], resourceId: nil, accentColor: nil, uiHooks: [], previewMode: false, uiHookIds: [], resourceType: nil) validateEnum('responseType', responseType, %w[HTML JSON]) validateEnum('resourceType', resourceType, %w[INVITE EMPLOYEE ENTRY]) unless resourceType.nil? faraday.post("/rest/v1/locations/#{locationId}/hooks/ui/trigger", { locationId: locationId, triggerName: triggerName, triggerNames: triggerNames, responseType: responseType, resourceId: resourceId, resourceType: resourceType, accentColor: accentColor, previewMode: previewMode, uiHookIds: uiHookIds || uiHooks }) end |
#triggerZoneUIHooks(responseType:, zoneIds:, triggerNames: [], resourceId: nil, resourceIds: [], resourceType: nil, accentColor: nil, previewMode: false, uiHookIds: []) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/envoy/hooks.rb', line 75 def triggerZoneUIHooks(responseType:, zoneIds:, triggerNames: [], resourceId: nil, resourceIds: [], resourceType: nil, accentColor: nil, previewMode: false, uiHookIds: []) validateEnum('responseType', responseType, %w[HTML JSON]) validateEnum('resourceType', resourceType, %w[INVITE EMPLOYEE ENTRY]) unless resourceType.nil? resource_ids = Array(resourceId || resourceIds) faraday.post('/rest/v1/zones/hooks/ui/trigger', { zoneIds: zoneIds, triggerNames: triggerNames, responseType: responseType, resourceIds: resource_ids, resourceType: resourceType, accentColor: accentColor, previewMode: previewMode, uiHookIds: uiHookIds }) end |
#upsertSubscription(subscriptionScope:, clientId:, status:, config: {}, externalId: nil, creatorUserId: nil, authorizedScopes: []) ⇒ Object
Should we require all these, or can we get some from the environment?
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/envoy/hooks.rb', line 34 def upsertSubscription(subscriptionScope:, clientId:, status:, config: {}, externalId: nil, creatorUserId: nil, authorizedScopes: []) # NOTE: - should we be doing these checks in here, or let the API handle it? if !subscriptionScope || !subscriptionScope[:type] || !subscriptionScope[:id] raise(Error, 'Must fully define a subscriptionScope for `upsertSubscription`') end validateEnum('subscriptionScope.type', subscriptionScope[:type], %w[LOCATION COMPANY USER ZONE]) validateEnum('status', status, %w[ENABLED DISABLED PENDING]) faraday.post('/rest/v1/subscriptions', { subscriptionScope: subscriptionScope, clientId: clientId, status: status, config: config, externalId: externalId, creatorUserId: creatorUserId, authorizedScopes: }) end |
#validateEnum(optionName, testOption, validOptions) ⇒ Object
159 160 161 162 163 164 |
# File 'lib/envoy/hooks.rb', line 159 def validateEnum(optionName, testOption, validOptions) return if validOptions.include?(testOption) raise(Error, "#{optionName} must be one of the allowed options: #{validOptions.join(', ')}") end |