Class: Itch::Rewards

Inherits:
Object
  • Object
show all
Includes:
Request, RequireAuth, SimpleInspect
Defined in:
lib/itch/rewards.rb

Overview

Fetch rewards and history

Constant Summary collapse

REWARD_DATA =
/GameEdit\.EditRewards\(.*?"rewards":(\[.*?\])/.freeze
REWARD_NOUN_DATA =
/GameEdit\.EditRewards\(.*?"reward_noun":"(.*?)(?<!\\)"/.freeze

Instance Method Summary collapse

Methods included from Request

#validate_response

Methods included from RequireAuth

#require_auth, #with_login

Methods included from SimpleInspect

#exclude_inspection, #inspect, #pretty_print_instance_variables

Constructor Details

#initialize(agent, game_id) ⇒ Rewards

Returns a new instance of Rewards.



21
22
23
24
# File 'lib/itch/rewards.rb', line 21

def initialize(agent, game_id)
  @agent = agent
  @game_id = game_id
end

Instance Method Details

#historyObject



26
27
28
29
30
31
32
33
34
# File 'lib/itch/rewards.rb', line 26

def history
  page =  do
    @agent.get(csv_url)
  end

  validate_response(page, action: "fetching reward CSV", content_type: "text/csv")

  CSV.new(page.content, headers: true)
end

#listObject



36
37
38
39
40
41
42
# File 'lib/itch/rewards.rb', line 36

def list
  rewards, _noun = fetch_rewards_data

  return [] unless rewards

  build_rewards(rewards)
end

#save(rewards) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/itch/rewards.rb', line 44

def save(rewards)
  _rewards, noun = fetch_rewards_data

  post_data = build_post_data(rewards, noun)

  result = @agent.post rewards_url, post_data

  validate_response(result, action: "updating rewards")

  list
end