Class: Sisense::API::Client
- Inherits:
-
Object
- Object
- Sisense::API::Client
- Includes:
- ERB::Util
- Defined in:
- lib/sisense/api/client.rb
Constant Summary collapse
- PATH_SEGMENT_PATTERN =
%r{[^/]+}.freeze
- VERB_MAP =
{ get: Net::HTTP::Get, post: Net::HTTP::Post, put: Net::HTTP::Put, patch: Net::HTTP::Patch, delete: Net::HTTP::Delete }.freeze
Instance Attribute Summary collapse
-
#http ⇒ Object
readonly
Returns the value of attribute http.
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path, params: {}) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #parsed_response(response, object_class:) ⇒ Object
- #patch(path, params: {}) ⇒ Object
- #post(path, params: {}) ⇒ Object
- #put(path, params: {}) ⇒ Object
Constructor Details
Instance Attribute Details
#http ⇒ Object (readonly)
Returns the value of attribute http.
28 29 30 |
# File 'lib/sisense/api/client.rb', line 28 def http @http end |
Instance Method Details
#delete(path) ⇒ Object
46 47 48 |
# File 'lib/sisense/api/client.rb', line 46 def delete(path) request :delete, path end |
#get(path, params: {}) ⇒ Object
30 31 32 |
# File 'lib/sisense/api/client.rb', line 30 def get(path, params: {}) request :get, path, params end |
#parsed_response(response, object_class:) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sisense/api/client.rb', line 50 def parsed_response(response, object_class:) response_hash = JSON.parse(response.body) if collection?(response_hash) response_hash .select { |obj| obj.is_a?(Hash) } .map { |json_item| object_class.new(json_item) } else object_class.new(response_hash) end end |
#patch(path, params: {}) ⇒ Object
42 43 44 |
# File 'lib/sisense/api/client.rb', line 42 def patch(path, params: {}) request :patch, path, params end |
#post(path, params: {}) ⇒ Object
34 35 36 |
# File 'lib/sisense/api/client.rb', line 34 def post(path, params: {}) request :post, path, params end |
#put(path, params: {}) ⇒ Object
38 39 40 |
# File 'lib/sisense/api/client.rb', line 38 def put(path, params: {}) request :put, path, params end |