spackle-ruby 0.0.4 → 0.0.6

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: 1a6b32c5881420c026c804b645c39a35cb223b3c926aeb5f6b02163f6c061400
4
- data.tar.gz: 2acfabcf67ea64675f95517b4ee6d0c9f224ac62882985d0baa304e03ce984b2
3
+ metadata.gz: 69b7dfaefe38c180f1057f25a9d882a747bc09f30aebb44af6154b3b040a2a37
4
+ data.tar.gz: b0252c13b04939fc3abb8fec6b57f26ebabd2529429898341c75d21096def49d
5
5
  SHA512:
6
- metadata.gz: 021e4b4b269c0e757ae38e525b02ab44f26d00b82336da3c082c39bb3099c19d7c238ccf330742214844d8fe048ad7cab21035c206c4f3a1ad8abbc2a310d493
7
- data.tar.gz: '058bce85874d0a04f037d0348214f3f487ae924c4abf17d9d544800d434d1fb2ad09363b801bd2da1a6287b77e43df3f6c95e982440b5cfc3a432c42919122f9'
6
+ metadata.gz: 4b7263e43ffb69eb8546ad4d90d56283064047d1659dfe286206d2f43dbd65d4b352889d3be3e306a43d8fa89db349e56cbac0e25b8c4938fd4154e10f6d58a8
7
+ data.tar.gz: 75bcdb13a9908ef0ee3c556092ec027940fb883457129b9fb912ad1faa13310fafceb9b3c5c9d739cb1a976e7b38997015dd898eaed997a49166ea594b29cf71
data/README.md CHANGED
@@ -115,10 +115,12 @@ In production, Spackle requires a valid Stripe customer. However, that is not de
115
115
  "cus_000000000": {
116
116
  "features": [
117
117
  {
118
+ "type": 0,
118
119
  "key": "flag_feature",
119
120
  "value_flag": true
120
121
  },
121
122
  {
123
+ "type": 1,
122
124
  "key": "limit_feature",
123
125
  "value_limit": 100
124
126
  }
@@ -149,10 +151,12 @@ Spackle.store = Spackle::MemoryStore.new()
149
151
  Spackle.store.set_customer_data("cus_000000000", {
150
152
  "features": [
151
153
  {
154
+ "type": 0,
152
155
  "key": "flag_feature",
153
156
  "value_flag": True,
154
157
  },
155
158
  {
159
+ "type": 1,
156
160
  "key": "limit_feature",
157
161
  "value_limit": 100,
158
162
  },
@@ -14,49 +14,36 @@ module Spackle
14
14
  end
15
15
 
16
16
  def get_customer_data(id)
17
- data = query({
18
- key_condition_expression: 'CustomerId = :customer_id',
19
- filter_expression: 'Version = :version',
20
- expression_attribute_values: {
21
- ':customer_id' => id,
22
- ':version' => Spackle.version
23
- },
24
- limit: 1
25
- })
17
+ result = get_item(id)
26
18
 
27
- if not data.items.any?
19
+ if result.nil? or result.item.nil?
28
20
  raise SpackleError.new "Customer #{id} not found"
29
21
  end
30
22
 
31
- JSON.parse(data.items[0]['State'])
23
+ JSON.parse(result.item['State'])
32
24
  end
33
25
 
34
26
  private
35
27
 
36
- def get_item(key)
37
- key = key.merge({
38
- 'AccountId' => @store_config['identity_id'],
39
- })
40
-
41
- response = @client.get_item({
42
- table_name: @table_name,
43
- key: key
44
- })
45
-
46
- JSON.parse(response.item['State'])
47
- end
48
-
49
- def query(query)
50
- query[:table_name] = @store_config['table_name']
51
- query[:key_condition_expression] = 'AccountId = :account_id AND ' + query[:key_condition_expression]
52
- query[:expression_attribute_values] = query[:expression_attribute_values].merge({
53
- ':account_id' => @store_config['identity_id']
28
+ def get_item(id)
29
+ return @client.get_item({
30
+ table_name: @store_config['table_name'],
31
+ key: {
32
+ AccountId: @store_config['identity_id'],
33
+ CustomerId: "#{id}:#{Spackle.version}"
34
+ }
54
35
  })
55
- @client.query(query)
36
+ rescue StandardError
37
+ return nil
56
38
  end
57
39
 
58
40
  def bootstrap_client
59
41
  Util.log_debug('Bootstrapping DynamoDB client...')
42
+
43
+ if Spackle.api_key.nil?
44
+ raise SpackleError.new 'API key not set'
45
+ end
46
+
60
47
  uri = URI(Spackle.api_base + '/sessions')
61
48
  https = Net::HTTP.new(uri.host, uri.port)
62
49
  https.use_ssl = true
data/lib/spackle.rb CHANGED
@@ -33,6 +33,10 @@ module Spackle
33
33
  def_delegators :@config, :version, :version=
34
34
  end
35
35
 
36
+ def self.bootstrap
37
+ Spackle.store
38
+ end
39
+
36
40
  class SpackleError < StandardError
37
41
  end
38
42
  end
data/spackle.gemspec CHANGED
@@ -2,7 +2,7 @@ $LOAD_PATH.unshift(::File.join(::File.dirname(__FILE__), "lib"))
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "spackle-ruby"
5
- s.version = "0.0.4"
5
+ s.version = "0.0.6"
6
6
  s.summary = "Spackle Ruby gem"
7
7
  s.description = "Spackle is the easiest way to integrate your Ruby app with Stripe Billing. " \
8
8
  "See https://www.spackle.so for details."
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spackle-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spackle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-06 00:00:00.000000000 Z
11
+ date: 2023-04-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Spackle is the easiest way to integrate your Ruby app with Stripe Billing.
14
14
  See https://www.spackle.so for details.