Class: WipApi::Client
- Inherits:
-
Object
- Object
- WipApi::Client
- Defined in:
- lib/wip_api/client.rb
Constant Summary collapse
- API_URL =
'https://wip.chat/graphql'
Class Attribute Summary collapse
-
.api_key ⇒ Object
writeonly
Sets the attribute api_key.
Instance Method Summary collapse
Class Attribute Details
.api_key=(value) ⇒ Object (writeonly)
Sets the attribute api_key
12 13 14 |
# File 'lib/wip_api/client.rb', line 12 def api_key=(value) @api_key = value end |
Instance Method Details
#make_request(query) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/wip_api/client.rb', line 16 def make_request(query) http = Net::HTTP.new(api_uri.host, api_uri.port) http.use_ssl = true header = { "Authorization" => "bearer #{api_key}", "Content-Type" => "application/json" } request = Net::HTTP::Post.new(api_uri.request_uri, header) request.body = { query: query }.to_json # Send the request response = http.request(request) raise ChangeRejectedError.new(response.) if response.class.eql?(Net::HTTPUnprocessableEntity) json = JSON.parse(response.body) if json.has_key? "errors" raise json["errors"].first["message"] end json end |