Class: ClashOfClansApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/clash_of_clans_api/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_token) ⇒ Client

Returns a new instance of Client.



13
14
15
# File 'lib/clash_of_clans_api/client.rb', line 13

def initialize(api_token)
	@api = Api.new(api_token)
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



11
12
13
# File 'lib/clash_of_clans_api/client.rb', line 11

def api
  @api
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/clash_of_clans_api/client.rb', line 17

def authorized?
	api.perform_request(:get, 'test').code == '404'
end

#capitalleaguesObject



65
66
67
# File 'lib/clash_of_clans_api/client.rb', line 65

def capitalleagues
	Models::PaginatedResponse.new(Models::CapitalLeague, api.capitalleagues, self)
end

#clan(tag) ⇒ Object



37
38
39
# File 'lib/clash_of_clans_api/client.rb', line 37

def clan(tag)
	Models::Clan.new(api.clan(tag), self)
end

#clan_currentwar(clan_tag) ⇒ Object



29
30
31
# File 'lib/clash_of_clans_api/client.rb', line 29

def clan_currentwar(clan_tag)
	Models::War.new(api.clan_currentwar(clan_tag), self)
end

#clan_currentwar_leaguegroup(clan_tag) ⇒ Object



21
22
23
# File 'lib/clash_of_clans_api/client.rb', line 21

def clan_currentwar_leaguegroup(clan_tag)
	Models::ClanWarLeagueGroup.new(api.clan_currentwar_leaguegroup(clan_tag), self)
end

#clan_members(tag) ⇒ Object



41
42
43
# File 'lib/clash_of_clans_api/client.rb', line 41

def clan_members(tag)
	Models::PaginatedResponse.new(Models::Player, api.clan_members(tag), self)
end

#clan_warlog(clan_tag) ⇒ Object



33
34
35
# File 'lib/clash_of_clans_api/client.rb', line 33

def clan_warlog(clan_tag)
	Models::PaginatedResponse.new(Models::War, api.clan_warlog(clan_tag), self)
end

#clanwarleagues_war(war_tag) ⇒ Object



25
26
27
# File 'lib/clash_of_clans_api/client.rb', line 25

def clanwarleagues_war(war_tag)
	Models::War.new(api.clanwarleagues_war(war_tag), self)
end

#league(id) ⇒ Object



77
78
79
# File 'lib/clash_of_clans_api/client.rb', line 77

def league(id)
	Models::League.new(api.league(id), self)
end

#league_season(league_id = 29000022, season_id, limit: 10, before: nil, after: nil) ⇒ Object

rubocop:disable Style/OptionalArguments



73
74
75
# File 'lib/clash_of_clans_api/client.rb', line 73

def league_season(league_id=29000022, season_id, limit: 10, before: nil, after: nil) # rubocop:disable Style/OptionalArguments
	Models::PaginatedResponse.new(Models::Player, api.league_season(league_id, season_id, query: {limit: limit, before: before, after: after}.compact), self)
end

#leaguesObject



69
70
71
# File 'lib/clash_of_clans_api/client.rb', line 69

def leagues
	Models::PaginatedResponse.new(Models::League, api.leagues, self)
end

#player(tag) ⇒ Object



45
46
47
# File 'lib/clash_of_clans_api/client.rb', line 45

def player(tag)
	Models::Player.new(api.player(tag), self)
end

#player_verifytoken(player_tag, token) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/clash_of_clans_api/client.rb', line 49

def player_verifytoken(player_tag, token)
	response = api.player_verifytoken(player_tag, token: token)
	
	raise "Sent player tag #{player_tag.inspect} but received #{response['tag'  ].inspect}." unless player_tag == response['tag'  ]
	raise "Sent token #{     token     .inspect} but received #{response['token'].inspect}." unless token      == response['token']
	
	case response['status']
		when 'ok'
			true
		when 'invalid'
			false
		else
			raise "Unknown status #{response['status'].inspect}."
	end
end