bunny_app 1.30.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/bunny_app/client.rb +11 -2
- data/lib/bunny_app/{usage.rb → feature_usage.rb} +4 -3
- data/lib/bunny_app/platform.rb +4 -3
- data/lib/bunny_app/portal_session.rb +2 -1
- data/lib/bunny_app/subscription.rb +20 -1
- data/lib/bunny_app/tenant.rb +40 -7
- data/lib/bunny_app/version.rb +1 -1
- data/lib/bunny_app.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddee2a75dd5e0d155b6262ef9a0af252be0da7a23bf65c5b7082afe8f87944b4
|
4
|
+
data.tar.gz: 3ff475f3847b63fb0b0a2b779bf3df21f0ba5ed6d8cc682764e60b0b71eab2e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 634afceda6fe87a0de908fdfd8926dde84c48d0d8a56ebc54d4a08defb94ab3ace346646ec037eb5c6ded014788beeb5602cb1c0560a69c0ac2e47a8a22355ce
|
7
|
+
data.tar.gz: e0c605da0b2f6e53f2aef46e62067e1f575d73641d16eaf9b246ae6291c4e3b8903dd8f4f38a46ef5e83eae3008fb78b0e241ea7e00397582863f34ac097cca7
|
data/README.md
CHANGED
@@ -89,11 +89,11 @@ If you have usage based billing or just want to track feature usage then use thi
|
|
89
89
|
|
90
90
|
```ruby
|
91
91
|
# Usage is tracked as if it just happened
|
92
|
-
response = BunnyApp::
|
92
|
+
response = BunnyApp::FeatureUsage.create(
|
93
93
|
quantity: 5, feature_code: 'products', tenant_code: '2')
|
94
94
|
|
95
95
|
# Usage is tracked using the date supplied
|
96
|
-
response = BunnyApp::
|
96
|
+
response = BunnyApp::FeatureUsage.create(
|
97
97
|
quantity: 5, feature_code: 'products', tenant_code: '2', usage_at: '2022-03-10')
|
98
98
|
```
|
99
99
|
|
data/lib/bunny_app/client.rb
CHANGED
@@ -19,6 +19,8 @@ module BunnyApp
|
|
19
19
|
'Content-Type' => 'application/json',
|
20
20
|
'Authorization' => "Bearer #{BunnyApp.access_token}"
|
21
21
|
}
|
22
|
+
|
23
|
+
@headers['host'] = host_header unless host_header.nil?
|
22
24
|
end
|
23
25
|
|
24
26
|
def fetch_access_token
|
@@ -59,7 +61,7 @@ module BunnyApp
|
|
59
61
|
case res.code.to_s
|
60
62
|
when /2[0-9][0-9]/ # HTTP 2xx
|
61
63
|
response_body = JSON.parse(res.body)
|
62
|
-
raise ResponseError, response_body['errors'] if response_body['errors']
|
64
|
+
raise ResponseError, (response_body['errors'].map { |error| error['message'] }) if response_body['errors']
|
63
65
|
|
64
66
|
response_body
|
65
67
|
|
@@ -74,7 +76,10 @@ module BunnyApp
|
|
74
76
|
when /403/ # HTTP 403
|
75
77
|
raise AuthorizationError, res.parsed_response['error_decscription']
|
76
78
|
else
|
77
|
-
|
79
|
+
# HTTP 400, 500 etc
|
80
|
+
puts "Bunny SDK Response Error Headers: #{res.headers}"
|
81
|
+
puts "Bunny SDK Response Error Body: #{res.body}"
|
82
|
+
raise ResponseError, res.body
|
78
83
|
end
|
79
84
|
end
|
80
85
|
|
@@ -89,5 +94,9 @@ module BunnyApp
|
|
89
94
|
def verify_ssl
|
90
95
|
return true unless ENV['IGNORE_SSL']
|
91
96
|
end
|
97
|
+
|
98
|
+
def host_header
|
99
|
+
ENV.fetch('BUNNY_HOST_HEADER', nil)
|
100
|
+
end
|
92
101
|
end
|
93
102
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module BunnyApp
|
2
|
-
class
|
2
|
+
class FeatureUsage
|
3
3
|
@feature_usage_create_mutation = <<-'GRAPHQL'
|
4
4
|
mutation featureUsageCreate ($attributes: FeatureUsageAttributes!) {
|
5
5
|
featureUsageCreate (attributes: $attributes) {
|
@@ -23,7 +23,7 @@ module BunnyApp
|
|
23
23
|
}
|
24
24
|
GRAPHQL
|
25
25
|
|
26
|
-
def self.
|
26
|
+
def self.create(quantity:, feature_code:, tenant_code:, usage_at: nil)
|
27
27
|
variables = {
|
28
28
|
attributes: {
|
29
29
|
quantity:,
|
@@ -34,7 +34,8 @@ module BunnyApp
|
|
34
34
|
|
35
35
|
variables[:attributes][:usageAt] = usage_at unless usage_at.nil?
|
36
36
|
|
37
|
-
Client.new.query(@feature_usage_create_mutation, variables)
|
37
|
+
res = Client.new.query(@feature_usage_create_mutation, variables)
|
38
|
+
res['data']['featureUsageCreate']['featureUsage']
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
data/lib/bunny_app/platform.rb
CHANGED
@@ -16,12 +16,13 @@ module BunnyApp
|
|
16
16
|
def self.create(name:, code:)
|
17
17
|
variables = {
|
18
18
|
attributes: {
|
19
|
-
name
|
20
|
-
code:
|
19
|
+
name:,
|
20
|
+
code:
|
21
21
|
}
|
22
22
|
}
|
23
23
|
|
24
|
-
Client.new.query(@platform_create_mutation, variables)
|
24
|
+
res = Client.new.query(@platform_create_mutation, variables)
|
25
|
+
res['data']['platformCreate']['platform']
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
@@ -38,6 +38,14 @@ module BunnyApp
|
|
38
38
|
}
|
39
39
|
GRAPHQL
|
40
40
|
|
41
|
+
@subscription_cancel_mutation = <<-'GRAPHQL'
|
42
|
+
mutation subscriptionCancel ($ids: [ID!]!) {
|
43
|
+
subscriptionCancel (ids: $ids) {
|
44
|
+
errors
|
45
|
+
}
|
46
|
+
}
|
47
|
+
GRAPHQL
|
48
|
+
|
41
49
|
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
42
50
|
def self.create(price_list_code:, options: {})
|
43
51
|
variables = {
|
@@ -67,7 +75,18 @@ module BunnyApp
|
|
67
75
|
}
|
68
76
|
end
|
69
77
|
|
70
|
-
Client.new.query(@subscription_create_mutation, variables)
|
78
|
+
res = Client.new.query(@subscription_create_mutation, variables)
|
79
|
+
res['data']['subscriptionCreate']['subscription']
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.cancel(subscription_id:)
|
83
|
+
variables = {
|
84
|
+
ids: [subscription_id]
|
85
|
+
}
|
86
|
+
|
87
|
+
Client.new.query(@subscription_cancel_mutation, variables)
|
88
|
+
|
89
|
+
true
|
71
90
|
end
|
72
91
|
end
|
73
92
|
end
|
data/lib/bunny_app/tenant.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module BunnyApp
|
2
2
|
class Tenant
|
3
3
|
@tenant_create_mutation = <<-'GRAPHQL'
|
4
|
-
mutation tenantCreate ($attributes: TenantAttributes
|
5
|
-
tenantCreate (attributes: $attributes
|
4
|
+
mutation tenantCreate ($attributes: TenantAttributes!) {
|
5
|
+
tenantCreate (attributes: $attributes) {
|
6
6
|
tenant {
|
7
7
|
code
|
8
8
|
id
|
@@ -18,17 +18,50 @@ module BunnyApp
|
|
18
18
|
}
|
19
19
|
GRAPHQL
|
20
20
|
|
21
|
-
|
21
|
+
@tenant_query = <<-'GRAPHQL'
|
22
|
+
query tenant ($code: String!) {
|
23
|
+
tenant (code: $code) {
|
24
|
+
id
|
25
|
+
code
|
26
|
+
name
|
27
|
+
subdomain
|
28
|
+
account {
|
29
|
+
id
|
30
|
+
name
|
31
|
+
billingDay
|
32
|
+
}
|
33
|
+
latestProvisioningChange {
|
34
|
+
change
|
35
|
+
createdAt
|
36
|
+
features
|
37
|
+
id
|
38
|
+
updatedAt
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
GRAPHQL
|
43
|
+
|
44
|
+
def self.create(name:, code:, account_id:, platform_code: 'main')
|
22
45
|
variables = {
|
23
46
|
attributes: {
|
24
47
|
name:,
|
25
48
|
code:,
|
26
|
-
platformCode: platform_code
|
27
|
-
|
28
|
-
|
49
|
+
platformCode: platform_code,
|
50
|
+
accountId: account_id
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
res = Client.new.query(@tenant_create_mutation, variables)
|
55
|
+
res['data']['tenantCreate']['tenant']
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.find_by(code:)
|
59
|
+
variables = {
|
60
|
+
code:
|
29
61
|
}
|
30
62
|
|
31
|
-
Client.new.query(@
|
63
|
+
res = Client.new.query(@tenant_query, variables)
|
64
|
+
res['data']['tenant']
|
32
65
|
end
|
33
66
|
end
|
34
67
|
end
|
data/lib/bunny_app/version.rb
CHANGED
data/lib/bunny_app.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bunny_app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bunny
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-
|
12
|
+
date: 2023-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -139,11 +139,11 @@ files:
|
|
139
139
|
- lib/bunny_app.rb
|
140
140
|
- lib/bunny_app/client.rb
|
141
141
|
- lib/bunny_app/errors.rb
|
142
|
+
- lib/bunny_app/feature_usage.rb
|
142
143
|
- lib/bunny_app/platform.rb
|
143
144
|
- lib/bunny_app/portal_session.rb
|
144
145
|
- lib/bunny_app/subscription.rb
|
145
146
|
- lib/bunny_app/tenant.rb
|
146
|
-
- lib/bunny_app/usage.rb
|
147
147
|
- lib/bunny_app/version.rb
|
148
148
|
- lib/bunny_app/webhook.rb
|
149
149
|
- lib/generators/bunny_app/install_generator.rb
|