From 04dc18e30cb3815af617ebfdb4a159ed7e050217 Mon Sep 17 00:00:00 2001 From: Cristhiano Figueira Date: Fri, 11 Aug 2017 10:18:56 -0300 Subject: [PATCH] MatchRequest#find options (#66) * Add cmd param to guard block * Includes options on MatchRequest#find params and creates MatchRequest#find_by_tournament * Keyword argument for match_id on MatchRequest#find --- Guardfile | 3 +-- lib/lol/match_request.rb | 18 ++++++++++++------ spec/lol/match_request_spec.rb | 26 ++++++++++---------------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Guardfile b/Guardfile index e6e7c78..04256c3 100644 --- a/Guardfile +++ b/Guardfile @@ -1,7 +1,7 @@ # A sample Guardfile # More info at https://github.com/guard/guard#readme -guard :rspec do +guard :rspec, cmd: "bundle exec rspec" do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } @@ -21,4 +21,3 @@ guard :rspec do watch(%r{^spec/acceptance/(.+)\.feature$}) watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } end - diff --git a/lib/lol/match_request.rb b/lib/lol/match_request.rb index dff9937..d314342 100644 --- a/lib/lol/match_request.rb +++ b/lib/lol/match_request.rb @@ -10,13 +10,11 @@ def api_base_path # Get match by match ID. # @param [Integer] match_id Match ID - # @param [String] tournament_code Optional tournament code the match belongs to + # @option options [Integer] forAccountId Optional used to identify the participant to be unobfuscated + # @option options [Integer] forPlatformId Optional used to identify the participant to be unobfuscated (for when user have changed regions) # @return [DynamicModel] Match representation - def find match_id, tournament_code: nil - url = "matches/#{match_id}".tap do |u| - u << "/by-tournament-code/#{tournament_code}" if tournament_code - end - DynamicModel.new perform_request api_url url + def find options={}, match_id: + DynamicModel.new perform_request api_url "matches/#{match_id}", options end # Get match timeline by match ID. @@ -33,6 +31,14 @@ def ids_by_tournament_code tournament_code perform_request api_url "matches/by-tournament-code/#{tournament_code}/ids" end + # Get match by match ID and tournament code. + # @param [Integer] match_id Match ID + # @param [String] tournament_code Tournament code the match belongs to + # @return [DynamicModel] Match representation + def find_by_tournament match_id, tournament_code + DynamicModel.new perform_request api_url "matches/#{match_id}/by-tournament-code/#{tournament_code}" + end + # Get matchlist for ranked games played on given account ID and platform ID and filtered using given filter parameters, if any. # @param [Integer] account_id Account ID # @param [Hash] options the options to pass to the call diff --git a/spec/lol/match_request_spec.rb b/spec/lol/match_request_spec.rb index 5d8c9d4..f1e2df9 100644 --- a/spec/lol/match_request_spec.rb +++ b/spec/lol/match_request_spec.rb @@ -11,22 +11,9 @@ end describe "#find" do - context "without a tournament code" do - let(:result) { subject.find 1 } - before { stub_request subject, 'match', "matches/1" } - - it "returns a DynamicModel" do - expect(result).to be_a DynamicModel - end - end - - context "with a tournament code" do - let(:result) { subject.find 1, tournament_code: 2 } - before { stub_request subject, 'match-with-tc', "matches/1/by-tournament-code/2" } - - it "returns a DynamicModel" do - expect(result).to be_a DynamicModel - end + it "returns a DynamicModel" do + stub_request subject, 'match', "matches/1" + expect(subject.find match_id: 1).to be_a DynamicModel end end @@ -46,6 +33,13 @@ end end + describe "#find_by_tournament" do + it "returns a DynamicModel" do + stub_request subject, 'match-with-tc', "matches/1/by-tournament-code/2" + expect(subject.find_by_tournament 1, 2).to be_a DynamicModel + end + end + describe "#all" do it "returns a DynamicModel" do stub_request subject, 'matches', "matchlists/by-account/1"