looker-sdk 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a9c372139d8df28af2b71bce4382f3badfa6d1c8
4
- data.tar.gz: 66910d788e066ef3767f76966e1973ca7312e3c4
2
+ SHA256:
3
+ metadata.gz: ae194b96e860627f144eecc7921ce55b3a27930d574040d81f12bb663c6e96ba
4
+ data.tar.gz: c6bbf41bafaf912397caa40e61afc6d1e11382785b50f042704d4d046a3b3629
5
5
  SHA512:
6
- metadata.gz: 043052d8df89d53724b1fe23e181ae5eafb598ff4aca2dd44d8d030510ffe98dffeb8c51a9a180c594b64597500d42b13db84f08d1969fcdb3d571c98e9eb49e
7
- data.tar.gz: 8627156eb5061245b16330094381786800e1c32c1fbb8340297e962429a97ad14cc75e2fc2fe8073297e4c7b61751298c629da8ee65721c38c0b5975b643f644
6
+ metadata.gz: 3e75dc981959db75e1ff4a849ad9208d7299f380af2484e44850db2075d75fbd359f82cb0f1fcb68c6b0165a0d7612161cc112ec86b285ee06057548f8ccef03
7
+ data.tar.gz: b3798c47cb1b978541a723a1840c19ff60dbd8d8b7584cc0e5b9438b2d0216fea627bf66ba920acbc6c6ec236e117578b48c9e6ec4bafc3bcd880130579e052f
data/.travis.yml CHANGED
@@ -4,7 +4,7 @@ rvm:
4
4
  - 2.0
5
5
  - 2.1
6
6
  - 2.3.1
7
- - jruby-1.7.19
7
+ - jruby-1.7.27
8
8
  - jruby-9.1.5.0
9
9
  cache:
10
10
  bundler: true
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at opensource@looker.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
@@ -0,0 +1,9 @@
1
+ require './sdk_setup'
2
+
3
+ users = sdk.all_users(fields:'id, is_disabled, display_name, credentials_embed').map do |u|
4
+ next if u.is_diabled || u.credentials_embed.empty?
5
+ creds = u.credentials_embed.first
6
+ [u.id, u.display_name, creds.external_user_id, creds.external_group_id, creds.logged_in_at]
7
+ end.compact
8
+
9
+ users.each{|u| p u}
@@ -190,10 +190,34 @@ module LookerSDK
190
190
  #
191
191
  # @return http status code
192
192
  def alive
193
- get '/alive'
193
+ without_authentication do
194
+ get '/alive'
195
+ end
194
196
  last_response.status
195
197
  end
196
198
 
199
+ # Are we connected to the server? - Does not attempt to authenticate.
200
+ def alive?
201
+ begin
202
+ without_authentication do
203
+ get('/alive')
204
+ end
205
+ true
206
+ rescue
207
+ false
208
+ end
209
+ end
210
+
211
+ # Are we connected and authenticated to the server?
212
+ def authenticated?
213
+ begin
214
+ ensure_logged_in
215
+ true
216
+ rescue
217
+ false
218
+ end
219
+ end
220
+
197
221
  # Response for last HTTP request
198
222
  #
199
223
  # @return [Sawyer::Response]
@@ -365,15 +389,20 @@ module LookerSDK
365
389
 
366
390
  # slight modification to the base class' decode_hash_value function to
367
391
  # less permissive when decoding time values.
392
+ # also prevent conversion from non-string types to Time e.g. integer/float timestamp
368
393
  #
369
394
  # See https://github.com/looker/looker-sdk-ruby/issues/53 for more details
370
395
  #
371
396
  # Base class function that we're overriding: https://github.com/lostisland/sawyer/blob/master/lib/sawyer/serializer.rb#L101-L121
372
397
  def decode_hash_value(key, value)
