buff 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,5 @@
1
1
  require 'spec_helper'
2
2
 
3
-
4
3
  describe Buff::Client do
5
4
  let(:id) { "5160746d54f04a5e3a00000f" }
6
5
 
@@ -14,95 +13,6 @@ describe Buff::Client do
14
13
  end
15
14
  end
16
15
 
17
- describe "#user_info" do
18
- let(:rash) { subject.user_info }
19
-
20
- before(:each) do
21
- url = "#{ base_path }/user.json"
22
- stub_with_to_return(:get, url, "user_authenticated.txt")
23
- end
24
-
25
- it "returns a Rash object" do
26
- rash.class.should eq(Buff::UserInfo)
27
- end
28
-
29
- it "provides an accessor for plan" do
30
- rash.plan.should eq("free")
31
- end
32
- end
33
-
34
- describe "#profiles" do
35
- let(:rash) { Buff::Client.new("some_token").profiles }
36
-
37
- before(:each) do
38
- url = "#{ base_path }/profiles.json"
39
- stub_with_to_return(:get, url, 'profile_authenticated.txt')
40
- end
41
-
42
- it "makes the correct url request" do
43
- subject.profiles
44
- end
45
-
46
- it "returns a Rash collection object" do
47
- rash[0].class.should eq(Buff::Profile)
48
- end
49
-
50
- it "provides an accessor for plan" do
51
- rash[0].service.should eq("twitter")
52
- end
53
- end
54
-
55
- describe "#profile_by_id" do
56
- let(:id) { "5160746d54f04a5e3a00000f" }
57
- before(:each) do
58
- url = "#{base_path}/profiles/#{id}.json"
59
- fixture_name = "profiles_by_id.txt"
60
- stub_with_to_return(:get, url, fixture_name)
61
- end
62
-
63
- let(:rash) { Buff::Client.new("some_token").profile_by_id(id) }
64
-
65
- it "returns a rash collection" do
66
- rash.class.should eq(Buff::Profile)
67
- end
68
-
69
- it "accesses formatted service" do
70
- rash.formatted_service.should eq("Twitter")
71
- end
72
- end
73
-
74
- describe "#profile_schedules_by_id" do
75
- before(:each) do
76
- url = "#{base_path}/profiles/#{id}/schedules.json"
77
- fixture_name = 'profile_schedules_by_id.txt'
78
- stub_with_to_return(:get, url, fixture_name)
79
- end
80
-
81
- let(:rash) { Buff::Client.new("some_token").profile_schedules_by_id(id) }
82
-
83
- it "returns a rash collection" do
84
- rash[0].class.should eq(Buff::Schedule)
85
- end
86
-
87
- it "accesses days" do
88
- expect(rash[0].days).to include("mon")
89
- end
90
-
91
- it "accesses times" do
92
- expect(rash[0].times).to include("06:13")
93
- end
94
- end
95
-
96
- describe "#set_schedules" do
97
- #not yet implemented
98
- xit "throw error if schedules is empty" do
99
- lambda {
100
- Buff::Client.new("some_token").set_schedules(id) }.
101
- should raise_error(ArgumentError)
102
-
103
- end
104
- end
105
-
106
16
  describe "#info" do
107
17
  before do
108
18
  stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token").
@@ -118,141 +28,3 @@ describe Buff::Client do
118
28
  end
119
29
  end
120
30
  end
