class MetallumCli::Client
Constants
- SITE_URL
Public Class Methods
format_array(arr, indexes)
click to toggle source
# File lib/metallum-cli/helpers/client.rb, line 46 def self.format_array(arr, indexes) unique = indexes.length formatted = [] aux = [] arr.each_with_index do |e, i| aux.push e if(i > 0 && i % unique == unique-1) # aux[-1] += "\n\n" formatted.push aux aux = [] end end formatted end
get(path)
click to toggle source
# File lib/metallum-cli/helpers/client.rb, line 13 def self.get(path) uri = URI("#{SITE_URL}/#{path}") req = Net::HTTP::Get.new(uri) res = Net::HTTP.start(uri.hostname, uri.port) {|http| http.request(req) } res end
get_json(path)
click to toggle source
# File lib/metallum-cli/helpers/client.rb, line 35 def self.get_json(path) # puts "#{SITE_URL}/#{path}" json_results "#{SITE_URL}/#{path}" end
get_url(path)
click to toggle source
# File lib/metallum-cli/helpers/client.rb, line 24 def self.get_url(path) uri = URI(path) req = Net::HTTP::Get.new(uri) res = Net::HTTP.start(uri.hostname, uri.port) {|http| http.request(req) } res.body end
json_results(url)
click to toggle source
# File lib/metallum-cli/helpers/client.rb, line 40 def self.json_results(url) response = Net::HTTP.get_response(URI.parse(url)) data = response.body JSON.parse(data) end
lang()
click to toggle source
# File lib/metallum-cli/helpers/client.rb, line 9 def self.lang Configuration.instance.lang end