373
- if time_field?(key, value) && value.is_a?(String)
374
- begin
375
- Time.iso8601(value)
376
- rescue ArgumentError
398
+ if time_field?(key, value)
399
+ if value.is_a?(String)
400
+ begin
401
+ Time.iso8601(value)
402
+ rescue ArgumentError
403
+ value
404
+ end
405
+ else
377
406
  value
378
407
  end
379
408
  else
@@ -2,6 +2,6 @@ module LookerSDK
2
2
 
3
3
  # Current version
4
4
  # @return [String]
5
- VERSION = "0.0.5"
5
+ VERSION = "0.0.6"
6
6
 
7
7
  end
data/looker-sdk.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = LookerSDK::VERSION
8
8
  s.date = "#{Time.now.strftime('%F')}"
9
9
  s.authors = ['Looker']
10
- s.email = 'support@looker.com'
10
+ s.email = 'opensource+sdkruby@looker.com'
11
11
  s.homepage = 'https://github.com/looker/looker-sdk-ruby'
12
12
  s.summary = %q{Looker Ruby SDK}
13
13
  s.description = 'Use this SDK to access the Looker API. The Looker API provides functions to perform administrative '+
@@ -23,5 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
24
24
  s.require_paths = %w(lib)
25
25
  s.add_dependency 'jruby-openssl' if s.platform == :jruby
26
- s.add_dependency 'sawyer', '0.6'
26
+ s.add_dependency 'sawyer', '~> 0.8'
27
+ s.add_dependency 'faraday', ['>= 0.9.0', '< 1.0']
27
28
  end
data/readme.md CHANGED
@@ -4,7 +4,7 @@ This SDK supports secure/authenticated access to the Looker RESTful API. The SDK
4
4
 
5
5
  The Looker API uses OAuth2 authentication. 'API3' keys can be generated by Looker admins for any Looker user account from the Looker admin panel. These 'keys' each consist of a client_id/client_secret pair. These keys should be carefully protected as one would with any critical password. When using the SDK, one creates a client object that is initialized with a client_id/client_secret pair and the base URL of the Looker instance's API endpoint. The SDK transparently logs in to the API with that key pair to generate a short-term auth token that it sends to the API with each subsequent call to provide authentication for that call.
6
6
 
7
- All calls to the Looker API must be done over a TSL/SSL connection. Requests and responses are then encrypted at that transport layer. It is highly recommended that Looker instance https endpoints use certificates that are properly signed by a trusted certificate authority. The SDK will, by default, validate server certificates. It is possible to disable that validation when creating an SDK client object if necessary. But, that configuration is discouraged.
7
+ All calls to the Looker API must be done over a TLS/SSL connection. Requests and responses are then encrypted at that transport layer. It is highly recommended that Looker instance https endpoints use certificates that are properly signed by a trusted certificate authority. The SDK will, by default, validate server certificates. It is possible to disable that validation when creating an SDK client object if necessary. But, that configuration is discouraged.
8
8
 
9
9
  Looker instances expose API documentation at: https://mygreatcompany.looker.com:19999/api-docs/index.html (the exact URL can be set in the Looker admin panel). By default, the documentation page requires a client_id/client_secret pair to load the detailed API information. That page also supports "Try it out!" links so that you can experiment with the API right from the documentation. The documentation is intended to show how to call the API endpoints via either raw RESTful https requests or using the SDK.
10
10
 
@@ -55,14 +55,14 @@ sdk = LookerSDK::Client.new(
55
55
  :netrc_file => "~/.net_rc",
56
56
  :api_endpoint => "https://mygreatcompany.looker.com:19999/api/3.0",
57
57
 
58
- # Disable cert verification if the looker has a self-signed cert.
58
+ # Set longer timeout to allow for long running queries. The default is 60 seconds and can be problematic.
59
+ :connection_options => {:request => {:timeout => 60 * 60, :open_timeout => 30}},
60
+
61
+ # Alternately, disable cert verification if the looker has a self-signed cert.
59
62
  # Avoid this if using real certificates; verification of the server cert is a very good thing for production.
60
63
  # :connection_options => {:ssl => {:verify => false}},
61
64
 
62
- # Set longer timeout to allow for long running queries.
63
- # :connection_options => {:request => {:timeout => 60 * 60, :open_timeout => 30}},
64
-
65
- # Support self-signed cert *and* set longer timeout to allow for long running queries.
65
+ # Alternately, support self-signed cert *and* set longer timeout to allow for long running queries.
66
66
  # :connection_options => {:ssl => {:verify => false}, :request => {:timeout => 60 * 60, :open_timeout => 30}},
67
67
  )
