Class: Clashinator::Clan
Overview
This class represents the clan model
Constant Summary
Constants inherited from Base
Base::CLASS_MAP, Base::OBJECT_MAP
Class Method Summary collapse
- .clan_info(http, clan_tag) ⇒ Object
- .clan_war_log(http, clan_tag, options = {}) ⇒ Object
- .list_clan_members(http, clan_tag, options = {}) ⇒ Object
- .search_clans(http, options) ⇒ Object
Instance Method Summary collapse
-
#initialize(attrs) ⇒ Clan
constructor
A new instance of Clan.
Methods inherited from Base
prepare_options, #verify_array_of_classes, #verify_hash_that_are_objects
Methods included from Camelizable
Methods included from Underscorable
Constructor Details
#initialize(attrs) ⇒ Clan
Returns a new instance of Clan.
4 5 6 |
# File 'lib/clashinator/clan.rb', line 4 def initialize(attrs) super(attrs) end |
Class Method Details
.clan_info(http, clan_tag) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/clashinator/clan.rb', line 8 def self.clan_info(http, clan_tag) clan_tag.gsub!('#', '%23') response = http.get( "/v1/clans/#{clan_tag}" ) parsed = JSON.parse(response.body) return new(parsed) if response.success? raise parsed['reason'] unless response.success? end |
.clan_war_log(http, clan_tag, options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/clashinator/clan.rb', line 46 def self.clan_war_log(http, clan_tag, = {}) # response.code will be 403 if clan war log is set to private = () clan_tag.gsub!('#', '%23') response = http.get("/v1/clans/#{clan_tag}/warlog", ) parsed = JSON.parse(response.body) if response.success? return Clashinator::ArrayResource.new( Clashinator::Warlog, parsed['items'], parsed['paging'] ) end raise parsed['reason'] unless response.success? end |
.list_clan_members(http, clan_tag, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/clashinator/clan.rb', line 33 def self.list_clan_members(http, clan_tag, = {}) = () clan_tag.gsub!('#', '%23') response = http.get("/v1/clans/#{clan_tag}/members", ) parsed = JSON.parse(response.body) if response.success? return Clashinator::ArrayResource.new( Clashinator::Player, parsed['items'], parsed['paging'] ) end raise parsed['message'] unless response.success? end |
.search_clans(http, options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/clashinator/clan.rb', line 19 def self.search_clans(http, ) = () response = http.get('/v1/clans', ) parsed = JSON.parse(response.body) if response.success? return Clashinator::ArrayResource.new( Clashinator::Clan, parsed['items'], parsed['paging'] ) end raise parsed['message'] unless response.success? end |