diff options
Diffstat (limited to 'tests/ruby.rb')
| -rw-r--r-- | tests/ruby.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/ruby.rb b/tests/ruby.rb new file mode 100644 index 0000000..004d516 --- /dev/null +++ b/tests/ruby.rb @@ -0,0 +1,49 @@ +class App < Struct.new(:id, :name, :os, :user_agent, :plans, :serial_options, keyword_init: true) + extend ActiveModel::Translation + + class AppNotFound < StandardError; end + class PlanNotFound < StandardError; end + + def initialize(*args) + super + + self.plans.map! { |plan| Plan.new(**plan) } + self.serial_options = SerialOptions.new(**self.serial_options) + end + + def icon + "apps/#{id}.png" + end + + def find_plan(id) + plans.detect { |plan| plan.id == id } || (raise PlanNotFound) + end + + def download_link + "https://services.panini.house/apps/#{id}/latest_releases" + end + + def download_link_for(serial_number) + "#{download_link}?serial_number=#{serial_number}" + end + + def marketing_list + Sendy.lists.optional[id] + end + + def checkout_recovery_list + Sendy.lists.optional["#{id}_checkout_recovery"] + end + + def self.all + template = ERB.new File.read(Rails.root.join("app", "data", "apps.yml.erb")) + + YAML.load(template.result) + .map(&:with_indifferent_access) + .map { |app| new(**app) } + end + + def self.find(id) + all.find { |app| app.id == id } || (raise AppNotFound) + end +end |
