A Ruby client for the Pylon API.
Add this line to your application's Gemfile:
gem 'pylon-api'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install pylon-api
First, initialize a client with your API key:
require 'pylon'
client = Pylon::Client.new(api_key: 'your_api_key')
# Enable debug mode to see request/response details
client = Pylon::Client.new(api_key: 'your_api_key', debug: true)
# Get current user details
me = client.get_current_user
# List accounts with pagination
accounts = client.list_accounts(page: 1, per_page: 20)
# Get a specific account
account = client.get_account('account_id')
# List issues (requires time range, max 30 days)
start_time = Time.now.utc - 86400 # 24 hours ago
end_time = Time.now.utc
issues = client.list_issues(
start_time: start_time.iso8601,
end_time: end_time.iso8601,
page: 1,
per_page: 20,
status: 'open' # optional filter
)
# Create an issue
issue = client.create_issue(
title: 'New Issue',
description: 'Issue description'
)
# List teams
teams = client.list_teams(page: 1, per_page: 20)
# Create a team
team = client.create_team(name: 'Engineering')
# Get a specific team
team = client.get_team('team_id')
# List users
users = client.list_users(page: 1, per_page: 20)
# Create a user
user = client.create_user(
email: '[email protected]',
name: 'New User'
)
# Get a specific user
user = client.get_user('user_id')
# Update a user
updated_user = client.update_user('user_id', { name: 'Updated Name' })
# List tags
tags = client.list_tags(page: 1, per_page: 20)
# Create a tag
tag = client.create_tag(
name: 'bug',
color: '#ff0000'
)
# List ticket forms
forms = client.list_ticket_forms(page: 1, per_page: 20)
# Create a ticket form
form = client.create_ticket_form(
name: 'Bug Report',
fields: [
{ name: 'severity', type: 'select' }
]
)
# Create an attachment
attachment = client.create_attachment(file_content)
The client will raise different types of errors based on the API response:
Pylon::AuthenticationError
- When the API key is invalidPylon::ResourceNotFoundError
- When the requested resource is not foundPylon::ValidationError
- When the request parameters are invalidPylon::ApiError
- For other API errors
Example:
begin
client.get_issue('non_existent_id')
rescue Pylon::ResourceNotFoundError => e
puts "Issue not found: #{e.message}"
rescue Pylon::ApiError => e
puts "API error: #{e.message}"
end
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests.
To install this gem onto your local machine, run bundle exec rake install
.
To test the gem locally:
- Build and install the gem:
gem build pylon-api.gemspec
gem install ./pylon-api-*.gem
- Create a test script:
require 'pylon'
client = Pylon::Client.new(api_key: ENV['PYLON_API_KEY'], debug: true)
begin
me = client.get_current_user
puts "Successfully connected as: #{me['email']}"
rescue => e
puts "Error: #{e.message}"
end
- Run with your API key:
PYLON_API_KEY=your_api_key_here ruby test.rb
Bug reports and pull requests are welcome on GitHub.
The gem is available as open source under the terms of the MIT License.