lib/nuva.rb in nuva-0.4.1 vs lib/nuva.rb in nuva-0.5.1

- old
+ new

@@ -58,25 +58,25 @@ def inspect "#<Nuva::Nuva version=#{version.major}.#{version.minor}.#{version.patch} diseaseCount=#{repositories.diseases.all.count} vaccineCount=#{repositories.vaccines.all.count} valenceCount=#{repositories.valences.all.count}>" end class << self - CDN_URI = URI("https://cdnnuva.mesvaccins.net/") + DEFAULT_CDN_URI = URI("https://nuva.svc.edge.scw.cloud") - def load(lang: "en", hash: nil) - init_http do |http| + def load(cdn_uri: DEFAULT_CDN_URI, lang: "en", hash: nil) + init_http(cdn_uri) do |http| # Fetch version manifest if necessary hash ||= fetch_latest_version_hash(http:) response = http.get("/proto/#{hash}_en.db") ::Nuva::Nuva.new(::Nuva::NuvaDatabase.decode(response.body)) end end - def fetch_latest_version_hash(http: nil) + def fetch_latest_version_hash(cdn_uri: DEFAULT_CDN_URI, http: nil) if http.nil? - http = init_http + http = init_http(cdn_uri) passed_http = false end response = http.get("/versions/last.json") hash = JSON.parse(response.body)["dump_hash"] http.finish unless passed_http @@ -87,14 +87,14 @@ Nuva.new(NuvaDatabase.decode(File.read(path))) end private - def init_http(&block) + def init_http(cdn_uri, &block) Net::HTTP.start( - CDN_URI.host, - CDN_URI.port, - use_ssl: CDN_URI.scheme == "https", + cdn_uri.host, + cdn_uri.port, + use_ssl: cdn_uri.scheme == "https", &block ) end end end