Skip to content

Commit

Permalink
MatchRequest#find options (#66)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cristhiano authored and Nicola Racco committed Aug 11, 2017
1 parent 9d9eafa commit 04dc18e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
3 changes: 1 addition & 2 deletions 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" }
Expand All @@ -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

18 changes: 12 additions & 6 deletions lib/lol/match_request.rb
Expand Up @@ -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.
Expand All @@ -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
Expand Down
26 changes: 10 additions & 16 deletions spec/lol/match_request_spec.rb
Expand Up @@ -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

Expand All @@ -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"
Expand Down

0 comments on commit 04dc18e

Please sign in to comment.