A Ruby client for the Autodesk Construction Cloud API.
- Installation
- Requirements
- Configuration
- Usage
- Example Application
- External Resources
- Development
- Testing
- Contributing
- License
Add this line to your application's Gemfile:
gem 'acc'And then execute:
bundle installOr install it yourself as:
gem install acc- Ruby 3.3.6 or higher
- Autodesk APS (formerly Forge) credentials:
- Client ID
- Client Secret
- Registered callback URL
- Appropriate scopes configured
Before using the gem, you need to configure it with your Autodesk APS credentials:
ACC.configure do |config|
# Required configuration
config.client_id = ENV['ACC_CLIENT_ID']
config.client_secret = ENV['ACC_CLIENT_SECRET']
config.callback_url = ENV['ACC_CALLBACK_URL']
# Optional configuration
config.scope = ['data:read', 'account:read'] # Default: ['data:read']
endIt's recommended to use environment variables for sensitive credentials. You can
also use a .env file:
# .env
ACC_CLIENT_ID=your_client_id
ACC_CLIENT_SECRET=your_client_secret
ACC_CALLBACK_URL=https://your-app.com/oauth/callbackThe gem implements OAuth 2.0 with 3-legged authentication:
# Initialize the auth client
auth = ACC::Resources::Auth.new
# Generate authorization URL for user consent
authorization_url = auth.authorization_url
redirect_to authorization_url
# Handle the OAuth callback
def oauth_callback
auth = ACC::Resources::Auth.new
begin
# Exchange the code for tokens
access_token = auth.exchange_code(params[:code])
# Store tokens securely
session[:access_token] = access_token
session[:refresh_token] = auth.refresh_token
rescue ACC::Errors::AuthError => e
# Handle authentication errors
logger.error "Authentication failed: #{e.message}"
end
end
# Refresh expired tokens
def refresh_tokens
auth = ACC::Resources::Auth.new(refresh_token: session[:refresh_token])
begin
access_token = auth.refresh_tokens
session[:access_token] = access_token
session[:refresh_token] = auth.refresh_token
rescue ACC::Errors::RefreshTokenError => e
# Handle refresh errors
logger.error "Token refresh failed: #{e.message}"
end
end# Initialize the auth client with your access token
auth = ACC::Resources::Auth.new(access_token: session[:access_token])
# Get issues for a project
issues_client = ACC::Resources::ConstructionCloud::Issues::Index.new(auth, project_id)
# Get all issues (handles pagination automatically)
all_issues = issues_client.all_paginated
# Process the issues
all_issues.each do |issue|
puts "Issue ID: #{issue['id']}"
puts "Title: #{issue['title']}"
puts "Status: #{issue['status']}"
endThe gem provides specific error classes for different scenarios:
begin
auth.exchange_code(code)
rescue ACC::Errors::MissingScopeError
# Handle missing scope configuration
rescue ACC::Errors::AccessTokenError
# Handle expired access token
rescue ACC::Errors::RefreshTokenError
# Handle expired refresh token
rescue ACC::Errors::AuthError => e
# Handle other authentication errors
puts "Authentication error: #{e.message}"
endCommon scopes include:
data:read- Read access to BIM 360 datadata:write- Write access to BIM 360 datadata:create- Create new items in BIM 360account:read- Read access to account informationaccount:write- Write access to account information
For more details about available endpoints and functionality, check the API Reference Documentation.
The gem includes a dummy Sinatra application that demonstrates the complete authentication flow. See dummy/README.md for details.
Useful documentation and references for working with the Autodesk Construction Cloud API:
| Resource | Description |
|---|---|
| Three-Legged Token Tutorial | Guide on implementing OAuth 2.0 auth |
| Rate Limits Documentation | Information about API rate limits |
| Issues API Reference | API reference for retrieving issues |
After checking out the repo, run bin/setup to install dependencies. Then, run
rake spec to run the tests. You can also run bin/console for an interactive
prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install.
To run all tests:
bundle exec rspecTo run specific tests:
bundle exec rspec path/to/spec_fileNote: When running existing tests, no real credentials are needed as VCR will use the recorded cassettes.
The project uses VCR for recording and replaying HTTP interactions in tests.
VCR cassettes are stored in spec/vcr_cassettes/.
- New Cassettes: Created automatically when running specs with
:vcrtag - Sensitive Data: The following data is automatically filtered in cassettes:
<CLIENT_ID><CLIENT_SECRET><ACCESS_TOKEN><REFRESH_TOKEN><PROJECT_ID>
Credentials are only needed when recording new cassettes or re-recording existing ones. For regular test runs, no real credentials are required.
To record cassettes with successful API interactions, you need to provide valid credentials and project ID. You can do this by setting environment variables when running the specs:
CLIENT_ID=your_client_id \
CLIENT_SECRET=your_client_secret \
PROJECT_ID=your_project_id \
bundle exec rspecYou can also store these in a .env file:
# .env
CLIENT_ID=your_client_id
CLIENT_SECRET=your_client_secret
PROJECT_ID=your_project_idNote: Make sure not to commit your
.envfile with real credentials to version control.
To re-record a specific cassette:
- Delete the cassette file
- Run the spec again
To re-record all cassettes:
- Delete all files in
spec/vcr_cassettes/ - Run the full test suite
Add :vcr metadata to your spec and run it. VCR will automatically record the
HTTP interactions:
describe '#my_method', :vcr do
it 'does something' do
# your test here
end
end- Fork it
- Create your feature branch
- Commit your changes
- Push to the branch
- Create new Pull Request
Bug reports and pull requests are welcome on GitHub.
The gem is available as open source under the terms of the MIT License.