lib/itch/rewards.rb in itch_client-0.4.1 vs lib/itch/rewards.rb in itch_client-0.4.2
- old
+ new
@@ -13,11 +13,12 @@
class Rewards
include SimpleInspect
include RequireAuth
include Request
- REWARD_DATA = /GameEdit\.EditRewards\(.*?(?:"rewards":(\[.*?\]),)?"reward_noun":"(.*?)(?<!\\)"/.freeze
+ REWARD_DATA = /GameEdit\.EditRewards\(.*?"rewards":(\[.*?\])/.freeze
+ REWARD_NOUN_DATA = /GameEdit\.EditRewards\(.*?"reward_noun":"(.*?)(?<!\\)"/.freeze
def initialize(agent, game_id)
@agent = agent
@game_id = game_id
end
@@ -93,13 +94,17 @@
end
raise Error, "Could not find game id #{@game_id} rewards" unless page.code == "200"
script = page.css("script").find do |node|
- node.text =~ REWARD_DATA
- end.text
+ node.text =~ REWARD_DATA && node.text =~ REWARD_NOUN_DATA
+ end
+ return [] unless script
+ script = script.text
- REWARD_DATA.match(script)[1..]
+ data = REWARD_DATA.match(script)[1]
+ noun = REWARD_NOUN_DATA.match(script)[1]
+ [data, noun]
end
def parse_row(row)
id = row.css('input[type="hidden"]').find do |input|
input.name.match(/^rewards\[(\d+)\]\[id\]/)