68
68
 
data/shell/shell.rb CHANGED
@@ -16,7 +16,7 @@ def sdk
16
16
  # Support self-signed cert *and* set longer timeout to allow for long running queries.
17
17
  :connection_options => {:ssl => {:verify => false}, :request => {:timeout => 60 * 60, :open_timeout => 30}},
18
18
 
19
- :api_endpoint => "https://self-signed.looker.com:19999/api/3.0",
19
+ :api_endpoint => "https://localhost:19999/api/3.0",
20
20
 
21
21
  # Customize to use your specific looker instance
22
22
  # :connection_options => {:ssl => {:verify => true}},
@@ -26,7 +26,8 @@ end
26
26
 
27
27
  begin
28
28
  puts "Connecting to Looker at '#{sdk.api_endpoint}'"
29
- puts (code = sdk.alive) == 200 ? "Looker is alive!" : "Sad Looker: #{code}"
29
+ puts sdk.alive? ? "Looker is alive!" : "Sad Looker, can't connect:\n #{sdk.last_error}"
30
+ puts sdk.authenticated? ? "Authenticated!" : "Sad Looker, can't authenticate:\n #{sdk.last_error}"
30
31
 
31
32
  binding.pry self
32
33
  rescue Exception => e
@@ -3,13 +3,13 @@
3
3
  "info": {
4
4
  "version": "3.0.0",
5
5
  "title": "Looker API",
6
- "description": "This document describes the Looker API.",
6
+ "description": "This document is a representative sample (subset) of the Looker API that should only be used to unit test the Looker ruby sdk. To get the current, actual Looker API metadata visit /api/3.0/swagger.json on your Looker instance.",
7
7
  "contact": {
8
8
  "name": "Looker Team <support@looker.com>"
9
9
  },
10
10
  "license": {
11
11
  "name": "EULA",
12
- "url": "https://localhost:9999/eula"
12
+ "url": "https://learn.looker.com/eula"
13
13
  }
14
14
  },
15
15
  "basePath": "/api/3.0",
@@ -1253,6 +1253,77 @@
1253
1253
  }
1254
1254
  }
1255
1255
  },
