Class: Persona::Connection
- Inherits:
-
Object
- Object
- Persona::Connection
- Defined in:
- lib/persona-ruby/connection.rb
Instance Method Summary collapse
- #delete(path, params = {}) ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(url, auth_token, options = { timeout: 60 }) ⇒ Connection
constructor
A new instance of Connection.
- #patch(path, params = {}) ⇒ Object
- #post(path, params = {}) ⇒ Object
- #request(method, path, params = {}) ⇒ Object
Constructor Details
#initialize(url, auth_token, options = { timeout: 60 }) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 13 14 15 |
# File 'lib/persona-ruby/connection.rb', line 7 def initialize(url, auth_token, = { timeout: 60 }) @connection = Faraday.new(url:) do |builder| builder.request :json builder.headers[:accept] = "application/json" builder.response :json builder.request :authorization, auth_token, "" builder..timeout = [:timeout] end end |
Instance Method Details
#delete(path, params = {}) ⇒ Object
17 18 19 |
# File 'lib/persona-ruby/connection.rb', line 17 def delete(path, params = {}) request(:delete, path, params) end |
#get(path, params = {}) ⇒ Object
21 22 23 |
# File 'lib/persona-ruby/connection.rb', line 21 def get(path, params = {}) request(:get, path, params) end |
#patch(path, params = {}) ⇒ Object
25 26 27 |
# File 'lib/persona-ruby/connection.rb', line 25 def patch(path, params = {}) request(:patch, path, params) end |
#post(path, params = {}) ⇒ Object
29 30 31 |
# File 'lib/persona-ruby/connection.rb', line 29 def post(path, params = {}) request(:post, path, params) end |
#request(method, path, params = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/persona-ruby/connection.rb', line 33 def request(method, path, params = {}) response = @connection.send(method, path, params) error = Error.from_response(response) raise error if error response.body end |