Sha256: 329f7a570d65f772ffc596c07e37e6ae472189f78440d4ddc498acbca8b307db
Contents?: true
Size: 741 Bytes
Versions: 5
Compression:
Stored size: 741 Bytes
Contents
require 'faraday' require 'faraday_middleware' require 'erb' module Pokemon module RestClient def self.get(endpoint, params=nil) if params.nil? query = endpoint else query = "#{endpoint}?#{params_to_query(params)}" end client.get(query) end protected def self.client @client = Faraday.new "#{API_URL}/v#{Pokemon.configuration.api_version}" do |conn| conn.response :xml, :content_type => /\bxml$/ conn.response :json, :content_type => /\bjson$/ conn.adapter Faraday.default_adapter end end def self.params_to_query(params) params.map {|p, v| "#{p}=#{ERB::Util.url_encode(v.to_s)}"}.join('&') end end end
Version data entries
5 entries across 5 versions & 1 rubygems