looker-sdk 0.0.5 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +3 -0
  3. data/.travis.yml +1 -2
  4. data/CODE_OF_CONDUCT.md +46 -0
  5. data/Gemfile +1 -1
  6. data/LICENSE.md +33 -0
  7. data/Makefile +81 -0
  8. data/Rakefile +24 -27
  9. data/authentication.md +3 -3
  10. data/examples/add_delete_users.rb +24 -0
  11. data/examples/change_credentials_email_address_for_users.rb +24 -0
  12. data/examples/convert_look_to_lookless_tile.rb +71 -0
  13. data/examples/create_credentials_email_for_users.rb +24 -0
  14. data/examples/delete_all_user_sessions.rb +24 -0
  15. data/examples/delete_credentials_google_for_users.rb +24 -0
  16. data/examples/generate_password_reset_tokens_for_users.rb +24 -0
  17. data/examples/ldap_roles_test.rb +24 -0
  18. data/examples/me.rb +24 -0
  19. data/examples/refresh_user_notification_addresses.rb +24 -0
  20. data/examples/roles_and_users_with_permission.rb +24 -0
  21. data/examples/sdk_setup.rb +24 -0
  22. data/examples/streaming_downloads.rb +24 -0
  23. data/examples/users_with_credentials_email.rb +24 -0
  24. data/examples/users_with_credentials_embed.rb +33 -0
  25. data/examples/users_with_credentials_google.rb +23 -1
  26. data/examples/users_with_credentials_google_without_credentials_email.rb +24 -0
  27. data/lib/looker-sdk/authentication.rb +27 -2
  28. data/lib/looker-sdk/client/dynamic.rb +61 -11
  29. data/lib/looker-sdk/client.rb +86 -21
  30. data/lib/looker-sdk/configurable.rb +28 -2
  31. data/lib/looker-sdk/default.rb +30 -0
  32. data/lib/looker-sdk/error.rb +28 -0
  33. data/lib/looker-sdk/rate_limit.rb +24 -0
  34. data/lib/looker-sdk/response/raise_error.rb +25 -3
  35. data/lib/looker-sdk/sawyer_patch.rb +25 -1
  36. data/lib/looker-sdk/version.rb +25 -1
  37. data/lib/looker-sdk.rb +50 -0
  38. data/looker-sdk.gemspec +4 -3
  39. data/readme.md +12 -9
  40. data/shell/.netrc +3 -1
  41. data/shell/shell.rb +27 -2
  42. data/test/fixtures/{.netrc → .netrc.template} +0 -0
  43. data/test/helper.rb +26 -2
  44. data/test/looker/swagger.json +74 -3
  45. data/test/looker/test_client.rb +102 -6
  46. data/test/looker/test_dynamic_client.rb +101 -4
  47. data/test/looker/test_dynamic_client_agent.rb +24 -0
  48. metadata +50 -22
  49. data/LICENSE +0 -21
@@ -1,3 +1,27 @@
1
+ ############################################################################################
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2018 Looker Data Sciences, Inc.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ ############################################################################################
24
+
1
25
  require 'rubygems'
2
26
  require 'bundler/setup'
3
27
 
@@ -1,3 +1,27 @@
1
+ ############################################################################################
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2018 Looker Data Sciences, Inc.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ ############################################################################################
24
+
1
25
  require './sdk_setup'
2
26
 
3
27
  # This snippet shows how to download sdk responses using http streaming.
@@ -1,3 +1,27 @@
1
+ ############################################################################################
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2018 Looker Data Sciences, Inc.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ ############################################################################################
24
+
1
25
  require './sdk_setup'
2
26
 
3
27
  users = sdk.all_users(:fields => 'id, is_disabled, credentials_email').
@@ -0,0 +1,33 @@
1
+ ############################################################################################
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2018 Looker Data Sciences, Inc.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ ############################################################################################
24
+
25
+ require './sdk_setup'
26
+
27
+ users = sdk.all_users(fields:'id, is_disabled, display_name, credentials_embed').map do |u|
28
+ next if u.is_diabled || u.credentials_embed.empty?
29
+ creds = u.credentials_embed.first
30
+ [u.id, u.display_name, creds.external_user_id, creds.external_group_id, creds.logged_in_at]
31
+ end.compact
32
+
33
+ users.each{|u| p u}
@@ -1,4 +1,26 @@
1
- # sdk.all_users(:fields => 'id,credentials_google').select{|u| u.credentials_google}.map{|u| u.id}
1
+ ############################################################################################
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2018 Looker Data Sciences, Inc.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ ############################################################################################
2
24
 
