lib/spyse/clients/base.rb in spysex-0.1.0 vs lib/spyse/clients/base.rb in spysex-0.2.0

- old
+ new

@@ -6,17 +6,33 @@ module Spyse module Client class Base HOST = "api.spyse.com" - VERSION = "v3" + VERSION = "v4" BASE_URL = "https://#{HOST}/#{VERSION}/data" def initialize(api_key) @api_key = api_key end + def _get(path, params = {}, &block) + uri = url_for(path) + uri.query = URI.encode_www_form(params) + get = Net::HTTP::Get.new(uri) + + request(get, &block) + end + + def _post(path, params = {}, &block) + post = Net::HTTP::Post.new(url_for(path)) + post.body = JSON.generate(params) + post["Content-Type"] = "application/json" + + request(post, &block) + end + private def url_for(path) URI(BASE_URL + path) end @@ -51,25 +67,9 @@ else error = json.dig("error", "message") || body raise Error, "Unsupported response code returned: #{code} - #{error}" end end - end - - def _get(path, params = {}, &block) - uri = url_for(path) - uri.query = URI.encode_www_form(params) - get = Net::HTTP::Get.new(uri) - - request(get, &block) - end - - def _post(path, params = {}, &block) - post = Net::HTTP::Post.new(url_for(path)) - post.body = JSON.generate(params) - post["Content-Type"] = "application/json" - - request(post, &block) end end end end