gratitude 0.0.8 → 0.0.9

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: f98788dbd6abb9015c3714caf00069350d02015f
4
- data.tar.gz: 321b4733b5987a3f46fe0f51b9efee0a0f242d79
3
+ metadata.gz: 6612f9265596c16760a8a6a57cdf792de502ac33
4
+ data.tar.gz: 2c3fd5e87e85e5797264db76467312616129bb3c
5
5
  SHA512:
6
- metadata.gz: ba9b54097f32bcd2e898a19e97d7a2ddd3d5c576b8842777d42efbdd48dd62567d8043757ddeb5d31ac321f7533777736d4a75397c5e3f290d2ba93a9bee5a21
7
- data.tar.gz: 175a691394abc0682d316ffd86e1aaab09c7ce12cf4fcf3aec96311963c781f684bf951fdb62bf1d8c6f1393bdc088e86a6791551cb79e6d87893dcb3a3df0fb
6
+ metadata.gz: 3508b34b260ee22ad4baeb21b8db6fe09cef53082d493841f5224c4ff8d895dd5f43477ded0eb7b8c352d2876cf048e6f672a2b11188a31a0eaf20ec891053cb
7
+ data.tar.gz: ba4d68e325ea9730e3cf2429a56a69cbe6a2e8ef9ae6272065de1bce026d9aed0d4296a19c05ebf0cb3eda506d563a6322c73c3dd6dc4d436c43a902968da5c0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  ### 0.1.0 (Upcoming Stable Release)
2
2
  * Implement all aspects of the Gittip API.
3
3
 
4
+ ### 0.0.8 (10/18/2013)
5
+ * Add client authentication.
6
+ * Add ability to retrieve a user's current tips.
7
+
4
8
  ### 0.0.7 (10/13/2013)
5
9
  * Update documentation.
6
10
  * Alias new to current in Statistics class.
data/README.md CHANGED
@@ -9,7 +9,7 @@ gratitude
9
9
 
