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.
Before we dive in, make sure you've got:
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
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."
Now that we're connected, let's implement some core operations:
def fetch_templates self.class.get('/templates', @options) end
def create_checklist(template_id, name) body = { templateId: template_id, name: name } self.class.post('/checklists', @options.merge(body: body.to_json)) end
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
def get_checklist(checklist_id) self.class.get("/checklists/#{checklist_id}", @options) end
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
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
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
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
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
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.
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!
For the complete source code and more examples, check out our GitHub repository: Process Street Ruby Integration
Happy coding!