Class: GithubApi::V4::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/github_api/v4/client/version.rb,
lib/github_api/v4/client.rb

Constant Summary collapse

VERSION =
'0.1.0'
ENDPOINT =
URI.parse('https://api.github.com')
ClientError =
Class.new(StandardError)
ServerError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ Client

Returns a new instance of Client.

Parameters:

  • access_token (String)


13
14
15
# File 'lib/github_api/v4/client.rb', line 13

def initialize(access_token)
  @access_token = access_token
end

Instance Method Details

#graphql(query:, variables: {}) ⇒ Hash

Parameters:

  • query (String)
  • variables (Hash) (defaults to: {})

Returns:

  • (Hash)


20
21
22
23
24
# File 'lib/github_api/v4/client.rb', line 20

def graphql(query:, variables: {})
  resp = post('/graphql', query: query, variables: variables)
  handle_errors(resp)
  JSON.parse(resp.body)
end

#schemaHash

Returns:

  • (Hash)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/github_api/v4/client.rb', line 27

def schema
  graphql(query: <<~GRAPHQL)
    query {
      __schema {
        types {
          name
          kind
          description
          fields {
            name
          }
        }
      }
    }
  GRAPHQL
end

#type(name) ⇒ Hash

Parameters:

  • name (String)

Returns:

  • (Hash)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/github_api/v4/client.rb', line 46

def type(name)
  graphql(query: <<~GRAPHQL)
    query {
      __type(name: #{name.dump}) {
        name
        kind
        description
        fields {
          name
        }
      }
    }
  GRAPHQL
end