Class: Itch::Rewards
- Inherits:
-
Object
- Object
- Itch::Rewards
- 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
- #history ⇒ Object
-
#initialize(agent, game_id) ⇒ Rewards
constructor
A new instance of Rewards.
- #list ⇒ Object
- #save(rewards) ⇒ Object
Methods included from Request
Methods included from RequireAuth
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
#history ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/itch/rewards.rb', line 26 def history page = with_login do @agent.get(csv_url) end validate_response(page, action: "fetching reward CSV", content_type: "text/csv") CSV.new(page.content, headers: true) end |
#list ⇒ Object
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 |