3
25
  require './sdk_setup'
4
26
 
@@ -1,3 +1,27 @@
1
+ ############################################################################################
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2018 Looker Data Sciences, Inc.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ ############################################################################################
24
+
1
25
  require './sdk_setup'
2
26
 
3
27
  users = sdk.all_users(:fields => 'id, is_disabled, credentials_email, credentials_google').
@@ -1,3 +1,27 @@
1
+ ############################################################################################
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2018 Looker Data Sciences, Inc.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ ############################################################################################
24
+
1
25
  module LookerSDK
2
26
 
3
27
  # Authentication methods for {LookerSDK::Client}
@@ -27,7 +51,8 @@ module LookerSDK
27
51
 
28
52
  set_access_token_from_params(nil)
29
53
  without_authentication do
30
- post('/login', {}, :query => application_credentials)
54
+ encoded_auth = Faraday::Utils.build_query(application_credentials)
55
+ post("#{URI.parse(api_endpoint).path}/login", encoded_auth, header: {:'Content-Type' => 'application/x-www-form-urlencoded'})
31
56
  raise "login failure #{last_response.status}" unless last_response.status == 200
32
57
  set_access_token_from_params(last_response.data)
33
58
  end
@@ -46,7 +71,7 @@ module LookerSDK
46
71
 
47
72
  def logout
48
73
  without_authentication do
49
- result = !!@access_token && ((delete('/logout') ; delete_succeeded?) rescue false)
74
+ result = !!@access_token && ((delete("#{URI.parse(api_endpoint).path}/logout") ; delete_succeeded?) rescue false)
50
75
  set_access_token_from_params(nil)
51
76
  result
52
77
  end
@@ -1,3 +1,27 @@
1
+ ############################################################################################
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2018 Looker Data Sciences, Inc.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ ############################################################################################
24
+
1
25
  module LookerSDK
2
26
  class Client
3
27
 
@@ -25,19 +49,39 @@ module LookerSDK
25
49
  def load_swagger
26
50
  # We only need the swagger if we are going to be building our own 'operations' hash
27
51
  return if shared_swagger && @@sharable_operations[api_endpoint]
28
- # Try to load w/o authenticating. Else, authenticate and try again.
29
- @swagger ||= without_authentication {try_load_swagger} || try_load_swagger
52
+ # First, try to load swagger.json w/o authenticating
53
+ @swagger ||= without_authentication { try_load_swagger }
54
+
55
+ unless @swagger
56
+ # try again, this time with authentication
57
+ @swagger = try_load_swagger
58
+ end
59
+
60
+ # in unit tests, @swagger may be nil and last_response nil because no HTTP request was made
61
+ if @swagger.nil?
62
+ if @last_error
63
+ raise @last_error
64
+ else
65
+ raise "Load of swagger.json failed."
66
+ end
67
+ end
68
+
69
+ @swagger
30
70
  end
31
71
 
32
72
  def operations
33
73
  return @@sharable_operations[api_endpoint] if shared_swagger && @@sharable_operations[api_endpoint]
34
74
 
75
+ if !@swagger && @lazy_swagger
76
+ load_swagger
77
+ end
78
+
35
79
  return nil unless @swagger
36
80
  @operations ||= Hash[
37
81
  @swagger[:paths].map do |path_name, path_info|
38
82
  path_info.map do |method, route_info|
39
83
  route = @swagger[:basePath].to_s + path_name.to_s
40
- [route_info[:operationId], {:route => route, :method => method, :info => route_info}]
84
+ [route_info[:operationId].to_sym, {:route => route, :method => method, :info => route_info}]
41
85
  end
42
86
  end.reduce(:+)
43
87
  ].freeze
@@ -70,7 +114,7 @@ module LookerSDK
70
114
  private
71
115
 
72
116
  def find_entry(method_name)
