Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/buffer/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ class Client

attr_accessor :access_token

URL = 'https://api.bufferapp.com/1/'.freeze

def initialize(access_token)
@access_token = access_token
url = "https://api.bufferapp.com/1/"
@connection = Faraday.new(url: url) do |faraday|
faraday.request :url_encoded
faraday.adapter Faraday.default_adapter
end

def connection
@connection ||= Faraday.new(url: URL) do |faraday|
faraday.request :url_encoded
faraday.adapter Faraday.default_adapter
end
end

def auth_query
{ access_token: @access_token }
end

end
end
4 changes: 2 additions & 2 deletions lib/buffer/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Core

def get(path, options = {})
options.merge!(auth_query)
response = @connection.get do |req|
response = connection.get do |req|
req.url path.remove_leading_slash
req.params = options
end
Expand All @@ -20,7 +20,7 @@ def get(path, options = {})
def post(path, options = {})
params = merge_auth_token_and_query(options)
params.merge!(options)
response = @connection.post do |req|
response = connection.post do |req|
req.url path.remove_leading_slash
req.headers['Content-Type'] = "application/x-www-form-urlencoded"
req.body = options[:body]
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/buffer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
end
end

describe "#connection" do
it "assigns the connection instance variable" do
subject.connection.should eq(subject.instance_variable_get(:@connection))
end
end

describe "#info" do
before do
stub_request(:get, "#{base_path}/info/configuration.json?access_token=some_token").
Expand Down