class Object

Public Instance Methods

create_api_client() click to toggle source
# File tests/spec/unit_tests_using_jwt_spec.rb, line 43
def create_api_client
  if $api_client.nil?
    self.login()
  end

  return $api_client
end
login() click to toggle source
# File tests/spec/unit_tests_using_jwt_spec.rb, line 8
def login
  begin
    if $api_client.nil?
      configuration = DocuSign_WebForms::Configuration.new
      configuration.host = $host

      $api_client = DocuSign_WebForms::ApiClient.new(configuration)
      $api_client.set_oauth_base_path(DocuSign_WebForms::OAuth::DEMO_OAUTH_BASE_PATH)
    end

    decode_base64_content = Base64.decode64(ENV["PRIVATE_KEY"])

    File.open($private_key_filename, "wb") do |f|
      f.write(decode_base64_content)
    end
    scopes = [DocuSign_WebForms::OAuth::SCOPE_IMPERSONATION, DocuSign_WebForms::OAuth::SCOPE_SIGNATURE, "webforms_read", "webforms_write", "webforms_instance_read", "webforms_instance_write"]
    token_obj = $api_client.request_jwt_user_token(ENV["INTEGRATOR_KEY_JWT"], ENV["USER_ID"], File.read($private_key_filename), $expires_in_seconds, scopes)
    user_info = $api_client.get_user_info(token_obj.access_token)

    if !user_info.nil?
      user_info.accounts.each do |account|
        if account.is_default == "true"
          account_id = account.account_id
          $api_client.set_base_path("https://apps-d.docusign.com/api/webforms")
          return account
        end
      end
    end
  rescue => e
    puts "Error during processing: #{$!}"
  end

  return nil
end