Class: Sisense::API::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



22
23
24
25
26
# File 'lib/sisense/api/client.rb', line 22

def initialize
  uri = URI.parse(base_uri)
  @http = Net::HTTP.new(uri.host, uri.port)
  @http.use_ssl = Sisense.use_ssl
end

Instance Attribute Details

#httpObject (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