Class: Clashinator::Clan

Inherits:
Base
  • Object
show all
Defined in:
lib/clashinator/clan.rb

Overview

This class represents the clan model

Constant Summary

Constants inherited from Base

Base::CLASS_MAP, Base::OBJECT_MAP

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

prepare_options, #verify_array_of_classes, #verify_hash_that_are_objects

Methods included from Camelizable

#to_camel_case

Methods included from Underscorable

#to_underscore

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, options = {})
  # response.code will be 403 if clan war log is set to private
  new_options = prepare_options(options)
  clan_tag.gsub!('#', '%23')
  response = http.get("/v1/clans/#{clan_tag}/warlog", new_options)
  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, options = {})
  new_options = prepare_options(options)
  clan_tag.gsub!('#', '%23')
  response = http.get("/v1/clans/#{clan_tag}/members", new_options)
  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, options)
  new_options = prepare_options(options)
  response = http.get('/v1/clans', new_options)
  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