architect-functions 0.2.0 → 0.3.0

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: 9f531e06892a92e481e3e7673ead66d00f142e7523ef919c0dfbceb4ff46ddb3
4
- data.tar.gz: 7588bf9ee9820135d97aece411821c3855c604fe95d5488f745f19b35d1c0b03
3
+ metadata.gz: 1d67b7204ebb63764681b926a6deb538500ba3dc7f01403d3f472a007ef4f5d3
4
+ data.tar.gz: 7c54f6b0f1ce9abd083bb246dc7725b10c8e1aaa19c87478e9d63a4cf3cff828
5
5
  SHA512:
6
- metadata.gz: 826d0372f2767e74b815bcc9d6d67521225184a34fe448ae7c0a135a0ab494c6c34f1724eae46c9dc6ecc9994ed6e57d2bd038cb1d35f93e6b496992bc2167b7
7
- data.tar.gz: 1e4ae45aa9f2700085bb6e7a307e9737c25b87793c39ce8964d17138ad903dcaf9568337db5302097ef56fe99cd60ca4e67927e27e5ac833eb684275b0119b19
6
+ metadata.gz: d302e7bc5785489422098ff7066c6aeeb77b146b74b8a18a985ecdd94367d244764c503dd1ec71647a75d88637a1c6ba93a126275ed68a5a74c527eac95b713b
7
+ data.tar.gz: 1b193694eb3ff53b532af908f832fc597d4e73fbfff94824048106def52e3616174955246778a1d649046f888963d219652a3f9f8547a11d58a4eae9b3bb1700
@@ -1,5 +1,7 @@
1
1
  require 'aws-sdk-sns'
2
+ require 'net/http'
2
3
  require 'json'
4
+
3
5
  require_relative 'reflect'
4
6
 
5
7
  module Arc
@@ -7,15 +9,22 @@ module Arc
7
9
  ##
8
10
  # publish a message to an SNS Topic
9
11
  #
10
- def self.publish(params)
11
- name = params[:name]
12
- payload = params[:payload]
13
- raise ArgumentError, 'missing name' unless name
14
- raise ArgumentError, 'missing payload' unless payload
15
- arc = Arc.reflect
16
- arn = arc['events'][name]
17
- sns = Aws::SNS::Client.new
18
- sns.publish :topic_arn=> arn, :message=> JSON.generate(payload)
12
+ def self.publish(name:, payload:)
13
+ if ENV['NODE_ENV'] == 'testing'
14
+ headers = {'content-type':'application/json'}
15
+ uri = URI('https://localhost:3334/events')
16
+ http = Net::HTTP.new(uri.host, uri.port)
17
+ req = Net::HTTP::Post.new(uri.path, headers)
18
+ req.body = {'name': name, 'payload': payload}.to_json
19
+ http.request(req).read_body
20
+ else
21
+ arc = Arc.reflect
22
+ arn = arc['events'][name]
23
+ sns = Aws::SNS::Client.new
24
+ sns.publish({topic_arn: arn, message: JSON.generate(payload)})
25
+ end
26
+ rescue => e
27
+ "arc.events.publish failed #{e}"
19
28
  end
20
29
  end
21
30
  end
@@ -2,8 +2,10 @@ module Arc
2
2
  module HTTP
3
3
  module Session
4
4
  def self.read()
5
+ puts 'wip'
5
6
  end
6
7
  def self.write()
8
+ puts 'wip'
7
9
  end
8
10
  end
9
11
  end
@@ -1,5 +1,7 @@
1
1
  require 'aws-sdk-sqs'
2
+ require 'net/http'
2
3
  require 'json'
4
+
3
5
  require_relative 'reflect'
4
6
 
5
7
  module Arc
@@ -7,19 +9,24 @@ module Arc
7
9
  ##
8
10
  # publish a message to an SQS Queue
9
11
  #
