lib/gcloud/bigquery/dataset/list.rb in gcloud-0.11.0 vs lib/gcloud/bigquery/dataset/list.rb in gcloud-0.12.0

- old
+ new

@@ -69,18 +69,14 @@ # if datasets.next? # next_datasets = datasets.next # end def next return nil unless next? - ensure_connection! + ensure_service! options = { all: @hidden, token: token, max: @max } - resp = @connection.list_datasets options - if resp.success? - self.class.from_response resp, @connection - else - fail ApiError.from_response(resp) - end + gapi = @service.list_datasets options + self.class.from_gapi gapi, @service, @hidden, @max end ## # Retrieves all datasets by repeatedly loading {#next} until {#next?} # returns `false`. Calls the given block once for each dataset, which is @@ -146,27 +142,27 @@ end end ## # @private New Dataset::List from a response object. - def self.from_response resp, conn, hidden = nil, max = nil - datasets = List.new(Array(resp.data["datasets"]).map do |gapi_object| - Dataset.from_gapi gapi_object, conn + def self.from_gapi gapi_list, service, hidden = nil, max = nil + datasets = List.new(Array(gapi_list.datasets).map do |gapi_object| + Dataset.from_gapi gapi_object, service end) - datasets.instance_variable_set "@token", resp.data["nextPageToken"] - datasets.instance_variable_set "@etag", resp.data["etag"] - datasets.instance_variable_set "@connection", conn - datasets.instance_variable_set "@hidden", hidden - datasets.instance_variable_set "@max", max + datasets.instance_variable_set :@token, gapi_list.next_page_token + datasets.instance_variable_set :@etag, gapi_list.etag + datasets.instance_variable_set :@service, service + datasets.instance_variable_set :@hidden, hidden + datasets.instance_variable_set :@max, max datasets end protected ## - # Raise an error unless an active connection is available. - def ensure_connection! - fail "Must have active connection" unless @connection + # Raise an error unless an active service is available. + def ensure_service! + fail "Must have active connection" unless @service end end end end end