Module: Credly::Connection
- Included in:
- Client
- Defined in:
- lib/credly/connection.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #delete(path, params = {}, headers = {}) ⇒ Object
- #get(path, params = {}, headers = {}) ⇒ Object
- #new_connection ⇒ Object
- #post(path, params = {}, headers = {}) ⇒ Object
- #put(path, params = {}, headers = {}) ⇒ Object
- #request(method, path, params, headers) ⇒ Object
Instance Method Details
#connection ⇒ Object
28 29 30 |
# File 'lib/credly/connection.rb', line 28 def connection @connection ||= new_connection end |
#delete(path, params = {}, headers = {}) ⇒ Object
44 45 46 |
# File 'lib/credly/connection.rb', line 44 def delete(path, params = {}, headers = {}) request(:delete, path, params, headers) end |
#get(path, params = {}, headers = {}) ⇒ Object
32 33 34 |
# File 'lib/credly/connection.rb', line 32 def get(path, params = {}, headers = {}) request(:get, path, params, headers) end |
#new_connection ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/credly/connection.rb', line 7 def new_connection = { :headers => { :accept => 'application/json', :content_type => 'application/x-www-form-urlencoded', :user_agent => Credly.user_agent, } } Faraday.new(self.base_url, ) do |builder| builder.use Credly::Response::FollowRedirects builder.request :multipart builder.request :url_encoded # builder.use Faraday::Request::Multipart # builder.use Faraday::Request::UrlEncoded builder.response :logger, ::Logger.new(STDOUT) if Credly.debugging? builder.adapter Faraday.default_adapter end end |
#post(path, params = {}, headers = {}) ⇒ Object
36 37 38 |
# File 'lib/credly/connection.rb', line 36 def post(path, params = {}, headers = {}) request(:post, path, params, headers) end |
#put(path, params = {}, headers = {}) ⇒ Object
40 41 42 |
# File 'lib/credly/connection.rb', line 40 def put(path, params = {}, headers = {}) request(:put, path, params, headers) end |
#request(method, path, params, headers) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/credly/connection.rb', line 48 def request(method, path, params, headers) response = connection.send(method) do |request| case method.to_sym when :delete, :get request.url(path, params) when :post, :put request.path = path request.body = params unless params.empty? end request.headers.merge!(headers) end response.body end |