Class: Pennylane::Client
- Inherits:
-
Object
- Object
- Pennylane::Client
- Defined in:
- lib/pennylane/client.rb
Constant Summary collapse
- BASE_URI =
'app.pennylane.com/api/external'.freeze
- VERSION =
'v1'.freeze
Instance Attribute Summary collapse
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #authorization(key) ⇒ Object
- #base_uri ⇒ Object
- #http ⇒ Object
-
#initialize(key, version: 'v1') ⇒ Client
constructor
A new instance of Client.
- #klass(method) ⇒ Object
- #request(method, path, params: {}, opts: {}) ⇒ Object
- #url(path, query = {}) ⇒ Object
Constructor Details
#initialize(key, version: 'v1') ⇒ Client
Returns a new instance of Client.
8 9 10 11 |
# File 'lib/pennylane/client.rb', line 8 def initialize(key, version: 'v1') @key = key @version = version end |
Instance Attribute Details
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/pennylane/client.rb', line 6 def version @version end |
Instance Method Details
#authorization(key) ⇒ Object
24 25 26 |
# File 'lib/pennylane/client.rb', line 24 def (key) "Bearer #{key}" end |
#base_uri ⇒ Object
19 20 21 |
# File 'lib/pennylane/client.rb', line 19 def base_uri URI("https://#{BASE_URI}") end |
#http ⇒ Object
27 28 29 30 31 |
# File 'lib/pennylane/client.rb', line 27 def http Net::HTTP.new(base_uri.host, base_uri.port).tap do |http| http.use_ssl = true end end |
#klass(method) ⇒ Object
33 34 35 |
# File 'lib/pennylane/client.rb', line 33 def klass(method) Net::HTTP.const_get(method.to_s.capitalize) end |
#request(method, path, params: {}, opts: {}) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/pennylane/client.rb', line 37 def request method, path, params: {}, opts: {} req = initialize_request(method, path, params[:query], opts).tap do |req| req.body = params[:body].to_json if params[:body] end http.request(req).tap do |resp| handle_error_response(resp) if should_handle_as_error?(resp.code) end end |