argonuts-ruby 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 +7 -0
 - data/README.md +84 -0
 - data/argonuts-ruby.gemspec +18 -0
 - data/lib/argonuts/api.rb +38 -0
 - data/lib/argonuts/client.rb +31 -0
 - data/lib/argonuts/error.rb +3 -0
 - data/lib/argonuts/job.rb +42 -0
 - data/lib/argonuts/metadata.rb +7 -0
 - data/lib/argonuts/version.rb +3 -0
 - data/lib/argonuts-ruby.rb +50 -0
 - data/test/argonuts_test.rb +72 -0
 - metadata +67 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: ab46eeb7dec91ab90a48e01bf6082116a8eb941b4777104d5b4d388952d1cbfb
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 496bd20b0cb8c7f9a8556684840a1a3e91ae2eb9340f7da81b4bde6bbe21ad31
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f55e87dda4006506fd344ef0706f46bc1d8bd269102d8e7afdc9a33ed2ab28b85e83ab02b18c1ba1a63a84db31ad2403eeae6c3c6a8748ccb53fbbeda1dd81a7
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: f28df646ced2df3ecea1c6ec7e6659f054a98a89c12fabcb53fdb7c30237a8baa42debebbd6be438b146037740e589d5bd381f6d78babd5cb7d87068dff25e18
         
     | 
    
        data/README.md
    ADDED
    
    | 
         @@ -0,0 +1,84 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Argonuts Ruby Library
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            The Argonuts Ruby library provides access to the Argonuts API.
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            ## Documentation
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            See the [full documentation](https://argonuts.co/docs).
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            You can install it via rubygems:
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            ```console
         
     | 
| 
      
 14 
     | 
    
         
            +
            gem install argonuts-ruby
         
     | 
| 
      
 15 
     | 
    
         
            +
            ```
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            ### Bundler
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            In Gemfile:
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 22 
     | 
    
         
            +
            gem 'argonuts-ruby'
         
     | 
| 
      
 23 
     | 
    
         
            +
            ```
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            And then, type in your terminal:
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            ```console
         
     | 
| 
      
 28 
     | 
    
         
            +
            bundle install
         
     | 
| 
      
 29 
     | 
    
         
            +
            ```
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            The library needs you to set your API key which can be found in your [dashboard](https://argonuts.co/dashboard).
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 37 
     | 
    
         
            +
            Argonuts.api_key = 'api-key'
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            Argonuts.notification = {
         
     | 
| 
      
 40 
     | 
    
         
            +
              type: "http",
         
     | 
| 
      
 41 
     | 
    
         
            +
              url: "https://yoursite.co/api/argonuts/webhook"
         
     | 
| 
      
 42 
     | 
    
         
            +
            }
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
            Argonuts.storage = {
         
     | 
| 
      
 45 
     | 
    
         
            +
              url: "https://yoursite.co/api/argonuts/upload",
         
     | 
| 
      
 46 
     | 
    
         
            +
            }
         
     | 
| 
      
 47 
     | 
    
         
            +
            ```
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            ## Creating a job
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 52 
     | 
    
         
            +
            Argonuts::Job.create(
         
     | 
| 
      
 53 
     | 
    
         
            +
              input: { url: "https://yoursite.co/path/file.mp4" },
         
     | 
| 
      
 54 
     | 
    
         
            +
              outputs: {
         
     | 
| 
      
 55 
     | 
    
         
            +
                "jpg:300x": { path: "/image.jpg" },
         
     | 
| 
      
 56 
     | 
    
         
            +
                "mp4:1080p": { path: "/1080p.mp4" },
         
     | 
| 
      
 57 
     | 
    
         
            +
                "httpstream": {
         
     | 
| 
      
 58 
     | 
    
         
            +
                  hls: { path: "hls/" }
         
     | 
| 
      
 59 
     | 
    
         
            +
                }
         
     | 
| 
      
 60 
     | 
    
         
            +
              }
         
     | 
| 
      
 61 
     | 
    
         
            +
            )
         
     | 
| 
      
 62 
     | 
    
         
            +
            ```
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            ## Getting information about a job
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 67 
     | 
    
         
            +
            Argonuts::Job.retrieve("OolQXaiU86NFki")
         
     | 
| 
      
 68 
     | 
    
         
            +
            ```
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            ## Retrieving metadata
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 73 
     | 
    
         
            +
            Argonuts::Metadata.retrieve("OolQXaiU86NFki")
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
            ```
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            ## Per-request configuration
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 80 
     | 
    
         
            +
            cli = Argonuts::Client.new(api_key: "api-key-prod")
         
     | 
| 
      
 81 
     | 
    
         
            +
            Argonuts::Job.create(job, client: cli)
         
     | 
| 
      
 82 
     | 
    
         
            +
            ```
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
            *Released under the [MIT license](http://www.opensource.org/licenses/mit-license.php).*
         
     | 
| 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $LOAD_PATH.unshift(::File.join(::File.dirname(__FILE__), "lib"))
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "argonuts/version"
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            Gem::Specification.new do |gem|
         
     | 
| 
      
 6 
     | 
    
         
            +
              gem.name        = "argonuts-ruby"
         
     | 
| 
      
 7 
     | 
    
         
            +
              gem.version     = Argonuts::VERSION
         
     | 
| 
      
 8 
     | 
    
         
            +
              gem.summary     = "Client library provides access to the Argonuts API (argonuts.co)"
         
     | 
| 
      
 9 
     | 
    
         
            +
              gem.description = "Official client library to the Argonuts API (argonuts.co)"
         
     | 
| 
      
 10 
     | 
    
         
            +
              gem.author      = "Argonuts"
         
     | 
| 
      
 11 
     | 
    
         
            +
              gem.email       = "admin@argonuts.co"
         
     | 
| 
      
 12 
     | 
    
         
            +
              gem.homepage    = "https://argonuts.co"
         
     | 
| 
      
 13 
     | 
    
         
            +
              gem.license     = "MIT"
         
     | 
| 
      
 14 
     | 
    
         
            +
              gem.files         = `git ls-files`.split("\n")
         
     | 
| 
      
 15 
     | 
    
         
            +
              gem.test_files    = `git ls-files -- test/*`.split("\n")
         
     | 
| 
      
 16 
     | 
    
         
            +
              gem.require_paths = ["lib"]
         
     | 
| 
      
 17 
     | 
    
         
            +
              gem.add_runtime_dependency "http"
         
     | 
| 
      
 18 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/argonuts/api.rb
    ADDED
    
    | 
         @@ -0,0 +1,38 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "http"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Argonuts
         
     | 
| 
      
 4 
     | 
    
         
            +
              # Argonuts::API is responsible for making API requests.
         
     | 
| 
      
 5 
     | 
    
         
            +
              # It takes a Argonuts::Client to send api_key, endpoint and region.
         
     | 
| 
      
 6 
     | 
    
         
            +
              class API
         
     | 
| 
      
 7 
     | 
    
         
            +
                def self.headers(cli)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  if cli.api_key.nil?
         
     | 
| 
      
 9 
     | 
    
         
            +
                    raise Argonuts::Error, "You must specify an API key with Argonuts.api_key="
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  HTTP.basic_auth(user: cli.api_key, pass: "").
         
     | 
| 
      
 13 
     | 
    
         
            +
                    headers(:user_agent => "Argonuts/v1 RubyBindings/#{Argonuts::VERSION}")
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                def self.request(verb, path, options={})
         
     | 
| 
      
 17 
     | 
    
         
            +
                  cli = options[:client] || Argonuts.default_client
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  case verb
         
     | 
| 
      
 20 
     | 
    
         
            +
                  when :get
         
     | 
| 
      
 21 
     | 
    
         
            +
                    resp = headers(cli).get("#{cli.endpoint}#{path}")
         
     | 
| 
      
 22 
     | 
    
         
            +
                  when :post
         
     | 
| 
      
 23 
     | 
    
         
            +
                    resp = headers(cli).post("#{cli.endpoint}#{path}", json: options[:json])
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  if resp.code > 399
         
     | 
| 
      
 27 
     | 
    
         
            +
                    # 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
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  return resp.parse
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Argonuts
         
     | 
| 
      
 2 
     | 
    
         
            +
              def self.default_client
         
     | 
| 
      
 3 
     | 
    
         
            +
                Client.new({
         
     | 
| 
      
 4 
     | 
    
         
            +
                  api_key: Argonuts.api_key,
         
     | 
| 
      
 5 
     | 
    
         
            +
                  region: Argonuts.region,
         
     | 
| 
      
 6 
     | 
    
         
            +
                  endpoint: Argonuts.endpoint
         
     | 
| 
      
 7 
     | 
    
         
            +
                })
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
              class Client
         
     | 
| 
      
 11 
     | 
    
         
            +
                attr_accessor :api_key, :endpoint, :region
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def initialize(options={})
         
     | 
| 
      
 14 
     | 
    
         
            +
                  @api_key = options[:api_key]
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @region = options[:region]
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @endpoint = options[:endpoint]
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                def endpoint
         
     | 
| 
      
 20 
     | 
    
         
            +
                  if @endpoint
         
     | 
| 
      
 21 
     | 
    
         
            +
                    return @endpoint
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  # if @region
         
     | 
| 
      
 25 
     | 
    
         
            +
                  #   return "https://argonuts.co/api-#{@region}/v1"
         
     | 
| 
      
 26 
     | 
    
         
            +
                  # end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  return Argonuts::ENDPOINT
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/argonuts/job.rb
    ADDED
    
    | 
         @@ -0,0 +1,42 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Argonuts
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Job < API
         
     | 
| 
      
 3 
     | 
    
         
            +
                attr_reader :id, :created_at, :completed_at, :status, :progress, :errors, :output_urls
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(attrs={})
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @id = attrs["id"]
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @created_at = attrs["created_at"]
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @completed_at = attrs["completed_at"]
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @status = attrs["status"]
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @progress = attrs["progress"]
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @errors = attrs["errors"]
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @output_urls = attrs["output_urls"]
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                def self.retrieve(job_id, options={})
         
     | 
| 
      
 16 
     | 
    
         
            +
                  resp = API.request(:get, "/jobs/#{job_id}", options)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  return Job.new(resp)
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def self.create(job, options={})
         
     | 
| 
      
 21 
     | 
    
         
            +
                  resp = API.request(:post, "/jobs", options.merge({
         
     | 
| 
      
 22 
     | 
    
         
            +
                    json: apply_settings(job)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  }))
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                  return Job.new(resp)
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def self.apply_settings(job)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  if notification = Argonuts.notification
         
     | 
| 
      
 30 
     | 
    
         
            +
                    job[:notification] ||= {}
         
     | 
| 
      
 31 
     | 
    
         
            +
                    job[:notification].merge!(notification)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  if storage = Argonuts.storage
         
     | 
| 
      
 35 
     | 
    
         
            +
                    job[:storage] ||= {}
         
     | 
| 
      
 36 
     | 
    
         
            +
                    job[:storage].merge!(storage)
         
     | 
| 
      
 37 
     | 
    
         
            +
                  end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                  return job
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,50 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "argonuts/api"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require "argonuts/error"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require "argonuts/client"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "argonuts/job"
         
     | 
| 
      
 5 
     | 
    
         
            +
            require "argonuts/metadata"
         
     | 
| 
      
 6 
     | 
    
         
            +
            require "argonuts/version"
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            module Argonuts
         
     | 
| 
      
 9 
     | 
    
         
            +
              ENDPOINT = "https://argonuts.co/api/v1"
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
              def self.api_key=(key)
         
     | 
| 
      
 12 
     | 
    
         
            +
                @api_key = key
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              def self.api_key
         
     | 
| 
      
 16 
     | 
    
         
            +
                @api_key
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              def self.region=(region)
         
     | 
| 
      
 20 
     | 
    
         
            +
                @region = region
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              def self.region
         
     | 
| 
      
 24 
     | 
    
         
            +
                @region
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              def self.endpoint=(endpoint)
         
     | 
| 
      
 28 
     | 
    
         
            +
                @endpoint = endpoint
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              def self.endpoint
         
     | 
| 
      
 32 
     | 
    
         
            +
                @endpoint
         
     | 
| 
      
 33 
     | 
    
         
            +
              end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
              def self.notification=(notification)
         
     | 
| 
      
 36 
     | 
    
         
            +
                @notification = notification
         
     | 
| 
      
 37 
     | 
    
         
            +
              end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
              def self.notification
         
     | 
| 
      
 40 
     | 
    
         
            +
                @notification
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
              def self.storage=(storage)
         
     | 
| 
      
 44 
     | 
    
         
            +
                @storage = storage
         
     | 
| 
      
 45 
     | 
    
         
            +
              end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
              def self.storage
         
     | 
| 
      
 48 
     | 
    
         
            +
                @storage
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,72 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $LOAD_PATH.unshift(::File.join(::File.dirname(__FILE__), "..", "lib"))
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "test/unit"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "argonuts-ruby"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            class ArgonutsTest < Test::Unit::TestCase
         
     | 
| 
      
 7 
     | 
    
         
            +
              INPUT_URL = "https://argonuts.co/sample1080p.mp4"
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 10 
     | 
    
         
            +
                Argonuts.api_key = ENV["ARGONUTS_API_KEY"]
         
     | 
| 
      
 11 
     | 
    
         
            +
                Argonuts.endpoint = ENV["ARGONUTS_ENDPOINT"]
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                Argonuts.notification = {
         
     | 
| 
      
 14 
     | 
    
         
            +
                  type: "http",
         
     | 
| 
      
 15 
     | 
    
         
            +
                  url: ENV["ARGONUTS_WEBHOOK_URL"]
         
     | 
| 
      
 16 
     | 
    
         
            +
                }
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              def create_job(j={}, options={})
         
     | 
| 
      
 20 
     | 
    
         
            +
                Argonuts::Job.create({
         
     | 
| 
      
 21 
     | 
    
         
            +
                  input: { url: INPUT_URL },
         
     | 
| 
      
 22 
     | 
    
         
            +
                  outputs: {
         
     | 
| 
      
 23 
     | 
    
         
            +
                    mp4: { path: "/test_create_job.mp4", duration: 1 }
         
     | 
| 
      
 24 
     | 
    
         
            +
                  }
         
     | 
| 
      
 25 
     | 
    
         
            +
                }.merge(j), options)
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
              def test_argonuts_api_key
         
     | 
| 
      
 29 
     | 
    
         
            +
                Argonuts.api_key = "apikey"
         
     | 
| 
      
 30 
     | 
    
         
            +
                assert "apikey", Argonuts.api_key
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
              def test_argonuts_default_endpoint
         
     | 
| 
      
 34 
     | 
    
         
            +
                assert "https://argonuts.co/api/v1", Argonuts.endpoint
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
              def test_overwrite_endpoint
         
     | 
| 
      
 38 
     | 
    
         
            +
                myendpoint = "https://argonuts.local/api/v1"
         
     | 
| 
      
 39 
     | 
    
         
            +
                Argonuts.endpoint = myendpoint
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                assert myendpoint, Argonuts.endpoint
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
              def test_create_job
         
     | 
| 
      
 45 
     | 
    
         
            +
                job = create_job
         
     | 
| 
      
 46 
     | 
    
         
            +
                assert job.is_a?(Argonuts::Job)
         
     | 
| 
      
 47 
     | 
    
         
            +
                assert_not_nil job.id
         
     | 
| 
      
 48 
     | 
    
         
            +
                assert_equal "job.starting", job.status
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 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
         
     | 
| 
      
 72 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,67 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: argonuts-ruby
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Argonuts
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire:
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2022-09-01 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 13 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 14 
     | 
    
         
            +
              name: http
         
     | 
| 
      
 15 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 16 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 17 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 18 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 19 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 20 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 21 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 22 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 23 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 24 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 25 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 26 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 27 
     | 
    
         
            +
            description: Official client library to the Argonuts API (argonuts.co)
         
     | 
| 
      
 28 
     | 
    
         
            +
            email: admin@argonuts.co
         
     | 
| 
      
 29 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 30 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 31 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 32 
     | 
    
         
            +
            files:
         
     | 
| 
      
 33 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 34 
     | 
    
         
            +
            - argonuts-ruby.gemspec
         
     | 
| 
      
 35 
     | 
    
         
            +
            - lib/argonuts-ruby.rb
         
     | 
| 
      
 36 
     | 
    
         
            +
            - lib/argonuts/api.rb
         
     | 
| 
      
 37 
     | 
    
         
            +
            - lib/argonuts/client.rb
         
     | 
| 
      
 38 
     | 
    
         
            +
            - lib/argonuts/error.rb
         
     | 
| 
      
 39 
     | 
    
         
            +
            - lib/argonuts/job.rb
         
     | 
| 
      
 40 
     | 
    
         
            +
            - lib/argonuts/metadata.rb
         
     | 
| 
      
 41 
     | 
    
         
            +
            - lib/argonuts/version.rb
         
     | 
| 
      
 42 
     | 
    
         
            +
            - test/argonuts_test.rb
         
     | 
| 
      
 43 
     | 
    
         
            +
            homepage: https://argonuts.co
         
     | 
| 
      
 44 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 45 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 46 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 47 
     | 
    
         
            +
            post_install_message:
         
     | 
| 
      
 48 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 49 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 50 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 51 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 52 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 53 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 54 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 55 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 56 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 57 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 58 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 59 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 60 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 61 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 62 
     | 
    
         
            +
            rubygems_version: 3.0.9
         
     | 
| 
      
 63 
     | 
    
         
            +
            signing_key:
         
     | 
| 
      
 64 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 65 
     | 
    
         
            +
            summary: Client library provides access to the Argonuts API (argonuts.co)
         
     | 
| 
      
 66 
     | 
    
         
            +
            test_files:
         
     | 
| 
      
 67 
     | 
    
         
            +
            - test/argonuts_test.rb
         
     |