browse_ai 1.0.1 → 1.0.3

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: 56398bbf96c77d517e531a411ab7f62a6d844364c756ee95f5bc1aeb79d2d4c4
4
- data.tar.gz: f5b8efb74c756d0a24d7438abfa7ce29f0ccb9be5fc4449307444c428509e3eb
3
+ metadata.gz: 4e7866506b5497da51c581127b313886e293c42b7751e582d043d378bfebfcf3
4
+ data.tar.gz: c776eeae73a97f1581de1ae3e11f1f34c174666b961b07e3f73efd6ec1eb15c6
5
5
  SHA512:
6
- metadata.gz: 9a85873d6f7f2b61fdaeaead78694221652296025c2e041064232d0bd2eb4f68e0f0d23626c5c637835205ea3c04d64ed0a35cdc27f122ceb6924c80c23c0762
7
- data.tar.gz: 2750f1044810fceffef860a1c46948cb097645e05525db52699ba9346af7ae33d46db862cff7d92de89ab8457ae67985261a920e7acfaa95b6ac939b8b93a33d
6
+ metadata.gz: 0534b89bb1a07bda3d140e6e9b6442743e1c1b1148c652bdf28f77a212c57f84cc667e7a3bea3d1fcc6b1ce13a297784192afe56c154b30cd5cd3ce1e5d053c5
7
+ data.tar.gz: 4f7e32004d613edb8fe7185714b4bdf2038f3a4b4deb9c01dab3c75d9f82b4af1d0dc6cf066a125d4451c26b8fd47167975dcb77e2d61e16b43d672e302942df
data/README.md CHANGED
@@ -47,6 +47,13 @@ Get a robot's task.
47
47
  task = BrowseAi.client.get_tasks(robot_id: '<robot UUID>', id: '<task UUID>')
48
48
  ```
49
49
 
50
+ Run a robot.
51
+ ```
52
+ # Example JSON payload. The input parameters will vary depending on your robot's configuration.
53
+ payload = {'inputParameters' => {'originUrl' => 'Test'}}.to_json
54
+ task = BrowseAi.client.run_robot(robot_id: '<robot UUID>', payload:)
55
+ ```
56
+
50
57
  Get a robot's monitors.
51
58
  ```
52
59
  monitors = BrowseAi.client.get_monitors(robot_id: '<robot UUID>')
@@ -0,0 +1,41 @@
1
+ require 'browse_ai/dsl'
2
+
3
+ module BrowseAi
4
+ module DSL::BulkRuns
5
+ # POST /robots/{robotId}/bulk-runs
6
+ # Executes a bulk run on a robot.
7
+ # @param [String] robot_id The ID of the robot the bulk_runs belongs to.
8
+ # @param [String] :payload The JSON payload to send to the robot.
9
+ # @raise [ArgumentError] If the method arguments are blank.
10
+ # @return [BrowseAi::Resources::BulkRun, nil].
11
+ def bulk_run_tasks(robot_id:, payload:)
12
+ raise ArgumentError, 'Robot ID cannot be blank' if robot_id.blank?
13
+ raise ArgumentError, 'Payload cannot be blank' if payload.blank?
14
+
15
+ Resources::BulkRun.parse(request(:post, "robots/#{robot_id}/bulk_runs/", payload), %w[result bulkRun])
16
+ end
17
+
18
+ # GET robots/{robotId}/bulk-runs
19
+ # Get bulk_runs.
20
+ # @param [String] robot_id The ID of the robot the bulk runs belongs to.
21
+ # @raise [ArgumentError] If the method arguments are blank.
22
+ # @return [Array, nil].
23
+ def get_bulk_runs(robot_id:)
24
+ raise ArgumentError, 'Robot ID cannot be blank' if robot_id.blank?
25
+
26
+ Resources::BulkRun.parse(request(:get, "robots/#{robot_id}/bulk-runs/", nil), %w[result items])
27
+ end
28
+
29
+ # GET robots/{robotId}/bulk-runs/{id}
30
+ # Get a bulk_run.
31
+ # @param [String] id A bulk run's ID.
32
+ # @raise [ArgumentError] If the method arguments are blank.
33
+ # @return [BrowseAi::Resources::BulkRun, nil].
34
+ def get_bulk_run(robot_id:, id:)
35
+ raise ArgumentError, 'Robot ID cannot be blank' if robot_id.blank?
36
+ raise ArgumentError, 'ID cannot be blank' if id.blank?
37
+
38
+ Resources::BulkRun.parse(request(:get, "robots/#{robot_id}/bulk-runs/#{id}"), %w[result bulkRun])
39
+ end
40
+ end
41
+ end
@@ -5,6 +5,7 @@ module BrowseAi
5
5
  # GET /Monitors
6
6
  # Get monitors.
7
7
  # @param [String] robot_id The ID of the robot the monitors belong to.
