Class: AddressService::Address
- Inherits:
-
Object
- Object
- AddressService::Address
- Defined in:
- lib/address-service/address.rb
Class Method Summary collapse
-
.create(resource_type, params) ⇒ Object
Create an address for a given resource type.
-
.destroy(resource_type, resource_idu) ⇒ Object
Create an address for a given resource type.
-
.find(resource_type, resource_id) ⇒ Object
Find address for resource.
-
.list(resource_type) ⇒ Object
List addresses for a given resource type.
-
.update(resource_type, resource_id, params) ⇒ Object
Update an address.
Class Method Details
.create(resource_type, params) ⇒ Object
Create an address for a given resource type
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/address-service/address.rb', line 33 def create(resource_type, params) path = "/resources/#{resource_type}/" response = client.post path, params case response.status when 201 # TODO: validate that response body is correct format. return response.body when 422 raise Errors::InputError, response.body else raise Errors::UnknownError end end |
.destroy(resource_type, resource_idu) ⇒ Object
Create an address for a given resource type
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/address-service/address.rb', line 68 def destroy(resource_type, resource_idu) path = "/resources/#{resource_type}/" response = client.delete path case response.status when 200 # TODO: validate that response body is correct format. return response.body when 404 raise Errors::ResourceNotFound else raise Errors::UnknownError end end |
.find(resource_type, resource_id) ⇒ Object
Find address for resource
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/address-service/address.rb', line 17 def find(resource_type, resource_id) path = "/resources/#{resource_type}/#{resource_id}" response = client.get path case response.status when 200 # TODO: validate that response body is correct format. return response.body when 404 raise Errors::ResourceNotFound else raise Errors::UnknownError end end |
.list(resource_type) ⇒ Object
List addresses for a given resource type
9 10 11 12 13 14 |
# File 'lib/address-service/address.rb', line 9 def list(resource_type) path = "/resources/#{resource_type}/" response = client.get path response.body end |
.update(resource_type, resource_id, params) ⇒ Object
Update an address
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/address-service/address.rb', line 50 def update(resource_type, resource_id, params) path = "/resources/#{resource_type}/#{resource_id}" response = client.patch path, params case response.status when 200 # TODO: validate that response body is correct format. return response.body when 404 raise Errors::ResourceNotFound when 422 raise Errors::InputError, response.body else raise Errors::UnknownError end end |