Class: ItchRewards::CLI::Commands::Rewards::Update

Inherits:
Dry::CLI::Command
  • Object
show all
Includes:
AuthOptions, Helper
Defined in:
lib/itch_rewards/cli.rb

Instance Method Summary collapse

Methods included from Helper

#authenticated_client, #authenticated_client!, #cli, #color, #objects_to_table, #render_table, #show_rewards

Methods included from AuthOptions

included

Instance Method Details

#call(game_id:, reward_id:, **options) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/itch_rewards/cli.rb', line 205

def call(game_id:, reward_id:, **options)
  client = authenticated_client!(options)
  game = client.game(game_id)
  rewards = game.rewards

  reward_id = reward_id.to_i
  reward_list = rewards.list

  reward = reward_list.find {|reward| reward.id == reward_id }

  unless reward
    cli.error "Could not find reward with id: #{reward_id} for game #{game.name} (#{game.id})"
    exit 1
  end
  
  unless options[:archived].nil?
    reward.archived = options[:archived]
  end

  i(amount description price title).each do |field|
    if options[field]
      reward.public_send("#{field}=", options[field])
    end
  end

  rewards.save reward_list
  
  show_rewards(game)
end