spackle-ruby 0.0.1 → 0.0.2
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 +1 -1
- data/lib/spackle/customer.rb +30 -7
- data/lib/spackle/dynamodb.rb +9 -4
- data/lib/spackle/spackle_configuration.rb +2 -0
- data/lib/spackle.rb +4 -0
- data/spackle.gemspec +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d27b263b4e2980ec835c98ddecf665742d566c746ac6e992b0b6c92a7c182bfa
|
4
|
+
data.tar.gz: 566c2461defd89631a9c514b44284718e218065ca6bb6b6ff04a558fe750ea23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a13b6955dddbe47c3c7385f657fb0d2a184c9decb18cd4ce3fdffdb9cf30cb00def4d354c1652f4e6b997467345d64d34f62d07076dc0d4505f102a61cd0e837
|
7
|
+
data.tar.gz: bad22643c179c73f4b87ecab410c86f2e33264e58dc61ef677f7ca1e67ae5eb2437e1f5e8e17f0a95599ab8fc9cbb4ba3dddd6f337fce86bb1f422baffe44053
|
data/README.md
CHANGED
data/lib/spackle/customer.rb
CHANGED
@@ -4,35 +4,58 @@ module Spackle
|
|
4
4
|
|
5
5
|
def self.retrieve(id)
|
6
6
|
Util.log_debug("Retrieving customer data for #{id}")
|
7
|
-
data = Spackle.client.
|
8
|
-
'CustomerId
|
7
|
+
data = Spackle.client.query({
|
8
|
+
key_condition_expression: 'CustomerId = :customer_id',
|
9
|
+
filter_expression: 'Version = :version',
|
10
|
+
expression_attribute_values: {
|
11
|
+
':customer_id' => id,
|
12
|
+
':version' => Spackle.version
|
13
|
+
},
|
14
|
+
limit: 1
|
9
15
|
})
|
16
|
+
|
17
|
+
if not data.items.any?
|
18
|
+
raise SpackleError.new "Customer #{id} not found"
|
19
|
+
end
|
20
|
+
|
10
21
|
Util.log_debug("Retrieved customer data for #{id}: #{data}")
|
11
|
-
Customer.new(data)
|
22
|
+
Customer.new(JSON.parse(data.items[0]['State']))
|
12
23
|
end
|
13
24
|
|
14
25
|
def initialize(data)
|
15
26
|
@data = data
|
16
27
|
end
|
17
28
|
|
29
|
+
def features
|
30
|
+
return @data['features']
|
31
|
+
end
|
32
|
+
|
33
|
+
def flag_features
|
34
|
+
features.select { |f| f['type'] == 0 }
|
35
|
+
end
|
36
|
+
|
37
|
+
def limit_features
|
38
|
+
features.select { |f| f['type'] == 1 }
|
39
|
+
end
|
40
|
+
|
18
41
|
def enabled(key)
|
19
|
-
|
42
|
+
flag_features.each do |f|
|
20
43
|
if f['key'] == key
|
21
44
|
return f['value_flag']
|
22
45
|
end
|
23
46
|
end
|
24
47
|
|
25
|
-
|
48
|
+
raise SpackleError.new "Flag feature #{key} not found"
|
26
49
|
end
|
27
50
|
|
28
51
|
def limit(key)
|
29
52
|
@data['features'].each do |f|
|
30
53
|
if f['key'] == key
|
31
|
-
return f['value_limit']
|
54
|
+
return f['value_limit'] || Float::INFINITY
|
32
55
|
end
|
33
56
|
end
|
34
57
|
|
35
|
-
|
58
|
+
raise SpackleError.new "Limit feature #{key} not found"
|
36
59
|
end
|
37
60
|
end
|
38
61
|
end
|
data/lib/spackle/dynamodb.rb
CHANGED
@@ -7,7 +7,6 @@ module Spackle
|
|
7
7
|
@client = nil
|
8
8
|
@identity_id = nil
|
9
9
|
@table_name = nil
|
10
|
-
@aws_region = nil
|
11
10
|
|
12
11
|
def initialize
|
13
12
|
@client = bootstrap_client
|
@@ -26,8 +25,16 @@ module Spackle
|
|
26
25
|
JSON.parse(response.item['State'])
|
27
26
|
end
|
28
27
|
|
29
|
-
|
28
|
+
def query(query)
|
29
|
+
query[:table_name] = @table_name
|
30
|
+
query[:key_condition_expression] = 'AccountId = :account_id AND ' + query[:key_condition_expression]
|
31
|
+
query[:expression_attribute_values] = query[:expression_attribute_values].merge({
|
32
|
+
':account_id' => @identity_id
|
33
|
+
})
|
34
|
+
response = @client.query(query)
|
35
|
+
end
|
30
36
|
|
37
|
+
private
|
31
38
|
|
32
39
|
def bootstrap_client
|
33
40
|
Util.log_debug('Bootstrapping DynamoDB client...')
|
@@ -44,7 +51,6 @@ module Spackle
|
|
44
51
|
|
45
52
|
@identity_id = data['identity_id']
|
46
53
|
@table_name = data['table_name']
|
47
|
-
@aws_region = data['aws_region']
|
48
54
|
|
49
55
|
credentials = SpackleCredentials.new(
|
50
56
|
data['role_arn'],
|
@@ -52,7 +58,6 @@ module Spackle
|
|
52
58
|
)
|
53
59
|
|
54
60
|
Aws::DynamoDB::Client.new(
|
55
|
-
region: @aws_region,
|
56
61
|
credentials: credentials,
|
57
62
|
)
|
58
63
|
end
|
@@ -6,11 +6,13 @@ module Spackle
|
|
6
6
|
attr_accessor :api_base
|
7
7
|
attr_accessor :log_level
|
8
8
|
attr_reader :logger
|
9
|
+
attr_reader :version
|
9
10
|
|
10
11
|
def initialize
|
11
12
|
@api_base = 'https://api.spackle.so'
|
12
13
|
@log_level = Logger::INFO
|
13
14
|
@logger = Logger.new(STDOUT, level: @log_level)
|
15
|
+
@version = 1
|
14
16
|
end
|
15
17
|
|
16
18
|
def log_level=(level)
|
data/lib/spackle.rb
CHANGED
@@ -23,6 +23,7 @@ module Spackle
|
|
23
23
|
def_delegators :@config, :api_base, :api_base=
|
24
24
|
def_delegators :@config, :log_level, :log_level=
|
25
25
|
def_delegators :@config, :logger, :logger=
|
26
|
+
def_delegators :@config, :version, :version=
|
26
27
|
end
|
27
28
|
|
28
29
|
def self.client
|
@@ -35,6 +36,9 @@ module Spackle
|
|
35
36
|
self.client
|
36
37
|
nil
|
37
38
|
end
|
39
|
+
|
40
|
+
class SpackleError < StandardError
|
41
|
+
end
|
38
42
|
end
|
39
43
|
|
40
44
|
Spackle.log_level = ENV["SPACKLE_LOG"] unless ENV["SPACKLE_LOG"].nil?
|
data/spackle.gemspec
CHANGED
@@ -2,9 +2,9 @@ $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.
|
5
|
+
s.version = "0.0.2"
|
6
6
|
s.summary = "Spackle Ruby gem"
|
7
|
-
s.description = "Spackle is the easiest way to integrate your Ruby app with Stripe Billing." \
|
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."
|
9
9
|
s.authors = ["Spackle"]
|
10
10
|
s.email = "support@spackle.so"
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spackle-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spackle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Spackle is the easiest way to integrate your Ruby app with Stripe Billing.
|
14
|
-
https://www.spackle.so for details.
|
13
|
+
description: Spackle is the easiest way to integrate your Ruby app with Stripe Billing.
|
14
|
+
See https://www.spackle.so for details.
|
15
15
|
email: support@spackle.so
|
16
16
|
executables:
|
17
17
|
- spackle-console
|