Skip to content

Commit

Permalink
0.6.0 being pressed; CTA refactor and Stars reorganized
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalextremist committed Jan 11, 2020
1 parent ba7340a commit 32bcef8
Show file tree
Hide file tree
Showing 28 changed files with 224 additions and 137 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 202001111110-7Vn3 0.6.0
* Many updates beyond these; this is only the most recent set over the past few hours:
* Refactored the CTA's and setup appropriate interfaces so individual presences as individually invoke them with low overhead

# 202001071703-3Qn8 0.5.3
* Fix version conflict in shard ( my bad )

Expand Down
11 changes: 5 additions & 6 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
name: stellar
version: 0.6.0
crystal: 0.31.1
crystal: 0.32.1

github: abstractive/stellar.cr

description: Microservice-based application ecosystem framework

executables:
- stellar
- galaxy
#de - stellar

authors:
- digitalextremist <[email protected]>

license: MIT

targets:
constellation:
main: src/processes/constellation.cr
cluster:
main: src/processes/cluster.cr
galaxy:
main: lib/artillery/src/activate/battery.cr

dependencies:
artillery:
Expand Down
4 changes: 0 additions & 4 deletions src/stellar.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ module Stellar
end

require "./stellar/templates"
require "./stellar/stars/cta"
require "./stellar/star"

require "./stellar/integrations/slack"
require "./stellar/integrations/sendgrid"

alias Star = Stellar::Star
59 changes: 59 additions & 0 deletions src/stellar/integrations/sendgrid.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require "sendgrid"

module Stellar
module SendGrid

API_URL = "https://api.sendgrid.com/v3/mail/send"

@@client = uninitialized ::Sendgrid::Client
Expand All @@ -15,6 +16,64 @@ module Stellar
extend self
extend Templates

def host_notice(payload,template, subject)
analyze_response templated_message({
subject: subject,
from: host_email(payload),
to: [ host_email(payload) ],
template_remote: "notify_host",
template_local: "sendgrid/host/#{template}",
model: payload
})
end

def guest_notice(payload,template, subject)
analyze_response templated_message({
subject: subject,
from: host_email(payload),
to: [ guest_email(payload) ],
template_remote: "notify_guest",
template_local: "sendgrid/guest/#{template}",
model: payload
})
end

def analyze_response(response)
case response.status_code
when 200, 202
#de Success
when 401
Slack.debug(":warning: Exceeded `SendGrid` API usage for today.")
when 429
Slack.debug(":warning: Overwhelmed `SendGrid` API rate limiter.")
else
Slack.debug(":warning: Unanticipated `SendGrid` API error: #{response.status_code}")
end
end

def host_email(payload)
{
name: "#{PRESENCE["name"]}",
address: "#{PRESENCE["email"]}"
}
end

def guest_email(payload)
{
name: guest_full_name(payload),
address: "#{payload["EmailAddress"]}"
}
end

def guest_full_name(payload)
name = ""
name += "#{payload["NameFirst"]} "
if !(middle = "#{payload["NameMiddle"]} ").empty?
name += middle
end
name += "#{payload["NameLast"]}"
end

