class DavinciRubyClientSDK::API

Public Class Methods

new() click to toggle source
# File lib/DavinciRubyClientSDK.rb, line 14
def initialize
  DavinciRubyClientSDK::Common.check_app_key
end

Public Instance Methods

call() click to toggle source
# File lib/DavinciRubyClientSDK.rb, line 27
def call
  begin

    url = DavinciRubyClientSDK::Setting.server_address + @call_path
    connect = Faraday.new(:url => url) do |faraday|
      faraday.request  :url_encoded
      faraday.adapter  Faraday.default_adapter
      faraday.basic_auth(DavinciRubyClientSDK::Setting.app_key, DavinciRubyClientSDK::Setting.app_secret)
    end

    response = connect.send("#{@call_method}") do |req|
      if @call_method    == 'post'
        req.body   = @call_body
      elsif @call_method == 'get'
        @call_params.map do |key, value|
          req.params[key] = value
        end
      end
    end.body

  rescue Exception => err
    @error = err

  ensure
    return @error, response

  end
end
draw(label, blueprints, options = {}) click to toggle source
# File lib/DavinciRubyClientSDK.rb, line 18
def draw(label, blueprints, options = {})
  options[:mode] ||= 'sync'
  @call_method = 'post'
  @call_path   = "/draw/#{options[:mode]}"
  @call_body   = {:label => label, :blueprint => blueprints}
  @call_body[:notify_url] = options[:notify_url] unless options[:notify_url].nil?
  self
end
get(path, params) click to toggle source
# File lib/DavinciRubyClientSDK.rb, line 56
def get(path, params)
  @call_method = 'get'
  @call_path   = path
  @call_params = params
  self
end
post(path, body) click to toggle source
# File lib/DavinciRubyClientSDK.rb, line 63
def post(path, body)
  @call_method = 'post'
  @call_path   = path
  @call_body   = body
  self
end