gratitude 0.0.12 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +34 -0
  3. data/.rubocop.yml +34 -0
  4. data/.travis.yml +4 -1
  5. data/CHANGELOG.md +2 -2
  6. data/CONTRIBUTING.md +97 -0
  7. data/Gemfile +11 -6
  8. data/Guardfile +4 -0
  9. data/README.md +3 -0
  10. data/Rakefile +12 -10
  11. data/gratitude.gemspec +4 -4
  12. data/lib/gratitude/chart.rb +5 -5
  13. data/lib/gratitude/client.rb +2 -1
  14. data/lib/gratitude/connection.rb +4 -2
  15. data/lib/gratitude/error.rb +28 -0
  16. data/lib/gratitude/payday.rb +12 -10
  17. data/lib/gratitude/profile.rb +4 -1
  18. data/lib/gratitude/statistics.rb +18 -16
  19. data/lib/gratitude/tips.rb +42 -10
  20. data/lib/gratitude/user_chart.rb +9 -7
  21. data/lib/gratitude/version.rb +3 -1
  22. data/lib/gratitude.rb +3 -1
  23. data/spec/cassettes/charts.json +8 -5
  24. data/spec/cassettes/current_tips.json +74 -5
  25. data/spec/cassettes/current_tips_not_authenticated.json +76 -0
  26. data/spec/cassettes/paydays.json +8 -5
  27. data/spec/cassettes/profiles.json +73 -17
  28. data/spec/cassettes/prune_tips_not_authenticated.json +76 -0
  29. data/spec/cassettes/statistics.json +8 -70
  30. data/spec/cassettes/update_and_prune.json +15 -15
  31. data/spec/cassettes/update_and_prune_bad_request.json +74 -0
  32. data/spec/cassettes/update_bad_request.json +74 -0
  33. data/spec/cassettes/update_tips.json +5 -5
  34. data/spec/cassettes/update_tips_not_authenticated.json +76 -0
  35. data/spec/cassettes/user_chart_not_found.json +76 -0
  36. data/spec/cassettes/user_charts.json +147 -1
  37. data/spec/gratitude/chart_spec.rb +11 -11
  38. data/spec/gratitude/client_spec.rb +5 -3
  39. data/spec/gratitude/connection_spec.rb +2 -0
  40. data/spec/gratitude/payday_spec.rb +9 -5
  41. data/spec/gratitude/profile_spec.rb +22 -13
  42. data/spec/gratitude/statistics_spec.rb +25 -23
  43. data/spec/gratitude/tips_spec.rb +177 -40
  44. data/spec/gratitude/user_chart_spec.rb +30 -17
  45. data/spec/gratitude/version_spec.rb +2 -0
  46. data/spec/spec_helper.rb +6 -4
  47. metadata +18 -2
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Gratitude::Profile do
@@ -9,6 +11,13 @@ describe Gratitude::Profile do
9
11
  end
10
12
 
11
13
  describe "instance methods" do
14
+ context "when the requested Gittip user does not exist" do
15
+ it "raises a UsernameNotFoundError" do
16
+ expect { Gratitude::Profile.new("non_existing_user").send(:response) }
17
+ .to raise_error(Gratitude::UsernameNotFoundError)
18
+ end
19
+ end
20
+
12
21
  before { VCR.insert_cassette "profiles" }
13
22
  after { VCR.eject_cassette }
14
23
  let(:complete_profile) { Gratitude::Profile.new("JohnKellyFerguson") }
@@ -23,19 +32,19 @@ describe Gratitude::Profile do
23
32
  it "returns the correct keys in the json hash" do
24
33
  expect(complete_profile.send(:response_body).keys)
25
34
  .to eq(
26
- [
27
- "avatar",
28
- "bitcoin",
29
- "elsewhere",
30
- "giving",
31
- "goal",
32
- "id",
33
- "npatrons",
34
- "number",
35
- "on",
36
- "receiving",
37
- "username"
38
- ]
35
+ %w(
36
+ avatar
37
+ bitcoin
38
+ elsewhere
39
+ giving
40
+ goal
41
+ id
42
+ npatrons
43
+ number
44
+ on
45
+ receiving
46
+ username
47
+ )
39
48
  )
40
49
  end
41
50
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Gratitude::Statistics do
@@ -17,27 +19,27 @@ describe Gratitude::Statistics do
17
19
  it "returns the correct keys in the json hash" do
18
20
  expect(stats.send(:response_body).keys)
