gratitude 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +4 -0
  3. data/.rubocop.yml +4 -0
  4. data/CHANGELOG.md +5 -0
  5. data/Gemfile +5 -4
  6. data/Guardfile +10 -8
  7. data/README.md +37 -37
  8. data/gratitude.gemspec +2 -2
  9. data/lib/gratitude/chart.rb +6 -5
  10. data/lib/gratitude/connection.rb +1 -1
  11. data/lib/gratitude/error.rb +2 -2
  12. data/lib/gratitude/payday.rb +7 -6
  13. data/lib/gratitude/profile.rb +36 -75
  14. data/lib/gratitude/statistics.rb +45 -89
  15. data/lib/gratitude/tips.rb +16 -24
  16. data/lib/gratitude/user_chart.rb +8 -4
  17. data/lib/gratitude/version.rb +1 -1
  18. data/spec/cassettes/charts.json +11 -11
  19. data/spec/cassettes/current_tips.json +23 -25
  20. data/spec/cassettes/current_tips_not_authenticated.json +14 -17
  21. data/spec/cassettes/paydays.json +11 -11
  22. data/spec/cassettes/profiles.json +1 -265
  23. data/spec/cassettes/prune_tips_not_authenticated.json +15 -18
  24. data/spec/cassettes/statistics.json +11 -11
  25. data/spec/cassettes/update_and_prune.json +33 -36
  26. data/spec/cassettes/update_and_prune_bad_request.json +12 -13
  27. data/spec/cassettes/update_bad_request.json +13 -14
  28. data/spec/cassettes/update_tips.json +13 -14
  29. data/spec/cassettes/update_tips_not_authenticated.json +15 -18
  30. data/spec/cassettes/user_chart_not_found.json +10 -10
  31. data/spec/cassettes/user_charts.json +22 -22
  32. data/spec/gratitude/chart_spec.rb +3 -10
  33. data/spec/gratitude/connection_spec.rb +2 -2
  34. data/spec/gratitude/payday_spec.rb +3 -10
  35. data/spec/gratitude/profile_spec.rb +47 -47
  36. data/spec/gratitude/statistics_spec.rb +27 -23
  37. data/spec/gratitude/tips_spec.rb +18 -18
  38. data/spec/gratitude/user_chart_spec.rb +17 -21
  39. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86d7979838448df774b9bd29f73c6b11e468c914
4
- data.tar.gz: cceea1e613fe4789536d8e91865edbc42e7efbed
3
+ metadata.gz: 48391aebfed3819006e439fb4e88d71f1b75b2db
4
+ data.tar.gz: 36bf3c70b0db909e11a6218d5cc5dc0015c159d7
5
5
  SHA512:
6
- metadata.gz: de3f92649c3322d05cbcd21218815e59c804cc850fdbf17536b19bcaf92bf7b0630f1ff0c536fa59dfbc45d668eb3b1facd568ce9ddc4678c5a5a7ea79eff4f9
7
- data.tar.gz: 3f13439f0b3f06ee18aba8438fc953d1cb7695af872c339fcc8221c0341aaeb32bd3b13f7a0762362106c1916e611854e25bef45f7d5cce0ec38841b7e91d5ca
6
+ metadata.gz: 2089335ffec10832f49c4939c3c8a7685ec3834706097ad59d2d0b7c8ac3f41a20a78baaadbf420293e5318bf19df7380464b382d3c5b5601a80f2885ffe455a
7
+ data.tar.gz: b632822e60d8bc53e64feef8d3f9f097180d9139b751340710bde40c78bd7ddc5d4610029f816e467d333eb58193fd271c7e17690478ba22a770122178778ee0
data/.hound.yml CHANGED
@@ -3,6 +3,7 @@ AllCops:
3
3
  - vendor/**/**
4
4
  - bin/**
5
5
  - gratitude.gemspec
6
+ - Guardfile
6
7
 
7
8
  CollectionMethods:
8
9
  # Mapping from undesired method to desired_method
@@ -32,3 +33,6 @@ SingleLineBlockParams:
32
33
 
33
34
  StringLiterals:
34
35
  EnforcedStyle: double_quotes
36
+
37
+ Style/DotPosition:
38
+ EnforcedStyle: leading
@@ -3,6 +3,7 @@ AllCops:
3
3
  - vendor/**/**
