bunny_app 1.20.0 → 1.23.0
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/README.md +20 -3
- data/lib/bunny_app/client.rb +1 -1
- data/lib/bunny_app/subscription.rb +53 -23
- data/lib/bunny_app/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de9822b5c8f2a3e7d121b0475e74e8f10bd974a2463257d2843b343fe72f188c
|
4
|
+
data.tar.gz: 836e2e8c9ceae9b0fa206b91e2b3be132afc1cae615cc6cc0bb640a3cc8d6c7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2900d6f1e399aab13c069032926c7dac253b0ae8577e5aa16bb5ed06af586d7e8b108a721bfce2f1c9bf04d905a8209707847ace93fdd3b040d11b8246552c9
|
7
|
+
data.tar.gz: 13a21e70ae4845830c3f0179cb5e502a9edca630a95c86a2396c236efef4bdf76671a34f594a7940226b344dad12e5ba6e5f797e1de59cae8444ea9842696b54
|
data/README.md
CHANGED
@@ -58,17 +58,34 @@ Create a config file at `config/initializers/bunny_app.rb`
|
|
58
58
|
> bin/rails g bunny_app:install
|
59
59
|
```
|
60
60
|
|
61
|
+
### Create a subscription
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
response = BunnyApp::Subscription.create(
|
65
|
+
product_plan_code: 'starter',
|
66
|
+
options: {
|
67
|
+
account_name: "Superdesk",
|
68
|
+
first_name: "Meg",
|
69
|
+
last_name: "La Don",
|
70
|
+
email: "meg@example.com",
|
71
|
+
trial: true,
|
72
|
+
tenant_code: "123456",
|
73
|
+
tenant_name: "Superdesk"
|
74
|
+
}
|
75
|
+
)
|
76
|
+
```
|
77
|
+
|
61
78
|
### Track feature usage
|
62
79
|
|
63
80
|
If you have usage based billing or just want to track feature usage then use this method.
|
64
81
|
|
65
82
|
```ruby
|
66
83
|
# Usage is tracked as if it just happened
|
67
|
-
|
84
|
+
response = BunnyApp::Usage.track(
|
68
85
|
quantity: 5, feature_code: 'products', tenant_code: '2')
|
69
86
|
|
70
87
|
# Usage is tracked using the date supplied
|
71
|
-
|
88
|
+
response = BunnyApp::Usage.track(
|
72
89
|
quantity: 5, feature_code: 'products', tenant_code: '2', usage_at: '2022-03-10')
|
73
90
|
```
|
74
91
|
|
@@ -109,7 +126,7 @@ variables = {
|
|
109
126
|
}
|
110
127
|
}
|
111
128
|
|
112
|
-
|
129
|
+
response = BunnyApp.query(query, variables)
|
113
130
|
```
|
114
131
|
|
115
132
|
### Verify webhook signature
|
data/lib/bunny_app/client.rb
CHANGED
@@ -58,7 +58,7 @@ module BunnyApp
|
|
58
58
|
|
59
59
|
case res.code.to_s
|
60
60
|
when /2[0-9][0-9]/ # HTTP 2xx
|
61
|
-
res.body
|
61
|
+
JSON.parse(res.body)
|
62
62
|
when /401/ # Access Token Expired
|
63
63
|
raise AuthorizationError, 'Invalid access token' unless BunnyApp.retryable
|
64
64
|
raise AuthorizationError, 'Invalid api credentials' if retries >= 1
|
@@ -3,40 +3,70 @@ module BunnyApp
|
|
3
3
|
@subscription_create_mutation = <<-'GRAPHQL'
|
4
4
|
mutation subscriptionCreate ($attributes: SubscriptionAttributes!) {
|
5
5
|
subscriptionCreate (attributes: $attributes) {
|
6
|
-
|
7
|
-
|
6
|
+
subscription {
|
7
|
+
id
|
8
|
+
account {
|
9
|
+
id
|
10
|
+
name
|
11
|
+
contacts {
|
8
12
|
id
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
endDate
|
13
|
-
state
|
14
|
-
productPlan {
|
15
|
-
name
|
16
|
-
}
|
17
|
-
tenant {
|
18
|
-
code
|
19
|
-
name
|
20
|
-
}
|
13
|
+
firstName
|
14
|
+
lastName
|
15
|
+
}
|
21
16
|
}
|
17
|
+
trialStartDate
|
18
|
+
trialEndDate
|
19
|
+
startDate
|
20
|
+
endDate
|
21
|
+
state
|
22
|
+
plan {
|
23
|
+
code
|
24
|
+
name
|
25
|
+
}
|
26
|
+
priceList {
|
27
|
+
code
|
28
|
+
name
|
29
|
+
}
|
30
|
+
tenant {
|
31
|
+
id
|
32
|
+
code
|
33
|
+
name
|
34
|
+
}
|
35
|
+
}
|
36
|
+
errors
|
22
37
|
}
|
23
|
-
|
38
|
+
}
|
24
39
|
GRAPHQL
|
25
40
|
|
26
|
-
|
41
|
+
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
42
|
+
def self.create(product_plan_code:, options: {})
|
27
43
|
variables = {
|
28
44
|
attributes: {
|
29
|
-
accountName: account_name,
|
30
|
-
firstName: first_name,
|
31
|
-
lastName: last_name,
|
32
|
-
email:,
|
33
45
|
productPlanCode: product_plan_code,
|
34
|
-
|
35
|
-
tenantCode: options[:tenant_code]&.to_s,
|
36
|
-
trial: options[:trial]
|
46
|
+
trial: options[:trial] || false
|
37
47
|
}
|
38
48
|
}
|
39
49
|
|
50
|
+
if options[:account_id]
|
51
|
+
variables[:attributes][:accountId] = options[:account_id]
|
52
|
+
else
|
53
|
+
variables[:attributes][:account] = {
|
54
|
+
name: options[:account_name]&.to_s,
|
55
|
+
billingContact: {
|
56
|
+
firstName: options[:first_name]&.to_s,
|
57
|
+
lastName: options[:last_name]&.to_s,
|
58
|
+
email: options[:email]&.to_s
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
if options[:tenant_code]
|
64
|
+
variables[:attributes][:tenant] = {
|
65
|
+
code: options[:tenant_code]&.to_s,
|
66
|
+
name: options[:tenant_name]&.to_s
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
40
70
|
Client.new.query(@subscription_create_mutation, variables)
|
41
71
|
end
|
42
72
|
end
|
data/lib/bunny_app/version.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: 1.
|
4
|
+
version: 1.23.0
|
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:
|
12
|
+
date: 2023-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|