forked from rileytestut/AltServer-Windows
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTeam.cpp
More file actions
executable file
·114 lines (91 loc) · 2.53 KB
/
Team.cpp
File metadata and controls
executable file
·114 lines (91 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// Team.cpp
// AltSign-Windows
//
// Created by Riley Testut on 8/9/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
#include "Team.hpp"
#include "PrefixHeader.pch"
Team::Team()
{
}
Team::~Team()
{
}
Team::Team(std::shared_ptr<Account> account, plist_t plist) /* throws */
{
auto nameNode = plist_dict_get_item(plist, "name");
auto identifierNode = plist_dict_get_item(plist, "teamId");
auto typeNode = plist_dict_get_item(plist, "type");
if (nameNode == nullptr || identifierNode == nullptr || typeNode == nullptr)
{
throw APIError(APIErrorCode::InvalidResponse);
}
char *name = nullptr;
plist_get_string_val(nameNode, &name);
char *identifier = 0;
plist_get_string_val(identifierNode, &identifier);
char *teamType = nullptr;
plist_get_string_val(typeNode, &teamType);
Team::Type type = Type::Unknown;
if (std::string(teamType) == "Company/Organization")
{
type = Type::Organization;
}
else if (std::string(teamType) == "Individual")
{
type = Type::Individual;
plist_t memberships = plist_dict_get_item(plist, "memberships");
if (memberships != nullptr && plist_array_get_size(memberships) == 1)
{
plist_t membership = plist_array_get_item(memberships, 0);
plist_t nameNode = plist_dict_get_item(membership, "name");
if (nameNode != nullptr)
{
char *rawName = nullptr;
plist_get_string_val(nameNode, &rawName);
// Make lowercase.
std::string name = rawName;
std::transform(name.begin(), name.end(), name.begin(), [](unsigned char c) {
return std::tolower(c);
});
if (name.find("free") != std::string::npos)
{
type = Type::Free;
}
}
}
}
else
{
type = Type::Unknown;
}
_name = name;
_identifier = identifier;
_type = type;
_account = account;
}
#pragma mark - Description -
std::ostream& operator<<(std::ostream& os, const Team& team)
{
os << "Name: " << team.name();
return os;
}
#pragma mark - Getters -
std::string Team::name() const
{
return _name;
}
std::string Team::identifier() const
{
return _identifier;
}
Team::Type Team::type() const
{
return _type;
}
std::shared_ptr<Account> Team::account() const
{
return _account;
}