tacklebox 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ff64434f68d2d5c10f1c8bf32082d9981fa2e3937469417e91c969319066d7b7
4
+ data.tar.gz: 0c0170bf3a73b529c63f5aa3949320d40dbc7b08f4abed2f63fc632403727304
5
+ SHA512:
6
+ metadata.gz: 488e0d45a5381be440bf4d6f3661f804647f3cfa9b07d8a417e2e4f07ce055ea902756e650c1c7d26d89b141d9e847d8e2fc6a3f56aa93cd72ef96fad82c2f6f
7
+ data.tar.gz: 2bb7448e77dffd5ada23182ecc13ec0339a767cf96a9e776c1e7cf756b9451f5b7e6400ede8a2ef26c82a5d2163e1a63c19f4ca8f844fbd05b323b4f53bf5bc5
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tacklebox.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Juan Palma, Kevin Counihan, Armando Mota, Kayl Thomas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # Tacklebox
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tacklebox`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tacklebox'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tacklebox
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tacklebox.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tacklebox"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/tacklebox.rb ADDED
@@ -0,0 +1,25 @@
1
+ require_relative "tacklebox/components/service"
2
+ require_relative "tacklebox/components/event_type"
3
+ require_relative "tacklebox/components/user"
4
+ require_relative "tacklebox/components/subscription"
5
+ require_relative "tacklebox/components/event"
6
+ require_relative "tacklebox/components/message"
7
+
8
+ class Tacklebox
9
+ attr_accessor :service, :event_type, :user, :subscription, :event, :message
10
+
11
+ def initialize(api_key, base_url)
12
+ config = {
13
+ api_key: api_key,
14
+ base_url: base_url,
15
+ stage: 'v1'
16
+ }
17
+
18
+ self.service = Service.new(config)
19
+ self.event_type = EventType.new(config)
20
+ self.user = User.new(config)
21
+ self.subscription = Subscription.new(config)
22
+ self.event = Event.new(config)
23
+ self.message = Message.new(config)
24
+ end
25
+ end
@@ -0,0 +1,46 @@
1
+ def new_error(error_type, detail)
2
+ {
3
+ Error: {
4
+ error_type: error_type,
5
+ detail: detail,
6
+ },
7
+ }
8
+ end
9
+
10
+ ERROR_TYPES = {
11
+ "missing_parameter" => "missing_parameter",
12
+ "max_retries_reached" => "max_retries_reached",
13
+ }
14
+
15
+ module Validation
16
+ def is_valid_id(id)
17
+ id && id.class == String
18
+ end
19
+
20
+ def is_valid_data(data)
21
+ !!data
22
+ end
23
+
24
+ def is_valid_name(data)
25
+ data['name'] && data['name'].class == String
26
+ end
27
+
28
+ def is_valid_subscription_data(data)
29
+ (
30
+ data['url'] &&
31
+ data['url'].class == String &&
32
+ data['event_types'] &&
33
+ data['event_types'].length > 0
34
+ )
35
+ end
36
+
37
+ def is_valid_event_data(data)
38
+ (
39
+ data['event_type'] &&
40
+ data['event_type'].class == String &&
41
+ data['idempotency_key'] &&
42
+ data['idempotency_key'].class == String &&
43
+ data['payload']
44
+ )
45
+ end
46
+ end
@@ -0,0 +1,89 @@
1
+ require_relative "error"
2
+ require_relative "http_request"
3
+ require_relative "http_client"
4
+
5
+ class EventApi
6
+ include Validation
7
+
8
+ attr_accessor :base_url, :http_client, :stage
9
+
10
+ def initialize(config)
11
+ self.base_url = config[:base_url]
12
+ self.stage = config[:stage]
13
+ self.http_client = HttpClient.new(config[:api_key])
14
+ end
15
+
16
+ def list_events(service_id, user_id)
17
+ if !self.is_valid_id(service_id)
18
+ return new_error(
19
+ ERROR_TYPES['missing_parameter'],
20
+ "The list_events method must be invoked with a non-empty string service_id argument."
21
+ )
22
+ end
23
+
24
+ if !self.is_valid_id(user_id)
25
+ return new_error(
26
+ ERROR_TYPES['missing_parameter'],
27
+ "The list_events method must be invoked with a non-empty string user_id argument."
28
+ )
29
+ end
30
+
31
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}/events"
32
+ request = HttpRequest.new("GET", @base_url, path)
33
+ @http_client.send(request)
34
+ end
35
+
36
+ def create_event(service_id, user_id, event_data)
37
+ if !self.is_valid_id(service_id)
38
+ return new_error(
39
+ ERROR_TYPES['missing_parameter'],
40
+ "The create_event method must be invoked with a non-empty string service_id argument."
41
+ )
42
+ end
43
+
44
+ if !self.is_valid_id(user_id)
45
+ return new_error(
46
+ ERROR_TYPES['missing_parameter'],
47
+ "The create_event method must be invoked with a non-empty string user_id argument."
48
+ )
49
+ end
50
+
51
+ if !self.is_valid_event_data(event_data)
52
+ return new_error(
53
+ ERROR_TYPES['missing_parameter'],
54
+ "The create_event method must be invoked with an event_data argument containing non-empty event_type and payload properties."
55
+ )
56
+ end
57
+
58
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}/events"
59
+ request = HttpRequest.new("POST", @base_url, path, event_data)
60
+ @http_client.send(request)
61
+ end
62
+
63
+ def get_event(service_id, user_id, event_id)
64
+ if !self.is_valid_id(service_id)
65
+ return new_error(
66
+ ERROR_TYPES['missing_parameter'],
67
+ "The get_event method must be invoked with a non-empty string service_id argument."
68
+ )
69
+ end
70
+
71
+ if !self.is_valid_id(user_id)
72
+ return new_error(
73
+ ERROR_TYPES['missing_parameter'],
74
+ "The get_event method must be invoked with a non-empty string user_id argument."
75
+ )
76
+ end
77
+
78
+ if !self.is_valid_id(event_id)
79
+ return new_error(
80
+ ERROR_TYPES['missing_parameter'],
81
+ "The get_event method must be invoked with a non-empty string event_id argument."
82
+ )
83
+ end
84
+
85
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}/events/#{event_id}"
86
+ request = HttpRequest.new("GET", @base_url, path)
87
+ @http_client.send(request)
88
+ end
89
+ end
@@ -0,0 +1,82 @@
1
+ require_relative "error"
2
+ require_relative "http_request"
3
+ require_relative "http_client"
4
+
5
+ class EventTypeApi
6
+ include Validation
7
+
8
+ attr_accessor :base_url, :http_client, :stage
9
+
10
+ def initialize(config)
11
+ self.base_url = config[:base_url]
12
+ self.stage = config[:stage]
13
+ self.http_client = HttpClient.new(config[:api_key])
14
+ end
15
+
16
+ def list_event_types(service_id)
17
+ if !self.is_valid_id(service_id)
18
+ return new_error(
19
+ ERROR_TYPES['missing_parameter'],
20
+ "The list_event_types method must be invoked with a non-empty string service_id argument."
21
+ )
22
+ end
23
+
24
+ path = "/#{@stage}/services/#{service_id}/event_types"
25
+ request = HttpRequest.new("GET", @base_url, path)
26
+ @http_client.send(request)
27
+ end
28
+
29
+ def create_event_type(service_id, event_type_data)
30
+ if !self.is_valid_id(service_id)
31
+ return new_error(
32
+ ERROR_TYPES['missing_parameter'],
33
+ "The create_event_types method must be invoked with a non-empty string service_id argument."
34
+ )
35
+ elsif !self.is_valid_data(event_type_data)
36
+ return new_error(
37
+ ERROR_TYPES['missing_parameter'],
38
+ "The create_event_types method must be invoked with an event_type_data object that contains a non-empty string name property."
39
+ )
40
+ end
41
+
42
+ path = "/#{@stage}/services/#{service_id}/event_types"
43
+ request = HttpRequest.new("POST", @base_url, path, event_type_data)
44
+ @http_client.send(request)
45
+ end
46
+
47
+ def delete_event_type(service_id, event_type_id)
48
+ if !self.is_valid_service_id(service_id)
49
+ return new_error(
50
+ ERROR_TYPES['missing_parameter'],
51
+ "The delete_event_type method must be invoked with a non-empty string service_id argument."
52
+ )
53
+ elsif !self.event_type_id(event_type_id)
54
+ return new_error(
55
+ ERROR_TYPES['missing_parameter'],
56
+ "The delete_event_type method must be invoked with a non-empty string event_type_id argument."
57
+ )
58
+ end
59
+
60
+ path = "/#{service_id}/event_types/#{event_type_id}"
61
+ request = HttpRequest.new("DELETE", @base_url, path)
62
+ @http_client.send(request)
63
+ end
64
+
65
+ def get_event_type(service_id, event_type_id)
66
+ if !self.is_valid_service_id(service_id)
67
+ return new_error(
68
+ ERROR_TYPES['missing_parameter'],
69
+ "The get_event_type method must be invoked with a non-empty string service_id argument."
70
+ )
71
+ elsif !self.event_type_id(event_type_id)
72
+ return new_error(
73
+ ERROR_TYPES['missing_parameter'],
74
+ "The get_event_type method must be invoked with a non-empty string event_type_id argument."
75
+ )
76
+ end
77
+
78
+ path = "/#{@stage}/services/#{service_id}/event_types/#{event_type_id}"
79
+ request = HttpRequest.new("GET", @base_url, path)
80
+ @http_client.send(request)
81
+ end
82
+ end
@@ -0,0 +1,50 @@
1
+ require "faraday"
2
+ require "json"
3
+
4
+ MAX_RETRY_ATTEMPTS = 5
5
+ MAX_TIMEOUT = 5
6
+
7
+ class HttpClient
8
+ def initialize(api_key)
9
+ @headers = {
10
+ "x-api-key" => api_key,
11
+ "Content-Type" => "application/json",
12
+ }
13
+ end
14
+
15
+ def send(request)
16
+ conn = Faraday.new(
17
+ url: request.base_url,
18
+ headers: @headers,
19
+ request: { timeout: MAX_TIMEOUT }
20
+ )
21
+
22
+ while request.attempt <= MAX_RETRY_ATTEMPTS
23
+ begin
24
+ case request.method
25
+ when "GET"
26
+ response = conn.get(request.path)
27
+ return JSON.parse(response.body)
28
+ when "POST"
29
+ response = conn.post(request.path) do |req|
30
+ req.body = request.data.to_json
31
+ end
32
+ return JSON.parse(response.body)
33
+ when "PUT"
34
+ response = conn.put(request.path) do |req|
35
+ req.body = request.data.to_json
36
+ end
37
+ return JSON.parse(response.body)
38
+ when "DELETE"
39
+ response = conn.delete(request.path)
40
+ return JSON.parse(response.body)
41
+ end
42
+ rescue Faraday::ConnectionFailed => e
43
+ puts "Connection failed: #{e}"
44
+ exit 1
45
+ end
46
+
47
+ request.attempt += 1;
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ class HttpRequest
2
+ attr_accessor :method, :base_url, :path, :data, :attempt
3
+
4
+ def initialize(method, base_url, path = nil, data = nil)
5
+ self.attempt = 1
6
+ self.method = method
7
+ self.base_url = base_url
8
+ self.path = path
9
+
10
+ if data && data['event_types']
11
+ data['eventTypes'] = data['event_types']
12
+ data.delete('event_types')
13
+ end
14
+
15
+ self.data = data
16
+ end
17
+ end
@@ -0,0 +1,86 @@
1
+ require_relative "error"
2
+ require_relative "http_request"
3
+ require_relative "http_client"
4
+
5
+ class MessageApi
6
+ include Validation
7
+
8
+ attr_accessor :base_url, :http_client, :stage
9
+
10
+ def initialize(config)
11
+ self.base_url = config[:base_url]
12
+ self.stage = config[:stage]
13
+ self.http_client = HttpClient.new(config[:api_key])
14
+ end
15
+
16
+ def list_messages(service_id, user_id)
17
+ if !self.is_valid_id(service_id)
18
+ return new_error(
19
+ ERROR_TYPES['missing_parameter'],
20
+ "The list_messages method must be invoked with a non-empty string service_id argument."
21
+ )
22
+ end
23
+ if !self.is_valid_id(user_id)
24
+ return new_error(
25
+ ERROR_TYPES['missing_parameter'],
26
+ "The list_messages method must be invoked with a non-empty string user_id argument."
27
+ )
28
+ end
29
+
30
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}/messages"
31
+ request = HttpRequest.new("GET", @base_url, path)
32
+ @http_client.send(request)
33
+ end
34
+
35
+ def resend_message(service_id, user_id, message_id)
36
+ if !self.is_valid_id(service_id)
37
+ return new_error(
38
+ ERROR_TYPES['missing_parameter'],
39
+ "The resend_message method must be invoked with a non-empty string service_id argument."
40
+ )
41
+ end
42
+ if !self.is_valid_id(user_id)
43
+ return new_error(
44
+ ERROR_TYPES['missing_parameter'],
45
+ "The resend_message method must be invoked with a non-empty string user_id argument."
46
+ )
47
+ end
48
+ if !self.is_valid_id(message_id)
49
+ return new_error(
50
+ ERROR_TYPES['missing_parameter'],
51
+ "The resend_message method must be invoked with a non-empty string message_id argument."
52
+ )
53
+ end
54
+
55
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}/messages/#{message_id}/resend"
56
+ request = HttpRequest.new("POST", @base_url, path)
57
+ @http_client.send(request)
58
+ end
59
+
60
+ def get_message(service_id, user_id, message_id)
61
+ if !self.is_valid_id(service_id)
62
+ return new_error(
63
+ ERROR_TYPES['missing_parameter'],
64
+ "The get_message method must be invoked with a non-empty string service_id argument."
65
+ )
66
+ end
67
+
68
+ if !self.is_valid_id(user_id)
69
+ return new_error(
70
+ ERROR_TYPES['missing_parameter'],
71
+ "The get_message method must be invoked with a non-empty string user_id argument."
72
+ )
73
+ end
74
+
75
+ if !self.is_valid_id(message_id)
76
+ return new_error(
77
+ ERROR_TYPES['missing_parameter'],
78
+ "The get_message method must be invoked with a non-empty string message_id argument."
79
+ )
80
+ end
81
+
82
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}/messages/#{message_id}"
83
+ request = HttpRequest.new("GET", @base_url, path)
84
+ @http_client.send(request)
85
+ end
86
+ end
@@ -0,0 +1,60 @@
1
+ require_relative "error"
2
+ require_relative "http_request"
3
+ require_relative "http_client"
4
+
5
+ class ServiceApi
6
+ include Validation
7
+
8
+ attr_accessor :base_url, :http_client, :stage
9
+
10
+ def initialize(config)
11
+ self.base_url = config[:base_url]
12
+ self.stage = config[:stage]
13
+ self.http_client = HttpClient.new(config[:api_key])
14
+ end
15
+
16
+ def list_services
17
+ path = "/#{@stage}/services"
18
+ request = HttpRequest.new("GET", @base_url, path)
19
+ self.http_client.send(request)
20
+ end
21
+
22
+ def create_service(service_data)
23
+ if !self.is_valid_data(service_data)
24
+ return new_error(
25
+ ERROR_TYPES['missing_parameter'],
26
+ "The create_service method must be invoked with a non-empty string name argument."
27
+ )
28
+ end
29
+
30
+ path = "/#{@stage}/services"
31
+ request = HttpRequest.new("POST", @base_url, path, service_data)
32
+ self.http_client.send(request)
33
+ end
34
+
35
+ def delete_service(service_id)
36
+ if !self.is_valid_id(service_id)
37
+ return new_error(
38
+ ERROR_TYPES['missing_parameter'],
39
+ "The get_service method must be invoked with a non-empty string service_id argument."
40
+ )
41
+ end
42
+
43
+ url = "#{self.base_url}/#{service_id}"
44
+ request = HttpRequest.new("DELETE", url)
45
+ self.http_client.send(request)
46
+ end
47
+
48
+ def get_service(service_id)
49
+ if !self.is_valid_id(service_id)
50
+ return new_error(
51
+ ERROR_TYPES['missing_parameter'],
52
+ "The get_service method must be invoked with a non-empty string service_id argument."
53
+ )
54
+ end
55
+
56
+ path = "/#{@stage}/services/#{service_id}"
57
+ request = HttpRequest.new("GET", @base_url, path)
58
+ self.http_client.send(request)
59
+ end
60
+ end
@@ -0,0 +1,109 @@
1
+ require_relative "error"
2
+ require_relative "http_request"
3
+ require_relative "http_client"
4
+
5
+ class SubscriptionApi
6
+ include Validation
7
+
8
+ attr_accessor :base_url, :http_client, :stage
9
+
10
+ def initialize(config)
11
+ self.base_url = config[:base_url]
12
+ self.stage = config[:stage]
13
+ self.http_client = HttpClient.new(config[:api_key])
14
+ end
15
+
16
+ def list_subscriptions(service_id, user_id)
17
+ if !self.is_valid_id(service_id)
18
+ return new_error(
19
+ ERROR_TYPES['missing_parameter'],
20
+ "The list_subscriptions method must be invoked with a non-empty string service_id argument."
21
+ )
22
+ end
23
+ if !self.is_valid_id(user_id)
24
+ return new_error(
25
+ ERROR_TYPES['missing_parameter'],
26
+ "The list_subscriptions method must be invoked with a non-empty string user_id argument."
27
+ )
28
+ end
29
+
30
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}/subscriptions"
31
+ request = HttpRequest.new("GET", @base_url, path)
32
+ @http_client.send(request)
33
+ end
34
+
35
+ def create_subscription(service_id, user_id, subscription_data)
36
+ if !self.is_valid_id(service_id)
37
+ return new_error(
38
+ ERROR_TYPES['missing_parameter'],
39
+ "The create_subscription method must be invoked with a non-empty string service_id argument."
40
+ )
41
+ end
42
+ if !self.is_valid_id(user_id)
43
+ return new_error(
44
+ ERROR_TYPES['missing_parameter'],
45
+ "The create_subscription method must be invoked with a non-empty string user_id argument."
46
+ )
47
+ end
48
+ if !self.is_valid_subscription_data(subscription_data)
49
+ return new_error(
50
+ ERROR_TYPES['missing_parameter'],
51
+ "The create_subscription method must be invoked with non-empty url and event_types arguments."
52
+ )
53
+ end
54
+
55
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}/subscriptions"
56
+ request = HttpRequest.new("POST", @base_url, path, subscription_data)
57
+ @http_client.send(request)
58
+ end
59
+
60
+ def get_subscription(service_id, user_id, subscription_id)
61
+ if !self.is_valid_id(service_id)
62
+ return new_error(
63
+ ERROR_TYPES['missing_parameter'],
64
+ "The get_subscription method must be invoked with a non-empty string service_id argument."
65
+ )
66
+ end
67
+ if !self.is_valid_id(user_id)
68
+ return new_error(
69
+ ERROR_TYPES['missing_parameter'],
70
+ "The get_subscription method must be invoked with a non-empty string user_id argument."
71
+ )
72
+ end
73
+ if !self.is_valid_id(subscription_id)
74
+ return new_error(
75
+ ERROR_TYPES['missing_parameter'],
76
+ "The get_subscription method must be invoked with a non-empty string subscription_id argument."
77
+ )
78
+ end
79
+
80
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}/subscriptions/#{subscription_id}"
81
+ request = HttpRequest.new("GET", @base_url, path)
82
+ @http_client.send(request)
83
+ end
84
+
85
+ def delete_subscription(service_id, user_id, subscription_id)
86
+ if !self.is_valid_id(service_id)
87
+ return new_error(
88
+ ERROR_TYPES['missing_parameter'],
89
+ "The delete_subscription method must be invoked with a non-empty string service_id argument."
90
+ )
91
+ end
92
+ if !self.is_valid_id(user_id)
93
+ return new_error(
94
+ ERROR_TYPES['missing_parameter'],
95
+ "The delete_subscription method must be invoked with a non-empty string user_id argument."
96
+ )
97
+ end
98
+ if !self.is_valid_id(subscription_id)
99
+ return new_error(
100
+ ERROR_TYPES['missing_parameter'],
101
+ "The delete_subscription method must be invoked with a non-empty string subscription_id argument."
102
+ )
103
+ end
104
+
105
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}/subscriptions/#{subscription_id}"
106
+ request = HttpRequest.new("DELETE", @base_url, path)
107
+ @http_client.send(request)
108
+ end
109
+ end
@@ -0,0 +1,88 @@
1
+ require_relative "error"
2
+ require_relative "http_request"
3
+ require_relative "http_client"
4
+
5
+ class UserApi
6
+ include Validation
7
+
8
+ attr_accessor :base_url, :http_client, :stage
9
+
10
+ def initialize(config)
11
+ self.base_url = config[:base_url]
12
+ self.stage = config[:stage]
13
+ self.http_client = HttpClient.new(config[:api_key])
14
+ end
15
+
16
+ def create_user(service_id, user_data)
17
+ if !self.is_valid_id(service_id)
18
+ return new_error(
19
+ ERROR_TYPES['missing_parameter'],
20
+ "The create_user method must be invoked with a non-empty string service_id argument."
21
+ )
22
+ end
23
+
24
+ if !self.is_valid_data(user_data)
25
+ return new_error(
26
+ ERROR_TYPES['missing_parameter'],
27
+ "The create_user method must be invoked with a non-empty string name argument."
28
+ )
29
+ end
30
+
31
+ path = "/#{@stage}/services/#{service_id}/users"
32
+ request = HttpRequest.new("POST", @base_url, path, user_data)
33
+ @http_client.send(request)
34
+ end
35
+
36
+ def get_user(service_id, user_id)
37
+ if !self.is_valid_id(service_id)
38
+ return new_error(
39
+ ERROR_TYPES['missing_parameter'],
40
+ "The get_user method must be invoked with a non-empty string service_id argument."
41
+ )
42
+ end
43
+
44
+ if !self.is_valid_id(user_id)
45
+ return new_error(
46
+ ERROR_TYPES['missing_parameter'],
47
+ "The get_user method must be invoked with a non-empty string user_id argument."
48
+ )
49
+ end
50
+
51
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}"
52
+ request = HttpRequest.new("GET", @base_url, path)
53
+ @http_client.send(request)
54
+ end
55
+
56
+ def delete_user(service_id, user_id)
57
+ if !self.is_valid_id(service_id)
58
+ return new_error(
59
+ ERROR_TYPES['missing_parameter'],
60
+ "The delete_user method must be invoked with a non-empty string service_id argument."
61
+ )
62
+ end
63
+
64
+ if !self.is_valid_id(user_id)
65
+ return new_error(
66
+ ERROR_TYPES['missing_parameter'],
67
+ "The delete_user method must be invoked with a non-empty string user_id argument."
68
+ )
69
+ end
70
+
71
+ path = "/#{@stage}/services/#{service_id}/users/#{user_id}"
72
+ request = HttpRequest.new("DELETE", @base_url, path)
73
+ @http_client.send(request)
74
+ end
75
+
76
+ def list_users(service_id)
77
+ if !self.is_valid_id(service_id)
78
+ return new_error(
79
+ ERROR_TYPES['missing_parameter'],
80
+ "The list_users method must be invoked with a non-empty string service_id argument."
81
+ )
82
+ end
83
+
84
+ path = "/#{@stage}/services/#{service_id}/users"
85
+ request = HttpRequest.new("GET", @base_url, path)
86
+ @http_client.send(request)
87
+ end
88
+ end
@@ -0,0 +1,21 @@
1
+ require_relative "../apis/event_api"
2
+
3
+ class Event
4
+ attr_accessor :api
5
+
6
+ def initialize(config)
7
+ self.api = EventApi.new(config)
8
+ end
9
+
10
+ def list(service_id, user_id)
11
+ self.api.list_events(service_id, user_id)
12
+ end
13
+
14
+ def create(service_id, user_id, event_data)
15
+ self.api.create_event(service_id, user_id, event_data)
16
+ end
17
+
18
+ def get(service_id, user_id, event_id)
19
+ self.api.get_event(service_id, user_id, event_id)
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "../apis/event_type_api"
2
+
3
+ class EventType
4
+ attr_accessor :api
5
+
6
+ def initialize(config)
7
+ self.api = EventTypeApi.new(config)
8
+ end
9
+
10
+ def list(service_id)
11
+ self.api.list_event_types(service_id)
12
+ end
13
+
14
+ def create(service_id, event_type_data)
15
+ self.api.createEventType(service_id, event_type_data)
16
+ end
17
+
18
+ def get(service_id, event_type_id)
19
+ self.api.getEventType(service_id, event_type_id)
20
+ end
21
+
22
+ def delete(service_id, event_type_id)
23
+ self.api.deleteEventType(service_id, event_type_id)
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ require_relative "../apis/message_api"
2
+
3
+ class Message
4
+ attr_accessor :api
5
+
6
+ def initialize(config)
7
+ self.api = MessageApi.new(config)
8
+ end
9
+
10
+ def list(service_id, user_id)
11
+ self.api.list_messages(service_id, user_id)
12
+ end
13
+
14
+ def resend(service_id, user_id, message_id)
15
+ self.api.resend_message(service_id, user_id, message_id)
16
+ end
17
+
18
+ def get(service_id, user_id, message_id)
19
+ self.api.get_message(service_id, user_id, message_id)
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "../apis/service_api"
2
+
3
+ class Service
4
+ attr_accessor :api
5
+
6
+ def initialize(config)
7
+ self.api = ServiceApi.new(config)
8
+ end
9
+
10
+ def list
11
+ self.api.list_services()
12
+ end
13
+
14
+ def create(serviceData)
15
+ self.api.create_service(serviceData)
16
+ end
17
+
18
+ def get(service_id)
19
+ self.api.get_service(service_id)
20
+ end
21
+
22
+ def delete(service_id)
23
+ self.api.delete_service(service_id)
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ require_relative "../apis/subscription_api"
2
+
3
+ class Subscription
4
+ attr_accessor :api
5
+
6
+ def initialize(config)
7
+ self.api = SubscriptionApi.new(config)
8
+ end
9
+
10
+ def list(service_id, user_id)
11
+ self.api.list_subscriptions(service_id, user_id)
12
+ end
13
+
14
+ def create(service_id, user_id, subscription_data)
15
+ self.api.create_subscription(
16
+ service_id,
17
+ user_id,
18
+ subscription_data
19
+ )
20
+ end
21
+
22
+ def get(service_id, user_id, subscription_id)
23
+ self.api.get_subscription(service_id, user_id, subscription_id)
24
+ end
25
+
26
+ def delete(service_id, user_id, subscription_id)
27
+ self.api.delete_subscription(service_id, user_id, subscription_id)
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ require_relative "../apis/user_api"
2
+
3
+ class User
4
+ attr_accessor :api
5
+
6
+ def initialize(config)
7
+ self.api = UserApi.new(config)
8
+ end
9
+
10
+ def list(service_id)
11
+ self.api.list_users(service_id)
12
+ end
13
+
14
+ def create(service_id, user_data)
15
+ self.api.create_user(service_id, user_data)
16
+ end
17
+
18
+ def get(service_id, user_id)
19
+ self.api.get_user(service_id, user_id)
20
+ end
21
+
22
+ def delete(service_id, user_id)
23
+ self.api.delete_user(service_id, user_id)
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Tacklebox
2
+ VERSION = "0.1.0"
3
+ end
data/tacklebox.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ require_relative 'lib/tacklebox/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "tacklebox"
5
+ spec.version = Tacklebox::VERSION
6
+ spec.authors = ["Juan Palma", "Kevin Counihan", "Armando Mota", "Kayl Thomas"]
7
+
8
+ spec.summary = %q{Tacklebox}
9
+ spec.description = %q{An open-source serverless framework that offers webhooks as a service.}
10
+ spec.homepage = "https://github.com/tacklebox-webhooks/ruby"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/tacklebox-webhooks/ruby"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+ spec.add_runtime_dependency 'faraday', '~> 1.4', '>= 1.4.1'
26
+ spec.add_runtime_dependency 'json', '~> 2.5', '>= 2.5.1'
27
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tacklebox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Palma
8
+ - Kevin Counihan
9
+ - Armando Mota
10
+ - Kayl Thomas
11
+ autorequire:
12
+ bindir: exe
13
+ cert_chain: []
14
+ date: 2021-05-21 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: faraday
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.4'
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 1.4.1
26
+ type: :runtime
27
+ prerelease: false
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '1.4'
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 1.4.1
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '2.5'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.5.1
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '2.5'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 2.5.1
56
+ description: An open-source serverless framework that offers webhooks as a service.
57
+ email:
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - lib/tacklebox.rb
69
+ - lib/tacklebox/apis/error.rb
70
+ - lib/tacklebox/apis/event_api.rb
71
+ - lib/tacklebox/apis/event_type_api.rb
72
+ - lib/tacklebox/apis/http_client.rb
73
+ - lib/tacklebox/apis/http_request.rb
74
+ - lib/tacklebox/apis/message_api.rb
75
+ - lib/tacklebox/apis/service_api.rb
76
+ - lib/tacklebox/apis/subscription_api.rb
77
+ - lib/tacklebox/apis/user_api.rb
78
+ - lib/tacklebox/components/event.rb
79
+ - lib/tacklebox/components/event_type.rb
80
+ - lib/tacklebox/components/message.rb
81
+ - lib/tacklebox/components/service.rb
82
+ - lib/tacklebox/components/subscription.rb
83
+ - lib/tacklebox/components/user.rb
84
+ - lib/tacklebox/version.rb
85
+ - tacklebox.gemspec
86
+ homepage: https://github.com/tacklebox-webhooks/ruby
87
+ licenses:
88
+ - MIT
89
+ metadata:
90
+ homepage_uri: https://github.com/tacklebox-webhooks/ruby
91
+ source_code_uri: https://github.com/tacklebox-webhooks/ruby
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.3.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 3.1.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Tacklebox
111
+ test_files: []