sugester 0.5.1 → 0.5.4
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/Gemfile.lock +1 -1
- data/lib/sugester.rb +43 -20
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 022cfc170f0b77327a4470217d52ef5534a06e2b
|
4
|
+
data.tar.gz: 3b4f70312007b06089e9a0a835fe1ca7bb6860fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9299ab731c0ff54e46a6111fcb01f2059a6ac35a1f8ce41b82de3d50a944cea10f99459f831ad762f267cf31d197ffd7beb3e1021391097d8c9a583b764b9b9a
|
7
|
+
data.tar.gz: fd3149735267ffa8733867043d4777a6fae340fe8a246d430a2170d2712ef2096e6927b7f5cf01f5bd3b393999d1ff5b6fe548e0e0033d42c95a7c8f583b3aef
|
data/Gemfile.lock
CHANGED
data/lib/sugester.rb
CHANGED
@@ -4,11 +4,18 @@ require 'digest'
|
|
4
4
|
|
5
5
|
module Sugester
|
6
6
|
|
7
|
-
VERSION = "0.5.
|
7
|
+
VERSION = "0.5.4"
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def self.puts_warning msg
|
12
|
+
$stderr.puts("WARNING: #{msg}, sugester #{VERSION}")
|
13
|
+
end
|
8
14
|
|
9
15
|
def self.assert(msg, v)
|
10
|
-
|
16
|
+
puts_warning msg unless v
|
11
17
|
end
|
18
|
+
|
12
19
|
def self.instance_assert(variable_name, variable, *klasses)
|
13
20
|
assert(
|
14
21
|
"#{variable_name} must be instance of #{klasses.join(" or ")}",
|
@@ -16,8 +23,14 @@ module Sugester
|
|
16
23
|
)
|
17
24
|
end
|
18
25
|
|
26
|
+
public
|
27
|
+
|
19
28
|
class SugesterQueue
|
20
29
|
|
30
|
+
def self.secret_corrupted_warning
|
31
|
+
Sugester.puts_warning "Secret corrupted. Visit sugester to get valid data."
|
32
|
+
end
|
33
|
+
|
21
34
|
private
|
22
35
|
|
23
36
|
def self.decrypt(msg)
|
@@ -34,28 +47,37 @@ module Sugester
|
|
34
47
|
return crypt
|
35
48
|
end
|
36
49
|
|
37
|
-
def config(property)
|
50
|
+
def config(property, throwable = false)
|
38
51
|
JSON.parse(SugesterQueue.decrypt(@secret)).deep_symbolize_keys[property]
|
39
|
-
rescue
|
40
|
-
|
52
|
+
rescue StandardError => e
|
53
|
+
SugesterQueue.secret_corrupted_warning
|
54
|
+
nil
|
41
55
|
end
|
42
56
|
|
43
57
|
|
44
58
|
def push(kind, client_id, msg)
|
45
59
|
Sugester.assert "unknown kind", MSG_KINDS.include?(kind)
|
46
60
|
Sugester.instance_assert "client_id", client_id, Integer
|
47
|
-
raw_push msg.merge({
|
61
|
+
raw_push msg.merge({
|
62
|
+
client_id: client_id,
|
63
|
+
kind: kind,
|
64
|
+
vsn: VERSION,
|
65
|
+
})
|
48
66
|
end
|
49
67
|
|
50
68
|
def raw_push(msg)
|
51
69
|
#TODO max length
|
52
|
-
@sqs
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
70
|
+
if @sqs
|
71
|
+
@sqs.send_message({
|
72
|
+
queue_url: config(:url),
|
73
|
+
message_body: msg.merge({
|
74
|
+
token: config(:token),
|
75
|
+
prefix: config(:prefix),
|
76
|
+
}).to_json,
|
77
|
+
})
|
78
|
+
else
|
79
|
+
SugesterQueue.secret_corrupted_warning
|
80
|
+
end
|
59
81
|
end
|
60
82
|
|
61
83
|
MSG_KINDS = [:activity, :property, :payment]
|
@@ -63,7 +85,8 @@ module Sugester
|
|
63
85
|
|
64
86
|
def initialize(secret)
|
65
87
|
@secret = secret
|
66
|
-
|
88
|
+
c = config(:config)
|
89
|
+
@sqs = Aws::SQS::Client.new(config(:config)) if c
|
67
90
|
end
|
68
91
|
|
69
92
|
def activity(client_id, name, options = {})
|
@@ -72,16 +95,16 @@ module Sugester
|
|
72
95
|
end
|
73
96
|
|
74
97
|
def property(client_id, options)
|
75
|
-
options.
|
76
|
-
|
77
|
-
|
78
|
-
end
|
98
|
+
#options.enum do |name, value|
|
99
|
+
# Sugester.instance_assert "name", name, String, Symbol
|
100
|
+
# Sugester.instance_assert "value", value, String, Symbol, Numeric, Time, DateTime, Date
|
101
|
+
#end
|
79
102
|
push :property, client_id, {options: options}
|
80
103
|
end
|
81
104
|
|
82
105
|
def payment(client_id, name, price, date_from, date_to)
|
83
|
-
Sugester.instance_assert "date_from", date_from, Time
|
84
|
-
Sugester.instance_assert "date_to", date_to, Time
|
106
|
+
Sugester.instance_assert "date_from", date_from, Time, Date, DateTime
|
107
|
+
Sugester.instance_assert "date_to", date_to, Time, Date, DateTime
|
85
108
|
Sugester.instance_assert "price", price, Numeric
|
86
109
|
Sugester.instance_assert "name", name, String, Symbol
|
87
110
|
|