10
10
  A simple Ruby wrapper for the [Gittip API](https://github.com/gittip/www.gittip.com#api).
11
11
 
12
- **Note**: This gem is currently under development and is not ready for use in a production environment. A stable version is planned for v0.1.0. Please follow the [Changelog](CHANGELOG.md) to check the status of the project.
12
+ **Note**: This gem is currently under development. A feature complete version that implements all features of the original Gittip API is planned for v0.1.0. Please follow the [Changelog](CHANGELOG.md) to check the status of the project.
13
13
 
14
14
 
15
15
  # Installation
data/gratitude.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "httparty", "~> 0.11"
22
+ spec.add_dependency "json"
22
23
  spec.add_development_dependency "bundler", "~> 1.3"
23
24
  spec.add_development_dependency "rake"
24
25
  end
@@ -2,16 +2,53 @@ module Gratitude
2
2
  class Client
3
3
  module Tips
4
4
 
5
+ def current_tips
6
+ self.class.get(tips_url, { :basic_auth => authorization }).parsed_response
7
+ end
8
+
9
+ def current_tips_total
10
+ current_tips.inject(0) { |total, tip| total + tip["amount"].to_f }
11
+ end
12
+
13
+ def update_tips(array_of_hashes_with_usernames_and_amounts)
14
+ self.class.post(tips_url,
15
+ {
16
+ :body => prepared_tips_array(array_of_hashes_with_usernames_and_amounts).to_json,
17
+ :basic_auth => authorization,
18
+ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
19
+ })
20
+ end
21
+
22
+ def update_tips_and_prune(array_of_hashes_with_usernames_and_amounts)
23
+ self.class.post(tips_url,
24
+ {
25
+ :body => prepared_tips_array(array_of_hashes_with_usernames_and_amounts).to_json,
26
+ :basic_auth => authorization,
27
+ :query => { :also_prune => "true"},
28
+ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
29
+ })
30
+ end
31
+
5
32
  def tips_url
6
33
  "https://www.gittip.com/#{username}/tips.json"
7
34
  end
8
35
 
9
36
  def authorization
10
- { :basic_auth => { :username => api_key } }
37
+ { :username => api_key }
11
38
  end
12
39
 
13
- def current_tips
14
- self.class.get(tips_url, authorization).parsed_response
40
+ def tip_hash_based_upon(username, amount)
41
+ { "amount" => "#{amount}", "platform" => "gittip", "username" => "#{username}" }
42
+ end
43
+
44
+ def prepared_tips_array(array_of_hashes_with_usernames_and_amounts)
45
+ prepared_array = []
46
+ array_of_hashes_with_usernames_and_amounts.each do |hash|
47
+ username = hash[:username] || hash["username"]
48
+ amount = hash[:amount] || hash["amount"]
49
+ prepared_array << tip_hash_based_upon(username, amount)
50
+ end
51
+ prepared_array
15
52
  end
16
53
 
17
54
  end # Tips
@@ -1,3 +1,3 @@
1
1
  module Gratitude
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -0,0 +1 @@
1
+ {"http_interactions":[{"request":{"method":"get","uri":"https://5962b93a-5bf7-4cb6-ae6f-aa4114c5e4f2:@www.gittip.com/gratitude_test/tips.json","body":{"encoding":"US-ASCII","string":""},"headers":{}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Content-Type":["application/json"],"Date":["Sun, 20 Oct 2013 01:41:31 GMT"],"Expires":["Thu, 01 Jan 1970 00:00:00 GMT"],"Server":["Aspen! Cheroot!"],"Set-Cookie":["csrf_token=qJFOtxb2kGqZhrlXEv5QRrLcP3H0wik9; expires=Sun, 19 Oct 2014 01:41:31 GMT; Path=/","session=c08eaad1dae3407c9d31f5ca904364bd; expires=Sun, 27 Oct 2013 01:41:31 GMT; httponly; Path=/; secure"],"Vary":["Cookie"],"X-Frame-Options":["SAMEORIGIN"],"X-Gittip-Version":["10.1.35"],"Content-Length":["210"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"[\n {\n \"amount\": \"1.00\",\n \"platform\": \"gittip\",\n \"username\": \"whit537\"\n },\n {\n \"amount\": \"0.25\",\n \"platform\": \"gittip\",\n \"username\": \"JohnKellyFerguson\"\n }\n]"},"http_version":null},"recorded_at":"Sun, 20 Oct 2013 01:41:36 GMT"}],"recorded_with":"VCR 2.5.0"}
@@ -0,0 +1 @@
1
+ {"http_interactions":[{"request":{"method":"post","uri":"https://5962b93a-5bf7-4cb6-ae6f-aa4114c5e4f2:@www.gittip.com/gratitude_test/tips.json","body":{"encoding":"UTF-8","string":"[{\"amount\":\"10\",\"platform\":\"gittip\",\"username\":\"whit537\"},{\"amount\":\"4\",\"platform\":\"gittip\",\"username\":\"JohnKellyFerguson\"}]"},"headers":{"Content-Type":["application/json"],"Accept":["application/json"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Content-Type":["application/json"],"Date":["Sun, 20 Oct 2013 03:12:30 GMT"],"Expires":["Thu, 01 Jan 1970 00:00:00 GMT"],"Server":["Aspen! Cheroot!"],"Set-Cookie":["csrf_token=zpQWN7H1DlHpCQvAB9mPs7aMjXroYDOV; expires=Sun, 19 Oct 2014 03:12:30 GMT; Path=/","session=c08eaad1dae3407c9d31f5ca904364bd; expires=Sun, 27 Oct 2013 03:12:30 GMT; httponly; Path=/; secure"],"Vary":["Cookie"],"X-Frame-Options":["SAMEORIGIN"],"X-Gittip-Version":["10.1.35"],"Content-Length":["205"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"[\n {\n \"amount\": \"10\",\n \"platform\": \"gittip\",\n \"username\": \"whit537\"\n },\n {\n \"amount\": \"4\",\n \"platform\": \"gittip\",\n \"username\": \"JohnKellyFerguson\"\n }\n]"},"http_version":null},"recorded_at":"Sun, 20 Oct 2013 03:12:37 GMT"}],"recorded_with":"VCR 2.5.0"}
@@ -0,0 +1 @@
1
+ {"http_interactions":[{"request":{"method":"post","uri":"https://5962b93a-5bf7-4cb6-ae6f-aa4114c5e4f2:@www.gittip.com/gratitude_test/tips.json","body":{"encoding":"UTF-8","string":"[{\"amount\":\"5\",\"platform\":\"gittip\",\"username\":\"whit537\"}]"},"headers":{"Content-Type":["application/json"],"Accept":["application/json"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Content-Type":["application/json"],"Date":["Sun, 20 Oct 2013 03:09:02 GMT"],"Expires":["Thu, 01 Jan 1970 00:00:00 GMT"],"Server":["Aspen! Cheroot!"],"Set-Cookie":["csrf_token=DRdyOGvuZo1D9zPRfgzXAbhOpQrP03Na; expires=Sun, 19 Oct 2014 03:09:02 GMT; Path=/","session=c08eaad1dae3407c9d31f5ca904364bd; expires=Sun, 27 Oct 2013 03:09:02 GMT; httponly; Path=/; secure"],"Vary":["Cookie"],"X-Frame-Options":["SAMEORIGIN"],"X-Gittip-Version":["10.1.35"],"Content-Length":["98"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"[\n {\n \"amount\": \"5\",\n \"platform\": \"gittip\",\n \"username\": \"whit537\"\n }\n]"},"http_version":null},"recorded_at":"Sun, 20 Oct 2013 03:09:09 GMT"}],"recorded_with":"VCR 2.5.0"}
@@ -0,0 +1 @@
1
+ {"http_interactions":[{"request":{"method":"post","uri":"https://5962b93a-5bf7-4cb6-ae6f-aa4114c5e4f2:@www.gittip.com/gratitude_test/tips.json","body":{"encoding":"UTF-8","string":"[{\"amount\":\"20\",\"platform\":\"gittip\",\"username\":\"not_a_real_user\"}]"},"headers":{"Content-Type":["application/json"],"Accept":["application/json"]}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Content-Type":["application/json"],"Date":["Sun, 20 Oct 2013 03:21:36 GMT"],"Expires":["Thu, 01 Jan 1970 00:00:00 GMT"],"Server":["Aspen! Cheroot!"],"Set-Cookie":["csrf_token=iyQSAZVfmuWKaWltmYauK2Jadl8oCunm; expires=Sun, 19 Oct 2014 03:21:36 GMT; Path=/","session=c08eaad1dae3407c9d31f5ca904364bd; expires=Sun, 27 Oct 2013 03:21:36 GMT; httponly; Path=/; secure"],"Vary":["Cookie"],"X-Frame-Options":["SAMEORIGIN"],"X-Gittip-Version":["10.1.35"],"Content-Length":["141"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"[\n {\n \"amount\": \"e\",\n \"error\": \"IntegrityError\",\n \"platform\": \"gittip\",\n \"username\": \"not_a_real_user\"\n }\n]"},"http_version":null},"recorded_at":"Sun, 20 Oct 2013 03:21:43 GMT"}],"recorded_with":"VCR 2.5.0"}
@@ -7,47 +7,181 @@ describe Gratitude::Client::Tips do
7
7
 
8
8
  let(:client) { Gratitude::Client.new(:username => username, :api_key => api_key) }
9
9
 
10
- describe "#tips_url" do
11
- it "returns the correct tips_url" do
12
- expect(client.tips_url).to eq("https://www.gittip.com/gratitude_test/tips.json")
10
+ describe "methods that do not interact with the API" do
11
+
12
+ describe "#tips_url" do
13
+ it "returns the correct tips_url" do
14
+ expect(client.tips_url).to eq("https://www.gittip.com/gratitude_test/tips.json")
15
+ end
13
16
  end
14
- end
15
17
 
16
- describe "#authorization" do
17
- it "returns the correct authorization hash" do
18
- expect(client.authorization).to eq({ :basic_auth => { :username => api_key } })
18
+ describe "#authorization" do
19
+ it "returns the correct authorization hash" do
20
+ expect(client.authorization).to eq({ :username => api_key })
21
+ end
19
22
  end
20
- end
21
23
 
24
+ describe "#tip_hash_based_upon(username, amount)" do
25
+ it "returns the correct tip hash when given an integer" do
26
+ expect(client.tip_hash_based_upon("whit537", 1)).to eq(
27
+ { "amount" => "1", "platform" => "gittip", "username" => "whit537" })
28
+ end
22
29
 
23
- describe "authentication and api requests" do
30
+ it "returns the correct tip hash when given an integer in a string" do
31
+ expect(client.tip_hash_based_upon("whit537", "1")).to eq(
32
+ { "amount" => "1", "platform" => "gittip", "username" => "whit537" })
33
+ end
24
34
 
25
- let(:current_tips) { [{"amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537"},
26
- {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}] }
35
+ it "returns the correct tip hash when given a float" do
36
+ expect(client.tip_hash_based_upon("whit537", 0.25)).to eq(
37
+ { "amount" => "0.25", "platform" => "gittip", "username" => "whit537" })
38
+ end
27
39
 
28
- before do
29
- VCR.insert_cassette "tips"
30
- end
40
+ it "returns the correct tip hash when given a float" do
41
+ expect(client.tip_hash_based_upon("whit537", "0.25")).to eq(
42
+ { "amount" => "0.25", "platform" => "gittip", "username" => "whit537" })
43
+ end
44
+ end #single_tip_hash
45
+
46
+
47
+ describe "#tips_array" do
48
+
49
+ context "when using symbols as keys" do
50
+ it "returns the correct tips array when given an array with one tip" do
51
+ expect(client.prepared_tips_array([:username => "whit537", :amount => "1"])).to eq(
52
+ [{ "amount" => "1", "platform" => "gittip", "username" => "whit537" }])
53
+ end
54
+
55
+ it "returns the correct tips array when given an array with two tips" do
56
+ expect(client.prepared_tips_array([
57
+ { :username => "whit537", :amount => "1" },
58
+ { :username => "JohnKellyFerguson", :amount => "0.25" }
59
+ ])).to eq([
60
+ { "amount" => "1", "platform" => "gittip", "username" => "whit537" },
61
+ { "amount" => "0.25", "platform" => "gittip", "username" => "JohnKellyFerguson" }
62
+ ])
63
+ end
64
+ end # symbols as keys
65
+
66
+ context "when using strings as keys" do
67
+ it "returns the correct tips array when given an array with one tip" do
68
+ expect(client.prepared_tips_array(["username" => "whit537", "amount" => "1"])).to eq(
69
+ [{ "amount" => "1", "platform" => "gittip", "username" => "whit537" }])
70
+ end
71
+
72
+ it "returns the correct tips array when given an array with one tip" do
73
+ expect(client.prepared_tips_array([
74
+ { "username" => "whit537", "amount" => "1" },
75
+ { "username" => "JohnKellyFerguson", "amount" => "0.25" }
76
+ ])).to eq([
77
+ { "amount" => "1", "platform" => "gittip", "username" => "whit537" },
78
+ { "amount" => "0.25", "platform" => "gittip", "username" => "JohnKellyFerguson" }
79
+ ])
80
+ end
81
+ end # strings as keys
82
+
83
+ end #tips_array
84
+
85
+ end # methods that do not interact with the API
31
86
 
32
- after do
33
- VCR.eject_cassette
34
- end
35
87
 
36
- describe "#current_tips" do
37
- it "returns the correct array of current tips" do
38
- expect(client.current_tips).to eq (current_tips)
88
+ describe "authentication and api requests" do
89
+
90
+ context "GET Requests" do
91
+ let(:current_tips) { [{"amount"=>"1.00", "platform"=>"gittip", "username"=>"whit537"},
92
+ {"amount"=>"0.25", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}] }
93
+
94
+ before do
95
+ VCR.insert_cassette "get_tips"
39
96
  end
40
- end
41
97
 
42
- describe "#update_tip" do
43
- end
98
+ after do
99
+ VCR.eject_cassette
100
+ end
44
101
 
45
- describe "#update_tips" do
46
- end
102
+ describe "#current_tips" do
103
+ it "returns the correct array of current tips" do
104
+ expect(client.current_tips).to eq (current_tips)
105
+ end
106
+ end
47
107
 
48
- describe "#update_tips_and_prune" do
49
- end
108
+ describe "#current_tips_total" do
109
+ it "returns the correct total of current tips" do
110
+ expect(client.current_tips_total).to eq(1.25)
111
+ end
112
+ end
113
+ end #GET Requests
114
+
115
+ context "POST Requests" do
116
+
117
+ describe "#update_tips" do
118
+
119
+ context "when updating a single tip" do
120
+ let(:single_tip_response) { [{"amount"=>"5", "platform"=>"gittip", "username"=>"whit537"}] }
121
+
122
+ before do
123
+ VCR.insert_cassette "post_single_tip"
124
+ end
125
+
126
+ after do
127
+ VCR.eject_cassette
128
+ end
129
+
130
+ it "updates the correct tip information" do
131
+ expect(
132
+ client.update_tips(
133
+ [{ :username => "whit537", :amount => "5" }]
134
+ ).parsed_response).to eq(single_tip_response)
135
+ end
136
+ end #updating a single tip
137
+
138
+ context "when updating multiple tips" do
139
+ let(:multi_tip_response) { [
140
+ {"amount"=>"10", "platform"=>"gittip", "username"=>"whit537"},
141
+ {"amount"=>"4", "platform"=>"gittip", "username"=>"JohnKellyFerguson"}
142
+ ] }
143
+
144
+ before do
145
+ VCR.insert_cassette "post_multiple_tips"
146
+ end
147
+
148
+ after do
149
+ VCR.eject_cassette
150
+ end
151
+
152
+ it "updates the correct tip information" do
153
+ expect(
154
+ client.update_tips(
155
+ [{ :username => "whit537", :amount => "10" },
156
+ { :username => "JohnKellyFerguson", :amount => "4"}]
157
+ ).parsed_response).to eq(multi_tip_response)
158
+ end
159
+ end # updating multiple tips
160
+
161
+ # context "when passing in a non-existent username" do
162
+ # before do
163
+ # VCR.insert_cassette "post_tip_error"
164
+ # end
165
+
166
+ # after do
167
+ # VCR.eject_cassette
168
+ # end
169
+
170
+ # it "raises an error" do
171
+ # expect(
172
+ # client.update_tips(
173
+ # [ {:username => "not_a_real_user", :amount => "20"} ]
174
+ # ).parsed_response).to eq()
175
+ # end
176
+ # end # non-existent username
177
+
178
+ end #update_tips
179
+
180
+ describe "#update_tips_and_prune" do
181
+
182
+ end
50
183
 
184
+ end #POST Requests
51
185
 
52
186
  end # authentication and api requests
53
187
  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.8
4
+ version: 0.0.9
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: 2013-10-18 00:00:00.000000000 Z
11
+ date: 2013-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -77,11 +91,14 @@ files:
77
91
  - lib/gratitude/tips.rb
78
92
  - lib/gratitude/version.rb
79
93
  - spec/cassettes/complete_profile.json
94
+ - spec/cassettes/get_tips.json
80
95
  - spec/cassettes/goal_profile.json
81
96
  - spec/cassettes/incomplete_profile.json
82
97
  - spec/cassettes/paydays.json
98
+ - spec/cassettes/post_multiple_tips.json
99
+ - spec/cassettes/post_single_tip.json
100
+ - spec/cassettes/post_tip_error.json
83
101
  - spec/cassettes/statistics.json
84
- - spec/cassettes/tips.json
85
102
  - spec/gratitude/client_spec.rb
86
103
  - spec/gratitude/payday_spec.rb
87
104
  - spec/gratitude/profile_spec.rb
@@ -115,11 +132,14 @@ specification_version: 4
115
132
  summary: A simple Ruby wrapper for the Gittip API.
116
133
  test_files:
117
134
  - spec/cassettes/complete_profile.json
135
+ - spec/cassettes/get_tips.json
118
136
  - spec/cassettes/goal_profile.json
119
137
  - spec/cassettes/incomplete_profile.json
120
138
  - spec/cassettes/paydays.json
139
+ - spec/cassettes/post_multiple_tips.json
140
+ - spec/cassettes/post_single_tip.json
141
+ - spec/cassettes/post_tip_error.json
121
142
  - spec/cassettes/statistics.json
122
- - spec/cassettes/tips.json
123
143
  - spec/gratitude/client_spec.rb
124
144
  - spec/gratitude/payday_spec.rb
125
145
  - spec/gratitude/profile_spec.rb
@@ -1 +0,0 @@
1
- {"http_interactions":[{"request":{"method":"get","uri":"https://5962b93a-5bf7-4cb6-ae6f-aa4114c5e4f2:@www.gittip.com/gratitude_test/tips.json","body":{"encoding":"US-ASCII","string":""},"headers":{}},"response":{"status":{"code":200,"message":"OK"},"headers":{"Content-Type":["application/json"],"Date":["Tue, 15 Oct 2013 19:26:37 GMT"],"Expires":["Thu, 01 Jan 1970 00:00:00 GMT"],"Server":["Aspen! Cheroot!"],"Set-Cookie":["csrf_token=nuo6OY6TglUcv9JyVD316bT5VDsTywEL; expires=Tue, 14 Oct 2014 19:26:37 GMT; Path=/","session=c08eaad1dae3407c9d31f5ca904364bd; expires=Tue, 22 Oct 2013 19:26:36 GMT; httponly; Path=/; secure"],"Vary":["Cookie"],"X-Frame-Options":["SAMEORIGIN"],"X-Gittip-Version":["10.1.33"],"Transfer-Encoding":["chunked"],"Connection":["keep-alive"]},"body":{"encoding":"UTF-8","string":"[\n {\n \"amount\": \"1.00\",\n \"platform\": \"gittip\",\n \"username\": \"whit537\"\n },\n {\n \"amount\": \"0.25\",\n \"platform\": \"gittip\",\n \"username\": \"JohnKellyFerguson\"\n }\n]"},"http_version":null},"recorded_at":"Tue, 15 Oct 2013 19:26:37 GMT"}],"recorded_with":"VCR 2.5.0"}