Class: GithubApi::V4::Client
- Inherits:
-
Object
- Object
- GithubApi::V4::Client
- Defined in:
- lib/github_api/v4/client/version.rb,
lib/github_api/v4/client.rb
Constant Summary collapse
- VERSION =
'0.2.0'- ENDPOINT =
URI.parse('https://api.github.com')
- ClientError =
Class.new(StandardError)
- ServerError =
Class.new(StandardError)
Instance Method Summary collapse
- #graphql(query:, variables: {}) ⇒ Hash
-
#initialize(access_token) ⇒ Client
constructor
A new instance of Client.
- #query_schema ⇒ Hash
- #rate_limit ⇒ Object
- #schema ⇒ Hash
- #type(name) ⇒ Hash
Constructor Details
#initialize(access_token) ⇒ Client
Returns a new instance of Client.
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
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 |
#query_schema ⇒ Hash
68 69 70 |
# File 'lib/github_api/v4/client.rb', line 68 def query_schema type('Query') end |
#rate_limit ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/github_api/v4/client.rb', line 130 def rate_limit graphql(query: " query {\n rateLimit {\n remaining\n limit\n }\n }\n GRAPHQL\nend\n").dig('data', 'rateLimit') |
#schema ⇒ Hash
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/github_api/v4/client.rb', line 27 def schema graphql(query: " query {\n __schema {\n types {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n name\n description\n type {\n name\n }\n defaultValue\n }\n type {\n name\n description\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n name\n description\n type {\n name\n }\n defaultValue\n }\n }\n }\n }\n GRAPHQL\nend\n") |
#type(name) ⇒ Hash
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/github_api/v4/client.rb', line 74 def type(name) graphql(query: " query {\n __type(name: \#{name.dump}) {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n name\n description\n type {\n name\n }\n defaultValue\n }\n type {\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n name\n description\n type {\n name\n }\n defaultValue\n }\n type {\n name\n description\n }\n isDeprecated\n deprecationReason\n }\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n name\n description\n type {\n name\n }\n defaultValue\n }\n }\n }\n GRAPHQL\nend\n") |