Class: Wip::Client
- Inherits:
-
Object
- Object
- Wip::Client
- Defined in:
- lib/wip/client.rb
Constant Summary collapse
- API_ENDPOINT =
"https://wip.co/graphql"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #data(key) ⇒ Object
- #header ⇒ Object
-
#initialize(api_key: Wip::Auth.api_key) ⇒ Client
constructor
A new instance of Client.
- #request(query) ⇒ Object
Constructor Details
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
10 11 12 |
# File 'lib/wip/client.rb', line 10 def api_key @api_key end |
#json ⇒ Object (readonly)
Returns the value of attribute json.
10 11 12 |
# File 'lib/wip/client.rb', line 10 def json @json end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
10 11 12 |
# File 'lib/wip/client.rb', line 10 def response @response end |
Instance Method Details
#data(key) ⇒ Object
38 39 40 |
# File 'lib/wip/client.rb', line 38 def data(key) json["data"][key] if json end |
#header ⇒ Object
31 32 33 34 35 36 |
# File 'lib/wip/client.rb', line 31 def header { "Authorization": "bearer #{@api_key}", "Content-Type": "application/json" } end |
#request(query) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wip/client.rb', line 16 def request(query) uri = URI.parse(API_ENDPOINT) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.request_uri, header) request.body = { query: query }.to_json @response = http.request(request) @json = JSON.parse(@response.body) if @json.has_key? "errors" raise @json["errors"].first["message"] end @json end |