argonuts-ruby 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +10 -0
- data/lib/argonuts/api.rb +20 -13
- data/lib/argonuts/version.rb +1 -1
- data/test/argonuts_test.rb +26 -22
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2eebc8c0a3b2502db0b47ad785762c0d237b753b02b26772a7b2174e67104d9
|
4
|
+
data.tar.gz: 50d0552f780e45ea9d3d97825c6e76c85040a9b9ade93199a45998610fc23747
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 211adbb3435d2ad43f5ca17596d9adc5f782ef0a7994d3111f4f4e020fead87a78a7bf35cbfc652953e969ec87432533f8a2c6657150180267147f489375e888
|
7
|
+
data.tar.gz: de68d2b6b95b31e770eaa605f9055f592df03ea1bb2990c78d3df3c81a79504a10cbd3c5fa9cfea69dd255a1e4e74a2cccee96c292e49d0d9364b8ff47284295
|
data/Rakefile
ADDED
data/lib/argonuts/api.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
require "http"
|
1
|
+
require "net/http"
|
2
|
+
require "base64"
|
3
|
+
require "json"
|
2
4
|
|
3
5
|
module Argonuts
|
4
6
|
# Argonuts::API is responsible for making API requests.
|
@@ -9,30 +11,35 @@ module Argonuts
|
|
9
11
|
raise Argonuts::Error, "You must specify an API key with Argonuts.api_key="
|
10
12
|
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
{
|
15
|
+
'X-Auth-Token': cli.api_key,
|
16
|
+
'User-Agent': "Argonuts/#{Argonuts::VERSION}",
|
17
|
+
}
|
14
18
|
end
|
15
19
|
|
16
|
-
def self.request(verb, path, options={})
|
20
|
+
def self.request(verb, path, options = {})
|
17
21
|
cli = options[:client] || Argonuts.default_client
|
18
22
|
|
23
|
+
url = URI("#{cli.endpoint}#{path}")
|
24
|
+
http = Net::HTTP.new(url.host, url.port)
|
25
|
+
|
19
26
|
case verb
|
20
27
|
when :get
|
21
|
-
|
28
|
+
request = Net::HTTP::Get.new(url, 'Content-Type' => 'application/json')
|
22
29
|
when :post
|
23
|
-
|
30
|
+
request = Net::HTTP::Post.new(url, 'Content-Type' => 'application/json')
|
31
|
+
request.body = options[:json].to_json
|
24
32
|
end
|
25
33
|
|
26
|
-
|
34
|
+
headers(cli).map { |k, v| request[k] = v }
|
35
|
+
resp = http.request(request)
|
36
|
+
|
37
|
+
if resp.code.to_i > 399
|
27
38
|
# if response is 400 or 401, we return the error message and error code
|
28
|
-
|
29
|
-
raise Argonuts::Error, "#{resp.parse["message"]} (code=#{resp.parse["error_code"]})"
|
30
|
-
else
|
31
|
-
raise Argonuts::Error, "Server returned HTTP status #{resp.code}."
|
32
|
-
end
|
39
|
+
raise Argonuts::Error, "Server returned HTTP status #{resp.code}."
|
33
40
|
end
|
34
41
|
|
35
|
-
return resp.
|
42
|
+
return JSON::parse(resp.body)
|
36
43
|
end
|
37
44
|
end
|
38
45
|
end
|
data/lib/argonuts/version.rb
CHANGED
data/test/argonuts_test.rb
CHANGED
@@ -14,13 +14,17 @@ class ArgonutsTest < Test::Unit::TestCase
|
|
14
14
|
type: "http",
|
15
15
|
url: ENV["ARGONUTS_WEBHOOK_URL"]
|
16
16
|
}
|
17
|
+
|
18
|
+
Argonuts.storage = {
|
19
|
+
url: ENV["ARGONUTS_STORAGE_URL"],
|
20
|
+
}
|
17
21
|
end
|
18
22
|
|
19
23
|
def create_job(j={}, options={})
|
20
24
|
Argonuts::Job.create({
|
21
25
|
input: { url: INPUT_URL },
|
22
26
|
outputs: {
|
23
|
-
mp4: { path: "/test_create_job.mp4"
|
27
|
+
mp4: { path: "/test_create_job.mp4" }
|
24
28
|
}
|
25
29
|
}.merge(j), options)
|
26
30
|
end
|
@@ -48,25 +52,25 @@ class ArgonutsTest < Test::Unit::TestCase
|
|
48
52
|
assert_equal "job.starting", job.status
|
49
53
|
end
|
50
54
|
|
51
|
-
def test_retrieve_job
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_create_job_error
|
59
|
-
|
60
|
-
rescue => e
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_retrieve_metadata
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
55
|
+
# def test_retrieve_job
|
56
|
+
# job = Argonuts::Job.retrieve(create_job.id)
|
57
|
+
# assert job.is_a?(Argonuts::Job)
|
58
|
+
# assert_not_nil job.id
|
59
|
+
# assert_equal "job.starting", job.status
|
60
|
+
# end
|
61
|
+
#
|
62
|
+
# def test_create_job_error
|
63
|
+
# create_job(input: {url: "notvalidurl"})
|
64
|
+
# rescue => e
|
65
|
+
# assert_equal e.class, Argonuts::Error
|
66
|
+
# end
|
67
|
+
#
|
68
|
+
# def test_retrieve_metadata
|
69
|
+
# job = create_job
|
70
|
+
# sleep 10
|
71
|
+
#
|
72
|
+
# md = Argonuts::Metadata.retrieve(job.id)
|
73
|
+
# assert md.is_a?(Hash)
|
74
|
+
# assert_not_nil md["metadata"]["input"]
|
75
|
+
# end
|
72
76
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: argonuts-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Argonuts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -31,6 +31,7 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- README.md
|
34
|
+
- Rakefile
|
34
35
|
- argonuts-ruby.gemspec
|
35
36
|
- lib/argonuts-ruby.rb
|
36
37
|
- lib/argonuts/api.rb
|