def templated_message(options : NamedTuple(
subject: String,
from: NamedTuple(name: String, address: String),
Expand Down
6 changes: 6 additions & 0 deletions src/stellar/integrations/slack.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ require "slack"

module Stellar
module Slack

extend self
extend Templates

@@default_url = uninitialized String
@@default_channel = uninitialized String
@@debug_url = uninitialized String
@@debug_channel = uninitialized String

def Slack.templated_message(payload, template : String, channel = Slack::DEFAULT_CHANNEL)
::Slack::Message.new(render_template("slack/#{template}", payload), channel: channel)
.send_to_hook(Slack::DEFAULT_URL)
end

if Artillery::SECRETS["slack"]["default"]?
if Artillery::SECRETS["slack"]["default"]["url"]?
Expand Down
13 changes: 13 additions & 0 deletions src/stellar/mixins/call_to_action.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require "../integrations/slack"
require "../integrations/sendgrid"

module Stellar
class Star
module CallToAction

include Stellar::Slack
include Stellar::SendGrid

end
end
end
2 changes: 0 additions & 2 deletions src/stellar/star.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module Stellar
abstract class Star < Artillery::Shot

include Templates
include CTA

property payload : Hash(String, JSON::Any)

def initialize(shell)
Expand Down
68 changes: 2 additions & 66 deletions src/stellar/stars/cta.cr
Original file line number Diff line number Diff line change
@@ -1,66 +1,2 @@
module Stellar
module CTA
def sendgrid_host_notice(template, subject)
analyze_sendgrid_response SendGrid.templated_message({
subject: subject,
from: host_email,
to: [ host_email ],
template_remote: "notify_host",
template_local: "sendgrid/host/#{template}",
model: @payload
})
end

def sendgrid_guest_notice(template, subject)
analyze_sendgrid_response SendGrid.templated_message({
subject: subject,
from: host_email,
to: [ guest_email ],
template_remote: "notify_guest",
template_local: "sendgrid/guest/#{template}",
model: @payload
})
end

def analyze_sendgrid_response(response)
case response.status_code
when 200
#de Success
when 401
Slack.debug(":warning: We exceeded our `SendGrid` API usage for today.")
when 429
Slack.debug(":warning: We overwhelmed the `SendGrid` API rate limiter.")
else
Slack.debug(":warning: Unanticipated `SendGrid` API error: #{response.status_code}")
end
end

def slack_templated_message(template : String, channel = Slack::DEFAULT_CHANNEL)
::Slack::Message.new(render_template("slack/#{template}", @payload), channel: channel)
.send_to_hook(Slack::DEFAULT_URL)
end

def host_email
{
name: "#{PRESENCE["name"]}",
address: "#{PRESENCE["email"]}"
}
end

def guest_email
{
name: guest_full_name,
address: "#{@payload["EmailAddress"]}"
}
end

def guest_full_name
name = ""
name += "#{@payload["NameFirst"]} "
if !(middle = "#{@payload["NameMiddle"]} ").empty?
name += middle
end
name += "#{@payload["NameLast"]}"
end
end
end
require "../../stellar"
require "./../stars/cta/**"
12 changes: 8 additions & 4 deletions src/stellar/stars/cta/join_gitlab.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require "../../../stellar"
require "../../mixins/call_to_action"

module Stellar
module CTA
class JoinGitLab < Star
class JoinGitlab < Star
include CallToAction
vector :post, "/cta/join/gitlab"
def post
if !@payload.nil?
slack_templated_message("cta_join_gitlab")
sendgrid_host_notice("cta_join_gitlab", "A request to join our GitLab workspace arrived.")
sendgrid_guest_notice("cta_join_gitlab", "Thank you for asking to join our GitLab workspace.")
Slack.templated_message(@payload, "cta_join_gitlab")
SendGrid.host_notice(@payload, "cta_join_gitlab", "A request to join our GitLab workspace arrived.")
SendGrid.guest_notice(@payload, "cta_join_gitlab", "Thank you for asking to join our GitLab workspace.")
success({ "success" => true })
else
error_payload_missing
Expand Down
10 changes: 7 additions & 3 deletions src/stellar/stars/cta/join_mattermost.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require "../../../stellar"
require "../../mixins/call_to_action"

module Stellar
module CTA
class JoinMattermost < Star
include CallToAction
vector :post, "/cta/join/mattermost"
def post
if !@payload.nil?
slack_templated_message("cta_join_mattermost")
sendgrid_host_notice("cta_join_mattermost", "A request to join our Mattermost workspace arrived.")
sendgrid_guest_notice("cta_join_mattermost", "Thank you for asking to join our Mattermost workspace.")
Slack.templated_message(@payload, "cta_join_mattermost")
SendGrid.host_notice(@payload, "cta_join_mattermost", "A request to join our Mattermost workspace arrived.")
SendGrid.guest_notice(@payload, "cta_join_mattermost", "Thank you for asking to join our Mattermost workspace.")
success({ "success" => true })
else
error_payload_missing
Expand Down
10 changes: 7 additions & 3 deletions src/stellar/stars/cta/join_slack.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require "../../../stellar"
require "../../mixins/call_to_action"

module Stellar
module CTA
class JoinSlack < Star
include CallToAction
vector :post, "/cta/join/slack"
def post
if !@payload.nil?
slack_templated_message("cta_join_slack")
sendgrid_host_notice("cta_join_slack", "A request to join our Slack workspace arrived.")
sendgrid_guest_notice("cta_join_slack", "Thank you for asking to join our Slack workspace.")
Slack.templated_message(@payload, "cta_join_slack")
SendGrid.host_notice(@payload, "cta_join_slack", "A request to join our Slack workspace arrived.")
SendGrid.guest_notice(@payload, "cta_join_slack", "Thank you for asking to join our Slack workspace.")
success({ "success" => true })
else
error_payload_missing
Expand Down
10 changes: 7 additions & 3 deletions src/stellar/stars/cta/make_contribution.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require "../../../stellar"
require "../../mixins/call_to_action"

module Stellar
module CTA
class MakeContribution < Star
include CallToAction
vector :post, "/cta/make/contribution"
def post
if !@payload.nil?
slack_templated_message("cta_make_contribution")
sendgrid_host_notice("cta_make_contribution", "A new contribution commitment arrived.")
sendgrid_guest_notice("cta_make_contribution", "Thank you for your contribution commitment.")
Slack.templated_message(@payload, "cta_make_contribution")
SendGrid.host_notice(@payload, "cta_make_contribution", "A new contribution commitment arrived.")
SendGrid.guest_notice(@payload, "cta_make_contribution", "Thank you for your contribution commitment.")
success({ "success" => true })
else
error_payload_missing
Expand Down
10 changes: 7 additions & 3 deletions src/stellar/stars/cta/make_payment.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require "../../../stellar"
require "../../mixins/call_to_action"

module Stellar
module CTA
class MakePayment < Star
include CallToAction
vector :post, "/cta/make/payment"
def post
if !@payload.nil?
slack_templated_message("cta_make_payment")
sendgrid_host_notice("cta_make_payment", "A new payment commitment arrived.")
sendgrid_guest_notice("cta_make_payment", "Thank you for your payment commitment.")
Slack.templated_message(@payload, "cta_make_payment")
SendGrid.host_notice(@payload, "cta_make_payment", "A new payment commitment arrived.")
SendGrid.guest_notice(@payload, "cta_make_payment", "Thank you for your payment commitment.")
success({ "success" => true })
else
error_payload_missing
Expand Down
10 changes: 7 additions & 3 deletions src/stellar/stars/cta/make_pledge.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require "../../../stellar"
require "../../mixins/call_to_action"

module Stellar
module CTA
class MakePledge < Star
include CallToAction
vector :post, "/cta/make/pledge"
def post
if !@payload.nil?
slack_templated_message("cta_make_pledge")
sendgrid_host_notice("cta_make_pledge", "A new pledge commitment arrived.")
sendgrid_guest_notice("cta_make_pledge", "Thank you for your pledge commitment.")
Slack.templated_message(@payload, "cta_make_pledge")
SendGrid.host_notice(@payload, "cta_make_pledge", "A new pledge commitment arrived.")
SendGrid.guest_notice(@payload, "cta_make_pledge", "Thank you for your pledge commitment.")
success({ "success" => true })
else
error_payload_missing
Expand Down
10 changes: 7 additions & 3 deletions src/stellar/stars/cta/request_access.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require "../../../stellar"
require "../../mixins/call_to_action"

module Stellar
module CTA
class RequestAccess < Star
include CallToAction
vector :post, "/cta/request/access"
def post
if !@payload.nil?
slack_templated_message("cta_request_access")
sendgrid_host_notice("cta_request_access", "A new access request arrived.")
sendgrid_guest_notice("cta_request_access", "Thank you for your access request.")
Slack.templated_message(@payload, "cta_request_access")
SendGrid.host_notice(@payload, "cta_request_access", "A new access request arrived.")
SendGrid.guest_notice(@payload, "cta_request_access", "Thank you for your access request.")
success({ "success" => true })
else
error_payload_missing
Expand Down
10 changes: 7 additions & 3 deletions src/stellar/stars/cta/request_answer.cr
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
require "../../../stellar"
require "../../mixins/call_to_action"

module Stellar
module CTA
class RequestAnswer < Star
include CallToAction
vector :post, "/cta/request/answer"
def post
if !@payload.nil?
slack_templated_message("cta_request_answer")
sendgrid_host_notice("cta_request_answer", "A new question arrived.")
sendgrid_guest_notice("cta_request_answer", "Thank you for your question.")
Slack.templated_message(@payload, "cta_request_answer")
SendGrid.host_notice(@payload, "cta_request_answer", "A new question arrived.")
SendGrid.guest_notice(@payload, "cta_request_answer", "Thank you for your question.")
success({ "success" => true })
else
error_payload_missing
Expand Down
Loading

0 comments on commit 32bcef8

Please sign in to comment.