19
21
  .to eq(
20
- [
21
- "average_tip",
22
- "average_tippees",
23
- "escrow",
24
- "last_thursday",
25
- "nach",
26
- "nactive",
27
- "ncc",
28
- "ngivers",
29
- "noverlap",
30
- "nreceivers",
31
- "other_people",
32
- "pcc",
33
- "punc",
34
- "statements",
35
- "this_thursday",
36
- "tip_distribution_json",
37
- "tip_n",
38
- "total_backed_tips",
39
- "transfer_volume"
40
- ]
22
+ %w(
23
+ average_tip
24
+ average_tippees
25
+ escrow
26
+ last_thursday
27
+ nach
28
+ nactive
29
+ ncc
30
+ ngivers
31
+ noverlap
32
+ nreceivers
33
+ other_people
34
+ pcc
35
+ punc
36
+ statements
37
+ this_thursday
38
+ tip_distribution_json
39
+ tip_n
40
+ total_backed_tips
41
+ transfer_volume
42
+ )
41
43
  )
42
44
  end
43
45
  end
@@ -183,13 +185,13 @@ describe Gratitude::Statistics do
183
185
 
184
186
  it "has statement as a key in each hash element" do
185
187
  stats.statements.each do |statement|
186
- expect(statement.has_key?("statement")).to be(true)
188
+ expect(statement.key?("statement")).to be(true)
187
189
  end
188
190
  end
189
191
 
190
192
  it "has username as a key in each hash element" do
191
193
  stats.statements.each do |statement|
192
- expect(statement.has_key?("username")).to be(true)
194
+ expect(statement.key?("username")).to be(true)
193
195
  end
194
196
  end
195
197
  end
@@ -1,77 +1,214 @@
1
+ # encoding: utf-8
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Gratitude::Client::Tips do
4
6
  let(:username) { "gratitude_test" }
5
7
  let(:api_key) { "5962b93a-5bf7-4cb6-ae6f-aa4114c5e4f2" }
6
8
  let(:client) do
7
- Gratitude::Client.new(:username => username, :api_key => api_key)
9
+ Gratitude::Client.new(username: username, api_key: api_key)
10
+ end
11
+ let(:unauthenticated_client) do
12
+ Gratitude::Client.new(username: username, api_key: "bad_key")
13
+ end
14
+ let(:current_tips) do
15
+ [
16
+ { "amount" => "1.00",
17
+ "platform" => "gittip",
18
+ "username" => "whit537"
19
+ },
20
+ { "amount" => "0.25",
21
+ "platform" => "gittip",
22
+ "username" => "JohnKellyFerguson"
23
+ }
24
+ ]
8
25
  end
9
26
 
10
27
  describe "GET Requests" do