73
- operations && operations[method_name.to_s] if dynamic
117
+ operations && operations[method_name.to_sym] if dynamic
74
118
  end
75
119
 
76
120
  def invoke_remote(entry, method_name, *args, &block)
@@ -85,19 +129,25 @@ module LookerSDK
85
129
  raise ArgumentError.new("wrong number of arguments (#{params_passed} for #{params_required}) in call to '#{method_name}'. See '#{method_link(entry)}'")
86
130
  end
87
131
 
88
- # substitute the actual params into the route template
89
- params.each {|param| route.sub!("{#{param[:name]}}", args.shift.to_s) }
132
+ # substitute the actual params into the route template, encoding if needed
133
+ params.each do |param|
134
+ value = args.shift.to_s
135
+ if value == CGI.unescape(value)
136
+ value = CGI.escape(value)
137
+ end
138
+ route.sub!("{#{param[:name]}}", value)
139
+ end
90
140
 
91
141
  a = args.length > 0 ? args[0] : {}
92
142
  b = args.length > 1 ? args[1] : {}
93
143
 
94
144
  method = entry[:method].to_sym
95
145
  case method
96
- when :get then get(route, a, &block)
97
- when :post then post(route, a, merge_content_type_if_body(a, b), &block)
98
- when :put then put(route, a, merge_content_type_if_body(a, b), &block)
99
- when :patch then patch(route, a, merge_content_type_if_body(a, b), &block)
100
- when :delete then delete(route, a) ; @raw_responses ? last_response : delete_succeeded?
146
+ when :get then get(route, a, true, &block)
147
+ when :post then post(route, a, merge_content_type_if_body(a, b), true, &block)
148
+ when :put then put(route, a, merge_content_type_if_body(a, b), true, &block)
149
+ when :patch then patch(route, a, merge_content_type_if_body(a, b), true, &block)
150
+ when :delete then delete(route, a, true) ; @raw_responses ? last_response : delete_succeeded?
101
151
  else raise "unsupported method '#{method}' in call to '#{method_name}'. See '#{method_link(entry)}'"
102
152
  end
103
153
  end
@@ -1,3 +1,27 @@
1
+ ############################################################################################
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2018 Looker Data Sciences, Inc.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ ############################################################################################
24
+
1
25
  require 'sawyer'
2
26
  require 'ostruct'
3
27
  require 'looker-sdk/sawyer_patch'
@@ -34,7 +58,9 @@ module LookerSDK
34
58
  @original_options = options.dup
35
59
 
36
60
  load_credentials_from_netrc unless application_credentials?
37
- load_swagger
61
+ if !@lazy_swagger
62
+ load_swagger
63
+ end
38
64
  self.dynamic = true
39
65
  end
40
66
 
@@ -65,11 +91,12 @@ module LookerSDK
65
91
  #
66
92
  # @param url [String] The path, relative to {#api_endpoint}
67
93
  # @param options [Hash] Query and header params for request
94
+ # @param encoded [Boolean] true: url already encoded, false: url needs encoding
68
95
  # @param &block [Block] Block to be called with |response, chunk| for each chunk of the body from
69
96
  # the server. The block must return true to continue, or false to abort streaming.
70
97
  # @return [Sawyer::Resource]
71
- def get(url, options = {}, &block)
72
- request :get, url, nil, parse_query_and_convenience_headers(options), &block
98
+ def get(url, options = {}, encoded=false, &block)
99
+ request :get, url, nil, parse_query_and_convenience_headers(options), encoded, &block
73
100
  end
74
101
 
75
102
  # Make a HTTP POST request
@@ -77,11 +104,12 @@ module LookerSDK
77
104
  # @param url [String] The path, relative to {#api_endpoint}
78
105
  # @param data [String|Array|Hash] Body and optionally header params for request
79
106
  # @param options [Hash] Optional header params for request
107
+ # @param encoded [Boolean] true: url already encoded, false: url needs encoding
80
108
  # @param &block [Block] Block to be called with |response, chunk| for each chunk of the body from
81
109
  # the server. The block must return true to continue, or false to abort streaming.
82
110
  # @return [Sawyer::Resource]
