New Instant Ruby API for Agree2 Templates
While Agree2 is all about people and small businesses taking charge of their own contracts, we have also designed it from the beginning to be integrated with other web applications.
Example Applications
For example imagine a web application helping small design or programming shops find new clients and projects. Once a client finds you, you simply click “Prepare contract” in the fictional web applications user interface and it creates a contract on Agree2 filling out all the details of you and your client.
Another example would be a service allowing people to create and manage options to buy services or items from other people. Call it OptionsBay. Once the details of the services or products to be optioned are worked out through the service, the service creates the actual options contract on Agree2 and invites all parties to accept it.
Getting your templates Instant Ruby API
We have come up with a very quick and easy way for you to integrate Agree2 Templates in your own web applications using Ruby. We will have a more general purpose Ruby wrapper library soon.
All of this works on top of standard REST API’s and you should be able to do something similar in any language. However for now we are making it very easy for Ruby developers.
In the following example we will use a public template for an Options Contract. However you could just as easily create your own template customized for your application and we offer an instant Ruby API for it.
If you already have an Agree2 account Login to Agree2 and follow along, otherwise register your name and email address for the Agree2 Beta and we will send you an invitation shortly.
First select a template you can create your own private template later to see how instant it really is. Here we will pick the options template:
Now you have selected the template and you can see that it has several fields that you can fill out. We call these Smart Fields and they are an important part of the flexibility of Agree2. Feel free to fill it out and hit “create agreement from template” to try it out. Then hit back to return the template page.
On the bottom part of the sidebar of the template page you will find this box called “Other formats”. These provide other views to the template. The agreement pages also have a similar box, but the template page has one in particular that we are interested in Instant Ruby API
Once you click on that file you will see a ruby library file that has been customized for this template and with your username already filled out.
Using the API
This API will allow you to do such things as:
# This creates an agreement from the template
@agreement=Agree2::OptionForHolderToBuyAssetTemplate.prepare( :holder =>"John Doe",
:asset =>"Consulting by Pelle Braendgaard",
:amount =>"10",
:units =>"hours",
:price =>"$100/h",
:valid_to =>"1 month from now")
# invite the parties
@party=@agreement.invite("johndoe@mailinator.com","John","Doe")
@party=@agreement.invite("pelle@stakeventures.com","Pelle","Brændgaard")
# Change something in the contract
@agreement.amount=20
@agreement.save
# Mark it as being final and ready to accept
@agreement.finalize
You can customize your template with fields within the text. The API will automatically update to support any new fields you add.
Requirements
- A recent Ruby (1.8.4) or higher
- RubyGems
- ActiveResource ( gem install activeresource --source http://gems.rubyonrails.org )
Installation
Download the api (hit “Save As” in your browser menu) and rename it option_for_holder_to_buy_asset.rb or whatever is recommended in the API.
If using it in a Ruby on Rails application we recommend saving it in the lib directory.
IMPORTANT: For security reasons we do not embed your password in this file. Remember to change it to your real password. Search for “YOUR PASSWORD” in this file and change it.
Now you can follow the simple steps above.
Try this next
Try creating your own template or duplicate an existing one. Try changing the smart fields and see how it automatically updates the API.
What’s next for us
We will provide a more fully featured general purpose API for Agree2 which will have full support for OAuth. The REST API is there already, but it needs to be documented and we might still change it.
We will document it and provide both a ruby gem and/or rails plugin that you will be able to integrate with greater flexibility into your application.
Trackbacks
Use this link to trackback from your own site.


