lib/cocRb/location.rb in cocRb-0.1.3 vs lib/cocRb/location.rb in cocRb-0.1.4
- old
+ new
@@ -1,137 +1,118 @@
-require 'faraday'
+require "faraday"
require "json"
module CocRb
- class << self
- attr_accessor :configuration
+ class << self
+ attr_accessor :configuration
end
def self.configure
- @configuration ||= Configuration.new
- yield(configuration)
+ @configuration ||= Configuration.new
+ yield(configuration)
end
class Configuration
- attr_accessor :token, :url
-
+ 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}"
+ @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 Location < Settings
+ # This method will get all the location ID including country name and country code.
+ def self.get_LocationId(_limit:false, status:false)
+ get
+ res = @conn.get("v1/locations") do |req|
+ req.params[:limit] = _limit if _limit
+ end
+ if status
+ res.status
+ else
+ val = res.body
+ convert = JSON.parse(val)
-def self.get_LocationId(_limit:false, status:false)
- get
- res = @conn.get("v1/locations") do |req|
- req.params[:limit] = _limit if _limit
end
-
- if status
- res.status
- else
- val = res.body
- convert = JSON.parse(val)
- end
-
-
end
-
-def self.get_LocationInfo(locationId:, status:false)
- get
- res = @conn.get("v1/locations/#{locationId}")
-
-
- if status
- res.status
- else
- val = res.body
- convert = JSON.parse(val)
+ # This method gets detailed location information takes Location as a paramter
+ def self.get_LocationInfo(locationId:, status:false)
+ get
+ res = @conn.get("v1/locations/#{locationId}")
+ if status
+ res.status
+ else
+ val = res.body
+ convert = JSON.parse(val)
end
-
-
end
-def self.get_LocationRankClan(locationId:, _limit:false, status:false)
-get
- res = @conn.get("v1/locations/#{locationId}/rankings/clans") do |req|
- req.params[:limit] = _limit if _limit
+ def self.get_LocationRankClan(locationId:, _limit:false, status:false)
+ get
+ res = @conn.get("v1/locations/#{locationId}/rankings/clans") do |req|
+ req.params[:limit] = _limit if _limit
end
-
-
- 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
-
-def self.get_LocationRankPlayer(locationId:, _limit:false, status:false)
- get
- res = @conn.get("v1/locations/#{locationId}/rankings/players") do |req|
- req.params[:limit] = _limit if _limit
+ def self.get_LocationRankPlayer(locationId:, _limit:false, status:false)
+ get
+ res = @conn.get("v1/locations/#{locationId}/rankings/players") do |req|
+ req.params[:limit] = _limit if _limit
end
-
-
- 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
-def self.get_LocationRank_ClanVersus(locationId:, _limit:false, status:false)
- get
- res = @conn.get("v1/locations/#{locationId}/rankings/clans-versus") do |req|
- req.params[:limit] = _limit if _limit
- end
-
- if status
- res.status
- else
- val = res.body
- convert = JSON.parse(val)
+ def self.get_LocationRankClanVersus(locationId:, _limit:false, status:false)
+ get
+ res = @conn.get("v1/locations/#{locationId}/rankings/clans-versus") do |req|
+ req.params[:limit] = _limit if _limit
end
-
-end
-
-def self.get_LocationRank_PlayerVersus(locationId:, _limit:false, status:false)
- get
- res = @conn.get("v1/locations/#{locationId}/rankings/players-versus") do |req|
- req.params[:limit] = _limit if _limit
+ 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_LocationRankPlayerVersus(locationId:, _limit:false, status:false)
+ get
+ res = @conn.get("v1/locations/#{locationId}/rankings/players-versus") do |req|
+ req.params[:limit] = _limit if _limit
+ end
+ if status
+ res.status
+ else
+ val = res.body
+ convert = JSON.parse(val)
+ end
+ end
+ end
end