83
- def post(url, data = {}, options = {}, &block)
84
- request :post, url, data, parse_query_and_convenience_headers(options), &block
111
+ def post(url, data = {}, options = {}, encoded=false, &block)
112
+ request :post, url, data, parse_query_and_convenience_headers(options), encoded, &block
85
113
  end
86
114
 
87
115
  # Make a HTTP PUT request
@@ -89,11 +117,12 @@ module LookerSDK
89
117
  # @param url [String] The path, relative to {#api_endpoint}
90
118
  # @param data [String|Array|Hash] Body and optionally header params for request
91
119
  # @param options [Hash] Optional header params for request
120
+ # @param encoded [Boolean] true: url already encoded, false: url needs encoding
92
121
  # @param &block [Block] Block to be called with |response, chunk| for each chunk of the body from
93
122
  # the server. The block must return true to continue, or false to abort streaming.
94
123
  # @return [Sawyer::Resource]
95
- def put(url, data = {}, options = {}, &block)
96
- request :put, url, data, parse_query_and_convenience_headers(options), &block
124
+ def put(url, data = {}, options = {}, encoded=false, &block)
125
+ request :put, url, data, parse_query_and_convenience_headers(options), encoded, &block
97
126
  end
98
127
 
99
128
  # Make a HTTP PATCH request
@@ -101,29 +130,32 @@ module LookerSDK
101
130
  # @param url [String] The path, relative to {#api_endpoint}
102
131
  # @param data [String|Array|Hash] Body and optionally header params for request
103
132
  # @param options [Hash] Optional header params for request
133
+ # @param encoded [Boolean] true: url already encoded, false: url needs encoding
104
134
  # @param &block [Block] Block to be called with |response, chunk| for each chunk of the body from
105
135
  # the server. The block must return true to continue, or false to abort streaming.
106
136
  # @return [Sawyer::Resource]
107
- def patch(url, data = {}, options = {}, &block)
108
- request :patch, url, data, parse_query_and_convenience_headers(options), &block
137
+ def patch(url, data = {}, options = {}, encoded=false, &block)
138
+ request :patch, url, data, parse_query_and_convenience_headers(options), encoded, &block
109
139
  end
110
140
 
111
141
  # Make a HTTP DELETE request
112
142
  #
113
143
  # @param url [String] The path, relative to {#api_endpoint}
114
144
  # @param options [Hash] Query and header params for request
145
+ # @param encoded [Boolean] true: url already encoded, false: url needs encoding
115
146
  # @return [Sawyer::Resource]
116
- def delete(url, options = {}, &block)
117
- request :delete, url, nil, parse_query_and_convenience_headers(options)
147
+ def delete(url, options = {}, encoded=false, &block)
148
+ request :delete, url, nil, parse_query_and_convenience_headers(options), encoded, &block
118
149
  end
119
150
 
120
151
  # Make a HTTP HEAD request
121
152
  #
122
153
  # @param url [String] The path, relative to {#api_endpoint}
123
154
  # @param options [Hash] Query and header params for request
155
+ # @param encoded [Boolean] true: url already encoded, false: url needs encoding
124
156
  # @return [Sawyer::Resource]
125
- def head(url, options = {}, &block)
126
- request :head, url, nil, parse_query_and_convenience_headers(options)
157
+ def head(url, options = {}, encoded=false, &block)
158
+ request :head, url, nil, parse_query_and_convenience_headers(options), encoded
127
159
  end
128
160
 
129
161
  # Make one or more HTTP GET requests, optionally fetching
@@ -168,7 +200,7 @@ module LookerSDK
168
200
  Sawyer::Agent.new(api_endpoint, options) do |http|
169
201
  http.headers[:accept] = default_media_type
170
202
  http.headers[:user_agent] = user_agent
171
- http.authorization('token', @access_token) if token_authenticated?
203
+ http.headers[:authorization] = "token #{@access_token}" if token_authenticated?
172
204
  end
173
205
  end
174
206
 
@@ -190,10 +222,34 @@ module LookerSDK
190
222
  #
191
223
  # @return http status code
192
224
  def alive
193
- get '/alive'
225
+ without_authentication do
226
+ get '/alive'
227
+ end
194
228
  last_response.status
195
229
  end
