File tree Expand file tree Collapse file tree 3 files changed +17
-8
lines changed
Expand file tree Collapse file tree 3 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -7,20 +7,23 @@ class Client
77 include Link
88 include Info
99
10- attr_accessor :access_token
10+ attr_accessor :access_token , :connection
11+
12+ URL = 'https://api.bufferapp.com/1/' . freeze
1113
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
2629end
Original file line number Diff line number Diff 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 ]
Original file line number Diff line number Diff line change 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" ) .
You can’t perform that action at this time.
0 commit comments