sisense 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sisense.rb +6 -2
- data/lib/sisense/api/client.rb +25 -4
- data/lib/sisense/api/error.rb +14 -0
- data/lib/sisense/api/not_found_error.rb +5 -0
- data/lib/sisense/api/resource.rb +1 -1
- data/lib/sisense/api/unprocessable_entity_error.rb +5 -0
- data/lib/sisense/group.rb +14 -2
- data/lib/sisense/utils/string.rb +2 -2
- data/lib/sisense/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c341c078fadf708c850b18d17e5f7feccee4ac814dcecba44d635d82a8ef3fc2
|
4
|
+
data.tar.gz: b728e16dbb30fd18d8831adb4c6e1189fc1f0baedef479e3a3d86e72ab3880a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ed7d1b9842bb6e7baf6166c4733e7cc0aa89f9c9babc358ed407c1a75ce249fb53127c4417b42061c30fb3b51efd9ef00cbb966e2f7170f9525da8f4d67b167
|
7
|
+
data.tar.gz: b40f1dcdebd041efd630b7254c17b9561253512642415dcf571122b9187cf15588b557cbf8f8bd423791f360099f74042df371e4db4996efa48a5ea077adfcd0
|
data/lib/sisense.rb
CHANGED
@@ -3,6 +3,9 @@ require 'sisense/version'
|
|
3
3
|
require 'sisense/api/client'
|
4
4
|
require 'sisense/api/resource'
|
5
5
|
require 'sisense/api/nested_resource'
|
6
|
+
require 'sisense/api/error'
|
7
|
+
require 'sisense/api/not_found_error'
|
8
|
+
require 'sisense/api/unprocessable_entity_error'
|
6
9
|
|
7
10
|
require 'sisense/alert'
|
8
11
|
require 'sisense/connection'
|
@@ -19,10 +22,11 @@ require 'sisense/widget'
|
|
19
22
|
|
20
23
|
module Sisense
|
21
24
|
@access_token = nil
|
22
|
-
@
|
25
|
+
@hostname = nil
|
26
|
+
@use_ssl = false
|
23
27
|
|
24
28
|
class << self
|
25
|
-
attr_accessor :access_token, :
|
29
|
+
attr_accessor :access_token, :hostname, :use_ssl
|
26
30
|
|
27
31
|
def api_resources
|
28
32
|
@api_resources ||= API::Resource.descendants.each_with_object({}) do |descendant, resources|
|
data/lib/sisense/api/client.rb
CHANGED
@@ -15,9 +15,9 @@ module Sisense
|
|
15
15
|
}.freeze
|
16
16
|
|
17
17
|
def initialize
|
18
|
-
uri = URI.parse(
|
18
|
+
uri = URI.parse(base_uri)
|
19
19
|
@http = Net::HTTP.new(uri.host, uri.port)
|
20
|
-
|
20
|
+
@http.use_ssl = Sisense.use_ssl
|
21
21
|
end
|
22
22
|
|
23
23
|
attr_reader :http
|
@@ -53,6 +53,10 @@ module Sisense
|
|
53
53
|
|
54
54
|
private
|
55
55
|
|
56
|
+
def base_uri
|
57
|
+
@base_uri ||= Sisense.use_ssl ? "https://#{Sisense.hostname}" : "http://#{Sisense.hostname}"
|
58
|
+
end
|
59
|
+
|
56
60
|
def collection?(response_body)
|
57
61
|
response_body.is_a?(Array)
|
58
62
|
end
|
@@ -65,7 +69,24 @@ module Sisense
|
|
65
69
|
request = VERB_MAP[method].new(encode_path(path), headers)
|
66
70
|
request.body = parameterize(params).to_json
|
67
71
|
end
|
68
|
-
http.request(request)
|
72
|
+
handle_response(http.request(request))
|
73
|
+
end
|
74
|
+
|
75
|
+
def handle_response(response)
|
76
|
+
return response if %w[200 201 204].include?(response.code)
|
77
|
+
handle_error(response)
|
78
|
+
end
|
79
|
+
|
80
|
+
def handle_error(response)
|
81
|
+
error_params = JSON.parse(response.body, symbolize_names: true)[:error]
|
82
|
+
case response.code
|
83
|
+
when '404'
|
84
|
+
raise Sisense::API::NotFoundError.new(error_params)
|
85
|
+
when '422'
|
86
|
+
raise Sisense::API::UnprocessableEntityError.new(error_params)
|
87
|
+
else
|
88
|
+
raise Sisense::API::Error.new(error_params)
|
89
|
+
end
|
69
90
|
end
|
70
91
|
|
71
92
|
def encode_path(path, params = nil)
|
@@ -86,7 +107,7 @@ module Sisense
|
|
86
107
|
|
87
108
|
obj.keys.each do |key|
|
88
109
|
obj[key] = parameterize_object(obj[key]) unless obj[key].is_a?(String)
|
89
|
-
obj[key.to_s.
|
110
|
+
obj[key.to_s.to_camel_case] = obj.delete(key)
|
90
111
|
end
|
91
112
|
end
|
92
113
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Sisense
|
2
|
+
module API
|
3
|
+
class Error < StandardError
|
4
|
+
attr_reader :code, :message, :status, :http_message
|
5
|
+
|
6
|
+
def initialize(**error_params)
|
7
|
+
@code = error_params[:code]
|
8
|
+
@message = error_params[:message]
|
9
|
+
@status = error_params[:status]
|
10
|
+
@http_message = error_params[:http_message]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/sisense/api/resource.rb
CHANGED
data/lib/sisense/group.rb
CHANGED
@@ -2,9 +2,21 @@ module Sisense
|
|
2
2
|
class Group < API::Resource
|
3
3
|
RESOURCE_NAME = 'groups'.freeze
|
4
4
|
|
5
|
-
def self.list
|
5
|
+
def self.list(params: nil)
|
6
6
|
path = resource_base_path
|
7
|
-
response = api_client.get(path)
|
7
|
+
response = api_client.get(path, params: params)
|
8
|
+
api_client.parsed_response(response, object_class: self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.retrieve(id:, params: nil)
|
12
|
+
path = [resource_base_path, id].join('/')
|
13
|
+
response = api_client.get(path, params: params)
|
14
|
+
api_client.parsed_response(response, object_class: self)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.create(params:)
|
18
|
+
path = resource_base_path
|
19
|
+
response = api_client.post(path, params: params)
|
8
20
|
api_client.parsed_response(response, object_class: self)
|
9
21
|
end
|
10
22
|
end
|
data/lib/sisense/utils/string.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class String
|
2
|
-
def
|
2
|
+
def to_snake_case
|
3
3
|
gsub(/::/, '/')
|
4
4
|
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
5
5
|
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
@@ -7,7 +7,7 @@ class String
|
|
7
7
|
.downcase
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def to_camel_case
|
11
11
|
split('_').each_with_object([]).with_index do |(string_part, string_parts), index|
|
12
12
|
string_part.capitalize! if index > 0
|
13
13
|
string_parts << string_part
|
data/lib/sisense/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sisense
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olivier Buffon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -129,8 +129,11 @@ files:
|
|
129
129
|
- lib/sisense.rb
|
130
130
|
- lib/sisense/alert.rb
|
131
131
|
- lib/sisense/api/client.rb
|
132
|
+
- lib/sisense/api/error.rb
|
132
133
|
- lib/sisense/api/nested_resource.rb
|
134
|
+
- lib/sisense/api/not_found_error.rb
|
133
135
|
- lib/sisense/api/resource.rb
|
136
|
+
- lib/sisense/api/unprocessable_entity_error.rb
|
134
137
|
- lib/sisense/connection.rb
|
135
138
|
- lib/sisense/dashboard.rb
|
136
139
|
- lib/sisense/dataset.rb
|