Project

copy_ai

0.0
The project is in a healthy, maintained state
A Ruby client library for accessing the Copy.ai API, allowing developers to easily integrate Copy.ai's text generation capabilities into their Ruby applications
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 7.1, >= 7.1.3.4
 Project Readme

A Ruby interface to the Copy.ai Workflows API

Installation

Install the gem and add to the application's Gemfile:

bundle add copy_ai

Or, to install directly:

gem install copy_ai

Usage

First, obtain credentials from https://docs.copy.ai/reference/authentication.

require "copy_ai"

copy_ai_credentials = {
  api_key:              "INSERT YOUR X API KEY HERE",
  api_endpoint:         "INSERT YOUR X API ENDPOINT HERE"
}

# Initialize a API client with your Workspace Api Key
copy_ai_client = CopyAi::Client.new(**copy_ai_credentials)

# Register webhook
# url: your site webhook URL
# event_type: https://docs.copy.ai/reference/register-webhook#event-types
# optional workflow_id: If a workflow ID is not specified, you will receive events for all workflows in your workspace.
response = CopyAi::Webook.register(copy_ai_client, url: 'https://cloud-asm.com/webhook', event_type: 'workflowRun.completed', workflow_id: <workflow-id>)
# {
    "status": "success",
    "data": {
      "id": "<id of webhook>",
      "url": "<https://mywebsite.com/webhook>",
      "eventType": "workflowRun.completed",
      "workflowId": "<workflow-id>"
    }
  }

# Starting a Workflow Run
post = copy_ai_client.post(body: {
  startVariables: {
	  "Input 1": "<Inputs vary depending on the workflow used.>",
	  "Input 2": "<The best way to see an example is to try it!>"
	},
	"metadata": {
    "api": true
	}
})
# { "status": "success", "data": { "id": "<run-id>" } }

# Tracking / Poll for Progress
copy_ai_client.get
# {
    "status": "success",
    "data":
    {
      "id": "<run-id>",
      "input":
      { 
        "Input 1": "Inputs vary depending on the workflow used.",
        "Input 2": "The best way to see an example is to try it!" 
      },
      "status": "PROCESSING",
      "output":
      {
        "Output 1": "<Outputs vary depending on the workflow used.>",
        "Output 2": "<The best way to see an example is to try it!>"
      },
      "createdAt": "2022-11-18T20:30:07.434Z"
    }
  }

# Run Completion
# When the run is complete, the status will change to COMPLETE and a POST request will be sent to the registered webhooks to notify of the workflow's completion.
# {
    "type": "workflowRun.completed",
    "workflowRunId": "<run-id>",
    "workflowId": "<workflow-id>",
    "result":
    {
      "Output 1": "<Outputs vary depending on the workflow used.>",
      "Output 2": "<The best way to see an example is to try it!>"
    },
    "metadata":
    {
      /* any metadata set on the workflow run */
    },
    "credits": 2 
  }

Development

  1. Checkout and repo:

    git checkout git@github.com:wwwfernand/copy_ai.git
    
  2. Enter the repo's directory:

    cd copy_ai
    
  3. Install dependencies via Bundler:

    bundle install
    
  4. Run the default Rake task to ensure all tests pass:

    bundle exec rake
    
  5. Create a new branch for your feature or bug fix:

    git checkout -b my-new-branch
    

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/wwwfernand/copy_ai.

Pull requests will only be accepted if they meet all the following criteria:

  1. Code must conform to Standard Ruby.

    bundle exec rake standard
    
  2. Code must conform to the RuboCop rules.

    bundle exec rake rubocop
    
  3. 100% LOC code coverage.

    bundle exec rake test
    
  4. 100% mutation coverage.

    bundle exec rake mutant
    
  5. RBS type signatures (in sig/copy_ai.rbs).

    bundle exec rake steep
    

License

The gem is available as open source under the terms of the MIT License.