bunny_app 1.20.0 → 1.22.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b7923c5262af141b61e7b3f2e433a5c15cfec74a5d334195a5b3971b5ebe4b2c
4
- data.tar.gz: ecdb5369782741c2fe30c1cc71a8e3c0e2d1778694c7fa8494042d20261d6906
3
+ metadata.gz: a5c53eb110f9d41ac200c04fead7c1110a09e186d6dea4225cbd57a4f28533c6
4
+ data.tar.gz: f68c49c373ca3c40e2f4203393995a8c8ae65949b24987052fca6c32780d7abc
5
5
  SHA512:
6
- metadata.gz: e1b25c0f1910e30eadec75891b6f459eb96a1cb6c3ccb585de4299093568fe56456eb8fd19fb5ef5530b2e25cbbc82908a37ef67ee009e8bdd3f373a711735fc
7
- data.tar.gz: f841cb3088700f279b25234c84f27cd4c50528be90ec54b9fc1a0ec9d4a86f87140a41e1accf83279a67e10f286ecd191ccf3492746538109c26d8d922e0489e
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
- json_response = BunnyApp::Usage.track(
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
- json_response = BunnyApp::Usage.track(
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
- json_response = BunnyApp.query(query, variables)
129
+ response = BunnyApp.query(query, variables)
113
130
  ```
114
131
 
115
132
  ### Verify webhook signature
@@ -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
- errors
7
- subscription {
6
+ errors
7
+ subscription {
8
+ id
9
+ account {
8
10
  id
9
- trialStartDate
10
- trialEndDate
11
- startDate
12
- endDate
13
- state
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
- def self.create(account_name:, first_name:, last_name:, email:, product_plan_code:, options: {})
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
- trialStartDate: options[:trial_start_date],
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BunnyApp
4
- VERSION = '1.20.0'
4
+ VERSION = '1.22.0'
5
5
  end
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.20.0
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-09-28 00:00:00.000000000 Z
12
+ date: 2022-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty