Class: Myrr::Budget
- Inherits:
-
Object
- Object
- Myrr::Budget
- Defined in:
- lib/myrr/budget.rb
Overview
Budget represents spending limit rules for an agent.
Instance Attribute Summary collapse
-
#agent_did ⇒ Object
readonly
Returns the value of attribute agent_did.
-
#allowed_merchant_categories ⇒ Object
readonly
Returns the value of attribute allowed_merchant_categories.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#daily_max ⇒ Object
readonly
Returns the value of attribute daily_max.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#monthly_max ⇒ Object
readonly
Returns the value of attribute monthly_max.
-
#per_transaction_max ⇒ Object
readonly
Returns the value of attribute per_transaction_max.
-
#topup_per_transaction_max ⇒ Object
readonly
Returns the value of attribute topup_per_transaction_max.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Class Method Summary collapse
-
.for_agent(agent_did) ⇒ Myrr::Budget?
Get budget for an agent.
-
.set(agent_did:, per_transaction_max_cents: nil, topup_per_transaction_max_cents: nil, daily_max_cents: nil, monthly_max_cents: nil, allowed_merchant_categories: nil) ⇒ Myrr::Budget
Create or update budget for an agent.
Instance Method Summary collapse
-
#initialize(attrs) ⇒ Budget
constructor
A new instance of Budget.
Constructor Details
#initialize(attrs) ⇒ Budget
Returns a new instance of Budget.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/myrr/budget.rb', line 21 def initialize(attrs) @id = attrs["id"] @agent_did = attrs["agent_did"] @per_transaction_max = attrs["per_transaction_max"] @topup_per_transaction_max = attrs["topup_per_transaction_max"] @daily_max = attrs["daily_max"] @monthly_max = attrs["monthly_max"] @allowed_merchant_categories = attrs["allowed_merchant_categories"] @created_at = attrs["created_at"] @updated_at = attrs["updated_at"] end |
Instance Attribute Details
#agent_did ⇒ Object (readonly)
Returns the value of attribute agent_did.
16 17 18 |
# File 'lib/myrr/budget.rb', line 16 def agent_did @agent_did end |
#allowed_merchant_categories ⇒ Object (readonly)
Returns the value of attribute allowed_merchant_categories.
16 17 18 |
# File 'lib/myrr/budget.rb', line 16 def allowed_merchant_categories @allowed_merchant_categories end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
16 17 18 |
# File 'lib/myrr/budget.rb', line 16 def created_at @created_at end |
#daily_max ⇒ Object (readonly)
Returns the value of attribute daily_max.
16 17 18 |
# File 'lib/myrr/budget.rb', line 16 def daily_max @daily_max end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
16 17 18 |
# File 'lib/myrr/budget.rb', line 16 def id @id end |
#monthly_max ⇒ Object (readonly)
Returns the value of attribute monthly_max.
16 17 18 |
# File 'lib/myrr/budget.rb', line 16 def monthly_max @monthly_max end |
#per_transaction_max ⇒ Object (readonly)
Returns the value of attribute per_transaction_max.
16 17 18 |
# File 'lib/myrr/budget.rb', line 16 def per_transaction_max @per_transaction_max end |
#topup_per_transaction_max ⇒ Object (readonly)
Returns the value of attribute topup_per_transaction_max.
16 17 18 |
# File 'lib/myrr/budget.rb', line 16 def topup_per_transaction_max @topup_per_transaction_max end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
16 17 18 |
# File 'lib/myrr/budget.rb', line 16 def updated_at @updated_at end |
Class Method Details
.for_agent(agent_did) ⇒ Myrr::Budget?
Get budget for an agent.
59 60 61 62 63 64 65 |
# File 'lib/myrr/budget.rb', line 59 def self.for_agent(agent_did) resp = Myrr.client.send(:get, "/v1/budgets/agent/#{agent_did}") new(resp) rescue Myrr::Error => e raise unless e..include?("agent_not_found") nil end |
.set(agent_did:, per_transaction_max_cents: nil, topup_per_transaction_max_cents: nil, daily_max_cents: nil, monthly_max_cents: nil, allowed_merchant_categories: nil) ⇒ Myrr::Budget
Create or update budget for an agent.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/myrr/budget.rb', line 42 def self.set(agent_did:, per_transaction_max_cents: nil, topup_per_transaction_max_cents: nil, daily_max_cents: nil, monthly_max_cents: nil, allowed_merchant_categories: nil) body = { agent_did: agent_did } body[:per_transaction_max] = per_transaction_max_cents if per_transaction_max_cents body[:topup_per_transaction_max] = topup_per_transaction_max_cents if topup_per_transaction_max_cents body[:daily_max] = daily_max_cents if daily_max_cents body[:monthly_max] = monthly_max_cents if monthly_max_cents body[:allowed_merchant_categories] = allowed_merchant_categories if allowed_merchant_categories resp = Myrr.client.send(:post, "/v1/budgets", body) new(resp) end |