Class: PersonaApi::Resource
- Inherits:
-
Object
- Object
- PersonaApi::Resource
show all
- Defined in:
- lib/persona_api/resource.rb
Direct Known Subclasses
AccountsResource, ApiLogsResource, CasesResource, DatabaseVerificationsResource, DocumentsResource, EventsResource, FilesResource, GovernmentIdVerificationsResource, InquiriesResource, ListItemsResource, ListsResource, PhoneCarrierVerificationsResource, PhoneNumberVerificationsResource, ReportsResource, SelfieVerificationsResource, TinDatabaseVerificationsResource, TransactionsResource, UserAuditLogsResource, VerificationsResource
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#delete_request(url, params: {}, headers: {}) ⇒ Object
-
#get_request(url, params: {}, headers: {}) ⇒ Object
-
#handle_response(response) ⇒ Object
-
#initialize(client) ⇒ Resource
constructor
A new instance of Resource.
-
#patch_request(url, body:, headers: {}) ⇒ Object
-
#post_request(url, body:, headers: {}) ⇒ Object
-
#put_request(url, body:, headers: {}) ⇒ Object
Constructor Details
#initialize(client) ⇒ Resource
Returns a new instance of Resource.
5
6
7
|
# File 'lib/persona_api/resource.rb', line 5
def initialize(client)
@client = client
end
|
Instance Attribute Details
Returns the value of attribute client.
3
4
5
|
# File 'lib/persona_api/resource.rb', line 3
def client
@client
end
|
Instance Method Details
#delete_request(url, params: {}, headers: {}) ⇒ Object
25
26
27
|
# File 'lib/persona_api/resource.rb', line 25
def delete_request(url, params: {}, headers: {})
handle_response client.connection.delete(url, params, )
end
|
#get_request(url, params: {}, headers: {}) ⇒ Object
9
10
11
|
# File 'lib/persona_api/resource.rb', line 9
def get_request(url, params: {}, headers: {})
handle_response client.connection.get(url, params, )
end
|
#handle_response(response) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/persona_api/resource.rb', line 29
def handle_response(response)
case response.status
when 400
raise Error, "The request was unacceptable, often due to invalid parameters."
when 401
raise Error, "Not authenticated - check your API key"
when 403
raise Error, "The given API key doesn't have permissions to perform the request or a quota has been exceeded."
when 404
raise Error, "The requested resource doesn't exist."
when 429
raise Error, "Your organization's rate limit has been exceeded. We recommend an exponential backoff on requests."
when 500
raise Error, "Something went wrong on Persona's end."
end
response
end
|
#patch_request(url, body:, headers: {}) ⇒ Object
17
18
19
|
# File 'lib/persona_api/resource.rb', line 17
def patch_request(url, body:, headers: {})
handle_response client.connection.patch(url, body, )
end
|
#post_request(url, body:, headers: {}) ⇒ Object
13
14
15
|
# File 'lib/persona_api/resource.rb', line 13
def post_request(url, body:, headers: {})
handle_response client.connection.post(url, body, )
end
|
#put_request(url, body:, headers: {}) ⇒ Object
21
22
23
|
# File 'lib/persona_api/resource.rb', line 21
def put_request(url, body:, headers: {})
handle_response client.connection.put(url, body, )
end
|