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":(\[.*\]),)?"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.
20 21 22 23 |
# File 'lib/itch/rewards.rb', line 20 def initialize(agent, game_id) @agent = agent @game_id = game_id end |
Instance Method Details
#history ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/itch/rewards.rb', line 25 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
35 36 37 38 39 40 41 |
# File 'lib/itch/rewards.rb', line 35 def list rewards, _noun = fetch_rewards_data return [] unless rewards build_rewards(rewards) end |
#save(rewards) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/itch/rewards.rb', line 43 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 |