Class: Credly::Connection
- Inherits:
-
Object
- Object
- Credly::Connection
- Defined in:
- lib/credly-ruby/connection.rb
Instance Method Summary collapse
- #auth_token=(auth_token) ⇒ Object
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(url, auth_token) ⇒ Connection
constructor
A new instance of Connection.
- #post(path, params = {}) ⇒ Object
- #put(path, params = {}) ⇒ Object
- #request(method, path, params) ⇒ Object
Constructor Details
#initialize(url, auth_token) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 13 |
# File 'lib/credly-ruby/connection.rb', line 7 def initialize(url, auth_token) @connection = Faraday.new(url: url) do |conn| conn.request :json conn.response :json conn.request :basic_auth, auth_token, '' end end |
Instance Method Details
#auth_token=(auth_token) ⇒ Object
15 16 17 |
# File 'lib/credly-ruby/connection.rb', line 15 def auth_token=(auth_token) @connection.set_basic_auth(auth_token, '') end |
#delete(path, params = {}) ⇒ Object
19 20 21 |
# File 'lib/credly-ruby/connection.rb', line 19 def delete(path, params = {}) request(:delete, path, params) end |
#get(path, params = {}) ⇒ Object
23 24 25 |
# File 'lib/credly-ruby/connection.rb', line 23 def get(path, params = {}) request(:get, path, params) end |
#post(path, params = {}) ⇒ Object
27 28 29 |
# File 'lib/credly-ruby/connection.rb', line 27 def post(path, params = {}) request(:post, path, params) end |
#put(path, params = {}) ⇒ Object
31 32 33 |
# File 'lib/credly-ruby/connection.rb', line 31 def put(path, params = {}) request(:put, path, params) end |
#request(method, path, params) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/credly-ruby/connection.rb', line 35 def request(method, path, params) response = @connection.public_send(method, path, params) do |request| request.headers[:accept] = 'application/json' end error = Error.from_response(response) raise error if error response.body end |