looker-sdk 0.0.7 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/scripts/wait_for_looker.sh +35 -0
- data/.github/workflows/release.yml +47 -0
- data/.github/workflows/ruby-ci.yml +60 -0
- data/.gitignore +3 -0
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +73 -26
- data/CONTRIBUTING.md +29 -0
- data/Gemfile +1 -1
- data/Makefile +81 -0
- data/Rakefile +0 -27
- data/authentication.md +3 -3
- data/lib/looker-sdk/authentication.rb +1 -1
- data/lib/looker-sdk/client/dynamic.rb +25 -18
- data/lib/looker-sdk/client.rb +28 -16
- data/lib/looker-sdk/configurable.rb +4 -2
- data/lib/looker-sdk/default.rb +6 -0
- data/lib/looker-sdk/response/raise_error.rb +1 -3
- data/lib/looker-sdk/version.rb +1 -1
- data/lib/looker-sdk.rb +0 -1
- data/looker-sdk.gemspec +4 -4
- data/readme.md +9 -5
- data/shell/Gemfile +1 -1
- data/test/fixtures/{.netrc → .netrc.template} +0 -0
- data/test/helper.rb +32 -6
- data/test/looker/swagger.json +1 -1
- data/test/looker/test_client.rb +93 -5
- data/test/looker/test_dynamic_client.rb +45 -29
- metadata +25 -20
- data/.travis.yml +0 -15
    
        data/lib/looker-sdk/client.rb
    CHANGED
    
    | @@ -58,7 +58,9 @@ module LookerSDK | |
| 58 58 | 
             
                  @original_options = options.dup
         | 
| 59 59 |  | 
| 60 60 | 
             
                  load_credentials_from_netrc unless application_credentials?
         | 
| 61 | 
            -
                   | 
| 61 | 
            +
                  if !@lazy_swagger
         | 
| 62 | 
            +
                    load_swagger
         | 
| 63 | 
            +
                  end
         | 
| 62 64 | 
             
                  self.dynamic = true
         | 
| 63 65 | 
             
                end
         | 
| 64 66 |  | 
| @@ -89,11 +91,12 @@ module LookerSDK | |
| 89 91 | 
             
                #
         | 
| 90 92 | 
             
                # @param url [String] The path, relative to {#api_endpoint}
         | 
| 91 93 | 
             
                # @param options [Hash] Query and header params for request
         | 
| 94 | 
            +
                # @param encoded [Boolean] true: url already encoded, false: url needs encoding
         | 
| 92 95 | 
             
                # @param &block [Block] Block to be called with |response, chunk| for each chunk of the body from
         | 
| 93 96 | 
             
                #   the server. The block must return true to continue, or false to abort streaming.
         | 
| 94 97 | 
             
                # @return [Sawyer::Resource]
         | 
| 95 | 
            -
                def get(url, options = {}, &block)
         | 
| 96 | 
            -
                  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
         | 
| 97 100 | 
             
                end
         | 
| 98 101 |  | 
| 99 102 | 
             
                # Make a HTTP POST request
         | 
| @@ -101,11 +104,12 @@ module LookerSDK | |
| 101 104 | 
             
                # @param url [String] The path, relative to {#api_endpoint}
         | 
| 102 105 | 
             
                # @param data [String|Array|Hash] Body and optionally header params for request
         | 
| 103 106 | 
             
                # @param options [Hash] Optional header params for request
         | 
| 107 | 
            +
                # @param encoded [Boolean] true: url already encoded, false: url needs encoding
         | 
| 104 108 | 
             
                # @param &block [Block] Block to be called with |response, chunk| for each chunk of the body from
         | 
| 105 109 | 
             
                #   the server. The block must return true to continue, or false to abort streaming.
         | 
| 106 110 | 
             
                # @return [Sawyer::Resource]
         | 
| 107 | 
            -
                def post(url, data = {}, options = {}, &block)
         | 
| 108 | 
            -
                  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
         | 
| 109 113 | 
             
                end
         | 
| 110 114 |  | 
| 111 115 | 
             
                # Make a HTTP PUT request
         | 
| @@ -113,11 +117,12 @@ module LookerSDK | |
| 113 117 | 
             
                # @param url [String] The path, relative to {#api_endpoint}
         | 
| 114 118 | 
             
                # @param data [String|Array|Hash] Body and optionally header params for request
         | 
| 115 119 | 
             
                # @param options [Hash] Optional header params for request
         | 
| 120 | 
            +
                # @param encoded [Boolean] true: url already encoded, false: url needs encoding
         | 
| 116 121 | 
             
                # @param &block [Block] Block to be called with |response, chunk| for each chunk of the body from
         | 
| 117 122 | 
             
                #   the server. The block must return true to continue, or false to abort streaming.
         | 
| 118 123 | 
             
                # @return [Sawyer::Resource]
         | 