8
+ # @raise [ArgumentError] If the method arguments are blank.
8
9
  # @return [Array, nil].
9
10
  def get_monitors(robot_id:)
10
11
  raise ArgumentError, 'Robot ID cannot be blank' if robot_id.blank?
@@ -2,9 +2,23 @@ require 'browse_ai/dsl'
2
2
 
3
3
  module BrowseAi
4
4
  module DSL::Tasks
5
- # GET /Tasks
5
+ # POST /robots/{robotId}/tasks
6
+ # Runs a task on a robot.
7
+ # @param [String] robot_id The ID of the robot the tasks belongs to.
8
+ # @param [String] :payload The JSON payload to send to the robot.
9
+ # @raise [ArgumentError] If the method arguments are blank.
10
+ # @return [BrowseAi::Resources::Task, nil].
11
+ def run_robot(robot_id:, payload:)
12
+ raise ArgumentError, 'Robot ID cannot be blank' if robot_id.blank?
13
+ raise ArgumentError, 'Payload cannot be blank' if payload.blank?
14
+
15
+ Resources::Task.parse(request(:post, "robots/#{robot_id}/tasks/", payload), ['result'])
16
+ end
17
+
18
+ # GET robots/{robotId}/tasks
6
19
  # Get tasks.
7
- # @param [String] robot_id The ID of the robot the tasks belong to.
20
+ # @param [String] robot_id The ID of the robot the tasks belongs to.
21
+ # @raise [ArgumentError] If the method arguments are blank.
8
22
  # @return [Array, nil].
9
23
  def get_tasks(robot_id:)
10
24
  raise ArgumentError, 'Robot ID cannot be blank' if robot_id.blank?
@@ -12,7 +26,7 @@ module BrowseAi
12
26
  Resources::Task.parse(request(:get, "robots/#{robot_id}/tasks/", nil), %w[tasks items])
13
27
  end
14
28
 
15
- # GET /Task/{id}
29
+ # GET robots/{robotId}/tasks/{id}
16
30
  # Get a task.
17
31
  # @param [String] id A task's ID.
18
32
  # @raise [ArgumentError] If the method arguments are blank.
@@ -5,6 +5,7 @@ module BrowseAi
5
5
  # GET /Webhooks
6
6
  # Get webhooks.
7
7
  # @param [String] robot_id The ID of the robot the webhooks belong to.
8
+ # @raise [ArgumentError] If the method arguments are blank.
8
9
  # @return [Array, nil].
9
10
  def get_webhooks(robot_id:)
10
11
  raise ArgumentError, 'Robot ID cannot be blank' if robot_id.blank?
data/lib/browse_ai/dsl.rb CHANGED
@@ -5,6 +5,7 @@ module BrowseAi
5
5
  end
6
6
  end
7
7
 
8
+ require 'browse_ai/dsl/bulk_runs'
8
9
  require 'browse_ai/dsl/monitors'
9
10
  require 'browse_ai/dsl/robots'
10
11
  require 'browse_ai/dsl/tasks'
@@ -14,6 +15,7 @@ require 'mime-types'
14
15
 
15
16
  module BrowseAi
16
17
  module DSL
18
+ include BulkRuns
17
19
  include Monitors
18
20
  include Robots
19
21
  include Tasks
@@ -0,0 +1,8 @@
1
+ require 'browse_ai/resources/object'
2
+
3
+ module BrowseAi
4
+ module Resources
5
+ class BulkRun < BrowseAi::Resources::Object
6
+ end
7
+ end
8
+ end
@@ -16,7 +16,7 @@ module BrowseAi
16
16
  attribute :date_updated_utc, Time
17
17
 
18
18
  def inspect
19
- "#<#{self.class.name}:#{format('0x00%x', (object_id << 1))} #{inspect_attributes}>"
19
+ "#<#{self.class.name}:#{format('0x00%x', object_id << 1)} #{inspect_attributes}>"
20
20
  end
21
21
 
22
22
  private
@@ -5,6 +5,7 @@ module BrowseAi
5
5
  end
6
6
  end
7
7
 
8
+ require 'browse_ai/resources/bulk_run'
8
9
  require 'browse_ai/resources/monitor'
9
10
  require 'browse_ai/resources/object'
10
11
  require 'browse_ai/resources/robot'
@@ -1,3 +1,3 @@
1
1
  module BrowseAi
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe BrowseAi::DSL::BulkRuns do
4
+ def robot_id
5
+ VCR.use_cassette('get_robots') do
6
+ robots = BrowseAi.client.get_robots
7
+ robots.first['id']
8
+ end
9
+ end
10
+
11
+ # POST /robots/{robotId}/bulk-runs
12
+ describe '#bulk_run_tasks' do
13
+ let(:payload) do
14
+ {
15
+ 'inputParameters' => {
16
+ 'originUrl' => 'Test',
17
+ }
18
+ }.to_json
19
+ end
20
+
21
+ it 'creates a bulk run and executes it on the robot' do
22
+ VCR.use_cassette('bulk_run_tasks') do
23
+ bulk_run = BrowseAi.client.bulk_run_tasks(robot_id:, payload:)
24
+ expect(bulk_run).to be_a(BulkRun)
25
+ end
26
+ end
27
+ end
28
+
29
+ # GET robots/{robotId}/bulk_runs
30
+ describe '#get_bulk_runs' do
31
+ it 'returns an array of bulk_runs' do
32
+ VCR.use_cassette('get_bulk_runs') do
33
+ bulk_runs = BrowseAi.client.get_bulk_runs(robot_id:)
34
+ expect(bulk_runs).to be_a(Array)
35
+ expect(bulk_runs.first).to be_a(BulkRun)
36
+ end
37
+ end
38
+ end
39
+
40
+ # GET robots/{robotId}/bulk_runs/{id}
41
+ describe '#get_bulk_run' do
42
+ it 'returns an bulk_run' do
43
+ id = VCR.use_cassette('get_bulk_runs') do
44
+ bulk_runs = BrowseAi.client.get_bulk_runs(robot_id:)
45
+ bulk_runs.first['id']
46
+ end
47
+
48
+ VCR.use_cassette('get_bulk_run') do
49
+ expect(BrowseAi.client.get_bulk_run(robot_id:, id:)).to be_a(BulkRun)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -8,7 +8,25 @@ describe BrowseAi::DSL::Tasks do
8
8
  end
9
9
  end
10
10
 
11
- # GET /tasks
11
+ # POST /robots/{robotId}/tasks
12
+ describe '#run_robot' do
13
+ let(:payload) do
14
+ {
15
+ 'inputParameters' => {
16
+ 'originUrl' => 'Test',
17
+ }
18
+ }.to_json
19
+ end
20
+
21
+ it 'creates a task and runs it' do
22
+ VCR.use_cassette('run_robot') do
23
+ task = BrowseAi.client.run_robot(robot_id:, payload:)
24
+ expect(task).to be_a(Task)
25
+ end
26
+ end
27
+ end
28
+
29
+ # GET robots/{robotId}/tasks
12
30
  describe '#get_tasks' do
13
31
  it 'returns an array of tasks' do
14
32
  VCR.use_cassette('get_tasks') do
@@ -19,7 +37,7 @@ describe BrowseAi::DSL::Tasks do
19
37
  end
20
38
  end
21
39
 
22
- # GET /tasks/{id}
40
+ # GET robots/{robotId}/tasks/{id}
23
41
  describe '#get_task' do
24
42
  it 'returns an task' do
25
43
  id = VCR.use_cassette('get_tasks') do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browse_ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Iorns
@@ -184,6 +184,7 @@ files:
184
184
  - lib/browse_ai.rb
185
185
  - lib/browse_ai/client.rb
186
186
  - lib/browse_ai/dsl.rb
187
+ - lib/browse_ai/dsl/bulk_runs.rb
187
188
  - lib/browse_ai/dsl/monitors.rb
188
189
  - lib/browse_ai/dsl/robots.rb
189
190
  - lib/browse_ai/dsl/tasks.rb
@@ -192,6 +193,7 @@ files:
192
193
  - lib/browse_ai/errors/client_error.rb
193
194
  - lib/browse_ai/errors/resource_not_found_error.rb
194
195
  - lib/browse_ai/resources.rb
196
+ - lib/browse_ai/resources/bulk_run.rb
195
197
  - lib/browse_ai/resources/monitor.rb
196
198
  - lib/browse_ai/resources/object.rb
197
199
  - lib/browse_ai/resources/object/attributes.rb
@@ -203,6 +205,7 @@ files:
203
205
  - lib/browse_ai/utils/url_helper.rb
204
206
  - lib/browse_ai/version.rb
205
207
  - spec/browse_ai/client_spec.rb
208
+ - spec/browse_ai/dsl/bulk_runs_spec.rb
206
209
  - spec/browse_ai/dsl/monitors_spec.rb
207
210
  - spec/browse_ai/dsl/robots_spec.rb
208
211
  - spec/browse_ai/dsl/tasks_spec.rb
@@ -231,6 +234,7 @@ specification_version: 4
231
234
  summary: A Ruby wrapper for the Browse AI API. https://www.browse.ai/docs/api/v2
232
235
  test_files:
233
236
  - spec/browse_ai/client_spec.rb
237
+ - spec/browse_ai/dsl/bulk_runs_spec.rb
234
238
  - spec/browse_ai/dsl/monitors_spec.rb
235
239
  - spec/browse_ai/dsl/robots_spec.rb
236
240
  - spec/browse_ai/dsl/tasks_spec.rb