whop 1.0.1 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f4c1e5809431db03714e0c34d8c97c18fa1bab3ee8483374634508b6d93d1d7
4
- data.tar.gz: 92cd8d195acbea810a055b8afc7a55abae6a2640a676af2179f82bf09d108001
3
+ metadata.gz: 459db38a252c7e59219c39e38a45aaf59d1efc155a3c35cadc82a9200783217e
4
+ data.tar.gz: 8e06ed8ac2da677b869457edcf325ae2300c5705339193f9e0f4f02d5300ae77
5
5
  SHA512:
6
- metadata.gz: 75986a9c460d6c0a8a041869dd84be895552661619ec9134396d1fcdeba86b8abfdfb347a48f5d1d703a93ba48bfd3c6a84f20758d72c0aacfcdc3fd82a1f9de
7
- data.tar.gz: 4a668336dc95ac2675026a44beb3a2235d97ae2201bb5172af340e8eb84f7846574de2bc6b0dc0095556aebb7c5c356e2593646dd02523273a2148a772d53422
6
+ metadata.gz: 962fbde15cb871d3fee2a911395eefa63acec49770f27ce513d93a78506d549d754d74925ec1186b7a22083fc50cbb4d144466af82ff34ba985b738a9a579f8c
7
+ data.tar.gz: aa7995d4c5cf75e84bb59d1dbef79e04ba9ebf8ef4cf42b2382b8f99591a7963ccc7809a39a080701412ade691a624e143a4268ba5291f068e01975fdd91da5b
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.graphql("CheckIfUserHasAccessToExperience", { userId: user_id, experienceId: experience_id })
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.graphql("CheckIfUserHasAccessToAccessPass", { userId: user_id, accessPassId: access_pass_id })
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.graphql("CheckIfUserHasAccessToCompany", { userId: user_id, companyId: company_id })
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.rb CHANGED
@@ -24,6 +24,15 @@ module Whop
24
24
  @methods[method_name.to_sym] = { type: :graphql, operation: operation, args: Array(args).map(&:to_sym) }
25
25
  end
26
26
 
27
+ def graphql_inline(method_name, operation:, query:, args: [])
28
+ @methods[method_name.to_sym] = {
29
+ type: :graphql_inline,
30
+ operation: operation,
31
+ query: query,
32
+ args: Array(args).map(&:to_sym)
33
+ }
34
+ end
35
+
27
36
  def rest_get(method_name, path:, args: [], params: [])
28
37
  @methods[method_name.to_sym] = { type: :rest_get, path: path, args: Array(args).map(&:to_sym), params: Array(params).map(&:to_sym) }
29
38
  end
@@ -63,6 +72,9 @@ module Whop
63
72
  when :graphql
64
73
  variables = build_named_args(spec[:args], args, kwargs)
65
74
  @client.graphql(spec[:operation], variables)
75
+ when :graphql_inline
76
+ variables = build_named_args(spec[:args], args, kwargs)
77
+ @client.graphql_query(spec[:operation], spec[:query], variables)
66
78
  when :rest_get
67
79
  path = interpolate_path(spec[:path], build_named_args(spec[:args], args, kwargs))
68
80
  query = kwargs.select { |k, _| spec[:params].include?(k.to_sym) }
@@ -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: "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]
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
@@ -34,16 +34,100 @@ Whop::DSL.define do
34
34
  end
35
35
 
36
36
  resource :payments do
37
- graphql :create_checkout_session, operation: "createCheckoutSession", args: %i[input]
38
- graphql :charge_user, operation: "chargeUser", args: %i[input]
39
- graphql :pay_user, operation: "payUser", args: %i[input]
40
- graphql :list_receipts_for_company, operation: "listReceiptsForCompany", args: %i[companyId first after filter]
37
+ graphql_inline :create_checkout_session,
38
+ operation: "createCheckoutSession",
39
+ args: %i[input],
40
+ query: <<~GQL
41
+ mutation createCheckoutSession($input: CreateCheckoutSessionInput!) {
42
+ createCheckoutSession(input: $input) {
43
+ id
44
+ planId
45
+ }
46
+ }
47
+ GQL
48
+
49
+ graphql_inline :charge_user,
50
+ operation: "chargeUser",
51
+ args: %i[input],
52
+ query: <<~GQL
53
+ mutation chargeUser($input: ChargeUserInput!) {
54
+ chargeUser(input: $input) {
55
+ status
56
+ inAppPurchase: checkoutSession {
57
+ id
58
+ planId
59
+ }
60
+ }
61
+ }
62
+ GQL
63
+
64
+ graphql_inline :pay_user,
65
+ operation: "payUser",
66
+ args: %i[input],
67
+ query: <<~GQL
68
+ mutation payUser($input: TransferFundsInput!) {
69
+ transferFunds(input: $input)
70
+ }
71
+ GQL
72
+
73
+ graphql_inline :list_receipts_for_company,
74
+ operation: "listReceiptsForCompany",
75
+ args: %i[companyId first after filter],
76
+ query: <<~GQL
77
+ query listReceiptsForCompany($companyId: ID!, $first: Int, $after: String, $filter: ReceiptV2Filters) {
78
+ company(id: $companyId) {
79
+ receipts: receiptsV2(first: $first, after: $after, filter: $filter) {
80
+ nodes {
81
+ id
82
+ createdAt
83
+ finalAmount
84
+ currency
85
+ }
86
+ pageInfo { hasNextPage endCursor }
87
+ }
88
+ }
89
+ }
90
+ GQL
41
91
  end
42
92
 
43
93
  resource :invoices do
44
- graphql :create_invoice, operation: "createInvoice", args: %i[input]
45
- graphql :get_invoice, operation: "getInvoice", args: %i[invoiceId companyId]
46
- graphql :list_invoices, operation: "listInvoices", args: %i[companyId after before first last]
94
+ graphql_inline :create_invoice,
95
+ operation: "createInvoice",
96
+ args: %i[input],
97
+ query: <<~GQL
98
+ mutation createInvoice($input: CreateInvoiceInput!) {
99
+ createInvoice(input: $input) {
100
+ invoice { id number status createdAt }
101
+ checkoutJobId
102
+ }
103
+ }
104
+ GQL
105
+
106
+ graphql_inline :get_invoice,
107
+ operation: "getInvoice",
108
+ args: %i[invoiceId companyId],
109
+ query: <<~GQL
110
+ query getInvoice($invoiceId: ID!, $companyId: ID!) {
111
+ company(id: $companyId) {
112
+ invoice(id: $invoiceId) { id number status createdAt }
113
+ }
114
+ }
115
+ GQL
116
+
117
+ graphql_inline :list_invoices,
118
+ operation: "listInvoices",
119
+ args: %i[companyId after before first last],
120
+ query: <<~GQL
121
+ query listInvoices($companyId: ID!, $after: String, $before: String, $first: Int, $last: Int) {
122
+ company(id: $companyId) {
123
+ invoices(after: $after, before: $before, first: $first, last: $last) {
124
+ totalCount
125
+ pageInfo { endCursor hasNextPage hasPreviousPage startCursor }
126
+ nodes { id number status createdAt }
127
+ }
128
+ }
129
+ }
130
+ GQL
47
131
  end
48
132
 
49
133
  resource :promo_codes do
data/lib/whop/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Whop
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.3"
3
3
  end
4
4
 
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikhil Nelson