class CocRb::ClanWar

Public Class Methods

get_ClanWar(tag:, status: false) click to toggle source

This method gets information about current on-going war,Takes tag as a paramter

Paramter Data Type => String

# File lib/cocRb/clanWar.rb, line 62
  def self.get_ClanWar(tag:, status: false)
        get
        io = tag
        tag = io.gsub('#', '%23')
        res = @conn.get("v1/clans/#{tag}/currentwar")

   if status
        puts res.status
   else
        val = res.body

        convert = JSON.parse(val)
   end
end
get_ClanWarMembers(tag:, teamInput:, status: false) click to toggle source

This method gets the members that are in war. In Descending to Ascending TH order. Takes tag as a paramter and teamInput.

Note: _The team Input options can be found in Github README._

Paramter Data Types => String

# File lib/cocRb/clanWar.rb, line 81
   def self.get_ClanWarMembers(tag:, teamInput:, status: false)
        get
        teamInput_Options = ["clan", "opponent"]

        check = teamInput_Options.include?(teamInput)

    if check == false
        puts 'Not a valid teamInput Option'
    elsif check == true
        io = tag
        tag = io.gsub('#', '%23')
        res = @conn.get("v1/clans/#{tag}/currentwar")

    if status
        puts res.status
    else
        val = res.body

        convert = JSON.parse(val)

        getClan_War_Members = convert[teamInput]['members']

        hash = getClan_War_Members.sort_by { |s| s['townhallLevel'] }

        sort = hash.sort_by { |_k, v| v }.reverse

     end
   end
end
get_WarLog(tag:, _limit:false, status: false) click to toggle source

This methods gets the current warLog for a clan, Takes clan tag as a paramter

Paramter Data Type => String

# File lib/cocRb/clanWar.rb, line 44
  def self.get_WarLog(tag:, _limit:false, status: false)
        get
        io = tag
        tag = io.gsub('#', '%23')
        res = @conn.get("v1/clans/#{tag}/warlog") do |req|
        req.params[:limit] = _limit if _limit
end

if status
        puts res.status
else
        val = res.body
        convert = JSON.parse(val)
   end
end
get_WarTime(tag:, status: false) click to toggle source

This method gets all the timings for on-going war in UTC Time Zone, Takes tag as a paramater

Note: _This method will also return the War Times in parsed Format_

Paramter Data Type => String

# File lib/cocRb/clanWar.rb, line 115
   def self.get_WarTime(tag:, status: false)
         get
         io = tag
         tag = io.gsub('#', '%23')
         res = @conn.get("v1/clans/#{tag}/currentwar")
   if status
         puts res.status
   else
         val = res.body

         convert = JSON.parse(val)

         time = convert["preparationStartTime"]

         time2 = convert["startTime"]

         time3 = convert["endTime"]

         t = Time.parse(time).strftime('%y-%m-%d, %I:%M:%S %p')
         t1 = Time.parse(time2).strftime('%y-%m-%d, %I:%M:%S %p')
         t2 = Time.parse(time3).strftime('%y-%m-%d, %I:%M:%S %p')

         warTimes = {
            "preparationStartTime" => time,
            "startTime" => time2,
            "endTime" => time3
         },
         {
            "parsed_preparationStartTime" => t,
            "parsed_startTime" => t1,
            "parsed_endTime" => t2
         }.freeze
   end
end