buffer 0.0.1 → 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 (54) hide show
  1. checksums.yaml +7 -0
  2. data/.bufferapprc.template +23 -0
  3. data/.gitignore +6 -0
  4. data/.rubocop.yml +18 -0
  5. data/.ruby-version +1 -0
  6. data/.travis.yml +5 -0
  7. data/API_COVERAGE.md +19 -0
  8. data/Gemfile +1 -1
  9. data/Guardfile +10 -0
  10. data/{LICENSE → LICENSE.txt} +1 -1
  11. data/README.md +62 -80
  12. data/Rakefile +25 -1
  13. data/TODO.md +3 -0
  14. data/bin/buffer +35 -0
  15. data/buffer.gemspec +26 -16
  16. data/lib/buffer/client.rb +26 -0
  17. data/lib/buffer/core.rb +64 -0
  18. data/lib/buffer/datastructure.rb +18 -0
  19. data/lib/buffer/encode.rb +33 -0
  20. data/lib/buffer/error.rb +10 -0
  21. data/lib/buffer/info.rb +10 -0
  22. data/lib/buffer/link.rb +10 -0
  23. data/lib/buffer/profile.rb +27 -0
  24. data/lib/buffer/update.rb +75 -0
  25. data/lib/buffer/user.rb +9 -0
  26. data/lib/buffer/version.rb +1 -1
  27. data/lib/buffer.rb +16 -102
  28. data/spec/fixtures/destroy.txt +10 -0
  29. data/spec/fixtures/info.txt +10 -0
  30. data/spec/fixtures/interactions_by_update_id.txt +10 -0
  31. data/spec/fixtures/link.txt +12 -0
  32. data/spec/fixtures/profile_authenticated.txt +11 -0
  33. data/spec/fixtures/profile_schedules_by_id.txt +10 -0
  34. data/spec/fixtures/profiles_by_id.txt +10 -0
  35. data/spec/fixtures/update_by_id.txt +10 -0
  36. data/spec/fixtures/update_by_id_non_auth.txt +9 -0
  37. data/spec/fixtures/updates_by_profile_id.txt +10 -0
  38. data/spec/fixtures/updates_by_profile_id_pending.txt +10 -0
  39. data/spec/fixtures/user_authenticated.txt +19 -0
  40. data/spec/lib/buffer/encode_spec.rb +42 -0
  41. data/spec/lib/buffer/link_spec.rb +22 -0
  42. data/spec/lib/buffer/profile_spec.rb +87 -0
  43. data/spec/lib/buffer/schedule_spec.rb +80 -0
  44. data/spec/lib/buffer/update_spec.rb +227 -0
  45. data/spec/lib/buffer/user_spec.rb +26 -0
  46. data/spec/lib/buffer_spec.rb +30 -0
  47. data/spec/lib/core_spec.rb +60 -0
  48. data/spec/spec_helper.rb +171 -0
  49. metadata +215 -67
  50. data/spec/buffer_spec.rb +0 -354
  51. data/spec/fixtures/create_body.txt +0 -1
  52. data/spec/fixtures/success.json +0 -1
  53. data/spec/fixtures/user.json +0 -1
  54. data/spec/helper.rb +0 -43
data/spec/buffer_spec.rb DELETED
@@ -1,354 +0,0 @@
1
- require 'helper'
2
-
3
- describe Buffer::Client do
4
-
5
- describe 'new' do
6
-
7
- it 'accepts a token' do
8
- client = Buffer::Client.new 'some_token'
9
- client.token.should eq('some_token')
10
- end
11
-
12
- it 'rejects an integer token' do
13
- lambda { client = Buffer::Client.new 123 }.should raise_error
14
- end
15
-
16
- it 'rejects an array token' do
17
- lambda { client = Buffer::Client.new [123, 'hello'] }.should raise_error
18
- end
19
-
20
- it 'rejects an hash token' do
21
- lambda { client = Buffer::Client.new :test => 123 }.should raise_error
22
- end
23
-
24
- end
25
-
26
- describe 'api' do
27
-
28
- subject do
29
- Buffer::Client.new 'some_token'
30
- end
31
-
32
- it 'is a method' do
33
- subject.respond_to?(:api).should be_true
34
- end
35
-
36
- describe 'api :get' do
37
-
38
- before do
39
- stub_get('user.json').
40
- with(:query => {:access_token => 'some_token'}).
41
- to_return(
42
- :body => fixture('user.json'),
43
- :headers => {:content_type => 'application/json; charset=utf-8'})
44
-
45
- stub_get('non_existent.json').
46
- with(:query => {:access_token => 'some_token'}).
47
- to_return(
48
- :body => '',
49
- :headers => {:content_type => 'application/json; charset=utf-8'})
50
-
51
- stub_get('mangled.json').
52
- with(:query => {:access_token => 'some_token'}).
53
- to_return(
54
- :body => '{dfpl:[}233]',
55
- :headers => {:content_type => 'application/json; charset=utf-8'})
56
- end
57
-
58
- it 'makes correct request to user.json with access token' do
59
- subject.api :get, 'user.json'
60
- a_get('user.json').
61
- with(:query => {:access_token => 'some_token'}).
62
- should have_been_made
63
- end
64
-
65
- it 'makes correct request when passed user' do
66
- subject.api :get, 'user'
67
- a_get('user.json').
68
- with(:query => {:access_token => 'some_token'}).
69
- should have_been_made
70
- end
71
-
72
- it 'returns correct parsed object' do
73
- res = subject.api :get, 'user'
74
- target = begin
75
- MultiJson.load fixture('user.json')
76
- end
77
- res.should eq(target)
78
- end
79
-
80
- it 'returns nil from non existent endpoint' do
81
- res = subject.api :get, 'non_existent'
82
- res.should eq(nil)
83
- end
84
-
85
- it 'returns nil from mangled data' do
86
- res = subject.api :get, 'mangled'
87
- res.should eq(nil)
88
- end
89
-
90
- end
91
-
92
- describe 'api :post' do
93
-
94
- before do
95
- stub_post('updates/create.json').
96
- with(
97
- :query => {:access_token => 'some_token'},
98
- :body => {
99
- "media"=>{"link"=>"http://google.com"},
100
- "profile_ids"=>[
101
- "4eb854340acb04e870000010",
102
- "4eb9276e0acb04bb81000067"],
103
- "text"=>"This is an example update"}).
104
- to_return(
105
- :body => fixture('success.json'),
106
- :status => 200)
107
-
108
- stub_post('updates/creatify.json').
109
- with(
110
- :query => {:access_token => 'some_token'},
111
- :body => {
112
- "media"=>{"link"=>"http://google.com"},
113
- "profile_ids"=>[
114
- "4eb854340acb04e870000010",
115
- "4eb9276e0acb04bb81000067"],
116
- "text"=>"This is an example update"}).
117
- to_return(
118
- :status => 200)
119
-
120
- stub_request(
121
- :post,
122
- "https://api.bufferapp.com/1/updates/create.json?access_token=some_token").
123
- with(:body => {"profile_ids"=>["fdf", "1"], "text"=>["a237623", "asb"]},
124
- :headers => {
125
- 'Accept'=>'*/*',
126
- 'Content-Type'=>'application/x-www-form-urlencoded',
127
- 'User-Agent'=>'Ruby'}).
128
- to_return(:status => 200, :body => "", :headers => {})
129
- end
130
-
131
- it 'should make the correct POST to updates/create.json' do
132
- subject.api :post,
133
- 'updates/create.json',
134
- :text => "This is an example update",
135
- :profile_ids => [
136
- '4eb854340acb04e870000010',
137
- '4eb9276e0acb04bb81000067'],
138
- :media => {:link => "http://google.com"}
139
- a_post('updates/create.json').
140
- with(
141
- :query => {:access_token => 'some_token'},
142
- :body => fixture_contents('create_body.txt')).
143
- should have_been_made
144
- end
145
-
146
- it 'should return a correctly parsed object' do
147
- res = subject.api :post,
148
- 'updates/create.json',
149
- :text => "This is an example update",
150
- :profile_ids => [
151
- '4eb854340acb04e870000010',
152
- '4eb9276e0acb04bb81000067'],
153
- :media => {:link => "http://google.com"}
154
- res['success'].should be_true
155
- end
156
-
157
- it 'should return nil from non existent endpoint' do
158
- res = subject.api :post,
159
- 'updates/creatify.json',
160
- :text => "This is an example update",
161
- :profile_ids => [
162
- '4eb854340acb04e870000010',
163
- '4eb9276e0acb04bb81000067'],
164
- :media => {:link => "http://google.com"}
165
- res.should eq(nil)
166
- end
167
-
168
- it 'should return nil when passes crap' do
169
- res = subject.api :post,
170
- 'updates/create.json',
171
- :text => [:a237623, 'asb'],
172
- :profile_ids => ['fdf', '1']
173
- res.should eq(nil)
174
- end
175
-
176
- end
177
-
178
- end
179
-
180
- describe 'get' do
181
-
182
- subject do
183
- Buffer::Client.new 'some_token'
184
- end
185
-
186
- it 'is a method' do
187
- subject.respond_to?(:get).should be_true
188
- end
189
-
190
- before do
191
- stub_get('user.json').
192
- with(:query => {:access_token => 'some_token'}).
193
- to_return(
194
- :body => fixture('user.json'),
195
- :headers => {:content_type => 'application/json; charset=utf-8'})
196
- end
197
-
198
- it 'makes correct request to user.json with access token' do
199
- subject.get 'user.json'
200
- a_get('user.json').
201
- with(:query => {:access_token => 'some_token'}).
202
- should have_been_made
203
- end
204
-
205
- it 'makes correct request when passed user' do
206
- subject.get 'user'
207
- a_get('user.json').
208
- with(:query => {:access_token => 'some_token'}).
209
- should have_been_made
210
- end
211
-
212
- end
213
-
214
- describe 'post' do
215
-
216
- subject do
217
- Buffer::Client.new 'some_token'
218
- end
219
-
220
- it 'is a method' do
221
- subject.respond_to?(:post).should be_true
222
- end
223
-
224
- before do
225
- stub_post('updates/create.json').
226
- with(
227
- :query => {:access_token => 'some_token'},
228
- :body => {
229
- "media"=>{"link"=>"http://google.com"},
230
- "profile_ids"=>[
231
- "4eb854340acb04e870000010",
232
- "4eb9276e0acb04bb81000067"],
233
- "text"=>"This is an example update"}).
234
- to_return(
235
- :body => fixture('success.json'),
236
- :status => 200)
237
- end
238
-
239
- it 'should make the correct POST to updates/create.json' do
240
- subject.post 'updates/create.json',
241
- :text => "This is an example update",
242
- :profile_ids => ['4eb854340acb04e870000010', '4eb9276e0acb04bb81000067'],
243
- :media => {:link => "http://google.com"}
244
- a_post('updates/create.json').
245
- with(
246
- :query => {:access_token => 'some_token'},
247
- :body => fixture_contents('create_body.txt')).
248
- should have_been_made
249
- end
250
-
251
- end
252
-
253
- end
254
-
255
- describe Buffer::User do
256
-
257
- describe 'new' do
258
-
259
- it 'accepts a token' do
260
- user = Buffer::User.new 'some_token'
261
- user.token.should eq('some_token')
262
- end
263
-
264
- it 'rejects an integer token' do
265
- lambda { user = Buffer::User.new 123 }.should raise_error
266
- end
267
-
268
- it 'rejects an array token' do
269
- lambda { user = Buffer::User.new [123, 'hello'] }.should raise_error
270
- end
271
-
272
- it 'rejects an hash token' do
273
- lambda { user = Buffer::User.new :test => 123 }.should raise_error
274
- end
275
-
276
- end
277
-
278
- describe 'helpers' do
279
-
280
- subject do
281
- Buffer::User.new 'some_token'
282
- end
283
-
284
- before do
285
- stub_get('user.json').
286
- with(:query => {:access_token => 'some_token'}).
287
- to_return(
288
- :body => fixture('user.json'),
289
- :headers => {:content_type => 'application/json; charset=utf-8'})
290
- end
291
-
292
- it 'respond with correct id' do
293
- subject.id.should eq('1234')
294
- end
295
-
296
- it 'do not respond to eye_color' do
297
- lambda { color = subject.eye_color }.should raise_error
298
- end
299
-
300
- it 'respond to get' do
301
- lambda { user = subject.get 'user' }.should_not raise_error
302
- end
303
-
304
- end
305
-
306
- describe 'cache' do
307
-
308
- subject do
309
- Buffer::User.new 'some_token'
310
- end
311
-
312
- before do
313
- stub_get('user.json').
314
- with(:query => {:access_token => 'some_token'}).
315
- to_return(
316
- :body => fixture('user.json'),
317
- :headers => {:content_type => 'application/json; charset=utf-8'})
318
- end
319
-
320
- describe 'access' do
321
-
322
- before do
323
- subject.id
324
- end
325
-
326
- it 'is used after accessing id once' do
327
- id = subject.id
328
- a_get('user.json').
329
- should_not have_been_made
330
- end
331
-
332
- end
333
-
334
- describe 'invalidation' do
335
-
336
- before do
337
- subject.id
338
- end
339
-
340
- it 'forces server access' do
341
- subject.invalidate
342
- id = subject.id
343
- a_get('user.json').
344
- with(:query => {:access_token => 'some_token'}).
345
- should have_been_made.times(2)
346
- end
347
-
348
- end
349
-
350
- end
351
-
352
- end
353
-
354
-
@@ -1 +0,0 @@
1
- text=This+is+an+example+update&profile_ids[]=4eb854340acb04e870000010&profile_ids[]=4eb9276e0acb04bb81000067&media[link]=http%3A%2F%2Fgoogle.com
@@ -1 +0,0 @@
1
- {"success":true}
@@ -1 +0,0 @@
1
- {"_id":"1234","activity_at":5678,"created_at":1234,"id":"1234","plan":"free","referral_link":"http:\/\/bufferapp.com\/r\/abc","referral_token":"abc","secret_email":"buffer-abc@to.bufferapp.com","timezone":""}
data/spec/helper.rb DELETED
@@ -1,43 +0,0 @@
1
- require 'simplecov'
2
- SimpleCov.start do
3
- add_filter 'spec'
4
- end
5
- require 'rspec'
6
- require 'webmock/rspec'
7
- require 'multi_json'
8
- require 'buffer'
9
-
10
- # Taken from https://github.com/sferik/twitter/blob/master/spec/helper.rb
11
- # for stubbing & mocking HTTP requests
12
-
13
- def endpoint
14
- 'https://api.bufferapp.com/1/'
15
- end
16
-
17
- def a_get(path)
18
- a_request(:get, endpoint + path)
19
- end
20
-
21
- def a_post(path)
22
- a_request(:post, endpoint + path)
23
- end
24
-
25
- def stub_get(path)
26
- stub_request(:get, endpoint + path)
27
- end
28
-
29
- def stub_post(path)
30
- stub_request(:post, endpoint + path)
31
- end
32
-
33
- def fixture_path
34
- File.expand_path("../fixtures", __FILE__)
35
- end
36
-
37
- def fixture(file)
38
- File.new(fixture_path + '/' + file)
39
- end
40
-
41
- def fixture_contents(file)
42
- File.open(fixture_path + '/' + file) { |f| f.read }
43
- end