buff 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -10
- data/lib/buff.rb +1 -0
- data/lib/buff/core.rb +2 -0
- data/lib/buff/encode.rb +15 -2
- data/lib/buff/profile.rb +3 -5
- data/lib/buff/update.rb +1 -8
- data/lib/buff/version.rb +1 -1
- data/spec/lib/buff/encode_spec.rb +59 -23
- data/spec/lib/buff/link_spec.rb +2 -2
- data/spec/lib/buff_spec.rb +23 -26
- data/spec/spec_helper.rb +21 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5cb0c530979c636b2ac80ac80b3b35b7d5a9fd7
|
4
|
+
data.tar.gz: 62293ac07b6119a4e43dd0339f8efa7143ccf9f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d91ca034732471dbdb7b71e0d4156adbf43a3cf687d6355b6f1560dad3eb2a172dd5230a72f10694ad0adfc47bcba741e9f918e463bf0ded16def658774b2a56
|
7
|
+
data.tar.gz: 798fa7a5620e33aee0c77cfcc0d892edf894dea9756a9061cd414eeb3e6e17b0554bce6c41ca77f3b0a03d4177cc531a1cfe8c42cd0dca03b733d5cbbb4963c8
|
data/README.md
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
Buff is a Buffer API Wrapper written in Ruby. It provides more thorough API coverage than the existing gem.
|
4
4
|
|
5
|
-
Since the gem is currently in ALPHA development, the interface is prone to change. Please wait until v0.1.0 is released to become reliant on interface.
|
5
|
+
Since the gem is currently in ALPHA development, the interface is prone to change. Please wait until v0.1.0 is released to become reliant on interface. As it stands, all of the basic API calls in BufferApp's spec are available. Some of the optional params are yet to be implemented.
|
6
|
+
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -14,7 +15,7 @@ Once Buff is released as a gem, the following instructions will work. For now pl
|
|
14
15
|
|
15
16
|
Add this line to your application's Gemfile:
|
16
17
|
|
17
|
-
gem 'buff', :
|
18
|
+
gem 'buff', :github => 'zph/buff'
|
18
19
|
|
19
20
|
And then execute:
|
20
21
|
|
@@ -27,25 +28,25 @@ Once gem is pushed to RubyGems:
|
|
27
28
|
|
28
29
|
## Usage
|
29
30
|
|
30
|
-
* Note
|
31
|
-
*
|
31
|
+
* Note that some of the optional params are not implemented!
|
32
|
+
* All methods are tested with Rspec and WebMock. Not all methods have integration tests that reach out to the live Buffer API servers. Proceed with caution until Buff reaches v0.1.0 and submit issues on Github Issues tab.
|
33
|
+
* Authentication is not included in this gem (Try OAuth-buffer) or use the single API key given when registering your own Buffer Dev credentials.
|
32
34
|
|
33
35
|
## API Coverage
|
34
36
|
|
35
37
|
#### Implemented
|
36
38
|
|
37
39
|
* User
|
38
|
-
* Profiles (:get)
|
39
|
-
* Updates (:get)
|
40
|
-
* Updates (:post, #create_update, #change_update_text, #destroy_update, #share_update, #shuffle_updates, #reorder_updates)
|
40
|
+
* Profiles (:get, :post)
|
41
|
+
* Updates (:get, :post)
|
41
42
|
* Links
|
42
43
|
* Info
|
43
44
|
* Error Codes
|
44
45
|
|
45
46
|
#### Not Implemented
|
46
47
|
|
47
|
-
* Profiles (:post, #set_schedules)
|
48
48
|
* Caching
|
49
|
+
* Various optional params
|
49
50
|
|
50
51
|
## Contributing
|
51
52
|
|
@@ -55,8 +56,8 @@ Once gem is pushed to RubyGems:
|
|
55
56
|
4. Push to the branch (`git push origin my-new-feature`)
|
56
57
|
5. Create new Pull Request
|
57
58
|
|
58
|
-
Issues,
|
59
|
+
Issues, refactoring, and feedback are all welcome.
|
59
60
|
|
60
61
|
Also, this project is newcomer friendly!! We'd love to be your first Open Source Software contribution and would be happy to assist in that process.
|
61
62
|
|
62
|
-
Reach out
|
63
|
+
Crafted with care by Zander. Reach out and say hi at [@_ZPH](http://twitter.com/_ZPH)
|
data/lib/buff.rb
CHANGED
data/lib/buff/core.rb
CHANGED
data/lib/buff/encode.rb
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
module Buff
|
2
2
|
class Encode
|
3
|
-
def self.encode(
|
4
|
-
|
3
|
+
def self.encode(arg)
|
4
|
+
if arg.respond_to?(:keys)
|
5
|
+
arg = arg[:schedules]
|
6
|
+
end
|
5
7
|
|
8
|
+
output = []
|
9
|
+
arg.each_with_index do |item, index|
|
10
|
+
uri = Addressable::URI.new
|
11
|
+
uri.query_values = item
|
12
|
+
pairs = uri.query.split("&").map do |pair|
|
13
|
+
key , value = pair.split("=")
|
14
|
+
"schedules[#{index}][#{key}][]=#{value}"
|
15
|
+
end
|
16
|
+
output << pairs.join("&")
|
17
|
+
end
|
18
|
+
output.join("&")
|
6
19
|
end
|
7
20
|
end
|
8
21
|
end
|
data/lib/buff/profile.rb
CHANGED
@@ -16,12 +16,10 @@ module Buff
|
|
16
16
|
response.map { |r| Buff::Schedule.new(r) }
|
17
17
|
end
|
18
18
|
|
19
|
-
# TODO massive bug
|
20
|
-
# currently deletes schedule due to malformed request
|
21
19
|
def set_schedules(id, options={})
|
22
|
-
|
23
|
-
response = post("/profiles/#{id}/schedules/update.json",
|
24
|
-
|
20
|
+
schedules = Buff::Encode.encode(options.fetch(:schedules) { raise ArgumentError })
|
21
|
+
response = post("/profiles/#{id}/schedules/update.json", schedules: schedules )
|
22
|
+
Buff::Response.new(JSON.parse(response.body))
|
25
23
|
end
|
26
24
|
end
|
27
25
|
end
|
data/lib/buff/update.rb
CHANGED
@@ -30,7 +30,7 @@ module Buff
|
|
30
30
|
|
31
31
|
def reorder_updates(profile_id, options={})
|
32
32
|
# order, optional: offset, utc
|
33
|
-
|
33
|
+
options.fetch(:order) { raise ArgumentError }
|
34
34
|
response = post("/profiles/#{profile_id}/updates/reorder.json", options)
|
35
35
|
end
|
36
36
|
|
@@ -41,13 +41,6 @@ module Buff
|
|
41
41
|
|
42
42
|
#TODO
|
43
43
|
def create_update(options={})
|
44
|
-
|
45
|
-
# POST Data
|
46
|
-
# text=This%20is%20an%20example%20update&
|
47
|
-
# profile_ids[]=4eb854340acb04e870000010&
|
48
|
-
# profile_ids[]=4eb9276e0acb04bb81000067&
|
49
|
-
# media[link]=http%3A%2F%2Fgoogle.com&
|
50
|
-
# media[description]=The%20google%20homepage
|
51
44
|
# options = {
|
52
45
|
# text: "bodytext",
|
53
46
|
# profile_ids: ["230958239058", "23059u2350923"],
|
data/lib/buff/version.rb
CHANGED
@@ -1,36 +1,72 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
+
# describe "Addressable Explorations" do
|
4
|
+
|
5
|
+
# describe "addressable conversions" do
|
6
|
+
|
7
|
+
# let(:uri) { Addressable::URI.new }
|
8
|
+
|
9
|
+
# it "should convert {:pony => 'pony' }" do
|
10
|
+
# h = { pony: "pony"}
|
11
|
+
# uri.query_values = h
|
12
|
+
# uri.query.should eq("pony=pony")
|
13
|
+
# end
|
14
|
+
|
15
|
+
# it "should convert {:pony => ['pony', 'horse'] }" do
|
16
|
+
# h = { pony: ["pony", "horse"]}
|
17
|
+
# uri.query_values = h
|
18
|
+
# uri.query.should eq("pony=pony&pony=horse")
|
19
|
+
# end
|
20
|
+
|
21
|
+
# it "should convert {:days => [mon, tues], :times => [....]}" do
|
22
|
+
# h = { days: ["mon", "tue"], times: ["12:00", "13:00"]}
|
23
|
+
# uri.query_values = h
|
24
|
+
# uri.query.should eq("days=mon&days=tue×=12%3A00×=13%3A00")
|
25
|
+
# end
|
26
|
+
# xit "should convert {schedules => {:days => [mon, tues], :times => [....]}" do
|
27
|
+
# h = { schedules: { :days => ["mon", "tue", "wed", "thu"], :times => ["12:00", "13:00"]} }
|
28
|
+
# # h = {:a => "a", :bd => ["c", "d", "e"]}
|
29
|
+
# uri.query_values = h
|
30
|
+
# uri.query.should eq("days=mon&days=tue×=12%3A00×=13%3A00")
|
31
|
+
# end
|
32
|
+
# end
|
3
33
|
describe Buff::Encode do
|
4
|
-
describe "#encode" do
|
5
34
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
35
|
+
context "successful code" do
|
36
|
+
|
37
|
+
let(:schedule_first) { { :days => ["mon", "tue", "wed", "thu"], :times => ["12:00", "13:00"]} }
|
38
|
+
let(:schedule_second) { { :days => ["sun", "sat"], :times => ["09:00", "24:00"]} }
|
39
|
+
let(:schedules_hash) { { schedules: [schedule_first, schedule_second] } }
|
40
|
+
let(:short_schedule) { { days: ["mon", "tue", "wed"], times: ["12:00", "17:00", "18:00"]} }
|
41
|
+
let(:short_schedule_encoded) { "[days][]=mon&[days][]=tue&[times][]=12%3A00&[times][]=13%3A00" }
|
42
|
+
let(:schedules_encoded) { "schedules[0][days][]=mon&schedules[0][days][]=tue&schedules[0][days][]=wed&schedules[0][times][]=12:00&schedules[0][times][]=17:00&schedules[0][times][]=18:00" }
|
43
|
+
let(:very_short_schedule) { { :days => ["sun", "sat"], :times => ["09:00", "24:00"]} }
|
11
44
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
45
|
+
|
46
|
+
describe "#encode"
|
47
|
+
it "converts to match Buffer API specs encoding" do
|
48
|
+
Buff::Encode.encode([short_schedule]).
|
49
|
+
should eq(schedules_encoded.gsub(/:/, '%3A'))
|
16
50
|
end
|
17
51
|
|
18
|
-
it "
|
19
|
-
|
20
|
-
|
21
|
-
uri.query.should eq("pony=pony&pony=horse")
|
52
|
+
it "processes an input array of schedules" do
|
53
|
+
Buff::Encode.encode([very_short_schedule, very_short_schedule]).
|
54
|
+
should eq("schedules[0][days][]=sun&schedules[0][days][]=sat&schedules[0][times][]=09%3A00&schedules[0][times][]=24%3A00&schedules[1][days][]=sun&schedules[1][days][]=sat&schedules[1][times][]=09%3A00&schedules[1][times][]=24%3A00")
|
22
55
|
end
|
23
56
|
|
24
|
-
it "
|
25
|
-
|
26
|
-
|
27
|
-
uri.query.should eq("days=mon&days=tue×=12%3A00×=13%3A00")
|
57
|
+
it "includes index in conversion when multiple schedules present" do
|
58
|
+
Buff::Encode.encode([very_short_schedule, very_short_schedule, very_short_schedule]).
|
59
|
+
should eq("schedules[0][days][]=sun&schedules[0][days][]=sat&schedules[0][times][]=09%3A00&schedules[0][times][]=24%3A00&schedules[1][days][]=sun&schedules[1][days][]=sat&schedules[1][times][]=09%3A00&schedules[1][times][]=24%3A00&schedules[2][days][]=sun&schedules[2][days][]=sat&schedules[2][times][]=09%3A00&schedules[2][times][]=24%3A00")
|
28
60
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
uri.query.should eq("days=mon&days=tue×=12%3A00×=13%3A00")
|
61
|
+
|
62
|
+
it "processes an input hash" do
|
63
|
+
Buff::Encode.encode({ schedules: [very_short_schedule, very_short_schedule, very_short_schedule] }).
|
64
|
+
should eq("schedules[0][days][]=sun&schedules[0][days][]=sat&schedules[0][times][]=09%3A00&schedules[0][times][]=24%3A00&schedules[1][days][]=sun&schedules[1][days][]=sat&schedules[1][times][]=09%3A00&schedules[1][times][]=24%3A00&schedules[2][days][]=sun&schedules[2][days][]=sat&schedules[2][times][]=09%3A00&schedules[2][times][]=24%3A00")
|
34
65
|
end
|
35
66
|
end
|
67
|
+
|
68
|
+
describe "#encode_schedule_primary" do
|
69
|
+
end
|
70
|
+
|
71
|
+
|
36
72
|
end
|
data/spec/lib/buff/link_spec.rb
CHANGED
@@ -6,8 +6,8 @@ describe Buff::Client do
|
|
6
6
|
let(:url) { %q{http://bufferapp.com} }
|
7
7
|
|
8
8
|
before do
|
9
|
-
stub_request(:get, "
|
10
|
-
|
9
|
+
stub_request(:get, "#{ base_path }/links/shares.json?#{ access_token_param }&url=http://bufferapp.com").
|
10
|
+
to_return(fixture('link.txt'))
|
11
11
|
end
|
12
12
|
|
13
13
|
it "connects to the correct endpoint" do
|
data/spec/lib/buff_spec.rb
CHANGED
@@ -18,9 +18,8 @@ describe Buff::Client do
|
|
18
18
|
let(:rash) { subject.user_info }
|
19
19
|
|
20
20
|
before(:each) do
|
21
|
-
|
22
|
-
|
23
|
-
to_return(fixture('user_authenticated.txt'))
|
21
|
+
url = "#{ base_path }/user.json"
|
22
|
+
stub_with_to_return(:get, url, "user_authenticated.txt")
|
24
23
|
end
|
25
24
|
|
26
25
|
it "returns a Rash object" do
|
@@ -36,9 +35,8 @@ describe Buff::Client do
|
|
36
35
|
let(:rash) { Buff::Client.new("some_token").profiles }
|
37
36
|
|
38
37
|
before(:each) do
|
39
|
-
|
40
|
-
|
41
|
-
to_return(fixture('profile_authenticated.txt'))
|
38
|
+
url = "#{ base_path }/profiles.json"
|
39
|
+
stub_with_to_return(:get, url, 'profile_authenticated.txt')
|
42
40
|
end
|
43
41
|
|
44
42
|
it "makes the correct url request" do
|
@@ -57,9 +55,9 @@ describe Buff::Client do
|
|
57
55
|
describe "#profile_by_id" do
|
58
56
|
let(:id) { "5160746d54f04a5e3a00000f" }
|
59
57
|
before(:each) do
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
url = "#{base_path}/profiles/#{id}.json"
|
59
|
+
fixture_name = "profiles_by_id.txt"
|
60
|
+
stub_with_to_return(:get, url, fixture_name)
|
63
61
|
end
|
64
62
|
|
65
63
|
let(:rash) { Buff::Client.new("some_token").profile_by_id(id) }
|
@@ -75,9 +73,9 @@ describe Buff::Client do
|
|
75
73
|
|
76
74
|
describe "#profile_schedules_by_id" do
|
77
75
|
before(:each) do
|
78
|
-
|
79
|
-
|
80
|
-
|
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)
|
81
79
|
end
|
82
80
|
|
83
81
|
let(:rash) { Buff::Client.new("some_token").profile_schedules_by_id(id) }
|
@@ -107,7 +105,7 @@ describe Buff::Client do
|
|
107
105
|
|
108
106
|
describe "#info" do
|
109
107
|
before do
|
110
|
-
stub_request(:get, "
|
108
|
+
stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token").
|
111
109
|
to_return(fixture("info.txt"))
|
112
110
|
end
|
113
111
|
|
@@ -182,8 +180,7 @@ EOF
|
|
182
180
|
|
183
181
|
it "dumping a double schedule yields correct json" do
|
184
182
|
schedules = Buff::Schedules.new
|
185
|
-
schedules << @schedule
|
186
|
-
schedules << @schedule
|
183
|
+
schedules << @schedule << @schedule
|
187
184
|
@sample_schedules = @sample_schedules.to_json
|
188
185
|
|
189
186
|
schedules.dump.should eq(@sample_schedules)
|
@@ -195,7 +192,7 @@ describe Buff::Client::Core do
|
|
195
192
|
let(:client) { Buff::Client.new("some_token") }
|
196
193
|
describe "#get" do
|
197
194
|
it "delegates to #handle_response_code when code != 200" do
|
198
|
-
stub_request(:get, "
|
195
|
+
stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token").
|
199
196
|
to_return(:status => 403, :body => "", :headers => {})
|
200
197
|
client.should_receive(:handle_response_code).once
|
201
198
|
client.info
|
@@ -203,7 +200,7 @@ describe Buff::Client::Core do
|
|
203
200
|
|
204
201
|
|
205
202
|
it "does not delegate to #handle_response_code when code = 200" do
|
206
|
-
stub_request(:get, "
|
203
|
+
stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token").
|
207
204
|
to_return(fixture("link.txt"))
|
208
205
|
client.should_not_receive(:handle_response_code)
|
209
206
|
client.info
|
@@ -214,20 +211,21 @@ describe Buff::Client::Core do
|
|
214
211
|
|
215
212
|
it "connects to the correct endpoint" do
|
216
213
|
|
217
|
-
#TODO improve test
|
214
|
+
#TODO improve test
|
218
215
|
response = %Q[{"success": true, "message": "Schedule saved successfully"}]
|
219
216
|
id = "4eb854340acb04e870000010"
|
220
|
-
stub_request(:post,
|
221
|
-
|
222
|
-
|
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'}).
|
223
220
|
to_return(:status => 200, :body => response, :headers => {})
|
224
221
|
client.set_schedules(id, :schedules => sample_schedules).success.
|
225
222
|
should eq(true)
|
226
223
|
end
|
227
224
|
|
228
225
|
xit "does not delegate to #handle_response_code when code = 200" do
|
229
|
-
|
230
|
-
|
226
|
+
url = "#{base_path}/info/configuration.json"
|
227
|
+
fixture_name = "link.txt"
|
228
|
+
stub_with_to_return(:get, url, fixture_name)
|
231
229
|
client.should_not_receive(:handle_response_code)
|
232
230
|
client.info
|
233
231
|
end
|
@@ -243,9 +241,8 @@ describe Buff::Client::Core do
|
|
243
241
|
context "fails gracefully with undocumented responses" do
|
244
242
|
it "responds to 401 unauthorized response" do
|
245
243
|
id = "4eb8565e0acb04bb82000004"
|
246
|
-
|
247
|
-
|
248
|
-
|
244
|
+
url = "#{base_path}/updates/#{id}.json?access_token=some_token"
|
245
|
+
stub_with_to_return(:get, url, "update_by_id_non_auth.txt")
|
249
246
|
lambda { client.update_by_id(id) }.
|
250
247
|
should raise_error(Buff::APIError)
|
251
248
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -26,12 +26,31 @@ def sample_schedules2
|
|
26
26
|
{days: %w[mon tue wed],
|
27
27
|
times: %w[12:00 17:00 18:00]},
|
28
28
|
]
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def base_path
|
33
|
+
"https://api.bufferapp.com/1"
|
34
|
+
end
|
35
|
+
|
36
|
+
def access_token_param
|
37
|
+
"access_token=some_token"
|
29
38
|
end
|
39
|
+
|
40
|
+
def stub_with_to_return(request_type, url, fixture_name, query_hash={})
|
41
|
+
query = access_hash.merge(query_hash)
|
42
|
+
stub_request(request_type, url).
|
43
|
+
with(query: query).
|
44
|
+
to_return(fixture(fixture_name))
|
45
|
+
end
|
46
|
+
|
47
|
+
def access_hash
|
48
|
+
{ 'access_token' => 'some_token'}
|
49
|
+
end
|
50
|
+
|
30
51
|
def sample_schedules
|
31
|
-
[
|
32
52
|
[{ days: %w[mon tue wed],
|
33
53
|
times: %w[12:00 17:00 18:00]}]
|
34
|
-
]
|
35
54
|
# @sample_schedules = JSON.parse <<EOF
|
36
55
|
# [{
|
37
56
|
# "days" : [
|
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.
|
4
|
+
version: 0.0.2
|
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-
|
11
|
+
date: 2013-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|