gratitude 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a3426a86627d58024de176a96959857d0032a69d
4
- data.tar.gz: c918f9fc3804023c7985c283c967d37dd83eae8e
3
+ metadata.gz: 7549b619bcc85a81bc995ca6a09f0363b52548e0
4
+ data.tar.gz: 704297b6b8f5f6b69dfed8b40b3ac73a7b8a179d
5
5
  SHA512:
6
- metadata.gz: beacd24fcdf3e11cc1459d76a9dc4bdaf3361368c2bc235a0c4d7faa42b2285d5d4e90cc7f45372b6ac40282dcc73cc2390006a24ebe3039f5408900fcbe95dc
7
- data.tar.gz: 87acf159f83bde5b85702f7a89e2bfac096fbc7db258aefb49c6e99ce29fecc24ff1d1be4752473fe0fea0bc37cbaf11f237ec61f40540a82fc68fe36ad471c1
6
+ metadata.gz: 9cb95f6be06a1f320b7066e338eb84ac6f2a59fe984100fdaf6a6833bf08931c041bc46678164aa70266ee938e6e1f5f9bd5fa6c4153de3ea812763705af5c5a
7
+ data.tar.gz: 8d51cb9fcbf942090fc7299b8de17338e850035853da7ee6c6738c20fd699a1e81442a45eaf13e4eed150064f75cf08e4ca7ab07e46cbdac8d83952a5d1d9808
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --format documentation
2
- --color
2
+ --color
data/CHANGELOG.md CHANGED
@@ -1,37 +1,41 @@
1
1
  ### 0.1.0 (Upcoming Stable Release)
2
2
  * Implement all aspects of the Gittip API.
3
3
 
4
- ### 0.0.10
4
+ ### 0.0.11 (March 29, 2014)
5
+ * Change to Faraday instead of HTTParty
6
+ * Update api methods to match current Gittip api implementation
7
+
8
+ ### 0.0.10 (March 27, 2014)
5
9
  * Add rake console task to enter an IRB session with Gratitude required
6
10
  * Simplify Tip's public interface
7
11
 
8
- ### 0.0.9 (10/19/2013)
12
+ ### 0.0.9 (October 19, 2013)
9
13
  * Add ability to update a user's current tips.
10
14
 
11
- ### 0.0.8 (10/18/2013)
15
+ ### 0.0.8 (October 18, 2013)
12
16
  * Add client authentication.
13
17
  * Add ability to retrieve a user's current tips.
14
18
 
15
- ### 0.0.7 (10/13/2013)
19
+ ### 0.0.7 (October 13, 2013)
16
20
  * Update documentation.
17
21
  * Alias new to current in Statistics class.
18
22
 
19
- ### 0.0.6 (9/19/2013)
23
+ ### 0.0.6 (October 19, 2013)
20
24
  * Complete Gittip's Statistics API integration.
21
25
  * Add more aliases and improve method clarity to signify method intent.
22
26
 
23
- ### 0.0.5 (9/17/2013)
27
+ ### 0.0.5 (September 17, 2013)
24
28
  * Complete Gittip's Paydays API integration.
25
29
  * Add aliases for all methods to correspond to Gittip's original API documentation.
26
30
 
27
- ### 0.0.4 (9/14/2013)
31
+ ### 0.0.4 (September 14, 2013)
28
32
  * Improve integration with Gittip's Public User API to better account for different user settings.
29
33
 
30
- ### 0.0.3 (9/11/2013)
34
+ ### 0.0.3 (September 11, 2013)
31
35
  * Fix release version.
32
36
 
33
- ### 0.0.2 (9/11/2013)
37
+ ### 0.0.2 (September 11, 2013)
34
38
  * Add ability to get a Gittip user's public information.
35
39
 
36
- ### 0.0.1 (9/10/2013)
40
+ ### 0.0.1 (September 10, 2013)
37
41
  * Initial release.
data/Gemfile CHANGED
@@ -2,14 +2,16 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- group :development, :test do
6
- gem "rspec", '~> 3.0.0.beta2'
7
- gem "webmock"
8
- gem "vcr"
5
+ group :development do
9
6
  gem "pry"
10
7
  gem "awesome_print"
8
+ gem "guard-rspec"
9
+ gem "terminal-notifier-guard", require: false
11
10
  end
12
11
 
13
12
  group :test do
13
+ gem "rspec", '~> 3.0.0.beta2'
14
+ gem "webmock"
15
+ gem "vcr"
14
16
  gem 'coveralls', require: false