| 119 | 
            -
                def put(url, data = {}, options = {}, &block)
         | 
| 120 | 
            -
                  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
         | 
| 121 126 | 
             
                end
         | 
| 122 127 |  | 
| 123 128 | 
             
                # Make a HTTP PATCH request
         | 
| @@ -125,29 +130,32 @@ module LookerSDK | |
| 125 130 | 
             
                # @param url [String] The path, relative to {#api_endpoint}
         | 
| 126 131 | 
             
                # @param data [String|Array|Hash] Body and optionally header params for request
         | 
| 127 132 | 
             
                # @param options [Hash] Optional header params for request
         | 
| 133 | 
            +
                # @param encoded [Boolean] true: url already encoded, false: url needs encoding
         | 
| 128 134 | 
             
                # @param &block [Block] Block to be called with |response, chunk| for each chunk of the body from
         | 
| 129 135 | 
             
                #   the server. The block must return true to continue, or false to abort streaming.
         | 
| 130 136 | 
             
                # @return [Sawyer::Resource]
         | 
| 131 | 
            -
                def patch(url, data = {}, options = {}, &block)
         | 
| 132 | 
            -
                  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
         | 
| 133 139 | 
             
                end
         | 
| 134 140 |  | 
| 135 141 | 
             
                # Make a HTTP DELETE request
         | 
| 136 142 | 
             
                #
         | 
| 137 143 | 
             
                # @param url [String] The path, relative to {#api_endpoint}
         | 
| 138 144 | 
             
                # @param options [Hash] Query and header params for request
         | 
| 145 | 
            +
                # @param encoded [Boolean] true: url already encoded, false: url needs encoding
         | 
| 139 146 | 
             
                # @return [Sawyer::Resource]
         | 
| 140 | 
            -
                def delete(url, options = {}, &block)
         | 
| 141 | 
            -
                  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
         | 
| 142 149 | 
             
                end
         | 
| 143 150 |  | 
| 144 151 | 
             
                # Make a HTTP HEAD request
         | 
| 145 152 | 
             
                #
         | 
| 146 153 | 
             
                # @param url [String] The path, relative to {#api_endpoint}
         | 
| 147 154 | 
             
                # @param options [Hash] Query and header params for request
         | 
| 155 | 
            +
                # @param encoded [Boolean] true: url already encoded, false: url needs encoding
         | 
| 148 156 | 
             
                # @return [Sawyer::Resource]
         | 
| 149 | 
            -
                def head(url, options = {}, &block)
         | 
| 150 | 
            -
                  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
         | 
| 151 159 | 
             
                end
         | 
| 152 160 |  | 
| 153 161 | 
             
                # Make one or more HTTP GET requests, optionally fetching
         | 
| @@ -192,7 +200,7 @@ module LookerSDK | |
| 192 200 | 
             
                  Sawyer::Agent.new(api_endpoint, options) do |http|
         | 
| 193 201 | 
             
                    http.headers[:accept] = default_media_type
         | 
| 194 202 | 
             
                    http.headers[:user_agent] = user_agent
         | 
| 195 | 
            -
                    http.authorization | 
| 203 | 
            +
                    http.headers[:authorization] = "token #{@access_token}" if token_authenticated?
         | 
| 196 204 | 
             
                  end
         | 
| 197 205 | 
             
                end
         | 
| 198 206 |  | 
| @@ -296,12 +304,16 @@ module LookerSDK | |
| 296 304 | 
             
                  @agent = nil
         | 
| 297 305 | 
             
                end
         | 
| 298 306 |  | 
| 299 | 
            -
                def request(method, path, data, options, &block)
         | 
| 307 | 
            +
                def request(method, path, data, options, encoded, &block)
         | 
| 300 308 | 
             
                  ensure_logged_in
         | 
| 301 309 | 
             
                  begin
         | 
| 310 | 
            +
                    path = path.to_s
         | 
| 311 | 
            +
                    if !encoded
         | 
| 312 | 
            +
                      path = URI::Parser.new.escape(path)
         | 
| 313 | 
            +
                    end
         | 
| 302 314 | 
             
                    @last_response = @last_error = nil
         | 
| 303 315 | 
             
                    return stream_request(method, path, data, options, &block) if block_given?
         | 
