Class: MetallumCli::Client
- Inherits:
-
Object
- Object
- MetallumCli::Client
- Defined in:
- lib/metallum-cli/helpers/client.rb
Constant Summary collapse
- SITE_URL =
"http://www.metal-archives.com"
Class Method Summary collapse
- .format_array(arr, indexes) ⇒ Object
- .get(path) ⇒ Object
- .get_json(path) ⇒ Object
- .get_url(path) ⇒ Object
- .json_results(url) ⇒ Object
- .lang ⇒ Object
Class Method Details
.format_array(arr, indexes) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# 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) ⇒ Object
35 36 37 38 |
# 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) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# 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) ⇒ Object
40 41 42 43 44 |
# 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 ⇒ Object
9 10 11 |
# File 'lib/metallum-cli/helpers/client.rb', line 9 def self.lang Configuration.instance.lang end |