11
- before { VCR.insert_cassette "current_tips" }
12
- after { VCR.eject_cassette }
13
- let(:current_tips) do
14
- [
15
- {"amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537"},
16
- {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
17
- ]
18
- end
19
-
20
28
  describe "#current_tips" do
21
- it "returns the correct array of current tips" do
22
- expect(client.current_tips).to eq (current_tips)
29
+ context "when properly authenticated" do
30
+ before { VCR.insert_cassette "current_tips" }
31
+ before { client.update_tips(current_tips) }
32
+ after { VCR.eject_cassette }
33
+ it "returns the correct array of current tips" do
34
+ expect(client.current_tips).to eq(current_tips)
35
+ end
36
+ end
37
+
38
+ context "when not properly authenticated" do
39
+ before { VCR.insert_cassette "current_tips_not_authenticated" }
40
+ after { VCR.eject_cassette }
41
+
42
+ it "raises an AuthenticationError" do
43
+ expect { unauthenticated_client.current_tips }
44
+ .to raise_error(Gratitude::AuthenticationError)
45
+ end
23
46
  end
24
47
  end
25
48
 
26
49
  describe "#current_tips_total" do
50
+ before { VCR.insert_cassette "current_tips" }
51
+ after { VCR.eject_cassette }
52
+
27
53
  it "returns the correct total of current tips" do
28
54
  expect(client.current_tips_total).to eq(1.25)
29
55
  end
30
56
  end
31
- end #GET Requests
57
+ end # GET Requests
32
58
 
33
59
  describe "POST Requests" do
34
60
  describe "#update_tips" do
35
- before { VCR.insert_cassette "update_tips" }
36
- after { VCR.eject_cassette }
37
-
38
61
  let(:multiple_tips) do
39
62
  [
40
- {"amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537"},
41
- {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"},
42
- {"amount"=>"1.00", "platform"=>"gittip", "username"=>"Gittip"}
63
+ { "amount" => "1.00",
64
+ "platform" => "gittip",
65
+ "username" => "whit537"
66
+ },
67
+ { "amount" => "0.25",
68
+ "platform" => "gittip",
69
+ "username" => "JohnKellyFerguson"
70
+ },
71
+ {
72
+ "amount" => "1.00",
73
+ "platform" => "gittip",
74
+ "username" => "Gittip"
75
+ }
43
76
  ]
44
77
  end
45
78
 
46
- it "updates the correct tip information" do
47
- expect(client.update_tips(multiple_tips)).to eq(multiple_tips)
79
+ context "when not properly authenticated" do
80
+ before { VCR.insert_cassette "update_tips_not_authenticated" }
81
+ after { VCR.eject_cassette }
82
+
83
+ it "raises an AuthenticationError" do
84
+ expect { unauthenticated_client.update_tips(multiple_tips) }
85
+ .to raise_error(Gratitude::AuthenticationError)
86
+ end
48
87
  end
49
- end #update_tips
50
88
 
51
- describe "#update_tips_and_prune" do
52
- before { VCR.insert_cassette "update_and_prune" }
53
- after { VCR.eject_cassette }
89
+ context "when there are bad request parameters" do
90
+ before { VCR.insert_cassette "update_bad_request" }
91
+ after { VCR.eject_cassette }
92
+ let(:incorrect_tips) do
93
+ [
94
+ {
95
+ "amount" => "1.00",
96
+ "platform" => "gittip",
97
+ "username" => "not_a_user_so_fake"
98
+ },
99
+ {
100
+ "amount" => "0.25",
101
+ "platform" => "gittip",
102
+ "username" => "lol_this_will_be_an_error"
103
+ },
104
+ {
105
+ "amount" => "1.00",
106
+ "platform" => "gittip",
107
+ "username" => "whit537"
108
+ },
109
+ {
110
+ "amount" => "0.25",
111
+ "platform" => "gittip",
112
+ "username" => "JohnKellyFerguson"
113
+ }
114
+ ]
115
+ end
54
116
 
55
- let(:previous_tips) do
56
- [
57
- {"amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537"},
58
- {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"},
59
- {"amount"=>"1.00", "platform"=>"gittip", "username"=>"Gittip"}
60
- ]
117
+ it "raises a TipUpdateError" do
118
+ expect { client.update_tips(incorrect_tips) }
119
+ .to raise_error(Gratitude::TipUpdateError)
120
+ end
121
+ end
122
+
123
+ context "when properly authenticated" do
124
+ before { VCR.insert_cassette "update_tips" }
125
+ after { VCR.eject_cassette }
126
+
127
+ it "updates the correct tip information" do
128
+ expect(client.update_tips(multiple_tips)).to eq(multiple_tips)
129
+ end
61
130
  end
131
+ end # update_tips
132
+
133
+ describe "#update_tips_and_prune" do
62
134
  let(:pruned_tips) do
63
135
  [
64
- {"amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537"},
65
- {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
136
+ {
137
+ "amount" => "1.00",
138
+ "platform" => "gittip",
139
+ "username" => "whit537"
140
+ },
141
+ {
142
+ "amount" => "0.25",
143
+ "platform" => "gittip",
144
+ "username" => "JohnKellyFerguson"
145
+ }
66
146
  ]
67
147
  end
68
148
 
69
- it "removes tips that were not part of the request" do
70
- expect { client.update_tips_and_prune(pruned_tips) }
71
- .to change { client.current_tips }
72
- .to(pruned_tips)
149
+ context "when properly authenticated" do
150
+ before { VCR.insert_cassette "update_and_prune" }
151
+ after { VCR.eject_cassette }
152
+ let(:previous_tips) do
153
+ [
154
+ {
155
+ "amount" => "1.00",
156
+ "platform" => "gittip",
157
+ "username" => "Gittip"
158
+ },
159
+ {
160
+ "amount" => "1.00",
161
+ "platform" => "gittip",
162
+ "username" => "whit537"
163
+ },
164
+ {
165
+ "amount" => "0.25",
166
+ "platform" => "gittip",
167
+ "username" => "JohnKellyFerguson"
168
+ }
169
+ ]
170
+ end
171
+
172
+ it "removes tips that were not part of the request" do
173
+ expect { client.update_tips_and_prune(pruned_tips) }
174
+ .to change { client.current_tips }
175
+ .from(previous_tips)
176
+ .to(pruned_tips)
177
+ end
178
+ end
179
+
180
+ context "when there are bad request parameters" do
181
+ before { VCR.insert_cassette "update_and_prune_bad_request" }
182
+ after { VCR.eject_cassette }
183
+ let(:incorrect_tips) do
184
+ [
185
+ { "amount" => "1.00",
186
+ "platform" => "gittip",
187
+ "username" => "not_a_user_so_fake"
188
+ },
189
+ {
190
+ "amount" => "0.25",
191
+ "platform" => "gittip",
192
+ "username" => "will_be_an_error"
193
+ }
194
+ ]
195
+ end
196
+
197
+ it "raises a TipUpdateError" do
198
+ expect { client.update_tips_and_prune(incorrect_tips) }
199
+ .to raise_error(Gratitude::TipUpdateError)
200
+ end
73
201
  end
74
- end
75
202
 
76
- end #POST Requests
77
- end
203
+ context "when not properly authenticated" do
204
+ before { VCR.insert_cassette "prune_tips_not_authenticated" }
205
+ after { VCR.eject_cassette }
206
+
207
+ it "raises an AuthenticationError" do
208
+ expect { unauthenticated_client.update_tips_and_prune(pruned_tips) }
209
+ .to raise_error(Gratitude::AuthenticationError)
210
+ end
211
+ end
212
+ end
213
+ end # POST Requests
214
+ end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Gratitude::UserChart do
@@ -22,30 +24,42 @@ describe Gratitude::UserChart do
22
24
  .to be(Array)
23
25
  end
24
26
 
25
- it "updates the USER_CHARTS constant when it is empty" do
26
- expect { Gratitude::UserChart.all_for_user("Gittip") }
27
- .to change { Gratitude::UserChart::USER_CHARTS.size }.from(0)
28
- end
27
+ context "when the requested Gittip user exists" do
28
+ it "updates the USER_CHARTS constant when it is empty" do
29
+ expect { Gratitude::UserChart.all_for_user("Gittip") }
30
+ .to change { Gratitude::UserChart::USER_CHARTS.size }.from(0)
31
+ end
32
+
33
+ it "its array should be comprised of User_Chart objects" do
34
+ Gratitude::UserChart.all_for_user("Gittip").each do |user_chart|
35
+ expect(user_chart.class).to eq(Gratitude::UserChart)
36
+ end
37
+ end
29
38
 
30
- it "its array should be comprised of User_Chart objects" do
31
- Gratitude::UserChart.all_for_user("Gittip").each do |user_chart|
32
- expect(user_chart.class).to eq(Gratitude::UserChart)
39
+ it "only includes charts for a given username" do
40
+ Gratitude::UserChart.all_for_user("whit537")
41
+ Gratitude::UserChart.all_for_user("Gittip").each do |user_chart|
42
+ expect(user_chart.username).to eq("Gittip")
43
+ end
33
44
  end
34
45
  end
35
46
 
36
- it "only includes charts for a given username" do
37
- Gratitude::UserChart.all_for_user("whit537")
38
- Gratitude::UserChart.all_for_user("Gittip").each do |user_chart|
39
- expect(user_chart.username).to eq("Gittip")
47
+ context "when the requested Gittip user does not exist" do
48
+ before { VCR.insert_cassette "user_chart_not_found" }
49
+ after { VCR.eject_cassette }
50
+
51
+ it "raises a UsernameNotFoundError" do
52
+ expect { Gratitude::UserChart.all_for_user("non_existing_user") }
53
+ .to raise_error(Gratitude::UsernameNotFoundError)
40
54
  end
41
55
  end
42
56
  end
43
57
 
44
-
45
58
  describe "#sort_by_date_for_user" do
46
59
  it "places the newest user chart before the oldest user chart" do
47
60
  expect(Gratitude::UserChart.sort_by_date_for_user("Gittip").first.date)
48
- .to be > (Gratitude::UserChart.sort_by_date_for_user("Gittip").last.date)
61
+ .to be >
62
+ (Gratitude::UserChart.sort_by_date_for_user("Gittip").last.date)
49
63
  end
50
64
  end
51
65
 
@@ -63,21 +77,20 @@ describe Gratitude::UserChart do
63
77
  end
64
78
  end
65
79
  end
80
+
66
81
  describe "initialization and instance methods" do
67
82
 
68
83
  it "adds the initialized object to the CHARTS constant" do
69
- expect { Gratitude::UserChart.new() }
70
- .to change{ Gratitude::UserChart::USER_CHARTS.size }.by(1)
84
+ expect { Gratitude::UserChart.new }
85
+ .to change { Gratitude::UserChart::USER_CHARTS.size }.by(1)
71
86
  end
72
87
 
73
88
  let(:user_chart) do
74
89
  Gratitude::UserChart.new(
75
- {
76
90
  "username" => "Gittip",
77
91
  "date" => "2014-03-27",
78
92
  "npatrons" => 137,
79
93
  "receipts" => 416.94
80
- }
81
94
  )
82
95
  end
83
96
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe Gratitude do
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,9 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ # encoding: utf-8
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
4
 
3
5
  # Coveralls
4
- require 'coveralls'
6
+ require "coveralls"
5
7
  Coveralls.wear!
6
8
 
7
9
  # dependencies
@@ -13,8 +15,8 @@ require "webmock"
13
15
 
14
16
  # VCR config
15
17
  VCR.configure do |c|
16
- c.cassette_library_dir = 'spec/cassettes'
18
+ c.cassette_library_dir = "spec/cassettes"
17
19
  c.hook_into :webmock
18
20
  c.default_cassette_options = { record: :new_episodes, serialize_with: :json }
19
- c.default_cassette_options = { re_record_interval: 604800 }
21
+ c.default_cassette_options = { re_record_interval: 604_800 }
20
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gratitude
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Kelly Ferguson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -88,9 +88,12 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".hound.yml"
91
92
  - ".rspec"
93
+ - ".rubocop.yml"
92
94
  - ".travis.yml"
93
95
  - CHANGELOG.md
96
+ - CONTRIBUTING.md
94
97
  - Gemfile
95
98
  - Guardfile
96
99
  - LICENSE.txt
@@ -102,6 +105,7 @@ files:
102
105
  - lib/gratitude/chart.rb
103
106
  - lib/gratitude/client.rb
104
107
  - lib/gratitude/connection.rb
108
+ - lib/gratitude/error.rb
105
109
  - lib/gratitude/payday.rb
106
110
  - lib/gratitude/profile.rb
107
111
  - lib/gratitude/statistics.rb
@@ -110,11 +114,17 @@ files:
110
114
  - lib/gratitude/version.rb
111
115
  - spec/cassettes/charts.json
112
116
  - spec/cassettes/current_tips.json
117
+ - spec/cassettes/current_tips_not_authenticated.json
113
118
  - spec/cassettes/paydays.json
114
119
  - spec/cassettes/profiles.json
120
+ - spec/cassettes/prune_tips_not_authenticated.json
115
121
  - spec/cassettes/statistics.json
116
122
  - spec/cassettes/update_and_prune.json
123
+ - spec/cassettes/update_and_prune_bad_request.json
124
+ - spec/cassettes/update_bad_request.json
117
125
  - spec/cassettes/update_tips.json
126
+ - spec/cassettes/update_tips_not_authenticated.json
127
+ - spec/cassettes/user_chart_not_found.json
118
128
  - spec/cassettes/user_charts.json
119
129
  - spec/gratitude/chart_spec.rb
120
130
  - spec/gratitude/client_spec.rb
@@ -153,11 +163,17 @@ summary: A simple Ruby wrapper for the Gittip API.
153
163
  test_files:
154
164
  - spec/cassettes/charts.json
155
165
  - spec/cassettes/current_tips.json
166
+ - spec/cassettes/current_tips_not_authenticated.json
156
167
  - spec/cassettes/paydays.json
157
168
  - spec/cassettes/profiles.json
169
+ - spec/cassettes/prune_tips_not_authenticated.json
158
170
  - spec/cassettes/statistics.json
159
171
  - spec/cassettes/update_and_prune.json
172
+ - spec/cassettes/update_and_prune_bad_request.json
173
+ - spec/cassettes/update_bad_request.json
160
174
  - spec/cassettes/update_tips.json
175
+ - spec/cassettes/update_tips_not_authenticated.json
176
+ - spec/cassettes/user_chart_not_found.json
161
177
  - spec/cassettes/user_charts.json
162
178
  - spec/gratitude/chart_spec.rb
163
179
  - spec/gratitude/client_spec.rb