| 304 | 
            -
                    @last_response = response = agent.call(method,  | 
| 316 | 
            +
                    @last_response = response = agent.call(method, path, data, options)
         | 
| 305 317 | 
             
                    @raw_responses ? response : response.data
         | 
| 306 318 | 
             
                  rescue StandardError => e
         | 
| 307 319 | 
             
                    @last_error = e
         | 
| @@ -66,7 +66,8 @@ module LookerSDK | |
| 66 66 | 
             
                attr_accessor :access_token, :auto_paginate, :client_id,
         | 
| 67 67 | 
             
                              :client_secret, :default_media_type, :connection_options,
         | 
| 68 68 | 
             
                              :middleware, :netrc, :netrc_file,
         | 
| 69 | 
            -
                              :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
         | 
| 70 71 | 
             
                attr_writer :web_endpoint, :api_endpoint
         | 
| 71 72 |  | 
| 72 73 | 
             
                class << self
         | 
| @@ -92,7 +93,8 @@ module LookerSDK | |
| 92 93 | 
             
                      :shared_swagger,
         | 
| 93 94 | 
             
                      :swagger,
         | 
| 94 95 | 
             
                      :raw_responses,
         | 
| 95 | 
            -
                      :web_endpoint
         | 
| 96 | 
            +
                      :web_endpoint,
         | 
| 97 | 
            +
                      :lazy_swagger,
         | 
| 96 98 | 
             
                    ]
         | 
| 97 99 | 
             
                  end
         | 
| 98 100 | 
             
                end
         | 
    
        data/lib/looker-sdk/default.rb
    CHANGED
    
    
| @@ -30,9 +30,7 @@ module LookerSDK | |
| 30 30 | 
             
              module Response
         | 
| 31 31 |  | 
| 32 32 | 
             
                # HTTP status codes returned by the API
         | 
| 33 | 
            -
                class RaiseError < Faraday:: | 
| 34 | 
            -
             | 
| 35 | 
            -
                  private
         | 
| 33 | 
            +
                class RaiseError < Faraday::Middleware
         | 
| 36 34 |  | 
| 37 35 | 
             
                  def on_complete(response)
         | 
| 38 36 | 
             
                    if error = LookerSDK::Error.from_response(response)
         | 
    
        data/lib/looker-sdk/version.rb
    CHANGED
    
    
    
        data/lib/looker-sdk.rb
    CHANGED
    
    
    
        data/looker-sdk.gemspec
    CHANGED
    
    | @@ -7,15 +7,15 @@ 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       = ' | 
| 11 | 
            -
              s.homepage    = 'https://github.com/looker/looker-sdk-ruby'
         | 
| 10 | 
            +
              s.email       = 'drstrangelove@google.com'
         | 
| 11 | 
            +
              s.homepage    = 'https://github.com/looker-open-source/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 '+
         | 
| 14 14 | 
             
                  'tasks such as provisioning users, configuring database connections, and so on. It also enables you to leverage '+
         | 
| 15 15 | 
             
                  'the Looker data analytics engine to fetch data or render visualizations defined in your Looker data models. '+
         | 
| 16 16 | 
             
                  'For more information, see https://looker.com.'
         | 
| 17 17 | 
             
              s.license     = 'MIT'
         | 
| 18 | 
            -
              s.required_ruby_version = '>= 2. | 
| 18 | 
            +
              s.required_ruby_version = '>= 2.5'
         | 
| 19 19 | 
             
              s.requirements = 'Looker version 4.0 or later'  # informational
         | 
| 20 20 |  | 
| 21 21 | 
             
              s.files         = `git ls-files`.split("\n")
         | 
| @@ -24,5 +24,5 @@ Gem::Specification.new do |s| | |
| 24 24 | 
             
              s.require_paths = %w(lib)
         | 
| 25 25 | 
             
              s.add_dependency 'jruby-openssl' if s.platform == :jruby
         | 
| 26 26 | 
             
              s.add_dependency 'sawyer', '~> 0.8'
         | 