196
230
 
231
+ # Are we connected to the server? - Does not attempt to authenticate.
232
+ def alive?
233
+ begin
234
+ without_authentication do
235
+ get('/alive')
236
+ end
237
+ true
238
+ rescue
239
+ false
240
+ end
241
+ end
242
+
243
+ # Are we connected and authenticated to the server?
244
+ def authenticated?
245
+ begin
246
+ ensure_logged_in
247
+ true
248
+ rescue
249
+ false
250
+ end
251
+ end
252
+
197
253
  # Response for last HTTP request
198
254
  #
199
255
  # @return [Sawyer::Response]
@@ -248,12 +304,16 @@ module LookerSDK
248
304
  @agent = nil
249
305
  end
250
306
 
251
- def request(method, path, data, options, &block)
307
+ def request(method, path, data, options, encoded, &block)
252
308
  ensure_logged_in
253
309
  begin
310
+ path = path.to_s
311
+ if !encoded
312
+ path = URI::Parser.new.escape(path)
313
+ end
254
314
  @last_response = @last_error = nil
255
315
  return stream_request(method, path, data, options, &block) if block_given?
256
- @last_response = response = agent.call(method, URI::Parser.new.escape(path.to_s), data, options)
316
+ @last_response = response = agent.call(method, path, data, options)
257
317
  @raw_responses ? response : response.data
258
318
  rescue StandardError => e
259
319
  @last_error = e
@@ -365,15 +425,20 @@ module LookerSDK
365
425
 
366
426
  # slight modification to the base class' decode_hash_value function to
367
427
  # less permissive when decoding time values.
428
+ # also prevent conversion from non-string types to Time e.g. integer/float timestamp
368
429
  #
369
430
  # See https://github.com/looker/looker-sdk-ruby/issues/53 for more details
370
431
  #
371
432
  # Base class function that we're overriding: https://github.com/lostisland/sawyer/blob/master/lib/sawyer/serializer.rb#L101-L121
372
433
  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
434
+ if time_field?(key, value)
435
+ if value.is_a?(String)
436
+ begin
437
+ Time.iso8601(value)
438
+ rescue ArgumentError
439
+ value
440
+ end
441
+ else
377
442
  value
378
443
  end
379
444
  else
@@ -1,3 +1,27 @@
1
+ ############################################################################################
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2018 Looker Data Sciences, Inc.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ ############################################################################################
24
+
1
25
  module LookerSDK
2
26
 
3
27
  # Configuration options for {Client}, defaulting to values
@@ -42,7 +66,8 @@ module LookerSDK
42
66
  attr_accessor :access_token, :auto_paginate, :client_id,
43
67
  :client_secret, :default_media_type, :connection_options,
44
68
  :middleware, :netrc, :netrc_file,
45
- :per_page, :proxy, :user_agent, :faraday, :swagger, :shared_swagger, :raw_responses
69
+ :per_page, :proxy, :user_agent, :faraday, :swagger, :shared_swagger, :raw_responses,
70
+ :lazy_swagger
46
71
  attr_writer :web_endpoint, :api_endpoint
47
72
 
48
73
  class << self
@@ -68,7 +93,8 @@ module LookerSDK
68
93
  :shared_swagger,
69
94
  :swagger,
70
95
  :raw_responses,
71
- :web_endpoint
96
+ :web_endpoint,
97
+ :lazy_swagger,
72
98
  ]
73
99
  end
74
100
  end
@@ -1,3 +1,27 @@
1
+ ############################################################################################
2
+ # The MIT License (MIT)
3
+ #
4
+ # Copyright (c) 2018 Looker Data Sciences, Inc.
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in
14
+ # all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ # THE SOFTWARE.
23
+ ############################################################################################
24
+
1
25
  require 'looker-sdk/response/raise_error'
2
26
  require 'looker-sdk/version'
3
27
 
@@ -101,6 +125,12 @@ module LookerSDK
101
125
  false
102
126
  end
103
127
 
128
+ # Default behavior for loading swagger during initialization or at first call
129
+ # @return [Boolean]
130
+ def lazy_swagger
131
+ false
132
+ end
133
+
104
134
  def raw_responses
105
135
  false
106
136
  end