Module: Credly::Connection
- Included in:
- Client
- Defined in:
- lib/credly/connection.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #connection=(con) ⇒ Object
- #delete(path, params = {}, headers = {}) ⇒ Object
- #get(path, params = {}, headers = {}) ⇒ Object
- #new_connection(options = {}) ⇒ Object
- #post(path, params = {}, headers = {}) ⇒ Object
- #put(path, params = {}, headers = {}) ⇒ Object
- #request(method, path, params, headers) ⇒ Object
Instance Method Details
#connection ⇒ Object
32 33 34 |
# File 'lib/credly/connection.rb', line 32 def connection @connection ||= new_connection end |
#connection=(con) ⇒ Object
36 37 38 |
# File 'lib/credly/connection.rb', line 36 def connection=(con) @connection = con end |
#delete(path, params = {}, headers = {}) ⇒ Object
52 53 54 |
# File 'lib/credly/connection.rb', line 52 def delete(path, params = {}, headers = {}) request(:delete, path, params, headers) end |
#get(path, params = {}, headers = {}) ⇒ Object
40 41 42 |
# File 'lib/credly/connection.rb', line 40 def get(path, params = {}, headers = {}) request(:get, path, params, headers) end |
#new_connection(options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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([:base_url] || 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 self.[:debugging] # builder.response :logger, ::Logger.new(STDOUT), :bodies => { :request => true, :response => false } builder.adapter Faraday.default_adapter end end |
#post(path, params = {}, headers = {}) ⇒ Object
44 45 46 |
# File 'lib/credly/connection.rb', line 44 def post(path, params = {}, headers = {}) request(:post, path, params, headers) end |
#put(path, params = {}, headers = {}) ⇒ Object
48 49 50 |
# File 'lib/credly/connection.rb', line 48 def put(path, params = {}, headers = {}) request(:put, path, params, headers) end |
#request(method, path, params, headers) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/credly/connection.rb', line 56 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 |