Class: Anilistrb::GqlClient
- Inherits:
-
Object
- Object
- Anilistrb::GqlClient
- Defined in:
- lib/Anilistrb/GqlClient.rb
Instance Method Summary collapse
- #build_request(query:, variables: nil) ⇒ Object
-
#initialize(url) ⇒ GqlClient
constructor
A new instance of GqlClient.
- #request(method:, query:, variables: nil) ⇒ Object
Constructor Details
#initialize(url) ⇒ GqlClient
Returns a new instance of GqlClient.
6 7 8 |
# File 'lib/Anilistrb/GqlClient.rb', line 6 def initialize(url) @url = url end |
Instance Method Details
#build_request(query:, variables: nil) ⇒ Object
10 11 12 13 14 |
# File 'lib/Anilistrb/GqlClient.rb', line 10 def build_request(query:, variables: nil) [ @url, headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }, body: { query: query, variables: variables }.to_json ] end |
#request(method:, query:, variables: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/Anilistrb/GqlClient.rb', line 16 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 |