Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit bf9283d

Browse files
authored
Merge pull request #7 from vierarb/master
Move Client @connection to its own, independent method
2 parents 10edfe6 + 75f04b2 commit bf9283d

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

lib/buffer/client.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ class Client
99

1010
attr_accessor :access_token
1111

12+
URL = 'https://api.bufferapp.com/1/'.freeze
13+
1214
def initialize(access_token)
1315
@access_token = access_token
14-
url = "https://api.bufferapp.com/1/"
15-
@connection = Faraday.new(url: url) do |faraday|
16-
faraday.request :url_encoded
17-
faraday.adapter Faraday.default_adapter
16+
end
17+
18+
def connection
19+
@connection ||= Faraday.new(url: URL) do |faraday|
20+
faraday.request :url_encoded
21+
faraday.adapter Faraday.default_adapter
1822
end
1923
end
2024

2125
def auth_query
2226
{ access_token: @access_token }
2327
end
24-
2528
end
2629
end

lib/buffer/core.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Core
99

1010
def get(path, options = {})
1111
options.merge!(auth_query)
12-
response = @connection.get do |req|
12+
response = connection.get do |req|
1313
req.url path.remove_leading_slash
1414
req.params = options
1515
end
@@ -20,7 +20,7 @@ def get(path, options = {})
2020
def post(path, options = {})
2121
params = merge_auth_token_and_query(options)
2222
params.merge!(options)
23-
response = @connection.post do |req|
23+
response = connection.post do |req|
2424
req.url path.remove_leading_slash
2525
req.headers['Content-Type'] = "application/x-www-form-urlencoded"
2626
req.body = options[:body]

spec/lib/buffer_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
end
1414
end
1515

16+
describe "#connection" do
17+
it "assigns the connection instance variable" do
18+
subject.connection.should eq(subject.instance_variable_get(:@connection))
19+
end
20+
end
21+
1622
describe "#info" do
1723
before do
1824
stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token").

0 commit comments

Comments
 (0)