Module: Spaceship::ConnectAPI::Users::API

Defined in:
spaceship/lib/spaceship/connect_api/users/users.rb

Defined Under Namespace

Modules: Version

Instance Method Summary collapse

Instance Method Details

#add_user_visible_apps(user_id: nil, app_ids: nil) ⇒ Object

Deprecated.

Add app permissions for user



67
68
69
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 67

def add_user_visible_apps(user_id: nil, app_ids: nil)
  post_user_visible_apps(user_id: user_id, app_ids: app_ids)
end

#delete_user(user_id: nil) ⇒ Object

Delete existing user



31
32
33
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 31

def delete_user(user_id: nil)
  users_request_client.delete("#{Version::V1}/users/#{user_id}")
end

#delete_user_invitation(user_invitation_id: nil) ⇒ Object

Remove invited user from team (not yet accepted)



161
162
163
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 161

def delete_user_invitation(user_invitation_id: nil)
  users_request_client.delete("#{Version::V1}/userInvitations/#{user_invitation_id}")
end

#delete_user_visible_apps(user_id: nil, app_ids: nil) ⇒ Object

Remove app permissions for user



99
100
101
102
103
104
105
106
107
108
109
110
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 99

def delete_user_visible_apps(user_id: nil, app_ids: nil)
  body = {
    data: app_ids.map do |app_id|
      {
        type: "apps",
        id: app_id
      }
    end
  }
  params = nil
  users_request_client.delete("#{Version::V1}/users/#{user_id}/relationships/visibleApps", params, body)
end

#get_user_invitation_visible_apps(user_invitation_id: id, limit: nil) ⇒ Object

Get all app permissions for invited user



166
167
168
169
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 166

def get_user_invitation_visible_apps(user_invitation_id: id, limit: nil)
  params = users_request_client.build_params(filter: {}, includes: nil, limit: limit, sort: nil)
  users_request_client.get("#{Version::V1}/userInvitations/#{user_invitation_id}/visibleApps", params)
end

#get_user_invitations(filter: {}, includes: nil, limit: nil, sort: nil) ⇒ Object

Get all invited users



123
124
125
126
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 123

def get_user_invitations(filter: {}, includes: nil, limit: nil, sort: nil)
  params = users_request_client.build_params(filter: filter, includes: includes, limit: limit, sort: sort)
  users_request_client.get("#{Version::V1}/userInvitations", params)
end

#get_user_visible_apps(user_id: id, limit: nil) ⇒ Object

Get app permissions for user



113
114
115
116
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 113

def get_user_visible_apps(user_id: id, limit: nil)
  params = users_request_client.build_params(filter: {}, includes: nil, limit: limit, sort: nil)
  users_request_client.get("#{Version::V1}/users/#{user_id}/visibleApps", params)
end

#get_users(filter: {}, includes: nil, limit: nil, sort: nil) ⇒ Object

Get list of users



25
26
27
28
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 25

def get_users(filter: {}, includes: nil, limit: nil, sort: nil)
  params = users_request_client.build_params(filter: filter, includes: includes, limit: limit, sort: sort)
  users_request_client.get("#{Version::V1}/users", params)
end

#patch_user(user_id:, all_apps_visible:, provisioning_allowed:, roles:, visible_app_ids:) ⇒ Object

Update existing user



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 36

def patch_user(user_id:, all_apps_visible:, provisioning_allowed:, roles:, visible_app_ids:)
  body = {
    data: {
      type: 'users',
      id: user_id,
      attributes: {
        allAppsVisible: all_apps_visible,
        provisioningAllowed: provisioning_allowed,
        roles: roles
      },
      relationships: {
        visibleApps: {
          data: visible_app_ids.map do |app_id|
            {
              type: "apps",
              id: app_id
            }
          end
        }
      }
    }
  }

  # Avoid API error: You cannot set visible apps for this user because the user's roles give them access to all apps.
  body[:data].delete(:relationships) if all_apps_visible

  users_request_client.patch("#{Version::V1}/users/#{user_id}", body)
end

#patch_user_visible_apps(user_id: nil, app_ids: nil) ⇒ Object

Replace app permissions for user



85
86
87
88
89
90
91
92
93
94
95
96
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 85

def patch_user_visible_apps(user_id: nil, app_ids: nil)
  body = {
    data: app_ids.map do |app_id|
      {
        type: "apps",
        id: app_id
      }
    end
  }

  users_request_client.patch("#{Version::V1}/users/#{user_id}/relationships/visibleApps", body)
end

#post_user_invitation(email: nil, first_name: nil, last_name: nil, roles: [], provisioning_allowed: nil, all_apps_visible: nil, visible_app_ids: []) ⇒ Object

Invite new users to App Store Connect



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 129

def post_user_invitation(email: nil, first_name: nil, last_name: nil, roles: [], provisioning_allowed: nil, all_apps_visible: nil, visible_app_ids: [])
  body = {
    data: {
      type: "userInvitations",
      attributes: {
        email: email,
        firstName: first_name,
        lastName: last_name,
        roles: roles,
        provisioningAllowed: provisioning_allowed,
        allAppsVisible: all_apps_visible
      },
      relationships: {
        visibleApps: {
          data: visible_app_ids.map do |id|
            {
              id: id,
              type: "apps"
            }
          end
        }
      }
    }
  }

  # Avoid API error: You cannot set visible apps for this user because the user's roles give them access to all apps.
  body[:data].delete(:relationships) if all_apps_visible

  users_request_client.post("#{Version::V1}/userInvitations", body)
end

#post_user_visible_apps(user_id: nil, app_ids: nil) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 71

def post_user_visible_apps(user_id: nil, app_ids: nil)
  body = {
    data: app_ids.map do |app_id|
      {
        type: "apps",
        id: app_id
      }
    end
  }

  users_request_client.post("#{Version::V1}/users/#{user_id}/relationships/visibleApps", body)
end

#users_request_clientObject

Raises:

  • (TypeError)


15
16
17
18
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 15

def users_request_client
  return @users_request_client if @users_request_client
  raise TypeError, "You need to instantiate this module with users_request_client"
end

#users_request_client=(users_request_client) ⇒ Object



11
12
13
# File 'spaceship/lib/spaceship/connect_api/users/users.rb', line 11

def users_request_client=(users_request_client)
  @users_request_client = users_request_client
end