15
- end
17
+ end
data/Guardfile ADDED
@@ -0,0 +1,6 @@
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
6
+
data/README.md CHANGED
@@ -21,9 +21,9 @@ A simple Ruby wrapper for the [Gittip API](https://github.com/gittip/www.gittip.
21
21
  The gratitude gem has four different components that interact with different aspects of the Gittip API. They are as follows:
22
22
 
23
23
  * [Paydays](#paydays-source-code)
24
- * [Statistics](#statistics)
24
+ * [Statistics](#statistics-source-code)
25
25
  * [Profile](#profile-source-code)
26
- * [Tips](#tips)
26
+ * [Tips](#tips-client-authentication-source-code-tips-source-code)
27
27
 
28
28
  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).
29
29
 
@@ -63,6 +63,11 @@ paydays.each do |payday|
63
63
  end
64
64
  ```
65
65
 
66
+ If you want to get the oldest payday:
67
+ ```ruby
68
+ Gratitude::Payday.oldest_payday
69
+ ```
70
+
66
71
  Finally, if you just want to get the most recent payday, you can do so by using:
67
72
 
68
73
  ```ruby
@@ -125,32 +130,53 @@ Gratitude::Profile.new("johnkellyferguson")
125
130
  The above will retrieve the public profile of the above user. You can then access all of the different information with the following methods:
126
131
 
127
132
  * `avatar_url` (alias: `avatar`)
128
- * `bitbucket_api_url` (alias: `bitbucket`)
129
- * returns the user's bitbucket api url if they have connected a bitbucket account.
133
+ * `bitcoin`
134
+ * returns a link to the user's bitcoin address
135
+ * `bitbucket`
136
+ * returns a hash containing their bitbucket username, id, and user id if the user has connected their bitbucket account.
130
137
  * otherwise, returns `nil`.
131
138
  * `bitbucket_username`
132
139
  * returns the user's bitbucket username if they have connected a bitbucket account.
133
140
  * otherwise, returns `nil`.
134
- * `bountysource_api_url` (alias: `bountysource`)
135
- * returns the user's bountysource api url if they have connected a bountysource account.
141
+ * `bountysource`
142
+ * returns a hash containing their bountysource username, id, and user id if the user has connected their bountysource account.
136
143
  * otherwise, returns `nil`.
137
144
  * `bountysource_username`
138
145
  * returns the user's bountysource username if they have connected a bountysource account.
139
146
  * otherwise, returns `nil`.
140
- * `github_api_url` (alias: `github`)
141
- * returns the user's github api url if they have connected a github account.
147
+ * `github`
148
+ * returns a hash containing their github username, id, and user id if the user has connected their github account.
142
149
  * otherwise, returns `nil`.
143
150
  * `github_username`
144
151
  * returns the user's github username if they have connected a github account.
145
152
  * otherwise, returns `nil`.
146
- * `twitter_api_url` (alias: `twitter`)
147
- * returns the user's twitter api url if they have connected a twitter account.
153
+ * `openstreetmap`
154
+ * returns a hash containing their openstreetmap username, id, and user id if the user has connected their openstreetmap account.
155
+ * otherwise, returns `nil`.
156
+ * `openstreetmap_username`
157
+ * returns the user's openstreetmap username if they have connected a openstreetmap account.
158
+ * otherwise, returns `nil`.
159
+ * `twitter`
160
+ * returns a hash containing their twitter username, id, and user id if the user has connected their twitter account.
161
+ * otherwise, returns `nil`.
162
+ * `twitter_username`
163
+ * returns the user's twitter username if they have connected a twitter account.
164
+ * otherwise, returns `nil`.
165
+ * `venmo`
166
+ * returns a hash containing their venmo username, id, and user id if the user has connected their venmo account.
148
167
  * otherwise, returns `nil`.
168
+ * `venmo_username`
169
+ * returns the user's venmo username if they have connected a venmo account.
170
+ * otherwise, returns `nil`.
149
171
  * `amount_giving` (alias: `giving`)
150
172
  * returns the amount (as a float) the user has pledged to give this week.
151
173
  * if the user has decided to donately privately then this will return 0.00.
152
174
  * `amount_receiving` (alias: `receiving`)
153
175
  * returns an estimate as a float of what the given user is expected to receive this week.
176
+ * `number_of_patrons` (alias: `npatrons`)
177
+ * returns the number of other gittipers that donate to the user being queried.
178
+ * `on`
179
+ * returns the platform name: "gittip"
154
180
  * `goal`
155
181
  * returns the amount (as a float) that the user would like to receive weekly if the user set such a goal.
156
182
  * returns `nil` if the user has defined themselves as a patron or has not set a specific monetary goal.
@@ -159,7 +185,6 @@ The above will retrieve the public profile of the above user. You can then acces
159
185
  * `id`
160
186
  * the id of the user.
161
187
 
162
- **TODO:** Implement the `my_tip` method into the Profile section once client authentication is finished.
163
188
 
164
189
  ##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))
165
190
  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.
data/gratitude.gemspec CHANGED
@@ -18,8 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "httparty", "~> 0.11"
21
+ spec.add_dependency "faraday", "~> 0.8"
22
+ spec.add_dependency "faraday_middleware", "~> 0.9"
22
23
  spec.add_dependency "json"
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "bundler", "~> 1.6"
24
25
  spec.add_development_dependency "rake"
25
26
  end
data/lib/gratitude.rb CHANGED
@@ -1,6 +1,8 @@
1
- require "httparty"
1
+ require "faraday"
2
+ require "faraday_middleware"
2
3
 
3
4
  require "gratitude/client"
5
+ require "gratitude/connection"
4
6
  require "gratitude/payday"
5
7
  require "gratitude/profile"
6
8
  require "gratitude/statistics"
@@ -1,8 +1,9 @@
1
+ require "gratitude/connection"
1
2
  require "gratitude/tips"
2
3
 
3
4
  module Gratitude
4
5
  class Client
5
- include HTTParty
6
+ include Gratitude::Connection
6
7
  include Gratitude::Client::Tips
7
8
 
8
9
  attr_reader :username, :api_key
@@ -10,7 +11,8 @@ module Gratitude
10
11
  def initialize(options = {})
11
12
  @username = options[:username]
12
13
  @api_key = options[:api_key]
14
+ faraday.basic_auth(api_key, "")
13
15
  end
14
16
 
15
17
  end # Payday
16
- end # Gratitude
18
+ end # Gratitude
@@ -0,0 +1,10 @@
1
+ module Gratitude
2
+ module Connection
3
+ def faraday
4
+ @faraday ||= Faraday.new(:url => "https://www.gittip.com/") do |faraday|
5
+ faraday.response :json, :content_type => /\bjson$/
6
+ faraday.adapter Faraday.default_adapter
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,7 +1,6 @@
1
1
  module Gratitude
2
2
  class Payday
3
- include HTTParty
4
- base_uri "https://www.gittip.com/about/paydays.json"
3
+ extend Connection
5
4
  PAYDAYS = []
6
5
 
7
6
  attr_reader :ach_fees_volume, :ach_volume, :charge_fees_volume,
@@ -11,19 +10,20 @@ module Gratitude
11
10
  :number_of_transfers, :transfer_volume, :transfer_end_time,
12
11
  :transfer_start_time
13
12
 
14
- # Provide aliases so all methods can correspond to the original Gittip API names.
15
- alias :nachs :number_of_ach_credits
16
- alias :number_of_achs :number_of_ach_credits
17
- alias :nactive :number_of_active_users
18
- alias :number_active :number_of_active_users
19
- alias :ncc_failing :number_of_failing_credit_cards
20
- alias :ncc_missing :number_of_missing_credit_cards
21
- alias :ncharges :number_of_charges
22
- alias :nparticipants :number_of_participants
23
- alias :ntippers :number_of_tippers
24
- alias :ntransfers :number_of_transfers
25
- alias :ts_end :transfer_end_time
26
- alias :ts_start :transfer_start_time
13
+ # Provide aliases so all methods can correspond to the original
14
+ # Gittip API names.
15
+ alias_method :nachs, :number_of_ach_credits
16
+ alias_method :number_of_achs, :number_of_ach_credits
17
+ alias_method :nactive, :number_of_active_users
18
+ alias_method :number_active, :number_of_active_users
19
+ alias_method :ncc_failing, :number_of_failing_credit_cards
20
+ alias_method :ncc_missing, :number_of_missing_credit_cards
21
+ alias_method :ncharges, :number_of_charges
22
+ alias_method :nparticipants, :number_of_participants
23
+ alias_method :ntippers, :number_of_tippers
24
+ alias_method :ntransfers, :number_of_transfers
25
+ alias_method :ts_end, :transfer_end_time
26
+ alias_method :ts_start, :transfer_start_time
27
27
 
28
28
  def initialize(options = {})
29
29
  @ach_fees_volume = options["ach_fees_volume"]
@@ -54,12 +54,18 @@ module Gratitude
54
54
  sort_by_ts_end.first
55
55
  end
56
56
 
57
+ def self.oldest_payday
58
+ sort_by_ts_end.last
59
+ end
60
+
57
61
  def self.sort_by_ts_end
58
62
  all.sort_by { |p| p.ts_end }.reverse
59
63
  end
60
64
 
65
+ private
66
+
61
67
  def self.get_paydays_from_gittip
62
- get(base_uri).to_a
68
+ faraday.get('/about/paydays.json').body.to_a
63
69
  end
64
70
 
65
71
  def self.collect_paydays
@@ -69,4 +75,4 @@ module Gratitude
69
75
  end
70
76
 
71
77
  end # Payday
72
- end # Gratitude
78
+ end # Gratitude
@@ -1,78 +1,109 @@
1
1
  module Gratitude
2
2
  class Profile
3
- include HTTParty
4
- base_uri "https://www.gittip.com"
5
- URI_SUFFIX = "/public.json"
6
-
7
- attr_reader :username, :response
3
+ include Connection
4
+ attr_reader :username
8
5
 
9
6
  def initialize(username)
10
7
  @username = username
11
- @response = self.class.get("/#{username}#{URI_SUFFIX}")
12
8
  end
13
9
 
14
10
  def avatar_url
15
- response["avatar"]
11
+ response_body["avatar"]
12
+ end
13
+ alias_method :avatar, :avatar_url
14
+
15
+ def bitcoin
16
+ response_body["bitcoin"]
16
17
  end
17
- alias :avatar :avatar_url
18
18
 
19
- def bitbucket_api_url
20
- response["elsewhere"]["bitbucket"]
19
+ def bitbucket
20
+ response_body["elsewhere"]["bitbucket"]
21
21
  end
22
- alias :bitbucket :bitbucket_api_url
23
22
 
24
23
  def bitbucket_username
25
- bitbucket_api_url.gsub("https://bitbucket.org/api/1.0/users/", "") if bitbucket_api_url
24
+ bitbucket["user_name"] if bitbucket
26
25
  end
27
26
 
28
- def bountysource_api_url
29
- response["elsewhere"]["bountysource"]
27
+ def bountysource
28
+ response_body["elsewhere"]["bountysource"]
30
29
  end
31
- alias :bountysource :bountysource_api_url
32
30
 
33
31
  def bountysource_username
34
- bountysource_api_url.gsub("https://api.bountysource.com/users/", "") if bountysource_api_url
32
+ bountysource["user_name"] if bountysource
35
33
  end
36
34
 
37
- def github_api_url
38
- response["elsewhere"]["github"]
35
+ def github
36
+ response_body["elsewhere"]["bountysource"]
39
37
  end
40
- alias :github :github_api_url
41
38
 
42
39
  def github_username
43
- github_api_url.gsub("https://api.github.com/users/", "") if github_api_url
40
+ github["user_name"] if github
41
+ end
42
+
43
+ def openstreetmap
44
+ response_body["elsewhere"]["openstreetmap"]
44
45
  end
45
46
 
46
- def twitter_api_url
47
- response["elsewhere"]["twitter"]
47
+ def openstreetmap_username
48
+ openstreetmap["user_name"] if openstreetmap
49
+ end
50
+
51
+ def twitter
52
+ response_body["elsewhere"]["twitter"]
48
53
  end
49
- alias :twitter :twitter_api_url
50
54
 
51
55
  def twitter_username
52
- nil
56
+ twitter["user_name"] if twitter
57
+ end
58
+
59
+ def venmo
60
+ response_body["elsewhere"]["venmo"]
61
+ end
62
+
63
+ def venmo_username
64
+ venmo["user_name"] if venmo
53
65
  end
54
66
 
55
67
  def amount_giving
56
- response["giving"].to_f
68
+ response_body["giving"].to_f
57
69
  end
58
- alias :giving :amount_giving
70
+ alias_method :giving, :amount_giving
59
71
 
60
72
  def amount_receiving
61
- response["receiving"].to_f
73
+ response_body["receiving"].to_f
62
74
  end
63
- alias :receiving :amount_receiving
75
+ alias_method :receiving, :amount_receiving
64
76
 
65
77
  def goal
66
- response["goal"].to_f if response["goal"]
78
+ response_body["goal"].to_f if response_body["goal"]
67
79
  end
68
80
 
69
81
  def account_type
70
- response["number"]
82
+ response_body["number"]
71
83
  end
72
- alias :number :account_type
84
+ alias_method :number, :account_type
73
85
 
74
86
  def id
75
- response["id"]
87
+ response_body["id"]
88
+ end
89
+
90
+ def number_of_patrons
91
+ response_body["npatrons"]
92
+ end
93
+ alias_method :npatrons, :number_of_patrons
94
+
95
+ def on
96
+ response_body["on"]
97
+ end
98
+
99
+ private
100
+
101
+ def response
102
+ @response ||= faraday.get("/#{username}/public.json")
103
+ end
104
+
105
+ def response_body
106
+ @response_body ||= response.body
76
107
  end
77
108
 
78
109
  end # Profile