whop 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/whop/access.rb +42 -3
- data/lib/whop/client.rb +12 -0
- data/lib/whop/dsl_prelude.rb +3 -3
- data/lib/whop/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b66a5c1ff726bf0d3142a0d2f3263f990c114f1de42c05dfe3d564d63719e702
|
|
4
|
+
data.tar.gz: c36bc051232dafa141659f0a11df945f5ce06aa8b852ae37504b752d72ed2cfc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 13b4f042216946a03e922f4c7642c6b8a478b3ea95b9c3e727a39e756f989ad7ae6cf248e7dfa74a3101637ea3eef5c9e89acf80d7cd4a322067c0eb4e529cf2
|
|
7
|
+
data.tar.gz: 417ab6ac4239fbe3bbbdccb3a7bf41326e847152318658449fc92fd74e28b2999ac556a8a27656322235eaf74e3ecafe384191a074a1030b15a6fa07ebef72b6
|
data/lib/whop/access.rb
CHANGED
|
@@ -5,18 +5,57 @@ module Whop
|
|
|
5
5
|
@client = client
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
+
QUERY_EXPERIENCE = <<~GRAPHQL
|
|
9
|
+
query checkIfUserHasAccessToExperience($experienceId: ID!, $userId: ID) {
|
|
10
|
+
hasAccessToExperience(experienceId: $experienceId, userId: $userId) {
|
|
11
|
+
hasAccess
|
|
12
|
+
accessLevel
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
GRAPHQL
|
|
16
|
+
|
|
17
|
+
QUERY_ACCESS_PASS = <<~GRAPHQL
|
|
18
|
+
query checkIfUserHasAccessToAccessPass($accessPassId: ID!, $userId: ID) {
|
|
19
|
+
hasAccessToAccessPass(accessPassId: $accessPassId, userId: $userId) {
|
|
20
|
+
hasAccess
|
|
21
|
+
accessLevel
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
GRAPHQL
|
|
25
|
+
|
|
26
|
+
QUERY_COMPANY = <<~GRAPHQL
|
|
27
|
+
query checkIfUserHasAccessToCompany($companyId: ID!, $userId: ID) {
|
|
28
|
+
hasAccessToCompany(companyId: $companyId, userId: $userId) {
|
|
29
|
+
hasAccess
|
|
30
|
+
accessLevel
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
GRAPHQL
|
|
34
|
+
|
|
8
35
|
def user_has_access_to_experience?(user_id:, experience_id:)
|
|
9
|
-
data = @client.
|
|
36
|
+
data = @client.graphql_query(
|
|
37
|
+
"checkIfUserHasAccessToExperience",
|
|
38
|
+
QUERY_EXPERIENCE,
|
|
39
|
+
{ userId: user_id, experienceId: experience_id }
|
|
40
|
+
)
|
|
10
41
|
extract_access_boolean(data)
|
|
11
42
|
end
|
|
12
43
|
|
|
13
44
|
def user_has_access_to_access_pass?(user_id:, access_pass_id:)
|
|
14
|
-
data = @client.
|
|
45
|
+
data = @client.graphql_query(
|
|
46
|
+
"checkIfUserHasAccessToAccessPass",
|
|
47
|
+
QUERY_ACCESS_PASS,
|
|
48
|
+
{ userId: user_id, accessPassId: access_pass_id }
|
|
49
|
+
)
|
|
15
50
|
extract_access_boolean(data)
|
|
16
51
|
end
|
|
17
52
|
|
|
18
53
|
def user_has_access_to_company?(user_id:, company_id:)
|
|
19
|
-
data = @client.
|
|
54
|
+
data = @client.graphql_query(
|
|
55
|
+
"checkIfUserHasAccessToCompany",
|
|
56
|
+
QUERY_COMPANY,
|
|
57
|
+
{ userId: user_id, companyId: company_id }
|
|
58
|
+
)
|
|
20
59
|
extract_access_boolean(data)
|
|
21
60
|
end
|
|
22
61
|
|
data/lib/whop/client.rb
CHANGED
|
@@ -55,6 +55,18 @@ module Whop
|
|
|
55
55
|
end
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
+
# GraphQL with inline query string (non-persisted). Useful when operationId is unavailable.
|
|
59
|
+
def graphql_query(operation_name, query_string, variables = {})
|
|
60
|
+
with_error_mapping do
|
|
61
|
+
response = Faraday.post("#{config.api_base_url}/public-graphql") do |req|
|
|
62
|
+
apply_common_headers(req.headers)
|
|
63
|
+
req.headers["Content-Type"] = "application/json"
|
|
64
|
+
req.body = JSON.generate({ operationName: operation_name, query: query_string, variables: variables })
|
|
65
|
+
end
|
|
66
|
+
parse_response!(response)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
58
70
|
# Simple GraphQL auto-pagination helper.
|
|
59
71
|
# Expects a query that returns { pageInfo: { hasNextPage, endCursor }, nodes: [...] } under a known path.
|
|
60
72
|
# Usage:
|
data/lib/whop/dsl_prelude.rb
CHANGED
|
@@ -2,9 +2,9 @@ require_relative "dsl"
|
|
|
2
2
|
|
|
3
3
|
Whop::DSL.define do
|
|
4
4
|
resource :access do
|
|
5
|
-
graphql :check_if_user_has_access_to_experience, operation: "
|
|
6
|
-
graphql :check_if_user_has_access_to_access_pass, operation: "
|
|
7
|
-
graphql :check_if_user_has_access_to_company, operation: "
|
|
5
|
+
graphql :check_if_user_has_access_to_experience, operation: "checkIfUserHasAccessToExperience", args: %i[userId experienceId]
|
|
6
|
+
graphql :check_if_user_has_access_to_access_pass, operation: "checkIfUserHasAccessToAccessPass", args: %i[userId accessPassId]
|
|
7
|
+
graphql :check_if_user_has_access_to_company, operation: "checkIfUserHasAccessToCompany", args: %i[userId companyId]
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
resource :users do
|
data/lib/whop/version.rb
CHANGED