Skip to content

Commit ee2993e

Browse files
committed
Use models for v2 addons and usages
1 parent ae80eb9 commit ee2993e

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

lib/travis/api/v3/models/v2_addon.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Travis::API::V3
2+
class Models::V2Addon
3+
attr_reader :id, :type, :current_usage
4+
5+
def initialize(attrs)
6+
@id = attrs.fetch('id')
7+
@type = attrs.fetch('type')
8+
@current_usage = attrs['current_usage'] && Models::V2AddonUsage.new(attrs['current_usage'])
9+
end
10+
end
11+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Travis::API::V3
2+
class Models::V2AddonUsage
3+
attr_reader :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :active
4+
5+
def initialize(attrs)
6+
@id = attrs.fetch('id')
7+
@addon_id = attrs.fetch('addon_id')
8+
@addon_quantity = attrs.fetch('addon_quantity')
9+
@addon_usage = attrs.fetch('addon_usage')
10+
@remaining = attrs.fetch('remaining')
11+
@active = attrs.fetch('active')
12+
end
13+
end
14+
end

lib/travis/api/v3/models/v2_subscription.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ class Models::V2Subscription
66

77
def initialize(attributes = {})
88
@id = attributes.fetch('id')
9-
plan_data = attributes.fetch('plan_config')
10-
@plan = plan_data && Models::V2PlanConfig.new(plan_data)
9+
@plan = attributes['plan_config'] && Models::V2PlanConfig.new(attributes['plan_config'])
1110
@permissions = Models::BillingPermissions.new(attributes.fetch('permissions'))
1211
@source = attributes.fetch('source')
1312
@billing_info = attributes['billing_info'] && Models::V2BillingInfo.new(@id, attributes['billing_info'])
1413
@credit_card_info = attributes['credit_card_info'] && Models::V2CreditCardInfo.new(@id, attributes['credit_card_info'])
1514
@payment_intent = attributes['payment_intent'] && Models::PaymentIntent.new(attributes['payment_intent'])
1615
@owner = fetch_owner(attributes.fetch('owner'))
1716
@client_secret = attributes.fetch('client_secret')
18-
@addons = attributes.fetch('addons')
17+
@addons = attributes['addons'].select { |addon| addon['current_usage']['status'] != 'expired' }.map { |addon| Models::V2Addon.new(addon) }
1918
@created_at = attributes.fetch('created_at')
2019
end
2120
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Travis::API::V3
2+
class Renderer::V2Addon < ModelRenderer
3+
representation(:standard, :id, :type, :current_usage)
4+
representation(:minimal, :id, :type, :current_usage)
5+
6+
def current_usage
7+
Renderer.render_model(model.current_usage, mode: :standard) unless model.current_usage.nil?
8+
end
9+
end
10+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Travis::API::V3
2+
class Renderer::V2AddonUsage < ModelRenderer
3+
representation(:standard, :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :active)
4+
representation(:minimal, :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :active)
5+
end
6+
end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Travis::API::V3
22
class Renderer::V2PlanConfig < ModelRenderer
3-
representation(:standard, :id, :name, :private_repos, :default_addons, :starting_price, :starting_users, :private_credits, :public_credits)
4-
representation(:minimal, :id, :name, :private_repos, :default_addons, :starting_price, :starting_users, :private_credits, :public_credits)
3+
representation(:standard, :id, :name, :private_repos, :starting_price, :starting_users, :private_credits, :public_credits)
4+
representation(:minimal, :id, :name, :private_repos, :starting_price, :starting_users, :private_credits, :public_credits)
55
end
66
end

0 commit comments

Comments
 (0)