README.md in gratitude-0.0.9 vs README.md in gratitude-0.0.10
- old
+ new
@@ -29,11 +29,13 @@
##Paydays ([source code](https://github.com/JohnKellyFerguson/gratitude/blob/master/lib/gratitude/payday.rb))
The Gittip API provides access to the historical data of all its paydays. To retrieve this information, simply use the following command:
- Gratitude::Payday.all
+```ruby
+Gratitude::Payday.all
+```
The above will return an array of Payday objects. Each Payday object responds to the following methods:
* `ach_fees_volume`
* `ach_volume`
@@ -51,30 +53,38 @@
* `transfer_end_time` (alias: `ts_end`)
* `transfer_start_time` (alias: `ts_start`)
You can then iterate through this array of payday objects to persist them to a database or get whatever information you need.
- paydays = Gratitude::Payday.all
- paydays.each do |payday|
- # get whatever information you want from the payday object
- # using the above mentioned methods.
- end
+```ruby
+paydays = Gratitude::Payday.all
+paydays.each do |payday|
+ # get whatever information you want from the payday object
+ # using the above mentioned methods.
+end
+```
Finally, if you just want to get the most recent payday, you can do so by using:
- Gratitude::Payday.most_recent
+```ruby
+Gratitude::Payday.most_recent
+```
##Statistics ([source code](https://github.com/JohnKellyFerguson/gratitude/blob/master/lib/gratitude/statistics.rb))
The Statistics aspect of the Gittip API provides the current statistics, as of that moment in time, for Gittip. Note that these stats can potentially change when making subsequent requests.
If you would like to get the current Gittip stats, you can do so by using:
- Gratitude::Statistics.current
+```ruby
+Gratitude::Statistics.current
+```
Alternatively, you can also use:
- Gratitude::Statistics.new
+```ruby
+Gratitude::Statistics.new
+```
Each of the above will return an object containing all of the current Gittip stats. You can access each of the Gittip stats using the following methods:
* `average_tip_amount` (alias: `average_tip`)
* `average_number_of_tippees` (alias: `average_tippees`)
@@ -95,22 +105,24 @@
* `statements`
* This returns an array of 16 hashes. Each hash provides the personal statement of a Gittip user and has the following keys: `statement`, `username`. Note that this will return a different array of hashes each time you query the Gittip API.
* `this_thursday`
* This refers to the upcoming Thursday when payments/transfers are set to occur. Possible values include: "this Thursday", "today", "right now!", and "next Thursday"
* `tip_distribution_json`
- * This returns a hash. Each key in the hash is a float which represents a tip amount (for example, $0.01, $0.25 or $1). The value of each key is an array. The first element in the array is an integer representing the total number of users who have pledged that amount. The second element in the array is a float which shows how much this tip amount makes up all of the possible tips. For example, the hash returned will look like the following: `{ 0.01: [11, 0.002153484729835552], … }`
-
+ * This returns a hash. Each key in the hash is a float which represents a tip amount (for example, $0.01, $0.25 or $1). The value of each key is an array. The first element in the array is an integer representing the total number of users who have pledged that amount. The second element in the array is a float which shows how much this tip amount makes up of all the possible tips. For example, the hash returned will look like the following: `{ 0.01: [11, 0.002153484729835552], … }`
+
In this example, the amount being tipped is $0.01. The amount of users tipping this amount is 11, and the total tip amount for this tip size makes up 0.2153484729835552% of all tips distributed. The hash will contain many more elements, each with the same structure.
* `number_of_tips` (alias: `tip_n`)
* `value_of_total_backed_tips` (alias: `total_backed_tips`)
* `transfer_volume`
##Profile ([source code](https://github.com/JohnKellyFerguson/gratitude/blob/master/lib/gratitude/profile.rb))
The Profile aspect of the Gittip API allows you to get the public profile information of any Gittip user. To do so, just pass their username as an initialization argument to the `Gratitude::Profile` class.
- Gratitude::Profile.new("johnkellyferguson")
+```ruby
+Gratitude::Profile.new("johnkellyferguson")
+```
The above will retrieve the public profile of the above user. You can then access all of the different information with the following methods:
* `avatar_url` (alias: `avatar`)
* `bitbucket_api_url` (alias: `bitbucket`)
@@ -148,42 +160,130 @@
* the id of the user.
**TODO:** Implement the `my_tip` method into the Profile section once client authentication is finished.
##Tips ([client authentication source code](https://github.com/JohnKellyFerguson/gratitude/blob/master/lib/gratitude/client.rb), [tips source code](https://github.com/JohnKellyFerguson/gratitude/blob/master/lib/gratitude/tips.rb))
-The Tips aspect of the Gittip API allows you to retrieve the current tips of a user. In order to get this information, you will need your username and API_KEY. To find out your API Key, log into your Gittip account, go to your profile and at the bottom of the page you will find your API_KEY.
+The Tips aspect of the Gittip API allows you to retrieve and update the current tips of an authenticated user. In order to interact with this aspect of the API, you will need your username and API_KEY. To find out your API Key, log into your Gittip account, go to your profile and at the bottom of the page you will find your API_KEY.
![Gittip API Key](api_key.png)
-Now that you have your API_KEY, you can find out your current tips using Gratitude.
+Now that you have your API_KEY, you can find out your current tips or update your tips using Gratitude.
-```
+### Determing Current Tips
+To find out the current tips of a user, follow these instructions:
+
+```ruby
# First establish a connection to the Gittip API by passing in your credentials to Gratitude::Client.new
# You will need to pass in your username and api key like so.
client = Gratitude::Client.new(:username => "my_username", :api_key => "my_api_key")
# Then, to find out your current tips, simply call the current_tips method.
client.current_tips
```
This will will return an array of hashes that represent your current tips and will look similar to the following.
[
+ {"amount"=>"2.00", "platform"=>"gittip", "username"=>"gittip"},
{"amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537"},
- {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"},
- …
+ {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
]
Please be aware that all of the amounts in the hash are strings and not floats.
+In addition, you can also find out the current total of all of a user's tips by using the `current_tips_total` method. This will return a float with a total of all of the user's tips.
+```ruby
+# Continuing the example
+client.current_tips_total
+=> 3.25
+```
-* **TODO:** Add the ability to post and update tips to Gittip's API.
+### Updating Tips
+It is also possible to update a user's tips. To do so, we will once again have to pass in our authentication information (or use our previously stored information).
+```ruby
+client = Gratitude::Client.new(:username => "my_username", :api_key => "my_api_key")
+```
+We can then call the `update_tips` method, which accepts an array of hashes containing a user's username and desired tip amount.
+```ruby
+client.update_tips([ { :username => "gittip", :amount => "3.50" },
+ { :username => "whit537", :amount => "3.50"},
+ { :username => "JohnKellyFerguson", :amount = "3.50" }])
+```
+When tips are successfully updated, the `update_tips` method will return an array representing the successfully updated tips.
+
+```ruby
+[
+ {"amount"=>"3.50", "platform"=>"gittip", "username"=>"gittip"},
+ {"amount"=>"3.50", "platform"=>"gittip", "username"=>"whit537"},
+ {"amount"=>"3.50", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
+]
+```
+Please note that you do not have to update all of a user's tips when using the `update_tips` method and that it is possible to either update only a subset of a user's tips or to add new tips.
+
+For example:
+
+```ruby
+client.update_tips([ { :username => "gittip", :amount => "4.50" } ])
+```
+will only updates the tips going to the "gittip"" user. All other tips will remain unchanged. We can see this by continuing our example and running the `current_tips` method.
+
+```ruby
+client.current_tips
+=> [
+ {"amount"=>"4.50", "platform"=>"gittip", "username"=>"gittip"},
+ {"amount"=>"3.50", "platform"=>"gittip", "username"=>"whit537"},
+ {"amount"=>"3.50", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
+ ]
+```
+
+New tips can also be added using the `update_tips` method.
+
+```ruby
+client.update_tips([ { :username => "steveklabnik", :amount=> "1.00" }])
+```
+The new tip will be added to the previously existing tips.
+
+```ruby
+client.current_tips
+=> [
+ {"amount"=>"4.50", "platform"=>"gittip", "username"=>"gittip"},
+ {"amount"=>"3.50", "platform"=>"gittip", "username"=>"whit537"},
+ {"amount"=>"3.50", "platform"=>"gittip", "username"=>"JohnKellyFerguson"},
+ {"amount"=>"1.00", "platform"=>"gittip", "username"=>"steveklabnik"}
+ ]
+```
+
+Finally, gratitude comes with the ability to update a specific tip and remove all other tips. This can be accomplished by using the `update_tips_and_prune` method, which again takes an array of hashes containing a user's username and desired tip amount.
+
+```ruby
+client.update_tips_and_prune([ { :username => "gittip", :amount => "25.00" } ])
+```
+
+Like the `update_tips` method, `update_tips_and_prune` will return an array of the successfully updated tips.
+
+```ruby
+[
+ {"amount"=>"25.00", "platform"=>"gittip", "username"=>"gittip"}
+]
+```
+
+All other tips have been removed, which we can see by using the `current_tips` method.
+
+```ruby
+client.current_tips
+=> [
+ {"amount"=>"25.00", "platform"=>"gittip", "username"=>"gittip"}
+ ]
+```
+
+
+
### Copyright and License
-Copyright John Kelly Ferguson and Contributors, 2013
+Copyright John Kelly Ferguson and Contributors, 2014
[MIT Licence](LICENSE.txt)