Permalink
Browse files

Add ruby marker for READMe.md

  • Loading branch information...
1 parent 7d9db2d commit 22b15b06177327ccc9c300e439d36fe07cfeaccd @jrichardlai committed Jun 22, 2012
Showing with 82 additions and 51 deletions.
  1. +82 −51 README.md
View
133 README.md
@@ -19,13 +19,14 @@ Or in a Gemfile:
In an initializer file.
- Taskrabbit.configure do |config|
- config.api_secret = 'your-client-secret'
- config.api_key = 'your-client-key'
- config.base_uri = 'https://sandbox.com'
- config.endpoint = 'api/v2'
- end
-
+```ruby
+Taskrabbit.configure do |config|
+ config.api_secret = 'your-client-secret'
+ config.api_key = 'your-client-key'
+ config.base_uri = 'https://sandbox.com'
+ config.endpoint = 'api/v2'
+end
+```
Available configuration options:
* api_secret: client secret that has been given to you by TaskRabbit
@@ -37,96 +38,126 @@ Available configuration options:
### use the API client
- tr = Taskrabbit::Api.new
-
+```ruby
+tr = Taskrabbit::Api.new
+```
+
or with a user token returned by TaskRabbit.
- tr = Taskrabbit::Api.new(user_token)
+```ruby
+tr = Taskrabbit::Api.new(user_token)
+```
### Get the list of all the tasks
- tr = Taskrabbit::Api.new
- # to get the /tasks
- tasks = tr.tasks.all
- # fetch the first task
- tasks.first
-
- tasks.all(:reload => true) # => will redo the query
+```ruby
+tr = Taskrabbit::Api.new
+# to get the /tasks
+tasks = tr.tasks.all
+# fetch the first task
+tasks.first
+
+tasks.all(:reload => true) # => will redo the query
+```
### Find a task
- tr = Taskrabbit::Api.new
- t = tr.tasks.find(31231) # This actually wont do the request
+```ruby
+tr = Taskrabbit::Api.new
+t = tr.tasks.find(31231) # This actually wont do the request
+```
To request the API:
- t.fetch # force fetching
+```ruby
+t.fetch # force fetching
+```
or simply access a property:
- t.name # will do the query
+```ruby
+t.name # will do the query
+```
### Find the tasks of an user
- tr.users.find(user_id).tasks
+```ruby
+tr.users.find(user_id).tasks
+```
### Create a task
- tr = Taskrabbit::Api.new(user_token)
- task = tr.tasks.create({:named_price => 32, :name => 'Ikea'})
+```ruby
+tr = Taskrabbit::Api.new(user_token)
+task = tr.tasks.create({:named_price => 32, :name => 'Ikea'})
+```
or
- task = tr.tasks.new({:named_price => 32, :name => 'Ikea'})
- task.save
+```ruby
+task = tr.tasks.new({:named_price => 32, :name => 'Ikea'})
+task.save
+```
### Update a task
- task = tr.tasks.find(32121)
- task.named_price = 45
- task.save
+```ruby
+task = tr.tasks.find(32121)
+task.named_price = 45
+task.save
+```
### Error for tasks creation or update
- tr = Taskrabbit::Api.new(user_token)
- task = tr.tasks.new
- unless task.save
- task.error # => "Task title can't be blank, \nAmount you are willing to pay is not a number"
- task.errors # => { "messages" => ["Task title can't be blank", "Amount you are willing to pay is not a number"],
- "fields" => [["name","can't be blank"], ["named_price","is not a number"]] }
- end
+```ruby
+tr = Taskrabbit::Api.new(user_token)
+task = tr.tasks.new
+unless task.save
+ task.error # => "Task title can't be blank, \nAmount you are willing to pay is not a number"
+ task.errors # => { "messages" => ["Task title can't be blank", "Amount you are willing to pay is not a number"],
+ "fields" => [["name","can't be blank"], ["named_price","is not a number"]] }
+end
+```
### Redirect
In some case TaskRabbit will return an url which should be used for further operations (i.e: when the user doesn't have a credit card).
- tr = Taskrabbit::Api.new(user_token)
- task = tr.tasks.new
- unless task.save
- if task.redirect?
- task.redirect_url #=> 'http://www.taskrabbit.com/somepath'
- end
- end
+```ruby
+tr = Taskrabbit::Api.new(user_token)
+task = tr.tasks.new
+unless task.save
+ if task.redirect?
+ task.redirect_url #=> 'http://www.taskrabbit.com/somepath'
+ end
+end
+```
## User account
- tr = Taskrabbit::Api.new(user_token)
- tr.account # => Taskrabbit::User object
+```ruby
+tr = Taskrabbit::Api.new(user_token)
+tr.account # => Taskrabbit::User object
- tr.account.tasks # => List of tasks
- tr.account.tasks.create(some_params)
+tr.account.tasks # => List of tasks
+tr.account.tasks.create(some_params)
+```
## Cities
### Get list of cities
- tr.cities.each do |city|
- city.name
- end
+```ruby
+tr.cities.each do |city|
+ city.name
+end
+```
### Find a city using the id
- tr.cities.find(3).name # => "SF Bay Area"
+```ruby
+tr.cities.find(3).name # => "SF Bay Area"
+```
### More informations

0 comments on commit 22b15b0

Please sign in to comment.