volley-ruby 1.0.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 +7 -0
- data/CHANGELOG.md +32 -0
- data/LICENSE +22 -0
- data/README.md +327 -0
- data/RELEASING.md +131 -0
- data/TESTING.md +155 -0
- data/examples/example.rb +42 -0
- data/lib/volley/models/connection.rb +22 -0
- data/lib/volley/models/delivery_attempt.rb +22 -0
- data/lib/volley/models/destination.rb +21 -0
- data/lib/volley/models/event.rb +23 -0
- data/lib/volley/models/organization.rb +20 -0
- data/lib/volley/models/project.rb +21 -0
- data/lib/volley/models/source.rb +29 -0
- data/lib/volley/models.rb +10 -0
- data/lib/volley/resources/connections_resource.rb +51 -0
- data/lib/volley/resources/delivery_attempts_resource.rb +38 -0
- data/lib/volley/resources/destinations_resource.rb +56 -0
- data/lib/volley/resources/events_resource.rb +54 -0
- data/lib/volley/resources/organizations_resource.rb +63 -0
- data/lib/volley/resources/projects_resource.rb +52 -0
- data/lib/volley/resources/sources_resource.rb +70 -0
- data/lib/volley/resources/webhooks_resource.rb +26 -0
- data/lib/volley/resources.rb +11 -0
- data/lib/volley/version.rb +7 -0
- data/lib/volley/volley_client.rb +133 -0
- data/lib/volley/volley_exception.rb +53 -0
- data/lib/volley.rb +10 -0
- data/volley-ruby.gemspec +43 -0
- metadata +173 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Volley
|
|
4
|
+
module Models
|
|
5
|
+
# Connection model.
|
|
6
|
+
class Connection
|
|
7
|
+
attr_accessor :id, :source_id, :destination_id, :status, :eps, :max_retries, :created_at, :updated_at
|
|
8
|
+
|
|
9
|
+
def initialize(data = {})
|
|
10
|
+
@id = data['id'] || data[:id]
|
|
11
|
+
@source_id = data['source_id'] || data[:source_id] || 0
|
|
12
|
+
@destination_id = data['destination_id'] || data[:destination_id] || 0
|
|
13
|
+
@status = data['status'] || data[:status] || ''
|
|
14
|
+
@eps = data['eps'] || data[:eps] || 0
|
|
15
|
+
@max_retries = data['max_retries'] || data[:max_retries] || 0
|
|
16
|
+
@created_at = data['created_at'] || data[:created_at] || ''
|
|
17
|
+
@updated_at = data['updated_at'] || data[:updated_at] || ''
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Volley
|
|
4
|
+
module Models
|
|
5
|
+
# Delivery Attempt model.
|
|
6
|
+
class DeliveryAttempt
|
|
7
|
+
attr_accessor :id, :event_id, :connection_id, :status, :status_code, :error_reason, :duration_ms, :created_at
|
|
8
|
+
|
|
9
|
+
def initialize(data = {})
|
|
10
|
+
@id = data['id'] || data[:id]
|
|
11
|
+
@event_id = data['event_id'] || data[:event_id] || ''
|
|
12
|
+
@connection_id = data['connection_id'] || data[:connection_id] || 0
|
|
13
|
+
@status = data['status'] || data[:status] || ''
|
|
14
|
+
@status_code = data['status_code'] || data[:status_code] || 0
|
|
15
|
+
@error_reason = data['error_reason'] || data[:error_reason]
|
|
16
|
+
@duration_ms = data['duration_ms'] || data[:duration_ms] || 0
|
|
17
|
+
@created_at = data['created_at'] || data[:created_at] || ''
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Volley
|
|
4
|
+
module Models
|
|
5
|
+
# Destination model.
|
|
6
|
+
class Destination
|
|
7
|
+
attr_accessor :id, :name, :url, :eps, :status, :created_at, :updated_at
|
|
8
|
+
|
|
9
|
+
def initialize(data = {})
|
|
10
|
+
@id = data['id'] || data[:id]
|
|
11
|
+
@name = data['name'] || data[:name] || ''
|
|
12
|
+
@url = data['url'] || data[:url] || ''
|
|
13
|
+
@eps = data['eps'] || data[:eps] || 0
|
|
14
|
+
@status = data['status'] || data[:status] || ''
|
|
15
|
+
@created_at = data['created_at'] || data[:created_at] || ''
|
|
16
|
+
@updated_at = data['updated_at'] || data[:updated_at] || ''
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Volley
|
|
4
|
+
module Models
|
|
5
|
+
# Event model.
|
|
6
|
+
class Event
|
|
7
|
+
attr_accessor :id, :event_id, :source_id, :project_id, :raw_body, :headers, :status, :delivery_attempts, :created_at
|
|
8
|
+
|
|
9
|
+
def initialize(data = {})
|
|
10
|
+
@id = data['id'] || data[:id]
|
|
11
|
+
@event_id = data['event_id'] || data[:event_id] || ''
|
|
12
|
+
@source_id = data['source_id'] || data[:source_id] || 0
|
|
13
|
+
@project_id = data['project_id'] || data[:project_id] || 0
|
|
14
|
+
@raw_body = data['raw_body'] || data[:raw_body] || ''
|
|
15
|
+
@headers = data['headers'] || data[:headers] || {}
|
|
16
|
+
@status = data['status'] || data[:status] || ''
|
|
17
|
+
@delivery_attempts = data['delivery_attempts'] || data[:delivery_attempts]
|
|
18
|
+
@created_at = data['created_at'] || data[:created_at] || ''
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Volley
|
|
4
|
+
module Models
|
|
5
|
+
# Organization model.
|
|
6
|
+
class Organization
|
|
7
|
+
attr_accessor :id, :name, :slug, :role, :account_id, :created_at
|
|
8
|
+
|
|
9
|
+
def initialize(data = {})
|
|
10
|
+
@id = data['id'] || data[:id]
|
|
11
|
+
@name = data['name'] || data[:name] || ''
|
|
12
|
+
@slug = data['slug'] || data[:slug] || ''
|
|
13
|
+
@role = data['role'] || data[:role] || ''
|
|
14
|
+
@account_id = data['account_id'] || data[:account_id]
|
|
15
|
+
@created_at = data['created_at'] || data[:created_at]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Volley
|
|
4
|
+
module Models
|
|
5
|
+
# Project model.
|
|
6
|
+
class Project
|
|
7
|
+
attr_accessor :id, :name, :organization_id, :user_id, :is_default, :created_at, :updated_at
|
|
8
|
+
|
|
9
|
+
def initialize(data = {})
|
|
10
|
+
@id = data['id'] || data[:id]
|
|
11
|
+
@name = data['name'] || data[:name] || ''
|
|
12
|
+
@organization_id = data['organization_id'] || data[:organization_id] || 0
|
|
13
|
+
@user_id = data['user_id'] || data[:user_id]
|
|
14
|
+
@is_default = data['is_default'] || data[:is_default] || false
|
|
15
|
+
@created_at = data['created_at'] || data[:created_at] || ''
|
|
16
|
+
@updated_at = data['updated_at'] || data[:updated_at] || ''
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Volley
|
|
4
|
+
module Models
|
|
5
|
+
# Source model.
|
|
6
|
+
class Source
|
|
7
|
+
attr_accessor :id, :slug, :ingestion_id, :type, :eps, :status, :connection_count, :auth_type,
|
|
8
|
+
:verify_signature, :webhook_secret_set, :auth_username, :auth_key_name, :created_at, :updated_at
|
|
9
|
+
|
|
10
|
+
def initialize(data = {})
|
|
11
|
+
@id = data['id'] || data[:id]
|
|
12
|
+
@slug = data['slug'] || data[:slug] || ''
|
|
13
|
+
@ingestion_id = data['ingestion_id'] || data[:ingestion_id] || ''
|
|
14
|
+
@type = data['type'] || data[:type] || ''
|
|
15
|
+
@eps = data['eps'] || data[:eps] || 0
|
|
16
|
+
@status = data['status'] || data[:status] || ''
|
|
17
|
+
@connection_count = data['connection_count'] || data[:connection_count] || 0
|
|
18
|
+
@auth_type = data['auth_type'] || data[:auth_type] || ''
|
|
19
|
+
@verify_signature = data['verify_signature'] || data[:verify_signature] || false
|
|
20
|
+
@webhook_secret_set = data['webhook_secret_set'] || data[:webhook_secret_set] || false
|
|
21
|
+
@auth_username = data['auth_username'] || data[:auth_username]
|
|
22
|
+
@auth_key_name = data['auth_key_name'] || data[:auth_key_name]
|
|
23
|
+
@created_at = data['created_at'] || data[:created_at] || ''
|
|
24
|
+
@updated_at = data['updated_at'] || data[:updated_at] || ''
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'models/organization'
|
|
4
|
+
require_relative 'models/project'
|
|
5
|
+
require_relative 'models/source'
|
|
6
|
+
require_relative 'models/destination'
|
|
7
|
+
require_relative 'models/connection'
|
|
8
|
+
require_relative 'models/event'
|
|
9
|
+
require_relative 'models/delivery_attempt'
|
|
10
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../models/connection'
|
|
4
|
+
|
|
5
|
+
module Volley
|
|
6
|
+
module Resources
|
|
7
|
+
# Connections API resource.
|
|
8
|
+
class ConnectionsResource
|
|
9
|
+
def initialize(client)
|
|
10
|
+
@client = client
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Create a new connection.
|
|
14
|
+
def create(project_id:, source_id:, destination_id:, status: nil, eps: nil, max_retries: nil)
|
|
15
|
+
data = {
|
|
16
|
+
'source_id' => source_id,
|
|
17
|
+
'destination_id' => destination_id
|
|
18
|
+
}
|
|
19
|
+
data['status'] = status if status
|
|
20
|
+
data['eps'] = eps if eps
|
|
21
|
+
data['max_retries'] = max_retries if max_retries
|
|
22
|
+
|
|
23
|
+
response = @client.request('POST', "/api/projects/#{project_id}/connections", data: data)
|
|
24
|
+
Models::Connection.new(response)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Get a connection by ID.
|
|
28
|
+
def get(connection_id:)
|
|
29
|
+
response = @client.request('GET', "/api/connections/#{connection_id}")
|
|
30
|
+
Models::Connection.new(response)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Update a connection.
|
|
34
|
+
def update(connection_id:, status: nil, eps: nil, max_retries: nil)
|
|
35
|
+
data = {}
|
|
36
|
+
data['status'] = status if status
|
|
37
|
+
data['eps'] = eps if eps
|
|
38
|
+
data['max_retries'] = max_retries if max_retries
|
|
39
|
+
|
|
40
|
+
response = @client.request('PUT', "/api/connections/#{connection_id}", data: data)
|
|
41
|
+
Models::Connection.new(response)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Delete a connection.
|
|
45
|
+
def delete(connection_id:)
|
|
46
|
+
@client.request('DELETE', "/api/connections/#{connection_id}")
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../models/delivery_attempt'
|
|
4
|
+
|
|
5
|
+
module Volley
|
|
6
|
+
module Resources
|
|
7
|
+
# Delivery Attempts API resource.
|
|
8
|
+
class DeliveryAttemptsResource
|
|
9
|
+
def initialize(client)
|
|
10
|
+
@client = client
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# List delivery attempts.
|
|
14
|
+
def list(project_id: nil, event_id: nil, connection_id: nil, status: nil, limit: nil, offset: nil)
|
|
15
|
+
query_params = {}
|
|
16
|
+
query_params['project_id'] = project_id if project_id
|
|
17
|
+
query_params['event_id'] = event_id if event_id
|
|
18
|
+
query_params['connection_id'] = connection_id if connection_id
|
|
19
|
+
query_params['status'] = status if status
|
|
20
|
+
query_params['limit'] = limit if limit
|
|
21
|
+
query_params['offset'] = offset if offset
|
|
22
|
+
|
|
23
|
+
response = @client.request('GET', '/api/delivery-attempts', query_params: query_params)
|
|
24
|
+
|
|
25
|
+
attempts_data = response['attempts'] || []
|
|
26
|
+
attempts = attempts_data.map { |attempt_data| Models::DeliveryAttempt.new(attempt_data) }
|
|
27
|
+
|
|
28
|
+
{
|
|
29
|
+
attempts: attempts,
|
|
30
|
+
total: response['total'] || 0,
|
|
31
|
+
limit: response['limit'] || 0,
|
|
32
|
+
offset: response['offset'] || 0
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../models/destination'
|
|
4
|
+
|
|
5
|
+
module Volley
|
|
6
|
+
module Resources
|
|
7
|
+
# Destinations API resource.
|
|
8
|
+
class DestinationsResource
|
|
9
|
+
def initialize(client)
|
|
10
|
+
@client = client
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# List all destinations for a project.
|
|
14
|
+
def list(project_id:)
|
|
15
|
+
response = @client.request('GET', "/api/projects/#{project_id}/destinations")
|
|
16
|
+
destinations_data = response['destinations'] || []
|
|
17
|
+
destinations_data.map { |destination_data| Models::Destination.new(destination_data) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Create a new destination.
|
|
21
|
+
def create(project_id:, name:, url:, eps: nil)
|
|
22
|
+
data = {
|
|
23
|
+
'name' => name,
|
|
24
|
+
'url' => url
|
|
25
|
+
}
|
|
26
|
+
data['eps'] = eps if eps
|
|
27
|
+
|
|
28
|
+
response = @client.request('POST', "/api/projects/#{project_id}/destinations", data: data)
|
|
29
|
+
Models::Destination.new(response)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Get a destination by ID.
|
|
33
|
+
def get(project_id:, destination_id:)
|
|
34
|
+
response = @client.request('GET', "/api/projects/#{project_id}/destinations/#{destination_id}")
|
|
35
|
+
Models::Destination.new(response)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Update a destination.
|
|
39
|
+
def update(project_id:, destination_id:, name: nil, url: nil, eps: nil)
|
|
40
|
+
data = {}
|
|
41
|
+
data['name'] = name if name
|
|
42
|
+
data['url'] = url if url
|
|
43
|
+
data['eps'] = eps if eps
|
|
44
|
+
|
|
45
|
+
response = @client.request('PUT', "/api/projects/#{project_id}/destinations/#{destination_id}", data: data)
|
|
46
|
+
Models::Destination.new(response)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Delete a destination.
|
|
50
|
+
def delete(project_id:, destination_id:)
|
|
51
|
+
@client.request('DELETE', "/api/projects/#{project_id}/destinations/#{destination_id}")
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../models/event'
|
|
4
|
+
|
|
5
|
+
module Volley
|
|
6
|
+
module Resources
|
|
7
|
+
# Events API resource.
|
|
8
|
+
class EventsResource
|
|
9
|
+
def initialize(client)
|
|
10
|
+
@client = client
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# List events for a project.
|
|
14
|
+
def list(project_id:, limit: nil, offset: nil, source_id: nil, status: nil, start_date: nil, end_date: nil)
|
|
15
|
+
query_params = {}
|
|
16
|
+
query_params['limit'] = limit if limit
|
|
17
|
+
query_params['offset'] = offset if offset
|
|
18
|
+
query_params['source_id'] = source_id if source_id
|
|
19
|
+
query_params['status'] = status if status
|
|
20
|
+
query_params['start_date'] = start_date if start_date
|
|
21
|
+
query_params['end_date'] = end_date if end_date
|
|
22
|
+
|
|
23
|
+
response = @client.request('GET', "/api/projects/#{project_id}/events", query_params: query_params)
|
|
24
|
+
|
|
25
|
+
events_data = response['requests'] || []
|
|
26
|
+
events = events_data.map { |event_data| Models::Event.new(event_data) }
|
|
27
|
+
|
|
28
|
+
{
|
|
29
|
+
events: events,
|
|
30
|
+
total: response['total'] || 0,
|
|
31
|
+
limit: response['limit'] || 0,
|
|
32
|
+
offset: response['offset'] || 0
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Get an event by ID.
|
|
37
|
+
def get(project_id:, event_id:)
|
|
38
|
+
response = @client.request('GET', "/api/projects/#{project_id}/events/#{event_id}")
|
|
39
|
+
Models::Event.new(response['request'] || {})
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Replay an event.
|
|
43
|
+
def replay(event_id:, destination_id: nil, connection_id: nil)
|
|
44
|
+
data = { 'event_id' => event_id }
|
|
45
|
+
data['destination_id'] = destination_id if destination_id
|
|
46
|
+
data['connection_id'] = connection_id if connection_id
|
|
47
|
+
|
|
48
|
+
response = @client.request('POST', '/api/replay-event', data: data)
|
|
49
|
+
response['message'] || 'Event replayed'
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../models/organization'
|
|
4
|
+
|
|
5
|
+
module Volley
|
|
6
|
+
module Resources
|
|
7
|
+
# Organizations API resource.
|
|
8
|
+
class OrganizationsResource
|
|
9
|
+
def initialize(client)
|
|
10
|
+
@client = client
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# List all organizations the user has access to.
|
|
14
|
+
#
|
|
15
|
+
# @return [Array<Models::Organization>]
|
|
16
|
+
def list
|
|
17
|
+
response = @client.request('GET', '/api/org/list')
|
|
18
|
+
orgs_data = response['organizations'] || []
|
|
19
|
+
orgs_data.map { |org_data| Models::Organization.new(org_data) }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Get the current organization.
|
|
23
|
+
#
|
|
24
|
+
# @param organization_id [Integer, nil] Optional organization ID. If nil, uses default organization.
|
|
25
|
+
# @return [Models::Organization]
|
|
26
|
+
def get(organization_id: nil)
|
|
27
|
+
original_org_id = @client.get_organization_id
|
|
28
|
+
@client.set_organization_id(organization_id) if organization_id
|
|
29
|
+
|
|
30
|
+
begin
|
|
31
|
+
response = @client.request('GET', '/api/org')
|
|
32
|
+
# GetOrganization returns id, name, slug, role (not account_id, created_at)
|
|
33
|
+
org_data = {
|
|
34
|
+
'id' => response['id'],
|
|
35
|
+
'name' => response['name'],
|
|
36
|
+
'slug' => response['slug'],
|
|
37
|
+
'role' => response['role'],
|
|
38
|
+
'account_id' => response['account_id'],
|
|
39
|
+
'created_at' => response['created_at']
|
|
40
|
+
}
|
|
41
|
+
Models::Organization.new(org_data)
|
|
42
|
+
ensure
|
|
43
|
+
if original_org_id
|
|
44
|
+
@client.set_organization_id(original_org_id)
|
|
45
|
+
else
|
|
46
|
+
@client.clear_organization_id
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Create a new organization.
|
|
52
|
+
#
|
|
53
|
+
# @param name [String] Organization name
|
|
54
|
+
# @return [Models::Organization]
|
|
55
|
+
def create(name:)
|
|
56
|
+
data = { 'name' => name }
|
|
57
|
+
response = @client.request('POST', '/api/org', data: data)
|
|
58
|
+
Models::Organization.new(response)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../models/project'
|
|
4
|
+
|
|
5
|
+
module Volley
|
|
6
|
+
module Resources
|
|
7
|
+
# Projects API resource.
|
|
8
|
+
class ProjectsResource
|
|
9
|
+
def initialize(client)
|
|
10
|
+
@client = client
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# List all projects in the current organization.
|
|
14
|
+
#
|
|
15
|
+
# @return [Array<Models::Project>]
|
|
16
|
+
def list
|
|
17
|
+
response = @client.request('GET', '/api/projects')
|
|
18
|
+
projects_data = response['projects'] || []
|
|
19
|
+
projects_data.map { |project_data| Models::Project.new(project_data) }
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Create a new project.
|
|
23
|
+
#
|
|
24
|
+
# @param name [String] Project name
|
|
25
|
+
# @return [Models::Project]
|
|
26
|
+
def create(name:)
|
|
27
|
+
data = { 'name' => name }
|
|
28
|
+
response = @client.request('POST', '/api/projects', data: data)
|
|
29
|
+
Models::Project.new(response)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Update a project.
|
|
33
|
+
#
|
|
34
|
+
# @param project_id [Integer] Project ID
|
|
35
|
+
# @param name [String] Updated project name
|
|
36
|
+
# @return [Models::Project]
|
|
37
|
+
def update(project_id:, name:)
|
|
38
|
+
data = { 'name' => name }
|
|
39
|
+
response = @client.request('PUT', "/api/projects/#{project_id}", data: data)
|
|
40
|
+
Models::Project.new(response)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Delete a project.
|
|
44
|
+
#
|
|
45
|
+
# @param project_id [Integer] Project ID to delete
|
|
46
|
+
def delete(project_id:)
|
|
47
|
+
@client.request('DELETE', "/api/projects/#{project_id}")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../models/source'
|
|
4
|
+
|
|
5
|
+
module Volley
|
|
6
|
+
module Resources
|
|
7
|
+
# Sources API resource.
|
|
8
|
+
class SourcesResource
|
|
9
|
+
def initialize(client)
|
|
10
|
+
@client = client
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# List all sources for a project.
|
|
14
|
+
#
|
|
15
|
+
# @param project_id [Integer] Project ID
|
|
16
|
+
# @return [Array<Models::Source>]
|
|
17
|
+
def list(project_id:)
|
|
18
|
+
response = @client.request('GET', "/api/projects/#{project_id}/sources")
|
|
19
|
+
sources_data = response['sources'] || []
|
|
20
|
+
sources_data.map { |source_data| Models::Source.new(source_data) }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Create a new source.
|
|
24
|
+
def create(project_id:, slug:, type:, eps: nil, auth_type: nil, auth_username: nil, auth_key: nil,
|
|
25
|
+
verify_signature: nil, webhook_secret: nil)
|
|
26
|
+
data = {
|
|
27
|
+
'slug' => slug,
|
|
28
|
+
'type' => type
|
|
29
|
+
}
|
|
30
|
+
data['eps'] = eps if eps
|
|
31
|
+
data['auth_type'] = auth_type if auth_type
|
|
32
|
+
data['auth_username'] = auth_username if auth_username
|
|
33
|
+
data['auth_key'] = auth_key if auth_key
|
|
34
|
+
data['verify_signature'] = verify_signature unless verify_signature.nil?
|
|
35
|
+
data['webhook_secret'] = webhook_secret if webhook_secret
|
|
36
|
+
|
|
37
|
+
response = @client.request('POST', "/api/projects/#{project_id}/sources", data: data)
|
|
38
|
+
Models::Source.new(response)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Get a source by ID.
|
|
42
|
+
def get(project_id:, source_id:)
|
|
43
|
+
response = @client.request('GET', "/api/projects/#{project_id}/sources/#{source_id}")
|
|
44
|
+
Models::Source.new(response)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Update a source.
|
|
48
|
+
def update(project_id:, source_id:, slug: nil, eps: nil, auth_type: nil, auth_username: nil, auth_key: nil,
|
|
49
|
+
verify_signature: nil, webhook_secret: nil)
|
|
50
|
+
data = {}
|
|
51
|
+
data['slug'] = slug if slug
|
|
52
|
+
data['eps'] = eps if eps
|
|
53
|
+
data['auth_type'] = auth_type if auth_type
|
|
54
|
+
data['auth_username'] = auth_username if auth_username
|
|
55
|
+
data['auth_key'] = auth_key if auth_key
|
|
56
|
+
data['verify_signature'] = verify_signature unless verify_signature.nil?
|
|
57
|
+
data['webhook_secret'] = webhook_secret if webhook_secret
|
|
58
|
+
|
|
59
|
+
response = @client.request('PUT', "/api/projects/#{project_id}/sources/#{source_id}", data: data)
|
|
60
|
+
Models::Source.new(response)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Delete a source.
|
|
64
|
+
def delete(project_id:, source_id:)
|
|
65
|
+
@client.request('DELETE', "/api/projects/#{project_id}/sources/#{source_id}")
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Volley
|
|
4
|
+
module Resources
|
|
5
|
+
# Webhooks API resource.
|
|
6
|
+
class WebhooksResource
|
|
7
|
+
def initialize(client)
|
|
8
|
+
@client = client
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Send a webhook.
|
|
12
|
+
def send(source_id:, destination_id:, body:, headers: nil)
|
|
13
|
+
data = {
|
|
14
|
+
'source_id' => source_id,
|
|
15
|
+
'destination_id' => destination_id,
|
|
16
|
+
'body' => body
|
|
17
|
+
}
|
|
18
|
+
data['headers'] = headers if headers
|
|
19
|
+
|
|
20
|
+
response = @client.request('POST', '/api/webhooks', data: data)
|
|
21
|
+
response['message'] || 'Webhook sent'
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'resources/organizations_resource'
|
|
4
|
+
require_relative 'resources/projects_resource'
|
|
5
|
+
require_relative 'resources/sources_resource'
|
|
6
|
+
require_relative 'resources/destinations_resource'
|
|
7
|
+
require_relative 'resources/connections_resource'
|
|
8
|
+
require_relative 'resources/events_resource'
|
|
9
|
+
require_relative 'resources/delivery_attempts_resource'
|
|
10
|
+
require_relative 'resources/webhooks_resource'
|
|
11
|
+
|