Class: ShopifyCLI::PartnersAPI::Organizations

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/partners_api/organizations.rb

Class Method Summary collapse

Class Method Details

.fetch(ctx, id:) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/shopify_cli/partners_api/organizations.rb', line 13

def fetch(ctx, id:)
  resp = PartnersAPI.query(ctx, "find_organization", id: id)
  org = resp&.dig("data", "organizations", "nodes")&.first
  return nil if org.nil?
  org["stores"] = (org.dig("stores", "nodes") || [])
  org
end

.fetch_all(ctx) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/shopify_cli/partners_api/organizations.rb', line 5

def fetch_all(ctx)
  resp = PartnersAPI.query(ctx, "all_organizations")
  (resp&.dig("data", "organizations", "nodes") || []).map do |org|
    org["stores"] = (org.dig("stores", "nodes") || [])
    org
  end
end

.fetch_all_with_apps(ctx) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/shopify_cli/partners_api/organizations.rb', line 21

def fetch_all_with_apps(ctx)
  resp = PartnersAPI.query(ctx, "all_orgs_with_apps")
  (resp&.dig("data", "organizations", "nodes") || []).map do |org|
    org["stores"] = (org.dig("stores", "nodes") || [])
    org["apps"] = (org.dig("apps", "nodes") || [])
    org
  end
end

.fetch_with_apps(ctx, id:) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/shopify_cli/partners_api/organizations.rb', line 30

def fetch_with_apps(ctx, id:)
  resp = PartnersAPI.query(ctx, "find_organization_with_apps", id: id)
  organization = resp&.dig("data", "organizations", "nodes")&.first
  return unless organization

  organization.tap { organization["apps"] = (organization.dig("apps", "nodes") || []) }
end

.fetch_with_extensions(ctx, type, id:) ⇒ Object



38
39
40
41
# File 'lib/shopify_cli/partners_api/organizations.rb', line 38

def fetch_with_extensions(ctx, type, id:)
  organization = fetch_with_apps(ctx, id: id)
  AppExtensions.fetch_apps_extensions(ctx, organization, type)
end