inngest 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cb26c60e6c8edd3ba8d6438633ae80d62ecaa2ccea31db0c15a5da5a732d17f0
4
+ data.tar.gz: b60f4751d72906d48ad9bd427a58e7d487bacf6eaff4efa9c1fa2e5f6fc8dddd
5
+ SHA512:
6
+ metadata.gz: 10cf3328ce243b9507516bf8d430abf5fd14782352ddc0fc661971a75d75f2deb85f47b816c5e3a4bced45452a136cabeae4fb946c82ed45c9b3427178fd6b1a
7
+ data.tar.gz: ce26340460ba4aa959686f8defb4039e3ff3245a1c58118fab563e16e82bdcd292a103e192e3981cbb47c5fbad5ce53d26bc731fbaf7cecd50631fab554b63e9
data/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2021 Inngest Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
File without changes
data/lib/exceptions.rb ADDED
@@ -0,0 +1,2 @@
1
+ class InngestException < Exception; end
2
+
data/lib/inngest.rb ADDED
@@ -0,0 +1,85 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require_relative 'exceptions'
4
+
5
+ module Inngest
6
+
7
+ class Client
8
+ API_ENDPOINT = "https://inn.gs"
9
+ HEADERS = {
10
+ 'Content-Type' => 'application/json',
11
+ 'User-Agent' => 'inngest-ruby-sdk/0.0.1',
12
+ }
13
+
14
+ def initialize(inngest_key, endpoint = API_ENDPOINT)
15
+ raise InngestException.new "Inngest Key can't be nil" if inngest_key.nil?
16
+
17
+ @url = "#{endpoint}/e/#{inngest_key}"
18
+ @http = http_client @url
19
+ end
20
+
21
+ def send(event)
22
+ raise InngestException.new "Event can't be nil" if event.nil?
23
+ event = Event.new(**event) if event.is_a? Hash
24
+ raise InngestException.new "Can't construct Event" unless event.is_a? Event
25
+
26
+ event.validate
27
+ request = Net::HTTP::Post.new(@url, HEADERS)
28
+ request.body = event.payload.to_json
29
+
30
+ @http.request(request)
31
+ end
32
+
33
+ private
34
+
35
+ def http_client(url)
36
+ uri = URI.parse(url)
37
+ http = Net::HTTP.new(uri.host, uri.port)
38
+ http.use_ssl = uri.instance_of? URI::HTTPS
39
+ http.read_timeout = 8
40
+ http.open_timeout = 4
41
+
42
+ http
43
+ end
44
+
45
+ end
46
+
47
+ class Event
48
+ attr_accessor :name, :data, :user, :version, :timestamp
49
+
50
+ def initialize (name: nil, data: {}, user: {}, version: nil, timestamp: nil)
51
+ @name = name
52
+ @data = data
53
+ @user = user
54
+ @version = version
55
+ @timestamp = timestamp ? timestamp : Time.now.to_i * 1000
56
+ end
57
+
58
+ def validate
59
+
60
+ unless @name&.strip
61
+ raise InngestException.new "Event name can't be empty"
62
+ end
63
+
64
+ unless @data
65
+ raise InngestException.new "Event data can't be empty"
66
+ end
67
+
68
+ begin
69
+ @data.to_json
70
+ rescue Exception
71
+ raise InngestException.new "Event data couldn't be serialized to json"
72
+ end
73
+ end
74
+
75
+ def payload
76
+ {
77
+ name: @name,
78
+ data: @data,
79
+ user: @user,
80
+ v: @version,
81
+ ts: @timestamp
82
+ }.compact
83
+ end
84
+ end
85
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inngest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Inngest, inc.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-08-15 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Inngest Ruby SDK
14
+ email: eng@inngest.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE.md
20
+ - README.md
21
+ - lib/exceptions.rb
22
+ - lib/inngest.rb
23
+ homepage: https://github.com/inngest/inngest-ruby
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubygems_version: 3.0.3
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Inngest Ruby SDK
46
+ test_files: []