10
- def self.publish(params)
11
- name = params[:name]
12
- payload = params[:payload]
13
- raise ArgumentError, 'missing name' unless name
14
- raise ArgumentError, 'missing payload' unless payload
15
- arc = Arc.reflect
16
- url = arc['queues'][name]
17
- sqs = Aws::SQS::Client.new
18
- sqs.send_message({
19
- queue_url: url,
20
- delay_seconds: 0,
21
- message_body: JSON.generate(payload)
22
- })
12
+ def self.publish(name:, payload:)
13
+ if ENV['NODE_ENV'] == 'testing'
14
+ headers = {'content-type':'application/json'}
15
+ uri = URI('https://localhost:3334/queues')
16
+ http = Net::HTTP.new(uri.host, uri.port)
17
+ req = Net::HTTP::Post.new(uri.path, headers)
18
+ req.body = {'name': name, 'payload': payload}.to_json
19
+ http.request(req).read_body
20
+ else
21
+ arc = Arc.reflect
22
+ url = arc['queues'][name]
23
+ sqs = Aws::SQS::Client.new
24
+ sqs.send_message({
25
+ queue_url: url,
26
+ delay_seconds: 0,
27
+ message_body: JSON.generate(payload)
28
+ })
29
+ end
23
30
  end
24
31
  end
25
32
  end
@@ -1,3 +1,5 @@
1
+ require 'aws-sdk-dynamodb'
2
+
1
3
  require_relative 'reflect'
2
4
 
3
5
  module Arc
@@ -5,9 +7,16 @@ module Arc
5
7
  ##
6
8
  # returns the physicalID for the given table name
7
9
  #
8
- def self.name(table)
9
- arc = Arc.reflect
10
- arc['tables'][table]
10
+ def self.name(tablename)
11
+ if ENV['NODE_ENV'] == 'testing'
12
+ tmp = "staging-#{tablename}"
13
+ db = Aws::DynamoDB::Resource.new :endpoint=> 'http://localhost:5000'
14
+ tbl = db.tables().detect {|e| e.name.include?(tmp)}
15
+ tbl.name
16
+ else
17
+ arc = Arc.reflect
18
+ arc['tables'][tablename]
19
+ end
11
20
  end
12
21
  end
13
22
  end
data/lib/architect/ws.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'aws-sdk-apigateway'
2
+ require 'net/http'
2
3
  require 'json'
4
+
3
5
  require_relative 'reflect'
4
6
 
5
7
  module Arc
@@ -7,18 +9,23 @@ module Arc
7
9
  ##
8
10
  # send a message to a web socket
9
11
  #
10
- def self.send(params)
11
- id = params[:id]
12
- payload = params[:payload]
13
- raise ArgumentError, 'missing id' unless id
14
- raise ArgumentError, 'missing payload' unless payload
15
- arc = Arc.reflect
16
- url = arc['ws']['https']
17
- api = Aws::ApiGatewayManagementApi::Client.new({endpoint: url})
18
- api.postToConnection({
19
- connection_id: id,
20
- data: JSON.stringify(payload)
21
- })
12
+ def self.send(id:, payload:)
13
+ if ENV['NODE_ENV'] == 'testing'
14
+ headers = {'content-type':'application/json'}
15
+ uri = URI('https://localhost:3333/__arc')
16
+ http = Net::HTTP.new(uri.host, uri.port)
17
+ req = Net::HTTP::Post.new(uri.path, headers)
18
+ req.body = payload.to_json
19
+ http.request(req).read_body
20
+ else
21
+ arc = Arc.reflect
22
+ url = arc['ws']['https']
23
+ api = Aws::ApiGatewayManagementApi::Client.new({endpoint: url})
24
+ api.postToConnection({
25
+ connection_id: id,
26
+ data: JSON.stringify(payload)
27
+ })
28
+ end
22
29
  end
23
30
  end
24
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: architect-functions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian LeRoux