121
-
122
- describe Buff::Schedules do
123
- before do
124
- @schedule = JSON.parse <<EOF
125
- {
126
- "days" : [
127
- "mon",
128
- "tue",
129
- "wed",
130
- "thu",
131
- "fri"
132
- ],
133
- "times" : [
134
- "12:00",
135
- "17:00",
136
- "18:00"
137
- ]
138
- }
139
- EOF
140
-
141
- @sample_schedules = JSON.parse <<EOF
142
- { "schedules" : [{
143
- "days" : [
144
- "mon",
145
- "tue",
146
- "wed",
147
- "thu",
148
- "fri"
149
- ],
150
- "times" : [
151
- "12:00",
152
- "17:00",
153
- "18:00"
154
- ]
155
- },
156
- {
157
- "days" : [
158
- "mon",
159
- "tue",
160
- "wed",
161
- "thu",
162
- "fri"
163
- ],
164
- "times" : [
165
- "12:00",
166
- "17:00",
167
- "18:00"
168
- ]
169
- }]
170
- }
171
- EOF
172
- end
173
-
174
- it "accepts an array of days" do
175
- lambda {
176
- schedules = Buff::Schedules.new
177
- schedules << Buff::Schedule.new
178
- }.should_not raise_error
179
- end
180
-
181
- it "dumping a double schedule yields correct json" do
182
- schedules = Buff::Schedules.new
183
- schedules << @schedule << @schedule
184
- @sample_schedules = @sample_schedules.to_json
185
-
186
- schedules.dump.should eq(@sample_schedules)
187
- end
188
- end
189
-
190
- describe Buff::Client::Core do
191
-
192
- let(:client) { Buff::Client.new("some_token") }
193
- describe "#get" do
194
- it "delegates to #handle_response_code when code != 200" do
195
- stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token").
196
- to_return(:status => 403, :body => "", :headers => {})
197
- client.should_receive(:handle_response_code).once
198
- client.info
199
- end
200
-
201
-
202
- it "does not delegate to #handle_response_code when code = 200" do
203
- stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token").
204
- to_return(fixture("link.txt"))
205
- client.should_not_receive(:handle_response_code)
206
- client.info
207
- end
208
- end
209
-
210
- describe "#post" do
211
-
212
- it "connects to the correct endpoint" do
213
-
214
- #TODO improve test
215
- response = %Q[{"success": true, "message": "Schedule saved successfully"}]
216
- id = "4eb854340acb04e870000010"
217
- stub_request(:post, "#{ base_path }/profiles/#{id}/schedules/update.json?access_token=some_token").
218
- with(:body => {"schedules"=>"schedules[0][days][]=mon&schedules[0][days][]=tue&schedules[0][days][]=wed&schedules[0][times][]=12%3A00&schedules[0][times][]=17%3A00&schedules[0][times][]=18%3A00"},
219
- :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.8.7'}).
220
- to_return(:status => 200, :body => response, :headers => {})
221
- client.set_schedules(id, :schedules => sample_schedules).success.
222
- should eq(true)
223
- end
224
-
225
- xit "does not delegate to #handle_response_code when code = 200" do
226
- url = "#{base_path}/info/configuration.json"
227
- fixture_name = "link.txt"
228
- stub_with_to_return(:get, url, fixture_name)
229
- client.should_not_receive(:handle_response_code)
230
- client.info
231
- end
232
-
233
- xit "transforms sample_schedule into correct formatted url" do
234
- u = Addressable::URI.new
235
- u.query_values = {schedules: sample_schedules[0]}
236
- u.query.should eq(post_data)
237
- end
238
- end
239
-
240
- describe "#handle_response_code" do
241
- context "fails gracefully with undocumented responses" do
242
- it "responds to 401 unauthorized response" do
243
- id = "4eb8565e0acb04bb82000004"
244
- url = "#{base_path}/updates/#{id}.json?access_token=some_token"
245
- stub_with_to_return(:get, url, "update_by_id_non_auth.txt")
246
- lambda { client.update_by_id(id) }.
247
- should raise_error(Buff::APIError)
248
- end
249
- end
250
- end
251
-
252
- describe "error_table" do
253
- it "should report 1001 as appropriate message" do
254
- table = Buff::Client::Core.error_table
255
- table['1001'].should eq("Access token required.")
256
- end
257
- end
258
- end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Buff::Client::Core do
4
+
5
+ let(:client) { Buff::Client.new("some_token") }
6
+ describe "#get" do
7
+ it "delegates to #handle_response_code when code != 200" do
8
+ stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token").
9
+ to_return(:status => 403, :body => "", :headers => {})
10
+ client.should_receive(:handle_response_code).once
11
+ client.info
12
+ end
13
+
14
+
15
+ it "does not delegate to #handle_response_code when code = 200" do
16
+ stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token").
17
+ to_return(fixture("link.txt"))
18
+ client.should_not_receive(:handle_response_code)
19
+ client.info
20
+ end
21
+ end
22
+
23
+ describe "#post" do
24
+
25
+ it "connects to the correct endpoint" do
26
+
27
+ #TODO improve test
28
+ response = %Q[{"success": true, "message": "Schedule saved successfully"}]
29
+ id = "4eb854340acb04e870000010"
30
+ stub_request(:post, "#{ base_path }/profiles/#{id}/schedules/update.json?access_token=some_token").
31
+ with(:body => {"schedules"=>"schedules[0][days][]=mon&schedules[0][days][]=tue&schedules[0][days][]=wed&schedules[0][times][]=12%3A00&schedules[0][times][]=17%3A00&schedules[0][times][]=18%3A00"},
32
+ :headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Faraday v0.8.7'}).
33
+ to_return(:status => 200, :body => response, :headers => {})
34
+ client.set_schedules(id, :schedules => sample_schedules).success.
35
+ should eq(true)
36
+ end
37
+
38
+ it "does not delegate to #handle_response_code when code = 200" do
39
+ url = "#{base_path}/info/configuration.json"
40
+ fixture_name = "link.txt"
41
+ stub_with_to_return(:get, url, fixture_name)
42
+ client.should_not_receive(:handle_response_code)
43
+ client.info
44
+ end
45
+
46
+ end
47
+
48
+ describe "#handle_response_code" do
49
+ context "fails gracefully with undocumented responses" do
50
+ it "responds to 401 unauthorized response" do
51
+ id = "4eb8565e0acb04bb82000004"
52
+ url = "#{base_path}/updates/#{id}.json?access_token=some_token"
53
+ stub_with_to_return(:get, url, "update_by_id_non_auth.txt")
54
+ lambda { client.update_by_id(id) }.
55
+ should raise_error(Buff::APIError)
56
+ end
57
+ end
58
+ end
59
+
60
+ end
data/spec/spec_helper.rb CHANGED
@@ -20,6 +20,88 @@ schedules[0][days][]=mon&schedules[0][days][]=tue&schedules[0][days][]=wed&sched
20
20
  EOF
21
21
  end
22
22
 
23
+ def modify_update_response
24
+ response =<<EOF
25
+ {
26
+ "success" : true,
27
+ "buffer_count" : 10,
28
+ "buffer_percentage" : 20,
29
+ "update" : {
30
+ "id" : "4ecda256512f7ee521000004",
31
+ "client_id" : "4f850cc93733aa9301000002",
32
+ "created_at" : 1320703582,
33
+ "day" : "Saturday 26th November",
34
+ "due_at" : 1320742680,
35
+ "due_time" : "11:05 am",
36
+ "media" : {
37
+ "link" : "http://google.com",
38
+ "title" : "Google",
39
+ "description" : "The google homepage"
40
+ },
41
+ "profile_id" : "4eb854340acb04e870000010",
42
+ "profile_service" : "twitter",
43
+ "status" : "buffer",
44
+ "text" : "This is an edited update",
45
+ "text_formatted" : "This is an edited update",
46
+ "user_id" : "4eb9276e0acb04bb81000067",
47
+ "via" : "api"
48
+ }
49
+ }
50
+ EOF
51
+ end
52
+
53
+ def create_update_return_body
54
+ create_update_return_body =<<EOF
55
+ {
56
+ "success" : true,
57
+ "buffer_count" : 10,
58
+ "buffer_percentage" : 20,
59
+ "updates" : [{
60
+ "id" : "4ecda256512f7ee521000004",
61
+ "created_at" : 1320703582,
62
+ "day" : "Saturday 26th November",
63
+ "due_at" : 1320742680,
64
+ "due_time" : "11:05 am",
65
+ "media" : {
66
+ "link" : "http://google.com",
67
+ "title" : "Google",
68
+ "description" : "The google homepage"
69
+ },
70
+ "profile_id" : "4eb854340acb04e870000010",
71
+ "profile_service" : "twitter",
72
+ "status" : "buffer",
73
+ "text" : "This is an example update",
74
+ "text_formatted" : "This is an example update",
75
+ "user_id" : "4eb9276e0acb04bb81000067",
76
+ "via" : "api"
77
+ }
78
+ ]
79
+ }
80
+ EOF
81
+ end
82
+ def reorder_updates_body_response
83
+ return_body =<<EOF
84
+ {
85
+ "success" : true,
86
+ "updates" : [{
87
+ "id" : "4eb854340acb04e870000010",
88
+ "created_at" : 1320703582,
89
+ "day" : "Saturday 5th November",
90
+ "due_at" : 1320742680,
91
+ "due_time" : "08:01 am",
92
+ "profile_id" : "4eb854340acb04e870000010",
93
+ "profile_service" : "twitter",
94
+ "status" : "buffer",
95
+ "text" : "3 Incredible Stories Made Possible Through Twitter j.mp/u...",
96
+ "text_formatted" : "3 Incredible Stories Made Possible Through Twit...",
97
+ "user_id" : "4eb9276e0acb04bb81000067",
98
+ "via" : "safari"
99
+ }
100
+ ]
101
+ }
102
+ EOF
103
+ end
104
+
23
105
  def sample_schedules2
24
106
  [{ days: %w[mon tue wed],
25
107
  times: %w[12:00 17:00 18:00]},
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZPH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-21 00:00:00.000000000 Z
11
+ date: 2013-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -216,6 +216,7 @@ files:
216
216
  - .gitignore
217
217
  - .ruby-version
218
218
  - .travis.yml
219
+ - API_COVERAGE.md
219
220
  - Gemfile
220
221
  - Guardfile
221
222
  - LICENSE.txt
@@ -223,17 +224,35 @@ files:
223
224
  - Rakefile
224
225
  - buff.gemspec
225
226
  - lib/buff.rb
227
+ - lib/buff/client.rb
226
228
  - lib/buff/core.rb
229
+ - lib/buff/datastructure.rb
227
230
  - lib/buff/encode.rb
228
231
  - lib/buff/error.rb
232
+ - lib/buff/info.rb
229
233
  - lib/buff/link.rb
230
234
  - lib/buff/profile.rb
231
235
  - lib/buff/update.rb
232
236
  - lib/buff/user.rb
233
237
  - lib/buff/version.rb
238
+ - spec/fixtures/destroy.txt
239
+ - spec/fixtures/info.txt
240
+ - spec/fixtures/interactions_by_update_id.txt
241
+ - spec/fixtures/link.txt
242
+ - spec/fixtures/profile_authenticated.txt
243
+ - spec/fixtures/profile_schedules_by_id.txt
244
+ - spec/fixtures/profiles_by_id.txt
245
+ - spec/fixtures/update_by_id.txt
246
+ - spec/fixtures/update_by_id_non_auth.txt
247
+ - spec/fixtures/updates_by_profile_id.txt
248
+ - spec/fixtures/updates_by_profile_id_pending.txt
249
+ - spec/fixtures/user_authenticated.txt
234
250
  - spec/lib/buff/encode_spec.rb
235
251
  - spec/lib/buff/link_spec.rb
252
+ - spec/lib/buff/profile_spec.rb
253
+ - spec/lib/buff/schedule_spec.rb
236
254
  - spec/lib/buff/update_spec.rb
255
+ - spec/lib/buff/user_spec.rb
237
256
  - spec/lib/buff_spec.rb
238
257
  - spec/lib/core_spec.rb
239
258
  - spec/spec_helper.rb
@@ -261,9 +280,24 @@ signing_key:
261
280
  specification_version: 4
262
281
  summary: Buff is an API Wrapper Gem for Bufferapp.com's API
263
282
  test_files:
283
+ - spec/fixtures/destroy.txt
284
+ - spec/fixtures/info.txt
285
+ - spec/fixtures/interactions_by_update_id.txt
286
+ - spec/fixtures/link.txt
287
+ - spec/fixtures/profile_authenticated.txt
288
+ - spec/fixtures/profile_schedules_by_id.txt
289
+ - spec/fixtures/profiles_by_id.txt
290
+ - spec/fixtures/update_by_id.txt
291
+ - spec/fixtures/update_by_id_non_auth.txt
292
+ - spec/fixtures/updates_by_profile_id.txt
293
+ - spec/fixtures/updates_by_profile_id_pending.txt
294
+ - spec/fixtures/user_authenticated.txt
264
295
  - spec/lib/buff/encode_spec.rb
265
296
  - spec/lib/buff/link_spec.rb
297
+ - spec/lib/buff/profile_spec.rb
298
+ - spec/lib/buff/schedule_spec.rb
266
299
  - spec/lib/buff/update_spec.rb
300
+ - spec/lib/buff/user_spec.rb
267
301
  - spec/lib/buff_spec.rb
268
302
  - spec/lib/core_spec.rb
269
303
  - spec/spec_helper.rb