bunny_app 1.19.0 → 1.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -3
- data/bunny_app.gemspec +1 -1
- data/lib/bunny_app/client.rb +1 -1
- data/lib/bunny_app/subscription.rb +46 -21
- data/lib/bunny_app/version.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: a5c53eb110f9d41ac200c04fead7c1110a09e186d6dea4225cbd57a4f28533c6
|
4
|
+
data.tar.gz: f68c49c373ca3c40e2f4203393995a8c8ae65949b24987052fca6c32780d7abc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f0d7471ce7a14217f607469c46586e822221c6e98287f87b194ca265ded78448bc85a6d6c66a25d7dbd2247288708b852bacba227940bc869918d938ba8e925
|
7
|
+
data.tar.gz: 63faa1a0439fd737c3dd4219a4f5b12b49cad8bb6ebb8815752fa4c72fd702883c2251167aec2c1169c6a10669f66f20f18337457b6eb948d8bd79251dee0328
|
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/bunny_app.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
|
11
11
|
spec.summary = 'Ruby SDK for Bunny App'
|
12
12
|
spec.description = 'Use Bunny for SaaS subscription management, cpq, billing and CRM'
|
13
|
-
spec.homepage = 'https://github.com/
|
13
|
+
spec.homepage = 'https://github.com/bunnyapp/bunny-ruby'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.platform = Gem::Platform::RUBY
|
16
16
|
spec.required_ruby_version = '>= 3.1.0'
|
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,65 @@ module BunnyApp
|
|
3
3
|
@subscription_create_mutation = <<-'GRAPHQL'
|
4
4
|
mutation subscriptionCreate ($attributes: SubscriptionAttributes!) {
|
5
5
|
subscriptionCreate (attributes: $attributes) {
|
6
|
-
|
7
|
-
|
6
|
+
errors
|
7
|
+
subscription {
|
8
|
+
id
|
9
|
+
account {
|
8
10
|
id
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
productPlan {
|
15
|
-
name
|
16
|
-
}
|
17
|
-
tenant {
|
18
|
-
code
|
19
|
-
name
|
11
|
+
name
|
12
|
+
contacts {
|
13
|
+
id
|
14
|
+
firstName
|
15
|
+
lastName
|
20
16
|
}
|
21
17
|
}
|
18
|
+
trialStartDate
|
19
|
+
trialEndDate
|
20
|
+
startDate
|
21
|
+
endDate
|
22
|
+
state
|
23
|
+
productPlan {
|
24
|
+
name
|
25
|
+
}
|
26
|
+
tenant {
|
27
|
+
id
|
28
|
+
code
|
29
|
+
name
|
30
|
+
}
|
31
|
+
}
|
22
32
|
}
|
23
33
|
}
|
24
34
|
GRAPHQL
|
25
35
|
|
26
|
-
|
36
|
+
# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
37
|
+
def self.create(product_plan_code:, options: {})
|
27
38
|
variables = {
|
28
39
|
attributes: {
|
29
|
-
accountName: account_name,
|
30
|
-
firstName: first_name,
|
31
|
-
lastName: last_name,
|
32
|
-
email:,
|
33
40
|
productPlanCode: product_plan_code,
|
34
|
-
|
35
|
-
tenantCode: options[:tenant_code]&.to_s,
|
36
|
-
trial: options[:trial]
|
41
|
+
trial: options[:trial] || false
|
37
42
|
}
|
38
43
|
}
|
39
44
|
|
45
|
+
if options[:account_id]
|
46
|
+
variables[:attributes][:account_id] = options[:account_id]
|
47
|
+
else
|
48
|
+
variables[:attributes][:account] = {
|
49
|
+
name: options[:account_name]&.to_s,
|
50
|
+
billingContact: {
|
51
|
+
firstName: options[:first_name]&.to_s,
|
52
|
+
lastName: options[:last_name]&.to_s,
|
53
|
+
email: options[:email]&.to_s
|
54
|
+
}
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
if options[:tenant_code]
|
59
|
+
variables[:attributes][:tenant] = {
|
60
|
+
code: options[:tenant_code]&.to_s,
|
61
|
+
name: options[:tenant_name]&.to_s
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
40
65
|
Client.new.query(@subscription_create_mutation, variables)
|
41
66
|
end
|
42
67
|
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.22.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: 2022-
|
12
|
+
date: 2022-12-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
@@ -146,7 +146,7 @@ files:
|
|
146
146
|
- lib/bunny_app/version.rb
|
147
147
|
- lib/bunny_app/webhook.rb
|
148
148
|
- lib/generators/bunny_app/install_generator.rb
|
149
|
-
homepage: https://github.com/
|
149
|
+
homepage: https://github.com/bunnyapp/bunny-ruby
|
150
150
|
licenses:
|
151
151
|
- MIT
|
152
152
|
metadata:
|