Back

Step by Step Guide to Building a Process Street API Integration in Ruby

Aug 15, 20247 minute read

Introduction

Hey there, fellow developer! Ready to supercharge your workflow with Process Street's API? In this guide, we'll walk through building a robust integration in Ruby. Process Street's API is a powerful tool for automating and managing business processes, and with Ruby's elegance, we'll create something beautiful together.

Prerequisites

Before we dive in, make sure you've got:

  • Ruby 2.7+ installed
  • Bundler for managing gems
  • A Process Street API key (if you don't have one, grab it from your account settings)

Setting up the environment

Let's kick things off by setting up our project:

mkdir process_street_integration cd process_street_integration bundle init

Open up your Gemfile and add these lines:

gem 'httparty' gem 'dotenv'

Now, let's install our gems:

bundle install

Create a .env file in your project root and add your API key:

PROCESS_STREET_API_KEY=your_api_key_here

Basic API Connection

Time to establish our connection to Process Street. Create a new file called process_street_client.rb:

require 'httparty' require 'dotenv/load' class ProcessStreetClient include HTTParty base_uri 'https://api.process.st/api/v1' def initialize @options = { headers: { 'Authorization' => "Bearer #{ENV['PROCESS_STREET_API_KEY']}", 'Content-Type' => 'application/json' } } end def test_connection self.class.get('/templates', @options) end end # Test the connection client = ProcessStreetClient.new response = client.test_connection puts response.code == 200 ? "Connected successfully!" : "Connection failed."

Core API Operations

Now that we're connected, let's implement some core operations:

Fetching Templates

def fetch_templates self.class.get('/templates', @options) end

Creating Checklists

def create_checklist(template_id, name) body = { templateId: template_id, name: name } self.class.post('/checklists', @options.merge(body: body.to_json)) end

Updating Checklist Items

def update_checklist_item(checklist_id, task_id, data) self.class.put("/checklists/#{checklist_id}/tasks/#{task_id}", @options.merge(body: data.to_json)) end

Retrieving Checklist Data

def get_checklist(checklist_id) self.class.get("/checklists/#{checklist_id}", @options) end

Error Handling and Rate Limiting

Let's add some resilience to our client:

def with_retry(max_retries = 3) retries = 0 begin yield rescue StandardError => e retries += 1 if retries <= max_retries sleep(2 ** retries) retry else raise e end end end

Now, wrap your API calls with this method:

def fetch_templates with_retry { self.class.get('/templates', @options) } end

Building a Simple CLI Tool

Let's create a simple command-line interface. Create a new file called cli.rb:

require_relative 'process_street_client' client = ProcessStreetClient.new case ARGV[0] when 'templates' puts client.fetch_templates when 'create_checklist' puts client.create_checklist(ARGV[1], ARGV[2]) when 'update_item' puts client.update_checklist_item(ARGV[1], ARGV[2], JSON.parse(ARGV[3])) when 'get_checklist' puts client.get_checklist(ARGV[1]) else puts "Unknown command" end

Advanced Features

Webhook Integration

Process Street supports webhooks. Here's a simple Sinatra server to handle them:

require 'sinatra' require 'json' post '/webhook' do payload = JSON.parse(request.body.read) # Process the webhook payload status 200 end

Bulk Operations

For bulk operations, consider using Ruby's parallel processing capabilities:

require 'parallel' def bulk_create_checklists(template_id, names) Parallel.map(names) do |name| create_checklist(template_id, name) end end

Testing the Integration

Don't forget to test! Here's a simple RSpec test:

require 'rspec' require_relative 'process_street_client' RSpec.describe ProcessStreetClient do let(:client) { ProcessStreetClient.new } it "successfully connects to the API" do response = client.test_connection expect(response.code).to eq(200) end end

Deployment Considerations

When deploying, ensure you're securely managing your API keys. Consider using environment variables or a secure key management system.

For scaling, implement proper error handling and consider using background jobs for long-running operations.

Conclusion

And there you have it! You've just built a solid foundation for a Process Street API integration in Ruby. Remember, this is just the beginning. The API offers many more endpoints and possibilities, so don't be afraid to explore and expand on this base.

Keep coding, keep automating, and most importantly, keep having fun with it!

Code Repository

For the complete source code and more examples, check out our GitHub repository: Process Street Ruby Integration

Happy coding!