|
1 | | -# devin_api |
| 1 | +# Devin API Client |
| 2 | +[](https://github.com/smasato/devin_api_client_rb/actions/workflows/rspec.yml?query=branch%3Amain) |
| 3 | + |
| 4 | +This Ruby gem is a client for the Devin API. |
| 5 | + |
| 6 | +This gem is not officially supported by Cognition AI, Inc. |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +Add this line to your application's Gemfile: |
| 11 | + |
| 12 | +```ruby |
| 13 | +gem 'devin_api' |
| 14 | +``` |
| 15 | + |
| 16 | +And then execute: |
| 17 | + |
| 18 | +```bash |
| 19 | +$ bundle install |
| 20 | +``` |
| 21 | + |
| 22 | +Or install it yourself as: |
| 23 | + |
| 24 | +```bash |
| 25 | +$ gem install devin_api |
| 26 | +``` |
| 27 | + |
| 28 | +## Usage |
| 29 | + |
| 30 | +### Endpoint-based API |
| 31 | + |
| 32 | +```ruby |
| 33 | +require 'devin_api' |
| 34 | + |
| 35 | +client = DevinApi::Client.new do |config| |
| 36 | + config.url = 'https://api.devin.ai' |
| 37 | + config.access_token = 'your_access_token' |
| 38 | +end |
| 39 | + |
| 40 | +# Sessions |
| 41 | +sessions = client.list_sessions(limit: 10) |
| 42 | +puts "Sessions: #{sessions}" |
| 43 | + |
| 44 | +new_session = client.create_session(prompt: 'Build a simple web app') |
| 45 | +session_id = new_session['id'] |
| 46 | +puts "Created session: #{session_id}" |
| 47 | + |
| 48 | +session_details = client.get_session(session_id) |
| 49 | +puts "Session details: #{session_details}" |
| 50 | + |
| 51 | +message_response = client.send_message(session_id, message: 'How do I start?') |
| 52 | +puts "Message response: #{message_response}" |
| 53 | + |
| 54 | +# Upload files to a session |
| 55 | +file = File.open('path/to/file.txt') |
| 56 | +upload_response = client.upload_file(file) |
| 57 | +puts "Upload response: #{upload_response}" |
| 58 | + |
| 59 | +# Update session tags |
| 60 | +tags_response = client.update_session_tags(session_id, tags: ['web', 'app']) |
| 61 | +puts "Tags update response: #{tags_response}" |
| 62 | + |
| 63 | +# Secrets |
| 64 | +secrets = client.list_secrets |
| 65 | +puts "Secrets: #{secrets}" |
| 66 | + |
| 67 | +# Knowledge |
| 68 | +knowledge_items = client.list_knowledge |
| 69 | +puts "Knowledge items: #{knowledge_items}" |
| 70 | + |
| 71 | +new_knowledge = client.create_knowledge( |
| 72 | + name: 'API Documentation', |
| 73 | + body: 'This is the API documentation for our service.', |
| 74 | + trigger_description: 'When API documentation is needed' |
| 75 | +) |
| 76 | +knowledge_id = new_knowledge['id'] |
| 77 | +puts "Created knowledge: #{knowledge_id}" |
| 78 | + |
| 79 | +# Enterprise (for enterprise customers) |
| 80 | +audit_logs = client.list_audit_logs(start_time: '2023-01-01T00:00:00Z') |
| 81 | +puts "Audit logs: #{audit_logs}" |
| 82 | + |
| 83 | +consumption = client.get_enterprise_consumption(period: 'current_month') |
| 84 | +puts "Consumption: #{consumption}" |
| 85 | +``` |
| 86 | + |
| 87 | +### Resource-based API |
| 88 | + |
| 89 | +```ruby |
| 90 | +require 'devin_api' |
| 91 | + |
| 92 | +client = DevinApi::Client.new do |config| |
| 93 | + config.url = 'https://api.devin.ai' |
| 94 | + config.access_token = 'your_access_token' |
| 95 | +end |
| 96 | + |
| 97 | +# Resource-based usage |
| 98 | +# Get a collection of sessions |
| 99 | +sessions = client.sessions |
| 100 | +sessions.each do |session| |
| 101 | + puts "Session ID: #{session.id}, Prompt: #{session[:prompt]}" |
| 102 | +end |
| 103 | + |
| 104 | +# Create a new session |
| 105 | +new_session = client.sessions.create(prompt: 'Build a simple web app') |
| 106 | +puts "Created session: #{new_session.session_id}" |
| 107 | + |
| 108 | +# Get a specific session |
| 109 | +session = client.session('session_id') |
| 110 | + |
| 111 | +# Send a message to the session |
| 112 | +response = session.send_message('How do I start?') |
| 113 | + |
| 114 | +# Upload files to the session |
| 115 | +files = [File.open('path/to/file.txt')] |
| 116 | +upload_response = session.upload_files(files) |
| 117 | + |
| 118 | +# Update session tags |
| 119 | +session.update_tags(['web', 'app']) |
| 120 | + |
| 121 | +# Pagination |
| 122 | +next_page = sessions.next_page |
| 123 | +if next_page |
| 124 | + next_page.each do |session| |
| 125 | + puts "Next page session: #{session.id}" |
| 126 | + end |
| 127 | +end |
| 128 | +``` |
| 129 | + |
| 130 | +## Contributing |
| 131 | + |
| 132 | +Bug reports and pull requests are welcome on GitHub at https://github.com/smasato/devin_api_client_rb. |
| 133 | + |
| 134 | +## License |
| 135 | + |
| 136 | +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
0 commit comments