4
4
  - bin/**
5
5
  - gratitude.gemspec
6
+ - Guardfile
6
7
 
7
8
  CollectionMethods:
8
9
  # Mapping from undesired method to desired_method
@@ -32,3 +33,6 @@ SingleLineBlockParams:
32
33
 
33
34
  StringLiterals:
34
35
  EnforcedStyle: double_quotes
36
+
37
+ Style/DotPosition:
38
+ EnforcedStyle: leading
@@ -1,3 +1,8 @@
1
+ ### 0.2.0 (October 13, 2014)
2
+ * Update interface to interact with new Gratipay API (formerly called Gittip
3
+ API).
4
+ * Privatize internally used class methods.
5
+
1
6
  ### 0.1.0 (May 16, 2014)
2
7
  * Add custom errors for authentication issues, incorrect usernames and tip update errors.
3
8
 
data/Gemfile CHANGED
@@ -3,11 +3,12 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- gem "jazz_hands", github: "nixme/jazz_hands", branch: "bring-your-own-debugger"
7
- gem "pry-byebug"
8
- gem "pry-coolline"
9
6
  gem "guard-rubocop", require: false
10
7
  gem "guard-rspec", require: false
8
+ gem "jazz_hands",
9
+ github: "nixme/jazz_hands", branch: "bring-your-own-debugger"
10
+ gem "pry-byebug"
11
+ gem "pry-coolline"
11
12
  gem "terminal-notifier-guard", require: false
12
13
  end
13
14
 
@@ -16,7 +17,7 @@ group :development, :test do
16
17
  end
17
18
 
18
19
  group :test do
19
- gem "rspec", "~> 3.0.0.beta2"
20
+ gem "rspec", "~> 3.1.0"
20
21
  gem "webmock"
21
22
  gem "vcr"
22
23
  gem "coveralls", require: false
data/Guardfile CHANGED
@@ -1,10 +1,12 @@
1
- guard :rspec do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
- watch('spec/spec_helper.rb') { "spec" }
5
- end
1
+ group :red_green_refactor, halt_on_fail: true do
2
+ guard :rspec do
3
+ watch(%r{^spec/.+_spec\.rb$})
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
5
+ watch('spec/spec_helper.rb') { "spec" }
6
+ end
6
7
 
7
- guard :rubocop do
8
- watch(%r{.+\.rb$})
9
- watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
8
+ guard :rubocop, all_on_start: false, notification: :failed do
9
+ watch(%r{.+\.rb$})
10
+ watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
11
+ end
10
12
  end
data/README.md CHANGED
@@ -6,7 +6,7 @@ gratitude
6
6
  [![Code Climate](https://codeclimate.com/github/JohnKellyFerguson/gratitude.png)](https://codeclimate.com/github/JohnKellyFerguson/gratitude)
7
7
  [![Coverage Status](https://coveralls.io/repos/JohnKellyFerguson/gratitude/badge.png)](https://coveralls.io/r/JohnKellyFerguson/gratitude)
8
8
 
9
- A simple Ruby wrapper for the [Gittip API](https://github.com/gittip/www.gittip.com#api). Please follow the [Changelog](CHANGELOG.md) to check the status of the project.
9
+ A simple Ruby wrapper for the [Gratipay API](https://github.com/gratipay/www.gratipay.com#api). Please follow the [Changelog](CHANGELOG.md) to check the status of the project.
10
10
 
11
11
 
12
12
  # Installation
@@ -15,7 +15,7 @@ A simple Ruby wrapper for the [Gittip API](https://github.com/gittip/www.gittip.
15
15
 
16
16
  # Usage
17
17
 
18
- The gratitude gem interacts with the six different endpoints of the Gittip API. They are as follows:
18
+ The gratitude gem interacts with the six different endpoints of the Gratipay API. They are as follows:
19
19
 
20
20
  * [Charts](#charts-source-code)
21
21
  * [Paydays](#paydays-source-code)
@@ -24,10 +24,10 @@ The gratitude gem interacts with the six different endpoints of the Gittip API.
24
24
  * [Profile](#profile-source-code)
25
25
  * [Tips](#tips-client-authentication-source-code-tips-source-code)
26
26
 
27
- When using gratitude to retrieve data from the Gittip API, please note that many of the JSON key names have been wrapped in more naturally sounding method names. However, all of the original JSON key names have also been maintained as aliases so as to maitain consistency with the original [Gittip API documentation](https://github.com/gittip/www.gittip.com#api).
27
+ When using gratitude to retrieve data from the Gratipay API, please note that many of the JSON key names have been wrapped in more naturally sounding method names. However, all of the original JSON key names have also been maintained as aliases so as to maitain consistency with the original [Gratipay API documentation](https://github.com/gratipay/www.gratipay.com#api).
28
28
 
29
29
  ##Charts ([source code](https://github.com/JohnKellyFerguson/gratitude/blob/master/lib/gratitude/chart.rb))
30
- The Chart endpoint of the Gittip API provides aggregate statistics over time which are used in Gittip's [chart page](https://www.gittip.com/about/charts.html). To retrieve this information, use the following command:
30
+ The Chart endpoint of the Gratipay API provides aggregate statistics over time which are used in Gratipay's [chart page](https://www.gratipay.com/about/charts.html). To retrieve this information, use the following command:
31
31
 
32
32
  ```ruby
33
33
  Gratitude::Chart.all
@@ -67,7 +67,7 @@ Gratitude::Chart.newest
67
67
 
68
68
  ##Paydays ([source code](https://github.com/JohnKellyFerguson/gratitude/blob/master/lib/gratitude/payday.rb))
69
69
 
70
- The Gittip API provides access to the historical data of all its paydays. To retrieve this information, simply use the following command:
70
+ The Gratipay API provides access to the historical data of all its paydays. To retrieve this information, simply use the following command:
71
71
 
72
72
  ```ruby
73
73
  Gratitude::Payday.all
@@ -113,9 +113,9 @@ Gratitude::Payday.newest
113
113
  ```
114
114
 
115
115
  ##Statistics ([source code](https://github.com/JohnKellyFerguson/gratitude/blob/master/lib/gratitude/statistics.rb))
116
- 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.
116
+ The Statistics aspect of the Gratipay API provides the current statistics, as of that moment in time, for Gratipay. Note that these stats can potentially change when making subsequent requests.
117
117
 
118
- If you would like to get the current Gittip stats, you can do so by using:
118
+ If you would like to get the current Gratipay stats, you can do so by using:
119
119
 
120
120
  ```ruby
121
121
  Gratitude::Statistics.current
@@ -127,7 +127,7 @@ Alternatively, you can also use:
127
127
  Gratitude::Statistics.new
128
128
  ```
129
129
 
130
- 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:
130
+ Each of the above will return an object containing all of the current Gratipay stats. You can access each of the Gratipay stats using the following methods:
131
131
 
132
132
  * `average_tip_amount` (alias: `average_tip`)
133
133
  * `average_number_of_tippees` (alias: `average_tippees`)
@@ -141,12 +141,12 @@ Each of the above will return an object containing all of the current Gittip sta
141
141
  * `number_who_give_and_receive` (alias: `noverlap`)
142
142
  * `number_of_receivers` (alias: `nreceivers`)
143
143
  * `other_people`
144
- * This returns a string describing how many people the average person on Gittip tips.
144
+ * This returns a string describing how many people the average person on Gratipay tips.
145
145
  * `percentage_of_users_with_credit_cards` (alias: `pcc`)
146
146
  * `punctuation` (alias: `punc`)
147
- * This is used internally by the Gittip API for figuring out `last_thursday` and `this_thursday`. It's unlikely that this will need to be utilized by anyone using the gratitude gem.
147
+ * This is used internally by the Gratipay API for figuring out `last_thursday` and `this_thursday`. It's unlikely that this will need to be utilized by anyone using the gratitude gem.
148
148
  * `statements`
149
- * 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.
149
+ * This returns an array of 16 hashes. Each hash provides the personal statement of a Gratipay user and has the following keys: `statement`, `username`. Note that this will return a different array of hashes each time you query the Gratipay API.
150
150
  * `this_thursday`
151
151
  * This refers to the upcoming Thursday when payments/transfers are set to occur. Possible values include: "this Thursday", "today", "right now!", and "next Thursday"
152
152
  * `tip_distribution_json`
@@ -158,7 +158,7 @@ Each of the above will return an object containing all of the current Gittip sta
158
158
  * `transfer_volume`
159
159
 
160
160
  ##User Charts ([source code](https://github.com/JohnKellyFerguson/gratitude/blob/master/lib/gratitude/user_chart.rb))
161
- The User Chart endpoint of the Gittip API provides aggregate stats over time for a given user.
161
+ The User Chart endpoint of the Gratipay API provides aggregate stats over time for a given user.
162
162
 
163
163
  To retrieve this information, do the following:
164
164
 
@@ -188,7 +188,7 @@ Gratitude::UserChart.newest_for("JohnKellyFerguson")
188
188
 
189
189
  ##Profile ([source code](https://github.com/JohnKellyFerguson/gratitude/blob/master/lib/gratitude/profile.rb))
190
190
 
191
- 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.
191
+ The Profile aspect of the Gratipay API allows you to get the public profile information of any Gratipay user. To do so, just pass their username as an initialization argument to the `Gratitude::Profile` class.
192
192
 
193
193
  ```ruby
194
194
  Gratitude::Profile.new("JohnKellyFerguson")
@@ -241,9 +241,9 @@ The above will retrieve the public profile of the above user. You can then acces
241
241
  * `amount_receiving` (alias: `receiving`)
242
242
  * returns an estimate as a float of what the given user is expected to receive this week.
243
243
  * `number_of_patrons` (alias: `npatrons`)
244
- * returns the number of other gittipers that donate to the user being queried.
244
+ * returns the number of other gratipayers that donate to the user being queried.
245
245
  * `on`
246
- * returns the platform name: "gittip"
246
+ * returns the platform name: "gratipay"
247
247
  * `goal`
248
248
  * returns the amount (as a float) that the user would like to receive weekly if the user set such a goal.
249
249
  * returns `nil` if the user has defined themselves as a patron or has not set a specific monetary goal.
@@ -254,9 +254,9 @@ The above will retrieve the public profile of the above user. You can then acces
254
254
 
255
255
 
256
256
  ##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))
257
- 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.
257
+ The Tips aspect of the Gratipay 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 Gratipay account, go to your profile and at the bottom of the page you will find your API_KEY.
258
258
 
259
- ![Gittip API Key](api_key.png)
259
+ ![Gratipay API Key](api_key.png)
260
260
 
261
261
  Now that you have your API_KEY, you can find out your current tips or update your tips using Gratitude.
262
262
 
@@ -264,7 +264,7 @@ Now that you have your API_KEY, you can find out your current tips or update you
264
264
  To find out the current tips of a user, follow these instructions:
265
265
 
266
266
  ```ruby
267
- # First establish a connection to the Gittip API by passing in your credentials to Gratitude::Client.new
267
+ # First establish a connection to the Gratipay API by passing in your credentials to Gratitude::Client.new
268
268
  # You will need to pass in your username and api key like so.
269
269
  client = Gratitude::Client.new(:username => "my_username", :api_key => "my_api_key")
270
270
  # Then, to find out your current tips, simply call the current_tips method.
@@ -274,9 +274,9 @@ This will will return an array of hashes that represent your current tips and wi
274
274
 
275
275
 
276
276
  [
277
- {"amount"=>"2.00", "platform"=>"gittip", "username"=>"gittip"},
278
- {"amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537"},
279
- {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
277
+ {"amount"=>"2.00", "platform"=>"gratipay", "username"=>"gratipay"},
278
+ {"amount"=>"1.00", "platform"=>"gratipay", "username"=>"whit537"},
279
+ {"amount"=>"0.25", "platform"=>"gratipay", "username"=>"JohnKellyFerguson"}
280
280
  ]
281
281
 
282
282
  Please be aware that all of the amounts in the hash are strings and not floats.
@@ -298,7 +298,7 @@ client = Gratitude::Client.new(:username => "my_username", :api_key => "my_api_k
298
298
  We can then call the `update_tips` method, which accepts an array of hashes containing a user's username and desired tip amount.
299
299
 
300
300
  ```ruby
301
- client.update_tips([ { :username => "gittip", :amount => "3.50" },
301
+ client.update_tips([ { :username => "gratipay", :amount => "3.50" },
302
302
  { :username => "whit537", :amount => "3.50"},
303
303
  { :username => "JohnKellyFerguson", :amount = "3.50" }])
304
304
  ```
@@ -307,9 +307,9 @@ When tips are successfully updated, the `update_tips` method will return an arra
307
307
 
308
308
  ```ruby
309
309
  [
310
- {"amount"=>"3.50", "platform"=>"gittip", "username"=>"gittip"},
311
- {"amount"=>"3.50", "platform"=>"gittip", "username"=>"whit537"},
312
- {"amount"=>"3.50", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
310
+ {"amount"=>"3.50", "platform"=>"gratipay", "username"=>"gratipay"},
311
+ {"amount"=>"3.50", "platform"=>"gratipay", "username"=>"whit537"},
312
+ {"amount"=>"3.50", "platform"=>"gratipay", "username"=>"JohnKellyFerguson"}
313
313
  ]
314
314
  ```
315
315
  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.
@@ -317,16 +317,16 @@ Please note that you do not have to update all of a user's tips when using the `
317
317
  For example:
318
318
 
319
319
  ```ruby
320
- client.update_tips([ { :username => "gittip", :amount => "4.50" } ])
320
+ client.update_tips([ { :username => "gratipay", :amount => "4.50" } ])
321
321
  ```
322
- 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.
322
+ will only updates the tips going to the "gratipay"" user. All other tips will remain unchanged. We can see this by continuing our example and running the `current_tips` method.
323
323
 
324
324
  ```ruby
325
325
  client.current_tips
326
326
  => [
327
- {"amount"=>"4.50", "platform"=>"gittip", "username"=>"gittip"},
328
- {"amount"=>"3.50", "platform"=>"gittip", "username"=>"whit537"},
329
- {"amount"=>"3.50", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
327
+ {"amount"=>"4.50", "platform"=>"gratipay", "username"=>"gratipay"},
328
+ {"amount"=>"3.50", "platform"=>"gratipay", "username"=>"whit537"},
329
+ {"amount"=>"3.50", "platform"=>"gratipay", "username"=>"JohnKellyFerguson"}
330
330
  ]
331
331
  ```
332
332
 
@@ -340,24 +340,24 @@ The new tip will be added to the previously existing tips.
340
340
  ```ruby
341
341
  client.current_tips
342
342
  => [
343
- {"amount"=>"4.50", "platform"=>"gittip", "username"=>"gittip"},
344
- {"amount"=>"3.50", "platform"=>"gittip", "username"=>"whit537"},
345
- {"amount"=>"3.50", "platform"=>"gittip", "username"=>"JohnKellyFerguson"},
346
- {"amount"=>"1.00", "platform"=>"gittip", "username"=>"steveklabnik"}
343
+ {"amount"=>"4.50", "platform"=>"gratipay", "username"=>"gratipay"},
344
+ {"amount"=>"3.50", "platform"=>"gratipay", "username"=>"whit537"},
345
+ {"amount"=>"3.50", "platform"=>"gratipay", "username"=>"JohnKellyFerguson"},
346
+ {"amount"=>"1.00", "platform"=>"gratipay", "username"=>"steveklabnik"}
347
347
  ]
348
348
  ```
349
349
 
350
350
  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.
351
351
 
352
352
  ```ruby
353
- client.update_tips_and_prune([ { :username => "gittip", :amount => "25.00" } ])
353
+ client.update_tips_and_prune([ { :username => "gratipay", :amount => "25.00" } ])
354
354
  ```
355
355
 
356
356
  Like the `update_tips` method, `update_tips_and_prune` will return an array of the successfully updated tips.
357
357
 
358
358
  ```ruby
359
359
  [
360
- {"amount"=>"25.00", "platform"=>"gittip", "username"=>"gittip"}
360
+ {"amount"=>"25.00", "platform"=>"gratipay", "username"=>"gratipay"}
361
361
  ]
362
362
  ```
363
363
 
@@ -366,7 +366,7 @@ All other tips have been removed, which we can see by using the `current_tips` m
366
366
  ```ruby
367
367
  client.current_tips
368
368
  => [
369
- {"amount"=>"25.00", "platform"=>"gittip", "username"=>"gittip"}
369
+ {"amount"=>"25.00", "platform"=>"gratipay", "username"=>"gratipay"}
370
370
  ]
371
371
  ```
372
372
 
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Gratitude::VERSION
9
9
  spec.authors = ["John Kelly Ferguson"]
10
10
  spec.email = ["hello@johnkellyferguson.com"]
11
- spec.description = %q(A simple Ruby wrapper for the Gittip API.)
12
- spec.summary = %q(A simple Ruby wrapper for the Gittip API.)
11
+ spec.description = %q(A simple Ruby wrapper for the Gratipay API.)
12
+ spec.summary = %q(A simple Ruby wrapper for the Gratipay API.)
13
13
  spec.homepage = "https://github.com/JohnKellyFerguson/gratitude"
14
14
  spec.license = "MIT"
15
15
 
@@ -33,17 +33,18 @@ module Gratitude
33
33
  end
34
34
 
35
35
  def self.sort_by_date
36
- all.sort_by { |chart| chart.date }.reverse
36
+ all.sort_by(&:date).reverse
37
37
  end
38
+ private_class_method :sort_by_date
38
39
 
39
- def self.charts_from_gittip
40
+ def self.charts_from_gratipay
40
41
  faraday.get("/about/charts.json").body.to_a
41
42
  end
43
+ private_class_method :charts_from_gratipay
42
44
 
43
45
  def self.collect_charts
44
- charts_from_gittip.each do |chart_hash|
45
- Chart.new(chart_hash)
46
- end
46
+ charts_from_gratipay.each { |chart_hash| Chart.new(chart_hash) }
47
47
  end
48
+ private_class_method :collect_charts
48
49
  end
49
50
  end
@@ -3,7 +3,7 @@
3
3
  module Gratitude
4
4
  module Connection
5
5
  def faraday
6
- @faraday ||= Faraday.new(url: "https://www.gittip.com/") do |faraday|
6
+ @faraday ||= Faraday.new(url: "https://gratipay.com/") do |faraday|
7
7
  faraday.response :json, content_type: /\bjson$/
8
8
  faraday.adapter Faraday.default_adapter
9
9
  end
@@ -5,7 +5,7 @@ module Gratitude
5
5
  def initialize(username)
6
6
  super(
7
7
  "The requested username, '#{username}', could not be found."\
8
- "Please note that Gittip API requests are case sensitive.")
8
+ "Please note that Gratipay API requests are case sensitive.")
9
9
  end
10
10
  end
11
11
 
@@ -13,7 +13,7 @@ module Gratitude
13
13
  def initialize
14
14
  super(
15
15
  "The supplied username and api_key could not properly authenticate "\
16
- "with Gittip.")
16
+ "with Gratipay.")
17
17
  end
18
18
  end
19
19
 
@@ -14,7 +14,7 @@ module Gratitude
14
14
  :transfer_start_time
15
15
 
16
16
  # Provide aliases so all methods can correspond to the original
17
- # Gittip API names.
17
+ # Gratipay API names.
18
18
  alias_method :nachs, :number_of_ach_credits
19
19
  alias_method :number_of_achs, :number_of_ach_credits
20
20
  alias_method :nactive, :number_of_active_users
@@ -66,17 +66,18 @@ module Gratitude
66
66
  end
67
67
 
68
68
  def self.sort_by_ts_end
69
- all.sort_by { |p| p.ts_end }.reverse
69
+ all.sort_by(&:ts_end).reverse
70
70
  end
71
+ private_class_method :sort_by_ts_end
71
72
 
72
- def self.paydays_from_gittip
73
+ def self.paydays_from_gratipay
73
74
  faraday.get("/about/paydays.json").body.to_a
74
75
  end
76
+ private_class_method :paydays_from_gratipay
75
77
 
76
78
  def self.collect_paydays
77
- paydays_from_gittip.each do |payday_hash|
78
- Payday.new(payday_hash)
79
- end
79
+ paydays_from_gratipay.each { |payday_hash| Payday.new(payday_hash) }
80
80
  end
81
+ private_class_method :collect_paydays
81
82
  end # Payday
82
83
  end # Gratitude
@@ -9,93 +9,54 @@ module Gratitude
9
9
  @username = username
10
10
  end
11
11
 
12
- def avatar_url
13
- response_body["avatar"]
12
+ %w(
13
+ avatar
14
+ elsewhere
15
+ id
16
+ npatrons
17
+ number
18
+ on
19
+ ).each do |response_key|
20
+ define_method(response_key) { response_body.fetch(response_key) }
14
21
  end
15
- alias_method :avatar, :avatar_url
16
22
 
17
- def bitcoin
18
- response_body["bitcoin"]
19
- end
23
+ alias_method :avatar_url, :avatar
24
+ alias_method :account_type, :number
25
+ alias_method :number_of_patrons, :npatrons
20
26
 
21
- def bitbucket
22
- response_body["elsewhere"]["bitbucket"]
27
+ def giving
28
+ response_body.fetch("giving").to_f
23
29
  end
24
-
25
- def bitbucket_username
26
- bitbucket["user_name"] if bitbucket
27
- end
28
-
29
- def bountysource
30
- response_body["elsewhere"]["bountysource"]
31
- end
32
-
33
- def bountysource_username
34
- bountysource["user_name"] if bountysource
35
- end
36
-
37
- def github
38
- response_body["elsewhere"]["bountysource"]
39
- end
40
-
41
- def github_username
42
- github["user_name"] if github
43
- end
44
-
45
- def openstreetmap
46
- response_body["elsewhere"]["openstreetmap"]
47
- end
48
-
49
- def openstreetmap_username
50
- openstreetmap["user_name"] if openstreetmap
51
- end
52
-
53
- def twitter
54
- response_body["elsewhere"]["twitter"]
55
- end
56
-
57
- def twitter_username
58
- twitter["user_name"] if twitter
59
- end
60
-
61
- def venmo
62
- response_body["elsewhere"]["venmo"]
63
- end
64
-
65
- def venmo_username
66
- venmo["user_name"] if venmo
67
- end
68
-
69
- def amount_giving
70
- response_body["giving"].to_f
71
- end
72
- alias_method :giving, :amount_giving
30
+ alias_method :amount_giving, :giving
73
31
 
74
32
  def amount_receiving
75
- response_body["receiving"].to_f
33
+ response_body.fetch("receiving").to_f
76
34
  end
77
35
  alias_method :receiving, :amount_receiving
78
36
 
79
37
  def goal
80
- response_body["goal"].to_f if response_body["goal"]
81
- end
82
-
83
- def account_type
84
- response_body["number"]
85
- end
86
- alias_method :number, :account_type
87
-
88
- def id
89
- response_body["id"]
90
- end
91
-
92
- def number_of_patrons
93
- response_body["npatrons"]
38
+ response_body.fetch("goal").to_f if response_body["goal"]
94
39
  end
95
- alias_method :npatrons, :number_of_patrons
96
40
 
97
- def on
98
- response_body["on"]
41
+ def bitcoin
42
+ response_body.fetch("bitcoin") { nil }
43
+ end
44
+
45
+ %w(
46
+ bitbucket
47
+ bountysource
48
+ github
49
+ openstreetmap
50
+ twitter
51
+ venmo
52
+ ).each do |other_account|
53
+ define_method(other_account) { elsewhere[other_account] }
54
+
55
+ define_method("#{other_account}_username") do
56
+ if send(other_account.to_sym)
57
+ send(other_account.to_sym).fetch("user_name")
58
+ end
59
+ end
99
60
  end
100
61
 
101
62
  private