Skip to content

Commit

Permalink
[spaceship] allow to specify fetched fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nekrich committed Sep 22, 2023
1 parent 4257191 commit 4bf0256
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
3 changes: 2 additions & 1 deletion spaceship/lib/spaceship/connect_api/api_client.rb
Expand Up @@ -87,13 +87,14 @@ def web_session?
return @token.nil?
end

def build_params(filter: nil, includes: nil, limit: nil, sort: nil, cursor: nil)
def build_params(filter: nil, includes: nil, fields: nil, limit: nil, sort: nil, cursor: nil)
params = {}

filter = filter.delete_if { |k, v| v.nil? } if filter

params[:filter] = filter if filter && !filter.empty?
params[:include] = includes if includes
params[:fields] = fields if fields
params[:limit] = limit if limit
params[:sort] = sort if sort
params[:cursor] = cursor if cursor
Expand Down
4 changes: 2 additions & 2 deletions spaceship/lib/spaceship/connect_api/models/certificate.rb
Expand Up @@ -79,9 +79,9 @@ def self.create_certificate_signing_request
# API
#

def self.all(client: nil, filter: {}, includes: nil, limit: nil, sort: nil)
def self.all(client: nil, filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
client ||= Spaceship::ConnectAPI
resps = client.get_certificates(filter: filter, includes: includes).all_pages
resps = client.get_certificates(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort).all_pages
return resps.flat_map(&:to_models)
end

Expand Down
4 changes: 2 additions & 2 deletions spaceship/lib/spaceship/connect_api/models/device.rb
Expand Up @@ -51,9 +51,9 @@ def enabled?
# API
#

def self.all(client: nil, filter: {}, includes: nil, limit: nil, sort: nil)
def self.all(client: nil, filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
client ||= Spaceship::ConnectAPI
resps = client.get_devices(filter: filter, includes: includes).all_pages
resps = client.get_devices(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort).all_pages
return resps.flat_map(&:to_models)
end

Expand Down
4 changes: 2 additions & 2 deletions spaceship/lib/spaceship/connect_api/models/profile.rb
Expand Up @@ -69,9 +69,9 @@ def valid?
# API
#

def self.all(client: nil, filter: {}, includes: nil, limit: nil, sort: nil)
def self.all(client: nil, filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
client ||= Spaceship::ConnectAPI
resps = client.get_profiles(filter: filter, includes: includes).all_pages
resps = client.get_profiles(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort).all_pages
return resps.flat_map(&:to_models)
end

Expand Down
18 changes: 12 additions & 6 deletions spaceship/lib/spaceship/connect_api/provisioning/provisioning.rb
Expand Up @@ -129,8 +129,8 @@ def delete_bundle_id_capability(bundle_id_capability_id:)
# certificates
#

def get_certificates(profile_id: nil, filter: {}, includes: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, limit: limit, sort: sort)
def get_certificates(profile_id: nil, filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort)
if profile_id.nil?
provisioning_request_client.get("certificates", params)
else
Expand Down Expand Up @@ -164,8 +164,8 @@ def delete_certificate(certificate_id: nil)
# devices
#

def get_devices(profile_id: nil, filter: {}, includes: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, limit: limit, sort: sort)
def get_devices(profile_id: nil, filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort)
if profile_id.nil?
provisioning_request_client.get("devices", params)
else
Expand Down Expand Up @@ -213,8 +213,8 @@ def patch_device(id: nil, status: nil, new_name: nil)
# profiles
#

def get_profiles(filter: {}, includes: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, limit: limit, sort: sort)
def get_profiles(filter: {}, includes: nil, fields: nil, limit: nil, sort: nil)
params = provisioning_request_client.build_params(filter: filter, includes: includes, fields: fields, limit: limit, sort: sort)
provisioning_request_client.get("profiles", params)
end

Expand Down Expand Up @@ -253,6 +253,12 @@ def post_profiles(bundle_id_id: nil, certificates: nil, devices: nil, attributes
provisioning_request_client.post("profiles", body)
end

def get_profile_bundle_id(profile_id: nil)
raise "Profile id is nil" if profile_id.nil?

provisioning_request_client.get("profiles/#{profile_id}/bundleId")
end

def delete_profile(profile_id: nil)
raise "Profile id is nil" if profile_id.nil?

Expand Down
13 changes: 11 additions & 2 deletions spaceship/spec/connect_api/api_client_spec.rb
Expand Up @@ -13,6 +13,7 @@
let(:one_filter) { { build: "123" } }
let(:two_filters) { { build: "123", app: "321" } }
let(:includes) { "model.attribute" }
let(:fields) { { a: 'aField', b: 'bField1,bField2' } }
let(:limit) { "30" }
let(:sort) { "asc" }

Expand Down Expand Up @@ -47,6 +48,13 @@
})
end

it 'builds params with fields' do
params = client.build_params(fields: fields)
expect(params).to eq({
fields: fields
})
end

it 'builds params with limit' do
params = client.build_params(limit: limit)
expect(params).to eq({
Expand All @@ -61,11 +69,12 @@
})
end

it 'builds params with one filter, includes, limit, and sort' do
params = client.build_params(filter: one_filter, includes: includes, limit: limit, sort: sort)
it 'builds params with one filter, includes, fields, limit, and sort' do
params = client.build_params(filter: one_filter, includes: includes, fields: fields, limit: limit, sort: sort)
expect(params).to eq({
filter: one_filter,
include: includes,
fields: fields,
limit: limit,
sort: sort
})
Expand Down

0 comments on commit 4bf0256

Please sign in to comment.