1256
+ "/users/{user_id}/attribute_values": {
1257
+ "get": {
1258
+ "tags": [
1259
+ "User"
1260
+ ],
1261
+ "operationId": "user_attribute_user_values",
1262
+ "summary": "Get User Attribute Values",
1263
+ "description": "### Get user attribute values for a given user.\n\nReturns the values of specified user attributes (or all user attributes) for a certain user.\n\nA value for each user attribute is searched for in the following locations, in this order:\n1. in the user's account information\n1. in groups that the user is a member of\n1. the default value of the user attribute\n\nIf more than one group has a value defined for a user attribute, the group with the lowest rank wins.\n\nThe response will only include user attributes for which values were found. Use `include_unset=true` to include\nempty records for user attributes with no value.\n\nThe value of all hidden user attributes will be blank.\n",
1264
+ "parameters": [
1265
+ {
1266
+ "name": "user_id",
1267
+ "in": "path",
1268
+ "description": "Id of user",
1269
+ "required": true,
1270
+ "type": "integer",
1271
+ "format": "int64"
1272
+ },
1273
+ {
1274
+ "name": "fields",
1275
+ "in": "query",
1276
+ "description": "Requested fields.",
1277
+ "required": false,
1278
+ "type": "string"
1279
+ },
1280
+ {
1281
+ "name": "user_attribute_ids",
1282
+ "in": "query",
1283
+ "description": "Specific user attributes to request. Omit or leave blank to request all user attributes.",
1284
+ "required": false,
1285
+ "type": "array",
1286
+ "items": {
1287
+ "type": "integer",
1288
+ "format": "int64"
1289
+ },
1290
+ "collectionFormat": "csv"
1291
+ },
1292
+ {
1293
+ "name": "all_values",
1294
+ "in": "query",
1295
+ "description": "If true, returns all values in the search path instead of just the first value found. Useful for debugging group precedence.",
1296
+ "required": false,
1297
+ "type": "boolean"
1298
+ },
1299
+ {
1300
+ "name": "include_unset",
1301
+ "in": "query",
1302
+ "description": "If true, returns an empty record for each requested attribute that has no user, group, or default value.",
1303
+ "required": false,
1304
+ "type": "boolean"
1305
+ }
1306
+ ],
1307
+ "responses": {
1308
+ "404": {
1309
+ "description": "Not Found",
1310
+ "schema": {
1311
+ "$ref": "#/definitions/Error"
1312
+ }
1313
+ },
1314
+ "200": {
1315
+ "description": "Value of user attribute.",
1316
+ "schema": {
1317
+ "type": "array",
1318
+ "items": {
1319
+ "$ref": "#/definitions/UserAttributeWithValue"
1320
+ }
1321
+ }
1322
+ }
1323
+ },
1324
+ "x-looker-status": "beta"
1325
+ }
1326
+ },
1256
1327
  "/users/{user_id}/roles": {
1257
1328
  "get": {
1258
1329
  "tags": [
@@ -212,12 +212,18 @@ describe LookerSDK::Client do
212
212
 
213
213
  describe 'Sawyer date/time parsing patch' do
214
214
  describe 'key matches time_field pattern' do
215
- it 'does not modify non-iso date/time string' do
215
+ it 'does not modify non-iso date/time string or integer fields' do
216
216
  values = {
217
217
  :test_at => '30 days',
218
218
  :test_on => 'July 20, 1969',
219
219
  :test_date => '1968-04-03 12:23:34', # this is not iso8601 format!
220
220
  :date => '2 months ago',
221
+ :test_int_at => 42,
222
+ :test_int_on => 42,
223
+ :test_int_date => 42.1,
224
+ :test_float_at => 42.1,
225
+ :test_float_on => 42.1,
226
+ :test_float_date => 42.1,
221
227
  }
222
228
 
223
229
  serializer = LookerSDK::Client.new.send(:serializer)
@@ -1,6 +1,6 @@
1
1
  require_relative '../helper'
2
2
 
3
- describe LookerSDK::Client::Dynamic do
3
+ class LookerDynamicClientTest < MiniTest::Spec
4
4
 
5
5
  def access_token
6
6
  '87614b09dd141c22800f96f11737ade5226d7ba8'
@@ -66,10 +66,21 @@ describe LookerSDK::Client::Dynamic do
66
66
  mock.verify
67
67
  end
68
68
 
69
-
70
69
  describe "swagger" do
71
70
 
72
- it "get" do
71
+ it "invalid method name" do
72
+ mock = MiniTest::Mock.new.expect(:call, response){|env| confirm_env(env, method, path, body, query, content_type)}
73
+ sdk = sdk_client(default_swagger, mock)
74
+ assert_raises NoMethodError do
75
+ sdk.this_method_name_doesnt_exist()
76
+ end
77
+
78
+ assert_raises NameError do
79
+ sdk.invoke(:this_method_name_doesnt_exist)
80
+ end
81
+ end
82
+
83
+ it "get no params" do
73
84
  verify(response, :get, '/api/3.0/user') do |sdk|
74
85
  sdk.me
75
86
  end
@@ -93,6 +104,20 @@ describe LookerSDK::Client::Dynamic do
93
104
  end
94
105
  end
95
106
 
107
+ it "get with array query param - string input (csv)" do
108
+ verify(response, :get, '/api/3.0/users/1/attribute_values','',{user_attribute_ids: '2,3,4'}) do |sdk|
109
+ sdk.user_attribute_user_values(1, {user_attribute_ids: '2,3,4'})
110
+ sdk.last_response.env.url.query.must_equal 'user_attribute_ids=2%2C3%2C4'
111
+ end
112
+ end
113
+
114
+ it "get with array query param - array input (multi[])" do
115
+ verify(response, :get, '/api/3.0/users/1/attribute_values','',{user_attribute_ids: ['2','3','4']}) do |sdk|
116
+ sdk.user_attribute_user_values(1, {user_attribute_ids: [2,3,4]})
117
+ sdk.last_response.env.url.query.must_equal 'user_attribute_ids%5B%5D=2&user_attribute_ids%5B%5D=3&user_attribute_ids%5B%5D=4'
118
+ end
119
+ end
120
+
96
121
  it "post" do
97
122
  verify(response, :post, '/api/3.0/users', {first_name:'Joe'}) do |sdk|
98
123
  sdk.create_user({first_name:'Joe'})
metadata CHANGED
@@ -1,38 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: looker-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Looker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-10 00:00:00.000000000 Z
11
+ date: 2018-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - '='
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.6'
18
+ version: '0.8'
19
19
  name: sawyer
20
20
  prerelease: false
21
21
  type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.6'
27
- description: Use this SDK to access the Looker API. The Looker API provides functions to perform administrative tasks such as provisioning users, configuring database connections, and so on. It also enables you to leverage the Looker data analytics engine to fetch data or render visualizations defined in your Looker data models. For more information, see https://looker.com.
28
- email: support@looker.com
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.0
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.0'
36
+ name: faraday
37
+ prerelease: false
38
+ type: :runtime
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.0
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ description: Use this SDK to access the Looker API. The Looker API provides functions
48
+ to perform administrative tasks such as provisioning users, configuring database
49
+ connections, and so on. It also enables you to leverage the Looker data analytics
50
+ engine to fetch data or render visualizations defined in your Looker data models.
51
+ For more information, see https://looker.com.
52
+ email: opensource+sdkruby@looker.com
29
53
  executables: []
30
54
  extensions: []
31
55
  extra_rdoc_files: []
32
56
  files:
33
- - .gitignore
34
- - .ruby-gemset
35
- - .travis.yml
57
+ - ".gitignore"
58
+ - ".ruby-gemset"
59
+ - ".travis.yml"
60
+ - CODE_OF_CONDUCT.md
36
61
  - Gemfile
37
62
  - LICENSE
38
63
  - Rakefile
@@ -51,6 +76,7 @@ files:
51
76
  - examples/sdk_setup.rb
52
77
  - examples/streaming_downloads.rb
53
78
  - examples/users_with_credentials_email.rb
79
+ - examples/users_with_credentials_embed.rb
54
80
  - examples/users_with_credentials_google.rb
55
81
  - examples/users_with_credentials_google_without_credentials_email.rb
56
82
  - lib/looker-sdk.rb
@@ -89,18 +115,18 @@ require_paths:
89
115
  - lib
90
116
  required_ruby_version: !ruby/object:Gem::Requirement
91
117
  requirements:
92
- - - '>='
118
+ - - ">="
93
119
  - !ruby/object:Gem::Version
94
120
  version: 1.9.3
95
121
  required_rubygems_version: !ruby/object:Gem::Requirement
96
122
  requirements:
97
- - - '>='
123
+ - - ">="
98
124
  - !ruby/object:Gem::Version
99
125
  version: '0'
100
126
  requirements:
101
127
  - Looker version 4.0 or later
102
128
  rubyforge_project:
103
- rubygems_version: 2.4.5
129
+ rubygems_version: 2.6.13
104
130
  signing_key:
105
131
  specification_version: 4
106
132
  summary: Looker Ruby SDK