Class: Clashinator::Location

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

Overview

This class represents the location 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) ⇒ Location

Returns a new instance of Location.



4
5
6
# File 'lib/clashinator/location.rb', line 4

def initialize(attrs)
  super(attrs)
end

Class Method Details

.list_locations(http, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/clashinator/location.rb', line 8

def self.list_locations(http, options = {})
  new_options = prepare_options(options)
  response = http.get('/v1/locations', new_options)
  parsed = JSON.parse(response.body)

  if response.success?
    return Clashinator::ArrayResource.new(
      Clashinator::Location, parsed['items'], parsed['paging']
    )
  end
  raise parsed['message'] unless response.success?
end

.location_clan_rankings(http, location_id, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/clashinator/location.rb', line 29

def self.location_clan_rankings(http, location_id, options = {})
  new_options = prepare_options(options)
  response = http.get("/v1/locations/#{location_id}/rankings/clans", new_options)
  parsed = JSON.parse(response.body)

  if response.success?
    return Clashinator::ArrayResource.new(
      Clashinator::ClanRanking, parsed['items'], parsed['paging']
    )
  end
  raise parsed['reason'] unless response.success?
end

.location_info(http, location_id) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/clashinator/location.rb', line 21

def self.location_info(http, location_id)
  response = http.get("/v1/locations/#{location_id}")
  parsed = JSON.parse(response.body)

  return new(parsed) if response.success?
  raise parsed['message'] unless response.success?
end

.location_player_rankings(http, location_id, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/clashinator/location.rb', line 42

def self.location_player_rankings(http, location_id, options = {})
  response = http.get(
    "/v1/locations/#{location_id}/rankings/players",
    prepare_options(options)
  )
  parsed = JSON.parse(response.body)

  return Clashinator::ArrayResource.new(
    Clashinator::PlayerRanking, parsed['items'], parsed['paging']
  ) if response.success?
  raise parsed['reason'] unless response.success?
end