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) ⇒ 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) ⇒ Connection
Returns a new instance of Connection.
7 8 9 10 11 12 13 14 |
# File 'lib/persona-ruby/connection.rb', line 7 def initialize(url, auth_token) @connection = Faraday.new(url:) do |builder| builder.request :json builder.headers[:accept] = "application/json" builder.response :json builder.request :authorization, auth_token, "" end end |
Instance Method Details
#delete(path, params = {}) ⇒ Object
16 17 18 |
# File 'lib/persona-ruby/connection.rb', line 16 def delete(path, params = {}) request(:delete, path, params) end |
#get(path, params = {}) ⇒ Object
20 21 22 |
# File 'lib/persona-ruby/connection.rb', line 20 def get(path, params = {}) request(:get, path, params) end |
#patch(path, params = {}) ⇒ Object
24 25 26 |
# File 'lib/persona-ruby/connection.rb', line 24 def patch(path, params = {}) request(:patch, path, params) end |
#post(path, params = {}) ⇒ Object
28 29 30 |
# File 'lib/persona-ruby/connection.rb', line 28 def post(path, params = {}) request(:post, path, params) end |
#request(method, path, params = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/persona-ruby/connection.rb', line 32 def request(method, path, params = {}) response = @connection.send(method, path, params) error = Error.from_response(response) raise error if error response.body end |