Class: Pago::V2026_04::Services::Benefits
- Defined in:
- lib/pago/v2026_04/services/benefits.rb,
sig/pago/v2026_04/generated.rbs
Instance Attribute Summary
Attributes inherited from Service
Instance Method Summary collapse
-
#create(body: {}) ⇒ Object
Create a benefit.
-
#delete(id) ⇒ nil
Delete a benefit.
-
#get(id) ⇒ Object
Get a benefit by ID.
-
#grants(id, is_granted: nil, customer_id: nil, member_id: nil, page: 1, limit: 10) ⇒ Models::ListResourceBenefitGrant
List the individual grants for a benefit.
-
#grants_each(id, is_granted: nil, customer_id: nil, member_id: nil, limit: 10) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of
grants, fetching pages on demand. -
#list(organization_id: nil, type: nil, id: nil, exclude_id: nil, query: nil, page: 1, limit: 10, sorting: ["-created_at"], metadata: nil) ⇒ Models::ListResourceBenefit
List benefits.
-
#list_each(organization_id: nil, type: nil, id: nil, exclude_id: nil, query: nil, limit: 10, sorting: ["-created_at"], metadata: nil) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of
list, fetching pages on demand. -
#update(id, body: {}) ⇒ Object
Update a benefit.
Methods inherited from Service
Constructor Details
This class inherits a constructor from Pago::Service
Instance Method Details
#create(body: {}) ⇒ Object
Create a benefit.
Scopes: benefits:write
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/pago/v2026_04/services/benefits.rb', line 54 def create(body: {}) data = client.request( http_method: "POST", path: "/v1/benefits/", path_params: {}, query: {}, body: body, response_type: :json, errors: { 422 => Errors::HTTPValidationError } ) Unions::Benefit.from_json(data) end |
#delete(id) ⇒ nil
Delete a benefit.
[!WARNING] Every grants associated with the benefit will be revoked. Users will lose access to the benefit.
Scopes: benefits:write
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/pago/v2026_04/services/benefits.rb', line 102 def delete(id) client.request( http_method: "DELETE", path: "/v1/benefits/{id}", path_params: { "id" => id }, query: {}, response_type: :none, errors: { 403 => Errors::NotPermitted, 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) end |
#get(id) ⇒ Object
Get a benefit by ID.
Scopes: benefits:read benefits:write
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/pago/v2026_04/services/benefits.rb', line 76 def get(id) data = client.request( http_method: "GET", path: "/v1/benefits/{id}", path_params: { "id" => id }, query: {}, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Unions::Benefit.from_json(data) end |
#grants(id, is_granted: nil, customer_id: nil, member_id: nil, page: 1, limit: 10) ⇒ Models::ListResourceBenefitGrant
List the individual grants for a benefit.
It's especially useful to check if a user has been granted a benefit.
Scopes: benefits:read benefits:write
152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/pago/v2026_04/services/benefits.rb', line 152 def grants(id, is_granted: nil, customer_id: nil, member_id: nil, page: 1, limit: 10) data = client.request( http_method: "GET", path: "/v1/benefits/{id}/grants", path_params: { "id" => id }, query: { "is_granted" => is_granted, "customer_id" => customer_id, "member_id" => member_id, "page" => page, "limit" => limit }, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Models::ListResourceBenefitGrant.from_json(data) end |
#grants_each(id, is_granted: nil, customer_id: nil, member_id: nil, limit: 10) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of grants, fetching pages on demand.
168 169 170 171 172 173 |
# File 'lib/pago/v2026_04/services/benefits.rb', line 168 def grants_each(id, is_granted: nil, customer_id: nil, member_id: nil, limit: 10, &block) paginator = ::Pago::Paginator.new do |page_number| grants(id, is_granted: is_granted, customer_id: customer_id, member_id: member_id, page: page_number, limit: limit) end block ? paginator.each(&block) : paginator end |
#list(organization_id: nil, type: nil, id: nil, exclude_id: nil, query: nil, page: 1, limit: 10, sorting: ["-created_at"], metadata: nil) ⇒ Models::ListResourceBenefit
List benefits.
Scopes: benefits:read benefits:write
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pago/v2026_04/services/benefits.rb', line 23 def list(organization_id: nil, type: nil, id: nil, exclude_id: nil, query: nil, page: 1, limit: 10, sorting: ["-created_at"], metadata: nil) data = client.request( http_method: "GET", path: "/v1/benefits/", path_params: {}, query: { "organization_id" => organization_id, "type" => type, "id" => id, "exclude_id" => exclude_id, "query" => query, "page" => page, "limit" => limit, "sorting" => sorting, "metadata" => }, response_type: :json, errors: { 422 => Errors::HTTPValidationError } ) Models::ListResourceBenefit.from_json(data) end |
#list_each(organization_id: nil, type: nil, id: nil, exclude_id: nil, query: nil, limit: 10, sorting: ["-created_at"], metadata: nil) {|item| ... } ⇒ Pago::Paginator
Enumerate every item of list, fetching pages on demand.
39 40 41 42 43 44 |
# File 'lib/pago/v2026_04/services/benefits.rb', line 39 def list_each(organization_id: nil, type: nil, id: nil, exclude_id: nil, query: nil, limit: 10, sorting: ["-created_at"], metadata: nil, &block) paginator = ::Pago::Paginator.new do |page_number| list(organization_id: organization_id, type: type, id: id, exclude_id: exclude_id, query: query, page: page_number, limit: limit, sorting: sorting, metadata: ) end block ? paginator.each(&block) : paginator end |
#update(id, body: {}) ⇒ Object
Update a benefit.
Scopes: benefits:write
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/pago/v2026_04/services/benefits.rb', line 123 def update(id, body: {}) data = client.request( http_method: "PATCH", path: "/v1/benefits/{id}", path_params: { "id" => id }, query: {}, body: body, response_type: :json, errors: { 404 => Errors::ResourceNotFound, 422 => Errors::HTTPValidationError } ) Unions::Benefit.from_json(data) end |