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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c28db98339446905816e23fcaf69a72412643caeaf412e983ae6fb717242d45d
4
- data.tar.gz: 967a6b247e4e7a5ff86abc1d3a9e5eb15a27bd60933ae2486fd3cfa03bb7476a
3
+ metadata.gz: e2eebc8c0a3b2502db0b47ad785762c0d237b753b02b26772a7b2174e67104d9
4
+ data.tar.gz: 50d0552f780e45ea9d3d97825c6e76c85040a9b9ade93199a45998610fc23747
5
5
  SHA512:
6
- metadata.gz: cd21f42e2c784afd8d4e29b27bf73cf7ee96534a0436d462a11f1bef21f60ccd42f5440188c462bf10a061a161f92dfa3bfcd5a5898ac972bee8497cf6b2520d
7
- data.tar.gz: 2a5134127893a0c71997bb5373575024f327b6332c2db0bd40a85cf7f9ff62597f7b088e455bb190ecf069a51f5e53ea6aea065de48af55fdce67658841bebd8
6
+ metadata.gz: 211adbb3435d2ad43f5ca17596d9adc5f782ef0a7994d3111f4f4e020fead87a78a7bf35cbfc652953e969ec87432533f8a2c6657150180267147f489375e888
7
+ data.tar.gz: de68d2b6b95b31e770eaa605f9055f592df03ea1bb2990c78d3df3c81a79504a10cbd3c5fa9cfea69dd255a1e4e74a2cccee96c292e49d0d9364b8ff47284295
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << "test"
5
+ t.test_files = FileList['test/*.rb']
6
+ # t.verbose = true
7
+ end
8
+
9
+ desc "Run tests"
10
+ task default: :test
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
- HTTP.basic_auth(user: cli.api_key, pass: "").
13
- headers(:user_agent => "Argonuts/v1 RubyBindings/#{Argonuts::VERSION}")
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
- resp = headers(cli).get("#{cli.endpoint}#{path}")
28
+ request = Net::HTTP::Get.new(url, 'Content-Type' => 'application/json')
22
29
  when :post
23
- resp = headers(cli).post("#{cli.endpoint}#{path}", json: options[:json])
30
+ request = Net::HTTP::Post.new(url, 'Content-Type' => 'application/json')
31
+ request.body = options[:json].to_json
24
32
  end
25
33
 
26
- if resp.code > 399
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
- if resp.code.between?(400, 401)
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.parse
42
+ return JSON::parse(resp.body)
36
43
  end
37
44
  end
38
45
  end
@@ -1,3 +1,3 @@
1
1
  module Argonuts
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -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", duration: 1 }
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
- job = Argonuts::Job.retrieve(create_job.id)
53
- assert job.is_a?(Argonuts::Job)
54
- assert_not_nil job.id
55
- assert_equal "job.starting", job.status
56
- end
57
-
58
- def test_create_job_error
59
- create_job(input: {url: "notvalidurl"})
60
- rescue => e
61
- assert_equal e.class, Argonuts::Error
62
- end
63
-
64
- def test_retrieve_metadata
65
- job = create_job
66
- sleep 10
67
-
68
- md = Argonuts::Metadata.retrieve(job.id)
69
- assert md.is_a?(Hash)
70
- assert_not_nil md["metadata"]["input"]
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.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-01 00:00:00.000000000 Z
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