selfsdk 0.0.193 → 0.0.196
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/lib/chat/file_object.rb +2 -1
- data/lib/messages/fact.rb +3 -6
- data/lib/messages/fact_response.rb +1 -1
- data/lib/messaging.rb +3 -2
- data/lib/services/chat.rb +4 -4
- data/lib/services/facts.rb +52 -47
- data/lib/sources.rb +87 -75
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 19017fa46da285bdfa8c3a36adca6321fa3f6f1b84eccb34d7949761f87736a5
|
|
4
|
+
data.tar.gz: 4e15f24fd771ea496cf3f5e00d7a29e7cef88eb701d9228a217c5d9533f71c70
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4648c3554ce576e4dcdf0198b4fa7fabf0afe43d93f1406cd02a618501d9d024e0309bd5446c6a12ec277467bec2d8ca10da9fd9dbbbb4e2958979a28cf9017f
|
|
7
|
+
data.tar.gz: 74938c4b8b9f4361af474cbd87082ae2d335c1585ed9783a1b03c41fc93aa7a3a7c68f885f6b942ff6aa40b3fd4f88858ef3c98ec281aa17c9f33d6fbc62ba8c
|
data/lib/chat/file_object.rb
CHANGED
data/lib/messages/fact.rb
CHANGED
|
@@ -14,14 +14,11 @@ module SelfSDK
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def parse(fact)
|
|
17
|
-
@name =
|
|
18
|
-
|
|
19
|
-
@operator = ""
|
|
20
|
-
@operator = SelfSDK::operator(fact[:operator]) if fact[:operator]
|
|
21
|
-
|
|
17
|
+
@name = @messaging.source.normalize_fact_name! fact[:fact]
|
|
18
|
+
@operator = @messaging.source.normalize_operator!(fact[:operator])
|
|
22
19
|
@sources = []
|
|
23
20
|
fact[:sources]&.each do |s|
|
|
24
|
-
@sources <<
|
|
21
|
+
@sources << @messaging.source.normalize_source!(s)
|
|
25
22
|
end
|
|
26
23
|
|
|
27
24
|
@expected_value = fact[:expected_value] || ""
|
data/lib/messaging.rb
CHANGED
|
@@ -17,7 +17,7 @@ module SelfSDK
|
|
|
17
17
|
DEFAULT_STORAGE_DIR="./.self_storage"
|
|
18
18
|
ON_DEMAND_CLOSE_CODE=3999
|
|
19
19
|
|
|
20
|
-
attr_accessor :client, :jwt, :device_id, :ack_timeout, :timeout, :type_observer, :uuid_observer, :encryption_client
|
|
20
|
+
attr_accessor :client, :jwt, :device_id, :ack_timeout, :timeout, :type_observer, :uuid_observer, :encryption_client, :source
|
|
21
21
|
|
|
22
22
|
# RestClient initializer
|
|
23
23
|
#
|
|
@@ -47,6 +47,7 @@ module SelfSDK
|
|
|
47
47
|
FileUtils.mkdir_p @storage_dir unless File.exist? @storage_dir
|
|
48
48
|
@offset_file = "#{@storage_dir}/#{@jwt.id}:#{@device_id}.offset"
|
|
49
49
|
@offset = read_offset
|
|
50
|
+
@source = SelfSDK::Sources.new("#{__dir__}/sources.json")
|
|
50
51
|
migrate_old_storage_format
|
|
51
52
|
|
|
52
53
|
unless options.include? :no_crypto
|
|
@@ -283,7 +284,7 @@ module SelfSDK
|
|
|
283
284
|
end
|
|
284
285
|
|
|
285
286
|
def subscribe(type, &block)
|
|
286
|
-
type =
|
|
287
|
+
type = @source.message_type(type) if type.is_a? Symbol
|
|
287
288
|
@type_observer[type] = { block: block }
|
|
288
289
|
end
|
|
289
290
|
|
data/lib/services/chat.rb
CHANGED
|
@@ -15,7 +15,7 @@ module SelfSDK
|
|
|
15
15
|
@messaging = messaging
|
|
16
16
|
@client = client
|
|
17
17
|
@app_id = @messaging.client.client.jwt.id
|
|
18
|
-
@
|
|
18
|
+
@jwt = @messaging.client.client.jwt
|
|
19
19
|
@self_url = @messaging.client.client.self_url
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -34,7 +34,7 @@ module SelfSDK
|
|
|
34
34
|
payload[:rid] = opts[:rid] if opts.key? :rid
|
|
35
35
|
payload[:objects] = opts[:objects] if opts.key? :objects
|
|
36
36
|
|
|
37
|
-
m = SelfSDK::Chat::Message.new(self, recipients, payload, @auth_token, @self_url)
|
|
37
|
+
m = SelfSDK::Chat::Message.new(self, recipients, payload, @jwt.auth_token, @self_url)
|
|
38
38
|
_req = send(m.recipients, m.payload)
|
|
39
39
|
|
|
40
40
|
m
|
|
@@ -43,7 +43,7 @@ module SelfSDK
|
|
|
43
43
|
# Subscribes to an incoming chat message
|
|
44
44
|
def on_message(opts = {}, &block)
|
|
45
45
|
@messaging.subscribe :chat_message do |msg|
|
|
46
|
-
cm = SelfSDK::Chat::Message.new(self, msg.payload[:aud], msg.payload, @auth_token, @self_url)
|
|
46
|
+
cm = SelfSDK::Chat::Message.new(self, msg.payload[:aud], msg.payload, @jwt.auth_token, @self_url)
|
|
47
47
|
|
|
48
48
|
cm.mark_as_delivered unless opts[:mark_as_delivered] == false
|
|
49
49
|
cm.mark_as_read if opts[:mark_as_read] == true
|
|
@@ -128,7 +128,7 @@ module SelfSDK
|
|
|
128
128
|
members: members }
|
|
129
129
|
|
|
130
130
|
if opts.key? :data
|
|
131
|
-
obj = SelfSDK::Chat::FileObject.new(@auth_token, @self_url)
|
|
131
|
+
obj = SelfSDK::Chat::FileObject.new(@jwt.auth_token, @self_url)
|
|
132
132
|
obj_payload = obj.build_from_data("", opts[:data], opts[:mime]).to_payload
|
|
133
133
|
obj_payload.delete(:name)
|
|
134
134
|
payload.merge! obj_payload
|
data/lib/services/facts.rb
CHANGED
|
@@ -139,13 +139,13 @@ module SelfSDK
|
|
|
139
139
|
fs = []
|
|
140
140
|
facts.each do |f|
|
|
141
141
|
fact = if f.is_a?(Hash)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
f
|
|
143
|
+
else
|
|
144
|
+
{ fact: f }
|
|
145
|
+
end
|
|
146
146
|
# validate_fact!(fact)
|
|
147
147
|
fs << fact
|
|
148
|
-
end
|
|
148
|
+
end
|
|
149
149
|
fs
|
|
150
150
|
end
|
|
151
151
|
|
|
@@ -156,67 +156,72 @@ module SelfSDK
|
|
|
156
156
|
raise 'provided fact does not specify a name' if f[:fact].empty?
|
|
157
157
|
return unless f.has_key? :sources
|
|
158
158
|
|
|
159
|
-
valid_sources = [
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
159
|
+
valid_sources = [SOURCE_USER_SPECIFIED,
|
|
160
|
+
SOURCE_PASSPORT,
|
|
161
|
+
SOURCE_DRIVING_LICENSE,
|
|
162
|
+
SOURCE_IDENTITY_CARD,
|
|
163
|
+
SOURCE_TWITTER,
|
|
164
|
+
SOURCE_LINKEDIN,
|
|
165
|
+
SOURCE_FACEBOK]
|
|
166
|
+
fact_for_passport = [FACT_DOCUMENT_NUMBER,
|
|
167
|
+
FACT_SURNAME,
|
|
168
|
+
FACT_GIVEN_NAMES,
|
|
169
|
+
FACT_DATE_OF_BIRTH,
|
|
170
|
+
FACT_DATE_OF_EXPIRATION,
|
|
171
|
+
FACT_SEX,
|
|
172
|
+
FACT_NATIONALITY,
|
|
173
|
+
FACT_COUNTRY_OF_ISSUANCE]
|
|
174
|
+
|
|
175
|
+
facts_for_dl = [FACT_DOCUMENT_NUMBER,
|
|
176
|
+
FACT_SURNAME,
|
|
177
|
+
FACT_GIVEN_NAMES,
|
|
178
|
+
FACT_DATE_OF_BIRTH,
|
|
179
|
+
FACT_DATE_OF_ISSUANCE,
|
|
180
|
+
FACT_DATE_OF_EXPIRATION,
|
|
181
|
+
FACT_ADDRESS,
|
|
182
|
+
FACT_ISSUING_AUTHORITY,
|
|
183
|
+
FACT_PLACE_OF_BIRTH,
|
|
184
|
+
FACT_COUNTRY_OF_ISSUANCE]
|
|
185
|
+
|
|
186
|
+
facts_for_user = [FACT_DOCUMENT_NUMBER,
|
|
187
|
+
FACT_DISPLAY_NAME,
|
|
188
|
+
FACT_EMAIL,
|
|
189
|
+
FACT_PHONE]
|
|
190
|
+
|
|
191
|
+
facts_for_twitter = [FACT_ACCOUNT_ID, FACT_NICKNAME]
|
|
192
|
+
facts_for_linkedin = [FACT_ACCOUNT_ID, FACT_NICKNAME]
|
|
193
|
+
facts_for_facebook = [FACT_ACCOUNT_ID, FACT_NICKNAME]
|
|
194
|
+
facts_for_live = [FACT_SELFIE]
|
|
195
|
+
|
|
195
196
|
f[:sources].each do |s|
|
|
196
197
|
raise errInvalidSource unless valid_sources.include? s.to_s
|
|
197
198
|
|
|
198
199
|
if s.to_s == SOURCE_PASSPORT || s.to_s == SOURCE_IDENTITY_CARD
|
|
199
|
-
raise errInvalidFactToSource unless
|
|
200
|
+
raise errInvalidFactToSource unless fact_for_passport.include? f[:fact]
|
|
200
201
|
end
|
|
201
202
|
|
|
202
203
|
if s.to_s == SOURCE_DRIVING_LICENSE
|
|
203
|
-
raise errInvalidFactToSource unless
|
|
204
|
+
raise errInvalidFactToSource unless facts_for_dl.include? f[:fact]
|
|
204
205
|
end
|
|
205
206
|
|
|
206
207
|
if s.to_s == SOURCE_USER_SPECIFIED
|
|
207
|
-
raise errInvalidFactToSource unless
|
|
208
|
+
raise errInvalidFactToSource unless facts_for_user.include? f[:fact].to_s
|
|
208
209
|
end
|
|
209
210
|
|
|
210
211
|
if s.to_s == SOURCE_TWITTER
|
|
211
|
-
raise errInvalidFactToSource unless
|
|
212
|
+
raise errInvalidFactToSource unless facts_for_twitter.include? f[:fact].to_s
|
|
212
213
|
end
|
|
213
214
|
|
|
214
215
|
if s.to_s == SOURCE_LINKEDIN
|
|
215
|
-
raise errInvalidFactToSource unless
|
|
216
|
+
raise errInvalidFactToSource unless facts_for_linkedin.include? f[:fact].to_s
|
|
216
217
|
end
|
|
217
218
|
|
|
218
219
|
if s.to_s == SOURCE_FACEBOOK
|
|
219
|
-
raise errInvalidFactToSource unless
|
|
220
|
+
raise errInvalidFactToSource unless facts_for_facebook.include? f[:fact].to_s
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
if s.to_s == SOURCE_LIVE
|
|
224
|
+
raise errInvalidFactToSource unless facts_for_live.include? f[:fact].to_s
|
|
220
225
|
end
|
|
221
226
|
end
|
|
222
227
|
end
|
data/lib/sources.rb
CHANGED
|
@@ -2,38 +2,95 @@
|
|
|
2
2
|
|
|
3
3
|
# frozen_string_literal: true
|
|
4
4
|
|
|
5
|
+
require "json"
|
|
5
6
|
module SelfSDK
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
7
|
+
class Sources
|
|
8
|
+
def initialize(sources_file)
|
|
9
|
+
data = JSON.parse('{
|
|
10
|
+
"sources": {
|
|
11
|
+
"user_specified": [
|
|
12
|
+
"document_number",
|
|
13
|
+
"display_name",
|
|
14
|
+
"email_address",
|
|
15
|
+
"phone_number"
|
|
16
|
+
],
|
|
17
|
+
"passport": [
|
|
18
|
+
"document_number",
|
|
19
|
+
"surname",
|
|
20
|
+
"given_names",
|
|
21
|
+
"date_of_birth",
|
|
22
|
+
"date_of_expiration",
|
|
23
|
+
"sex",
|
|
24
|
+
"nationality",
|
|
25
|
+
"country_of_issuance"
|
|
26
|
+
],
|
|
27
|
+
"driving_license": [
|
|
28
|
+
"document_number",
|
|
29
|
+
"surname",
|
|
30
|
+
"given_names",
|
|
31
|
+
"date_of_birth",
|
|
32
|
+
"date_of_issuance",
|
|
33
|
+
"date_of_expiration",
|
|
34
|
+
"address",
|
|
35
|
+
"issuing_authority",
|
|
36
|
+
"place_of_birth"
|
|
37
|
+
],
|
|
38
|
+
"identity_card": [
|
|
39
|
+
"document_number",
|
|
40
|
+
"surname",
|
|
41
|
+
"given_names",
|
|
42
|
+
"date_of_birth",
|
|
43
|
+
"date_of_expiration",
|
|
44
|
+
"sex",
|
|
45
|
+
"nationality",
|
|
46
|
+
"country_of_issuance"
|
|
47
|
+
],
|
|
48
|
+
"twitter": [
|
|
49
|
+
"account_id",
|
|
50
|
+
"nickname"
|
|
51
|
+
],
|
|
52
|
+
"linkedin": [
|
|
53
|
+
"account_id",
|
|
54
|
+
"nickname"
|
|
55
|
+
],
|
|
56
|
+
"facebook": [
|
|
57
|
+
"account_id",
|
|
58
|
+
"nickname"
|
|
59
|
+
],
|
|
60
|
+
"live": [
|
|
61
|
+
"selfie_verification"
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
}')
|
|
65
|
+
@sources = data["sources"]
|
|
66
|
+
@facts = []
|
|
67
|
+
@sources.each do |source, facts|
|
|
68
|
+
@facts.push(*facts)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def normalize_fact_name!(fact)
|
|
73
|
+
fact = fact.to_s
|
|
74
|
+
raise "invalid fact '#{fact}'" unless @facts.include?(fact)
|
|
75
|
+
fact
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def validate_source!(source)
|
|
79
|
+
raise "invalid source '#{source}'" unless @sources.keys.include?(source.to_s)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def normalize_operator!(input)
|
|
83
|
+
return "" unless input
|
|
27
84
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
85
|
+
operators = { equals: '==',
|
|
86
|
+
different: '!=',
|
|
87
|
+
great_or_equal_than: '>=',
|
|
88
|
+
less_or_equal: '<=',
|
|
89
|
+
great_than: '>',
|
|
90
|
+
less_than: '<' }
|
|
91
|
+
get(operators, input, "operator")
|
|
92
|
+
end
|
|
35
93
|
|
|
36
|
-
class << self
|
|
37
94
|
def message_type(s)
|
|
38
95
|
types = { authentication_request: SelfSDK::Messages::AuthenticationReq::MSG_TYPE,
|
|
39
96
|
authentication_response: SelfSDK::Messages::AuthenticationResp::MSG_TYPE,
|
|
@@ -51,51 +108,7 @@ module SelfSDK
|
|
|
51
108
|
return types[s]
|
|
52
109
|
end
|
|
53
110
|
|
|
54
|
-
|
|
55
|
-
operators = { equals: '==',
|
|
56
|
-
different: '!=',
|
|
57
|
-
great_or_equal_than: '>=',
|
|
58
|
-
less_or_equal: '<=',
|
|
59
|
-
great_than: '>',
|
|
60
|
-
less_than: '<' }
|
|
61
|
-
get(operators, input, "operator")
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def fact_name(input)
|
|
65
|
-
facts = { email_address: FACT_EMAIL,
|
|
66
|
-
phone_number: FACT_PHONE,
|
|
67
|
-
display_name: FACT_DISPLAY_NAME,
|
|
68
|
-
document_number: FACT_DOCUMENT_NUMBER,
|
|
69
|
-
given_names: FACT_GIVEN_NAMES,
|
|
70
|
-
surname: FACT_SURNAME,
|
|
71
|
-
sex: FACT_SEX,
|
|
72
|
-
issuing_authority: FACT_ISSUING_AUTHORITY,
|
|
73
|
-
nationality: FACT_NATIONALITY,
|
|
74
|
-
address: FACT_ADDRESS,
|
|
75
|
-
place_of_birth: FACT_PLACE_OF_BIRTH,
|
|
76
|
-
date_of_birth: FACT_DATE_OF_BIRTH,
|
|
77
|
-
date_of_issuance: FACT_DATE_OF_ISSUANCE,
|
|
78
|
-
date_of_expiration: FACT_DATE_OF_EXPIRATION,
|
|
79
|
-
valid_from: FACT_VALID_FROM,
|
|
80
|
-
valid_to: FACT_VALID_TO,
|
|
81
|
-
categories: FACT_CATEGORIES,
|
|
82
|
-
sort_code: FACT_SORT_CODE,
|
|
83
|
-
country_of_issuance: FACT_COUNTRY_OF_ISSUANCE,
|
|
84
|
-
account_id: FACT_ACCOUNT_ID,
|
|
85
|
-
nickname: FACT_NICKNAME }
|
|
86
|
-
get(facts, input, "fact")
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def source(input)
|
|
90
|
-
sources = { user_specified: SOURCE_USER_SPECIFIED,
|
|
91
|
-
passport: SOURCE_PASSPORT,
|
|
92
|
-
driving_license: SOURCE_DRIVING_LICENSE,
|
|
93
|
-
identity_card: SOURCE_IDENTITY_CARD,
|
|
94
|
-
twitter: SOURCE_TWITTER,
|
|
95
|
-
linkedin: SOURCE_LINKEDIN,
|
|
96
|
-
facebook: SOURCE_FACEBOOK }
|
|
97
|
-
get(sources, input, "source")
|
|
98
|
-
end
|
|
111
|
+
private
|
|
99
112
|
|
|
100
113
|
def get(options, input, option_type)
|
|
101
114
|
if input.is_a? Symbol
|
|
@@ -105,6 +118,5 @@ module SelfSDK
|
|
|
105
118
|
raise "invalid #{option_type} '#{input}'" unless options.values.include? input
|
|
106
119
|
input
|
|
107
120
|
end
|
|
108
|
-
|
|
109
121
|
end
|
|
110
122
|
end
|