bunny_app 1.29.0 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dccce34d5f6262056050a985f9e8130bbec9ee245c9f4aca9fc9a8742f3e83bc
4
- data.tar.gz: 34db494e834dec66fdfee684447db25e5599a1ffa8d09f2a16c70f2fbdb7d552
3
+ metadata.gz: 9ef0fdf58b7fc7c4973466ba5c722802b73b2d94529087aa3dd1332290f2c044
4
+ data.tar.gz: 8903c12d6412863560b7f25b6be25c2580a0b01cc8f8d9451b121e810b93333c
5
5
  SHA512:
6
- metadata.gz: 1b104a3cc34f6dea3f964a1f5e6309dafd81be3d2b3e41a443c8a7385d02d9116d6d0328e26ec3ddb75900151d7e57fa2b6c1324004a991cb85dc979aea2f889
7
- data.tar.gz: 45e63afdd192f68abbb6c91106d04816a8d57d56a12b085b096953ba65a656a3da93240bf1a102de91855969959a0dc2ddd871108b87d0805f01016ad0eaebf3
6
+ metadata.gz: b95f160e2ed4c9b90a498310efd2dffc0909a825bb60ea3c8707c2bb2b7343b6e565561b046186c9874467c3cceaaef6795c696bbc8c969506aa18255ccd28d1
7
+ data.tar.gz: 8a4e13af567f9cfd02f99135ca9fdd72bbf0a1e9787137944b6f3c22aef529f4c9ac8a2d35bd5991c96c9284a0ff4150b5a60b018757f0f24c70847984bc8180
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::Usage.track(
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::Usage.track(
96
+ response = BunnyApp::FeatureUsage.create(
97
97
  quantity: 5, feature_code: 'products', tenant_code: '2', usage_at: '2022-03-10')
98
98
  ```
99
99
 
@@ -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
 
@@ -89,5 +91,9 @@ module BunnyApp
89
91
  def verify_ssl
90
92
  return true unless ENV['IGNORE_SSL']
91
93
  end
94
+
95
+ def host_header
96
+ ENV.fetch('BUNNY_HOST_HEADER', nil)
97
+ end
92
98
  end
93
99
  end
@@ -1,5 +1,5 @@
1
1
  module BunnyApp
2
- class Usage
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.track(quantity:, feature_code:, tenant_code:, usage_at: nil)
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
@@ -16,12 +16,13 @@ module BunnyApp
16
16
  def self.create(name:, code:)
17
17
  variables = {
18
18
  attributes: {
19
- name: name,
20
- code: 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
@@ -16,7 +16,8 @@ module BunnyApp
16
16
  expiry: expiry_hours
17
17
  }
18
18
 
19
- Client.new.query(@portal_session_create_mutation, variables)
19
+ res = Client.new.query(@portal_session_create_mutation, variables)
20
+ res['data']['portalSessionCreate']['token']
20
21
  end
21
22
  end
22
23
  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
@@ -1,8 +1,8 @@
1
1
  module BunnyApp
2
2
  class Tenant
3
3
  @tenant_create_mutation = <<-'GRAPHQL'
4
- mutation tenantCreate ($attributes: TenantAttributes!, $subscriptionId: ID!) {
5
- tenantCreate (attributes: $attributes, subscriptionId: $subscriptionId) {
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
- def self.create(name:, code:, platform_code: 'main', subscription_id: nil)
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
- subscriptionId: subscription_id
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(@tenant_create_mutation, variables)
63
+ res = Client.new.query(@tenant_query, variables)
64
+ res['data']['tenant']
32
65
  end
33
66
  end
34
67
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BunnyApp
4
- VERSION = '1.29.0'
4
+ VERSION = '2.0.0'
5
5
  end
data/lib/bunny_app.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'bunny_app/version'
2
2
  require 'bunny_app/errors'
3
3
  require 'bunny_app/client'
4
- require 'bunny_app/usage'
4
+ require 'bunny_app/feature_usage'
5
5
  require 'bunny_app/platform'
6
6
  require 'bunny_app/tenant'
7
7
  require 'bunny_app/subscription'
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.29.0
4
+ version: 2.0.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: 2023-06-16 00:00:00.000000000 Z
12
+ date: 2023-08-18 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