lib/soccers_api.rb in soccers_api-1.0.5 vs lib/soccers_api.rb in soccers_api-1.0.6
- old
+ new
@@ -1,50 +1,100 @@
-require "soccers_api/continent"
+# frozen_string_literal: true
+
+require 'soccers_api/continent'
+require 'soccers_api/configuration'
+require 'rest-client'
+
+module SoccersApi
+ class << self
+ attr_accessor :configuration
+ end
+
+ def self.configuration
+ @configuration ||= Configuration.new
+ end
+
+ def self.reset
+ @configuration = Configuration.new
+ end
+
+ def self.configure
+ yield(configuration)
+ end
+
+ def self.username
+ @configuration.username
+ end
+
+ def self.token
+ @configuration.token
+ end
+
+ protected
+
+ def self.api_url(api_for:, type:, id_type: nil , id: nil, id_type_two: nil, id_two: nil)
+ if type=='list'
+ url = "https://api.soccersapi.com/v2.2/#{api_for}/?user=#{
+ username
+ }&token=#{token}&t=list"
+ elsif id_type_two.present? && id_two.present?
+ url = "https://api.soccersapi.com/v2.2/#{api_for}/?user=#{
+ username
+ }&token=#{token}&t=#{type}&#{id_type}=#{id}&#{id_type_two}=#{id_two}"
+ else
+ url = "https://api.soccersapi.com/v2.2/#{api_for}/?user=#{
+ username
+ }&token=#{token}&t=#{type}&#{id_type}=#{id}"
+ end
+ response = RestClient.get url
+ JSON.parse(response.body)
+ end
+end