| 27 | 
            -
              s.add_dependency 'faraday', ['>=  | 
| 27 | 
            +
              s.add_dependency 'faraday', ['>= 1.2', '< 2.0']
         | 
| 28 28 | 
             
            end
         | 
    
        data/readme.md
    CHANGED
    
    | @@ -1,4 +1,5 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            [](https://github.com/looker-open-source/looker-sdk-ruby/actions/workflows/ruby-ci.yml)
         | 
| 2 | 
            +
            # [Looker](http://looker.com/) SDK for Ruby
         | 
| 2 3 | 
             
            ### Overview
         | 
| 3 4 | 
             
            This SDK supports secure/authenticated access to the Looker RESTful API. The SDK binds dynamically to the Looker API and builds mappings for the sets of API methods that the Looker instance exposes. This allows for writing straightforward Ruby scripts to interact with the Looker API. And, it allows the SDK to provide access to new Looker API features in each Looker release without requiring an update to the SDK each time.
         | 
| 4 5 |  | 
| @@ -14,7 +15,7 @@ When trying to access a resource with the API that the current user is not allow | |
| 14 15 |  | 
| 15 16 | 
             
            ### Installation
         | 
| 16 17 | 
             
            ```bash
         | 
| 17 | 
            -
            $ git clone git@github.com:looker/looker-sdk-ruby.git looker-sdk
         | 
| 18 | 
            +
            $ git clone git@github.com:looker-open-source/looker-sdk-ruby.git looker-sdk
         | 
| 18 19 | 
             
            $ cd looker-sdk
         | 
| 19 20 | 
             
            $ gem install bundle
         | 
| 20 21 | 
             
            $ bundle install
         | 
| @@ -23,10 +24,13 @@ $ rake install | |
| 23 24 |  | 
| 24 25 | 
             
            ### Development
         | 
| 25 26 |  | 
| 27 | 
            +
            Rename test/fixtures/.netrc.template to test/fixtures/.netrc and add API3
         | 
| 28 | 
            +
            credentials for tests to pass.
         | 
| 29 | 
            +
            Comment out coverage configuration in test/helper.rb for debugging.
         | 
| 26 30 | 
             
            ```bash
         | 
| 27 31 | 
             
            $ bundle install
         | 
| 28 32 | 
             
            $ rake test # run the test suite
         | 
| 29 | 
            -
            $  | 
| 33 | 
            +
            $ make install test # run the test suite on all supported Rubies
         | 
| 30 34 | 
             
            ```
         | 
| 31 35 |  | 
| 32 36 | 
             
            ### Basic Usage
         | 
| @@ -39,7 +43,7 @@ require 'looker-sdk' | |
| 39 43 | 
             
            sdk = LookerSDK::Client.new(
         | 
| 40 44 | 
             
              :client_id => "4CN7jzm7yrkcy2MC4CCG",
         | 
| 41 45 | 
             
              :client_secret => "Js3rZZ7vHfbc2hBynSj7zqKh",
         | 
| 42 | 
            -
              :api_endpoint => "https://mygreatcompany.looker.com:19999/api/ | 
| 46 | 
            +
              :api_endpoint => "https://mygreatcompany.looker.com:19999/api/4.0"
         | 
| 43 47 | 
             
            )
         | 
| 44 48 |  | 
| 45 49 | 
             
            # If you don't want to provide explicit credentials: (trust me you don't)
         | 
| @@ -53,7 +57,7 @@ sdk = LookerSDK::Client.new( | |
| 53 57 | 
             
            sdk = LookerSDK::Client.new(
         | 
| 54 58 | 
             
              :netrc      => true,
         | 
| 55 59 | 
             
              :netrc_file => "~/.net_rc",
         | 
| 56 | 
            -
              :api_endpoint => "https://mygreatcompany.looker.com:19999/api/ | 
| 60 | 
            +
              :api_endpoint => "https://mygreatcompany.looker.com:19999/api/4.0",
         | 
| 57 61 |  | 
| 58 62 | 
             
              # Set longer timeout to allow for long running queries. The default is 60 seconds and can be problematic.
         | 
| 59 63 | 
             
              :connection_options => {:request => {:timeout => 60 * 60, :open_timeout => 30}},
         | 
    
        data/shell/Gemfile
    CHANGED
    
    | @@ -2,5 +2,5 @@ source 'https://rubygems.org' | |
| 2 2 |  | 
| 3 3 | 
             
            gem 'pry', '~> 0.10.1'
         | 
| 4 4 | 
             
            gem 'netrc', '~> 0.7.7'
         | 
| 5 | 
            -
            # gem 'looker-sdk',  :git => 'git@github.com:looker/looker-sdk-ruby.git'
         | 
| 5 | 
            +
            # gem 'looker-sdk',  :git => 'git@github.com:looker-open-source/looker-sdk-ruby.git'
         | 
| 6 6 | 
             
            gem 'looker-sdk',  :path => '../'
         | 
| 
            File without changes
         | 
    
        data/test/helper.rb
    CHANGED
    
    | @@ -52,19 +52,45 @@ def fix_netrc_permissions(path) | |
| 52 52 | 
             
              File.chmod(0600, path) unless s.mode.to_s(8)[3..5] == "0600"
         | 
| 53 53 | 
             
            end
         | 
| 54 54 |  | 
| 55 | 
            -
             | 
| 55 | 
            +
            begin
         | 
| 56 | 
            +
              fix_netrc_permissions(File.join(fixture_path, '.netrc'))
         | 
| 57 | 
            +
            rescue => e
         | 
| 58 | 
            +
              puts e
         | 
| 59 | 
            +
            end
         | 
| 56 60 |  | 
| 57 61 | 
             
            def setup_sdk
         | 
| 58 62 | 
             
              LookerSDK.reset!
         | 
| 63 | 
            +
             | 
| 64 | 
            +
              base_url = ENV['LOOKERSDK_BASE_URL'] || 'https://localhost:20000'
         | 
| 65 | 
            +
              verify_ssl = case ENV['LOOKERSDK_VERIFY_SSL']
         | 
| 66 | 
            +
                           when /false/i
         | 
| 67 | 
            +
                             false
         | 
| 68 | 
            +
                           when /f/i
         | 
| 69 | 
            +
                             false
         | 
| 70 | 
            +
                           when '0'
         | 
| 71 | 
            +
                             false
         | 
| 72 | 
            +
                           else
         | 
| 73 | 
            +
                             true
         | 
| 74 | 
            +
                           end
         | 
| 75 | 
            +
              api_version = ENV['LOOKERSDK_API_VERSION'] || '4.0'
         | 
| 76 | 
            +
              client_id = ENV['LOOKERSDK_CLIENT_ID']
         | 
| 77 | 
            +
              client_secret = ENV['LOOKERSDK_CLIENT_SECRET']
         | 
| 78 | 
            +
             | 
| 59 79 | 
             
              LookerSDK.configure do |c|
         | 
| 60 | 
            -
                c. | 
| 61 | 
            -
                c. | 
| 62 | 
            -
                 | 
| 80 | 
            +
                c.lazy_swagger = true
         | 
| 81 | 
            +
                c.connection_options = {:ssl => {:verify => false}} unless verify_ssl
         | 
| 82 | 
            +
                if (client_id && client_secret) then
         | 
| 83 | 
            +
                  c.client_id = client_id
         | 
| 84 | 
            +
                  c.client_secret = client_secret
         | 
| 85 | 
            +
                  c.api_endpoint = "#{base_url}/api/#{api_version}"
         | 
| 86 | 
            +
                else
         | 
| 87 | 
            +
                  c.netrc = true
         | 
| 88 | 
            +
                  c.netrc_file =  File.join(fixture_path, '.netrc')
         | 
| 89 | 
            +
                end
         | 
| 63 90 | 
             
              end
         | 
| 64 91 | 
             
            end
         | 
| 65 92 |  | 
| 66 93 | 
             
            def teardown_sdk
         | 
| 94 | 
            +
              setup_sdk  # put back initial config
         | 
| 67 95 | 
             
              LookerSDK.logout
         | 
| 68 96 | 
             
            end
         | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
    
        data/test/looker/swagger.json
    CHANGED
    
    | @@ -5,7 +5,7 @@ | |
| 5 5 | 
             
                "title": "Looker API",
         | 
| 6 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 | 
            -
                  "name": "Looker Team < | 
| 8 | 
            +
                  "name": "Looker Team <https://help.looker.com>"
         | 
| 9 9 | 
             
                },
         | 
| 10 10 | 
             
                "license": {
         | 
| 11 11 | 
             
                  "name": "EULA",
         | 
    
        data/test/looker/test_client.rb
    CHANGED
    
    | @@ -30,8 +30,52 @@ describe LookerSDK::Client do | |
| 30 30 | 
             
               setup_sdk
         | 
| 31 31 | 
             
              end
         | 
| 32 32 |  | 
| 33 | 
            -
               | 
| 34 | 
            -
             | 
| 33 | 
            +
              base_url = ENV['LOOKERSDK_BASE_URL'] || 'https://localhost:20000'
         | 
| 34 | 
            +
              verify_ssl = case ENV['LOOKERSDK_VERIFY_SSL']
         | 
| 35 | 
            +
                           when /false/i
         | 
| 36 | 
            +
                             false
         | 
| 37 | 
            +
                           when /f/i
         | 
| 38 | 
            +
                             false
         | 
| 39 | 
            +
                           when '0'
         | 
| 40 | 
            +
                             false
         | 
| 41 | 
            +
                           else
         | 
| 42 | 
            +
                             true
         | 
| 43 | 
            +
                           end
         | 
| 44 | 
            +
              api_version = ENV['LOOKERSDK_API_VERSION'] || '4.0'
         | 
| 45 | 
            +
              client_id = ENV['LOOKERSDK_CLIENT_ID']
         | 
| 46 | 
            +
              client_secret = ENV['LOOKERSDK_CLIENT_SECRET']
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              opts = {}
         | 
| 49 | 
            +
              if (client_id && client_secret) then
         | 
| 50 | 
            +
                opts.merge!({
         | 
| 51 | 
            +
                  :client_id => client_id,
         | 
| 52 | 
            +
                  :client_secret => client_secret,
         | 
| 53 | 
            +
                  :api_endpoint => "#{base_url}/api/#{api_version}",
         | 
| 54 | 
            +
                })
         | 
| 55 | 
            +
                opts[:connection_options] = {:ssl => {:verify => false}} unless verify_ssl
         | 
| 56 | 
            +
              else
         | 
| 57 | 
            +
                opts.merge!({
         | 
| 58 | 
            +
                  :netrc => true,
         | 
| 59 | 
            +
                  :netrc_file => File.join(fixture_path, '.netrc'),
         | 
| 60 | 
            +
                  :connection_options => {:ssl => {:verify => false}},
         | 
| 61 | 
            +
                })
         | 
| 62 | 
            +
             | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              describe "lazy load swagger" do
         | 
| 66 | 
            +
                it "lazy loads swagger" do
         | 
| 67 | 
            +
                  LookerSDK.reset!
         | 
| 68 | 
            +
                  client = LookerSDK::Client.new(opts.merge({:lazy_swagger => true}))
         | 
| 69 | 
            +
                  assert_nil client.swagger
         | 
| 70 | 
            +
                  client.me()
         | 
| 71 | 
            +
                  assert client.swagger
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                it "loads swagger initially" do
         | 
| 75 | 
            +
                  LookerSDK.reset!
         | 
| 76 | 
            +
                  client = LookerSDK::Client.new(opts.merge({:lazy_swagger => false}))
         | 
| 77 | 
            +
                  assert client.swagger
         | 
| 78 | 
            +
                end
         | 
| 35 79 | 
             
              end
         | 
| 36 80 |  | 
| 37 81 | 
             
              describe "module configuration" do
         | 
| @@ -50,8 +94,9 @@ describe LookerSDK::Client do | |
| 50 94 | 
             
                end
         | 
| 51 95 |  | 
| 52 96 | 
             
                it "inherits the module configuration" do
         | 
| 53 | 
            -
                  client = LookerSDK::Client.new
         | 
| 97 | 
            +
                  client = LookerSDK::Client.new(:lazy_swagger => true)
         | 
| 54 98 | 
             
                  LookerSDK::Configurable.keys.each do |key|
         | 
| 99 | 
            +
                    next if key == :lazy_swagger
         | 
| 55 100 | 
             
                    client.instance_variable_get(:"@#{key}").must_equal("Some #{key}")
         | 
| 56 101 | 
             
                  end
         | 
| 57 102 | 
             
                end
         | 
| @@ -63,7 +108,8 @@ describe LookerSDK::Client do | |
| 63 108 | 
             
                        :connection_options => {:ssl => {:verify => false}},
         | 
| 64 109 | 
             
                        :per_page => 40,
         | 
| 65 110 | 
             
                        :client_id    => "looker_client_id",
         | 
| 66 | 
            -
                        :client_secret => "client_secret2"
         | 
| 111 | 
            +
                        :client_secret => "client_secret2",
         | 
| 112 | 
            +
                        :lazy_swagger => true,
         | 
| 67 113 | 
             
                    }
         | 
| 68 114 | 
             
                  end
         | 
| 69 115 |  | 
| @@ -110,8 +156,13 @@ describe LookerSDK::Client do | |
| 110 156 |  | 
| 111 157 | 
             
                  describe "with .netrc"  do
         | 
| 112 158 | 
             
                    it "can read .netrc files" do
         | 
| 159 | 
            +
                      skip unless File.exist?(File.join(fixture_path, '.netrc'))
         | 
| 113 160 | 
             
                      LookerSDK.reset!
         | 
| 114 | 
            -
                      client = LookerSDK::Client.new( | 
| 161 | 
            +
                      client = LookerSDK::Client.new(
         | 
| 162 | 
            +
                        :lazy_swagger => true,
         | 
| 163 | 
            +
                        :netrc => true,
         | 
| 164 | 
            +
                        :netrc_file => File.join(fixture_path, '.netrc'),
         | 
| 165 | 
            +
                      )
         | 
| 115 166 | 
             
                      client.client_id.wont_be_nil
         | 
| 116 167 | 
             
                      client.client_secret.wont_be_nil
         | 
| 117 168 | 
             
                    end
         | 
| @@ -122,6 +173,9 @@ describe LookerSDK::Client do | |
| 122 173 |  | 
| 123 174 | 
             
                  before do
         | 
| 124 175 | 
             
                    LookerSDK.reset!
         | 
| 176 | 
            +
                    LookerSDK.configure do |c|
         | 
| 177 | 
            +
                      c.lazy_swagger = true
         | 
| 178 | 
            +
                    end
         | 
| 125 179 | 
             
                  end
         | 
| 126 180 |  | 
| 127 181 | 
             
                  it "sets oauth token with .configure" do
         | 
| @@ -232,6 +286,40 @@ describe LookerSDK::Client do | |
| 232 286 | 
             
                  end
         | 
| 233 287 | 
             
                end
         | 
| 234 288 |  | 
| 289 | 
            +
                [
         | 
| 290 | 
            +
                    [:get, '/api/3.0/users/foo%2Fbar', false],
         | 
| 291 | 
            +
                    [:get, '/api/3.0/users/foo%252Fbar', true],
         | 
| 292 | 
            +
                    [:post, '/api/3.0/users/foo%2Fbar', false],
         | 
| 293 | 
            +
                    [:post, '/api/3.0/users/foo%252Fbar', true],
         | 
| 294 | 
            +
                    [:put, '/api/3.0/users/foo%2Fbar', false],
         | 
| 295 | 
            +
                    [:put, '/api/3.0/users/foo%252Fbar', true],
         | 
| 296 | 
            +
                    [:patch, '/api/3.0/users/foo%2Fbar', false],
         | 
| 297 | 
            +
                    [:patch, '/api/3.0/users/foo%252Fbar', true],
         | 
| 298 | 
            +
                    [:delete, '/api/3.0/users/foo%2Fbar', false],
         | 
| 299 | 
            +
                    [:delete, '/api/3.0/users/foo%252Fbar', true],
         | 
| 300 | 
            +
                    [:head, '/api/3.0/users/foo%2Fbar', false],
         | 
| 301 | 
            +
                    [:head, '/api/3.0/users/foo%252Fbar', true],
         | 
| 302 | 
            +
                ].each do |method, path, encoded|
         | 
| 303 | 
            +
                  it "handles request path encoding" do
         | 
| 304 | 
            +
                    expected_path = '/api/3.0/users/foo%252Fbar'
         | 
| 305 | 
            +
             | 
| 306 | 
            +
                    resp = OpenStruct.new(:data => "hi", :status => 204)
         | 
| 307 | 
            +
                    mock = MiniTest::Mock.new.expect(:call, resp, [method, expected_path, nil, {}])
         | 
| 308 | 
            +
                    Sawyer::Agent.stubs(:new).returns(mock, mock)
         | 
| 309 | 
            +
             | 
| 310 | 
            +
                    sdk = LookerSDK::Client.new
         | 
| 311 | 
            +
                    if [:get, :delete, :head].include? method
         | 
| 312 | 
            +
                      args = [method, path, nil, encoded]
         | 
| 313 | 
            +
                    else
         | 
| 314 | 
            +
                      args = [method, path, nil, nil, encoded]
         | 
| 315 | 
            +
                    end
         | 
| 316 | 
            +
                    sdk.without_authentication do
         | 
| 317 | 
            +
                      value = sdk.public_send *args
         | 
| 318 | 
            +
                      assert_equal "hi", value
         | 
| 319 | 
            +
                    end
         | 
| 320 | 
            +
                    mock.verify
         | 
| 321 | 
            +
                  end
         | 
| 322 | 
            +
                end
         | 
| 235 323 | 
             
              end
         | 
| 236 324 |  | 
| 237 325 | 
             
              describe 'Sawyer date/time parsing patch' do
         | 
| @@ -36,6 +36,7 @@ class LookerDynamicClientTest < MiniTest::Spec | |
| 36 36 | 
             
                  conn.adapter :rack, engine
         | 
| 37 37 | 
             
                end
         | 
| 38 38 |  | 
| 39 | 
            +
                LookerSDK.reset!
         | 
| 39 40 | 
             
                LookerSDK::Client.new do |config|
         | 
| 40 41 | 
             
                  config.swagger = swagger
         | 
| 41 42 | 
             
                  config.access_token = access_token
         | 
| @@ -92,41 +93,30 @@ class LookerDynamicClientTest < MiniTest::Spec | |
| 92 93 |  | 
| 93 94 | 
             
              describe "swagger" do
         | 
| 94 95 |  | 
| 95 | 
            -
                it " | 
| 96 | 
            -
                   | 
| 97 | 
            -
             | 
| 98 | 
            -
                   | 
| 99 | 
            -
                   | 
| 100 | 
            -
                  sdk.stubs(:looker_warn).once
         | 
| 101 | 
            -
             | 
| 102 | 
            -
                  sdk.load_swagger
         | 
| 96 | 
            +
                it "raises when swagger.json can't be loaded" do
         | 
| 97 | 
            +
                  mock = MiniTest::Mock.new.expect(:call, nil) {raise "no swagger for you"}
         | 
| 98 | 
            +
                  mock.expect(:call, nil) {raise "still no swagger for you"}
         | 
| 99 | 
            +
                  err = assert_raises(RuntimeError) { sdk_client(nil, mock) }
         | 
| 100 | 
            +
                  assert_equal "still no swagger for you", err.message
         | 
| 103 101 | 
             
                end
         | 
| 104 102 |  | 
| 105 | 
            -
                it " | 
| 106 | 
            -
                   | 
| 107 | 
            -
             | 
| 108 | 
            -
                   | 
| 109 | 
            -
                   | 
| 110 | 
            -
                  sdk.stubs(:try_load_swagger).returns(nil, {key: "my data"})
         | 
| 111 | 
            -
                  sdk.stubs(:looker_warn).never
         | 
| 112 | 
            -
             | 
| 113 | 
            -
                  sdk.load_swagger
         | 
| 103 | 
            +
                it "loads swagger without authentication" do
         | 
| 104 | 
            +
                  resp = [200, {'Content-Type' => 'application/json'}, [default_swagger.to_json]]
         | 
| 105 | 
            +
                  mock = MiniTest::Mock.new.expect(:call, resp, [Hash])
         | 
| 106 | 
            +
                  sdk = sdk_client(nil, mock)
         | 
| 107 | 
            +
                  assert_equal default_swagger, sdk.swagger
         | 
| 114 108 | 
             
                end
         | 
| 115 109 |  | 
| 116 | 
            -
                it " | 
| 117 | 
            -
                   | 
| 118 | 
            -
             | 
| 119 | 
            -
                   | 
| 120 | 
            -
                   | 
| 121 | 
            -
                   | 
| 122 | 
            -
                  sdk.stubs(:looker_warn).never
         | 
| 123 | 
            -
             | 
| 124 | 
            -
                  sdk.load_swagger
         | 
| 110 | 
            +
                it "loads swagger with authentication" do
         | 
| 111 | 
            +
                  resp = [200, {'Content-Type' => 'application/json'}, [default_swagger.to_json]]
         | 
| 112 | 
            +
                  mock = MiniTest::Mock.new.expect(:call, nil) {raise "login first!"}
         | 
| 113 | 
            +
                  mock.expect(:call, resp, [Hash])
         | 
| 114 | 
            +
                  sdk = sdk_client(nil, mock)
         | 
| 115 | 
            +
                  assert_equal default_swagger, sdk.swagger
         | 
| 125 116 | 
             
                end
         | 
| 126 117 |  | 
| 127 118 | 
             
                it "invalid method name" do
         | 
| 128 | 
            -
                   | 
| 129 | 
            -
                  sdk = sdk_client(default_swagger, mock)
         | 
| 119 | 
            +
                  sdk = sdk_client(default_swagger, nil)
         | 
| 130 120 | 
             
                  assert_raises NoMethodError do
         | 
| 131 121 | 
             
                    sdk.this_method_name_doesnt_exist()
         | 
| 132 122 | 
             
                  end
         | 
| @@ -136,18 +126,44 @@ class LookerDynamicClientTest < MiniTest::Spec | |
| 136 126 | 
             
                  end
         | 
| 137 127 | 
             
                end
         | 
| 138 128 |  | 
| 129 | 
            +
                describe "operation maps" do
         | 
| 130 | 
            +
                  it "invoke by string operationId" do
         | 
| 131 | 
            +
                    verify(response, :get, '/api/3.0/user') do |sdk|
         | 
| 132 | 
            +
                      sdk.invoke('me')
         | 
| 133 | 
            +
                    end
         | 
| 134 | 
            +
                  end
         | 
| 135 | 
            +
             | 
| 136 | 
            +
                  it "invoke by symbol operationId" do
         | 
| 137 | 
            +
                    verify(response, :get, '/api/3.0/user') do |sdk|
         | 
| 138 | 
            +
                      sdk.invoke(:me)
         | 
| 139 | 
            +
                    end
         | 
| 140 | 
            +
                  end
         | 
| 141 | 
            +
                end
         | 
| 142 | 
            +
             | 
| 139 143 | 
             
                it "get no params" do
         | 
| 140 144 | 
             
                  verify(response, :get, '/api/3.0/user') do |sdk|
         | 
| 141 145 | 
             
                    sdk.me
         | 
| 142 146 | 
             
                  end
         | 
| 143 147 | 
             
                end
         | 
| 144 148 |  | 
| 145 | 
            -
                it "get with  | 
| 149 | 
            +
                it "get with params" do
         | 
| 146 150 | 
             
                  verify(response, :get, '/api/3.0/users/25') do |sdk|
         | 
| 147 151 | 
             
                    sdk.user(25)
         | 
| 148 152 | 
             
                  end
         | 
| 149 153 | 
             
                end
         | 
| 150 154 |  | 
| 155 | 
            +
                it "get with params that need encoding" do
         | 
| 156 | 
            +
                  verify(response, :get, '/api/3.0/users/foo%2Fbar') do |sdk|
         | 
| 157 | 
            +
                    sdk.user("foo/bar")
         | 
| 158 | 
            +
                  end
         | 
| 159 | 
            +
                end
         | 
| 160 | 
            +
             | 
| 161 | 
            +
                it "get with params already encoded" do
         | 
| 162 | 
            +
                    verify(response, :get, '/api/3.0/users/foo%2Fbar') do |sdk|
         | 
| 163 | 
            +
                    sdk.user("foo%2Fbar")
         | 
| 164 | 
            +
                  end
         | 
| 165 | 
            +
                end
         | 
| 166 | 
            +
             | 
| 151 167 | 
             
                it "get with query" do
         | 
| 152 168 | 
             
                  verify(response, :get, '/api/3.0/user', '', {bar:"foo"}) do |sdk|
         | 
| 153 169 | 
             
                    sdk.me({bar:'foo'})
         |