Sha256: 9e7a89ff8704a8913f245d34347ce94b915e2e8368e7ee14a05636172be0affe
Contents?: true
Size: 910 Bytes
Versions: 2
Compression:
Stored size: 910 Bytes
Contents
module NintendoEshop class APIRequest class << self; end private def request(method, to_json: {}) case method when :post post(to_json: to_json) end end def post(to_json: {}) uri = URI("#{NintendoEshop.base_url}#{self.class::RESOURCE_PATH}?#{url_params}") http = setup_http(uri) req = Net::HTTP::Post.new(uri) req.add_field "Accept", "application/json" req.add_field "Content-Type", "application/json" req.body = JSON.dump(to_json) res = http.request(req) JSON.parse(res.body, symbolize_names: true) end def setup_http(uri) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_PEER http end def url_params "x-algolia-api-key=#{NintendoEshop.api_key}&x-algolia-application-id=#{NintendoEshop.app_id}" end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nintendo_eshop-0.1.0.alpha2 | lib/nintendo_eshop/api_request.rb |
nintendo_eshop-0.1.0.alpha1 | lib/nintendo_eshop/api_request.rb |