lib/cocRb/league.rb in cocRb-0.1.3 vs lib/cocRb/league.rb in cocRb-0.1.4

- old
+ new

@@ -1,140 +1,130 @@ -require 'faraday' +require "faraday" require "json" module CocRb class << self - attr_accessor :configuration + attr_accessor :configuration end def self.configure - @configuration ||= Configuration.new - yield(configuration) + @configuration ||= Configuration.new + yield(configuration) end - class Configuration - attr_accessor :token, :url + class Configuration + attr_accessor :token, :url def initialize - @token = nil - @url = nil + @token = nil + @url = nil end end + class Settings - def self.get - @conn = Faraday.new( - url:"https://api.clashofclans.com" , - headers: { - 'Content-Type' => 'application/json', - 'Authorization' => "Bearer #{CocRb.configuration.token}" + + def self.get + @conn = Faraday.new( + url:"https://api.clashofclans.com", + headers: { + 'Content-Type' => 'application/json', + 'Authorization' => "Bearer #{CocRb.configuration.token}" } ) - rescue => e - raise "Oops Unexpected error Caught!" - puts e + rescue => e + raise "Oops Unexpected error Caught!" + puts e end end + class League < Settings -def self.getLeaguesID(_limit:false, status:false) - get - res = @conn.get('v1/leagues') do |req| - req.params[:limit] = _limit if _limit - end - if status - res.status + def self.get_LeaguesID(_limit:false, status:false) + get + res = @conn.get('v1/leagues') do |req| + req.params[:limit] = _limit if _limit + end - else - val = res.body - convert = JSON.parse(val) - end + if status + res.status -end + else + val = res.body + convert = JSON.parse(val) -def self.getSeasons(leagueId:, _limit:false, status:false) - get -if leagueId != 29000022 - puts "Not a valid League id,Seasons are only available for Legend League" -else - res = @conn.get("v1/leagues/#{leagueId}/seasons") do |req| - req.params[:limit] = _limit if _limit end +end - if status - res.status - - else - val = res.body - convert = JSON.parse(val) +def self.get_Seasons(leagueId:, _limit:false, status:false) + get + if leagueId != 29000022 + puts "Not a valid League id,Seasons are only available for Legend League" + else + res = @conn.get("v1/leagues/#{leagueId}/seasons") do |req| + req.params[:limit] = _limit if _limit end -end -end - -def self.getLeague_SeasonRank(leagueId:, seasonId:, _limit:false, status:false) - get - if leagueId != 29000022 - puts "Not a valid League id,Seasons are only available for Legend League" - else - res = @conn.get("v1/leagues/#{leagueId}/seasons/#{seasonId}") do |req| - req.params[:limit] = _limit if _limit + if status + res.status + else + val = res.body + convert = JSON.parse(val) + end + end end - if status - res.status - - else - val = res.body - convert = JSON.parse(val) - end - end - + def self.get_LeagueSeasonRank(leagueId:, seasonId:, _limit:false, status:false) + get + if leagueId != 29000022 + puts "Not a valid League id,Seasons are only available for Legend League" + else + res = @conn.get("v1/leagues/#{leagueId}/seasons/#{seasonId}") do |req| + req.params[:limit] = _limit if _limit + end + if status + res.status + else + val = res.body + convert = JSON.parse(val) + end + end end -def self.get_LeagueInfo(leagueId:, status:false) - get - res = @conn.get("v1/leagues/#{leagueId}") + def self.get_LeagueInfo(leagueId:, status:false) + get + res = @conn.get("v1/leagues/#{leagueId}") + if status + res.status + else + val = res.body + convert = JSON.parse(val) - if status - res.status - - else - val = res.body - convert = JSON.parse(val) - - end - + end end -def self.get_WarLeagueId(_limit:false, status:false) - get - res = @conn.get("v1/warleagues") do |req| - req.params[:limit] = _limit if _limit - end + def self.get_WarLeagueId(_limit:false, status:false) + get + res = @conn.get("v1/warleagues") do |req| + req.params[:limit] = _limit if _limit + end - if status - res.status - else - val = res.body - convert = JSON.parse(val) - end + if status + res.status + else + val = res.body + convert = JSON.parse(val) + end + end -end -def self.get_WarLeagueInfo(warLeagueId:, status:false) - get - res = @conn.get("v1/warleagues/#{warLeagueId}") - - if status - res.status - - else - val = res.body - convert = JSON.parse(val) - - end -end - - -end - + def self.get_WarLeagueInfo(warLeagueId:, status:false) + get + res = @conn.get("v1/warleagues/#{warLeagueId}") + if status + res.status + else + val = res.body + convert = JSON.parse(val) + end + end + end end