1. You'll need to request your specific access token from the CreativeX team. This is your unique token which will allow you to create pre-flights for your organization using the Content API. This is required in order to make any calls to any of our endpoints.

  2. Before creating preflights, you'll need to upload assets (images / videos) to our S3 data store. To do this, you can retrieve a pre-signed url from our API, and then upload your image or video to that url:

require 'net/http'
require 'rest_client'
require 'uri'
require 'json'

def access_token
  # Insert your access token here
end

def base_url
  'https://creativex.com/api/v1'
end

def url(path, params)
  "#{base_url}?#{URI.encode_www_form(params)}"
end

def presigned_url
  params = { access_token: access_token }
  path = '/presigned_url'

  uri = URI(url(path, params))
  res = Net::HTTP.get_response(uri)
  URI.parse(JSON.parse(res.body))
end

You can then upload a locally stored image or video to the url returned from above:

def local_image_path
	'path/image.jpg'
end

def upload_image_to_presigned_url
	RestClient.put(presigned_url.to_s, File.read(local_image_path), :content_type => 'image/jpg')
end

Once we have access to these assets, you're ready to start creating preflights!

def create_preflight
  params = { access_token: access_token }
  body = {
    assets: [{ url: presigned_url, content_type: 'image/png', filename: 'image.jpg' }],
    name: 'MyPreflight',
    brand: 'Pepsi',
    market: 'United Kingdom',
    channel: 'facebook_paid',
    placements: [
      { publisher: 'facebook', placement: 'feed' }
    ]
  }
  path = '/preflights'
  
  req = Net::HTTP::Post.new(url(path, params))
  res = Net::HTTP.start(base_url.hostname, base_url.port) do |http|
    http.request(req)
  end

  JSON.parse(res.body)
end

You've now created your first preflight! You can always check the status of a preflight through the GET /preflight route as well:

def get_preflight_status
  preflight_id = 'MyPreflightId'
  params = { access_token: access_token }
  path = "/preflights/#{preflight_id}"
    
  uri = URI(url(path, params))
  res = Net::HTTP.get_response(uri)
  JSON.parse(res.body)
end

Once the preflight has completed processing, the results returned from the above route should look something like:

{"status"=>"completed",
 "preflight"=>
  {"id"=>716030,
   "name"=>"MyPreflight",
   "brand"=>"Pepsi",
   "assets"=>
    [{"url"=>
       "https://s3.amazonaws.com/picassolabs-assets/original/12a270b9-6fcb-4d6c-980c-9bffb41fea10-d7522eda-3be8-4ffc-82dc-cebcc0c57b42-video2.mp4",
      "score"=>50.0,
      "filename"=>"image.jpg",
      "content_type"=>"image",
      "rule_results"=>
       [{"name"=>"Brand - Present", "passed"=>false, "weight"=>25},
        {"name"=>"Designed for Sound Off", "passed"=>true, "weight"=>25},
        {"name"=>"Designed for Sound On", "passed"=>false, "weight"=>0},
        {"name"=>"[Optional] Brand - Audio Mention",
         "passed"=>false,
         "weight"=>0},
        {"name"=>"[Optional] Branding From Second Zero",
         "passed"=>true,
         "weight"=>0},
        {"name"=>"[Optional] Clear Concise Text", "passed"=>true, "weight"=>0},
        {"name"=>"[Optional] Close-Ups: Human Face",
         "passed"=>false,
         "weight"=>0},
        {"name"=>"[Optional] Highlight The Product",
         "passed"=>true,
         "weight"=>0},
        {"name"=>"[Optional] Movement", "passed"=>true, "weight"=>0},
        {"name"=>"[Optional] Short Video Length",
         "passed"=>false,
         "weight"=>0},
        {"name"=>"Quick Shots", "passed"=>false, "weight"=>25},
        {"name"=>"Tight Framing", "passed"=>true, "weight"=>25}]},
   ]
   "market"=>"United Kingdom",
   "channel"=>"facebook_paid"}}