pdsdk 0.7.4 → 0.7.5

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: c1d0a609e294668878ce9b0b2a89de4dfd9a5724e92570e4ceb3a1648a22a2b1
4
- data.tar.gz: e09160fb1ac1ec11ab818a98136faf901fedddb9ce8fac5f3f1c9e822f0055e3
3
+ metadata.gz: cd52f5de406dd4f0552df729eef585c235e4a43ae1925bf3d9b61241e17779dd
4
+ data.tar.gz: 4e033570f17fac80033f260c4885e75872759c9971e07e7caf8ad65b6d854b38
5
5
  SHA512:
6
- metadata.gz: f1c0d31594d2bab7a67bdd11a99b40be219d44a64108b86622328dacf33539780e922ad1657bae57908a961413d67c7146c58c3108b8f2e95d7eef4dc0c15223
7
- data.tar.gz: 035ab6f0537f28471d74ad604e2842dfb1e737a5c0616862adaa9a6953012bcc7a321eb07b9580d7096af06cc175d71ff46caf17beaaef7fa0eb830ae3a2940a
6
+ metadata.gz: b5c98a6735c9c7a98e127fff990d4f76254a6640b34ebba1d9ef86a786a7335575c4cb78d6e5de783ad86a9b75f35771f64a67cf9d3502460691be37d347782f
7
+ data.tar.gz: fe5e9484f5acc6a5584ba7ab13de3f53af86e08fdbc172e3832fca808cbefa2902be205f07751eabb5a4db6008c4a0a6e6d59c6a433c306670d5da2ac18eda03
@@ -1,7 +1,6 @@
1
1
  require "pdsdk/version"
2
2
  require "pdsdk/logger"
3
3
  require "json"
4
- require 'concurrent'
5
4
 
6
5
  module Pdsdk
7
6
  class Error < StandardError
@@ -27,41 +26,48 @@ module Pdsdk
27
26
  if !@secret_key
28
27
  logger.warn "no $#{ENV_SECRET_KEY_KEY} detected, will not sign payloads"
29
28
  end
29
+
30
+ @hostname = ENV["PD_SDK_HOST"] || "sdk.m.pipedream.net"
31
+ @proto = ENV["PD_SDK_PROTO"] || "https"
30
32
  end
31
33
 
32
- # XXX self.send_message for string and becomes { message } ?
33
- def send_event(api_key, raw_event, opts={}, include_response = false)
34
- hostname = ENV["PD_SDK_HOST"] || "sdk.m.pipedream.net"
35
- proto = ENV["PD_SDK_PROTO"] || "https"
34
+ def sync_send_event(api_key, raw_event, opts={}, include_response=false)
36
35
  event = opts[:exports] || {}
37
36
  event[:raw_event] = raw_event
37
+ # logger.info "going to send event: #{event} to #{api_key}"
38
38
  if opts[:deployment]
39
- _uri = "#{proto}://#{hostname}/pipelines/#{api_key}/deployments/#{opts[:deployment]}/events"
39
+ _uri = "#{@proto}://#{@hostname}/pipelines/#{api_key}/deployments/#{opts[:deployment]}/events"
40
40
  else
41
- _uri = "#{proto}://#{hostname}/pipelines/#{api_key}/events"
41
+ _uri = "#{@proto}://#{@hostname}/pipelines/#{api_key}/events"
42
42
  end
43
43
  uri = URI(_uri)
44
- use_ssl = uri.scheme == "https"
45
- # TODO clean up old connections
46
- # TODO ensure reconnects if client disconnects
47
- @http_connection ||= Concurrent::ThreadLocalVar.new { Net::HTTP.start(uri.host, uri.port, use_ssl: use_ssl, open_timeout: 1) }
48
- logger.info "going to send event: #{event} to #{api_key}" # TODO remove
49
- payload = event.to_json
50
- headers = {
51
- "user-agent" => "pipedream-sdk:ruby/1",
52
- "content-type" => "application/json",
53
- "accept" => "application/json",
54
- "x-pd-sdk-version" => Pdsdk::VERSION,
55
- }
56
- headers["x-pd-sig"] = "sha256=#{OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @secret_key, payload)}" if @secret_key
57
- req = Net::HTTP::Post.new(uri.request_uri, headers)
58
- req.body = payload
59
- resp = @http_connection.value.request(req)
60
- logger.info "received response: #{resp}" # TODO remove
61
- if include_response
62
- { 'code' => resp.code.to_i, 'body' => resp.body }
63
- else
64
- { 'code' => resp.code.to_i }
44
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https", open_timeout: 1) do |http|
45
+ payload = event.to_json
46
+ headers = {
47
+ "user-agent" => "pipedream-sdk:ruby/1",
48
+ "content-type" => "application/json",
49
+ "accept" => "application/json",
50
+ "x-pd-sdk-version" => Pdsdk::VERSION,
51
+ }
52
+ headers["x-pd-sig"] = "sha256=#{OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @secret_key, payload)}" if @secret_key
53
+ req = Net::HTTP::Post.new(uri.request_uri, headers)
54
+ req.body = payload
55
+ resp = http.request(req)
56
+ # logger.info "received response: #{resp}"
57
+ if include_response
58
+ { 'code' => resp.code.to_i, 'body' => resp.body }
59
+ else
60
+ { 'code' => resp.code.to_i }
61
+ end
62
+ end
63
+ end
64
+
65
+ # XXX self.send_message for string and becomes { message } ?
66
+ def send_event(api_key, raw_event, opts={})
67
+ # TODO make a proper worker with queue in separate thread rather than making new every time
68
+ # ... mostly so we can connect http client once
69
+ Thread.new do
70
+ sync_send_event(api_key, raw_event, opts)
65
71
  end
66
72
  end
67
73
 
@@ -1,3 +1,3 @@
1
1
  module Pdsdk
2
- VERSION = "0.7.4"
2
+ VERSION = "0.7.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdsdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.4
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pipedream Team
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.0.1
64
+ rubygems_version: 3.1.2
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: Pipedream SDK