Sha256: 0351fd334f9063a2f9d7ad82a9915fb6097d761cf9cc12830903930e3b2273b4

Contents?: true

Size: 766 Bytes

Versions: 2

Compression:

Stored size: 766 Bytes

Contents

require 'httparty'
require 'json'

module Anilistrb
  class GqlClient
    def initialize(url)
      @url = url
    end

    def build_request(query:, variables: nil)
      [ @url, 
        headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' },
        body: { query: query, variables: variables }.to_json ]
    end

    def request(method:, query:, variables: nil)
      # TODO: check if status code not 200
      if method == 'POST'
        HTTParty.post(*build_request(query: query, variables: variables))
      elsif method == 'GET'
        HTTParty.get(*build_request(query: query, variables: variables))
      else                       
        puts "#{method} not supported."
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
Anilistrb-0.1.2 lib/Anilistrb/GqlClient.rb
Anilistrb-0.1.1 lib/Anilistrb/GqlClient.rb