knuverse-knufactor 0.0.1 → 0.0.2
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6495c6005e362bb072ac482e12e65e230948415
|
4
|
+
data.tar.gz: e2715ef043a98af50920e28a190c3eea25eecd04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ad718408ab62421877b13b2c111f1df17732a3eae75acde1d1ffd5895e4a3737bf24ee3435ad85dee670dd6b935dc09f79752e7d2332e3992c8eb7deb4f34b4
|
7
|
+
data.tar.gz: 13662a52e850d3827f9efab976d72808200f1f1a30cc29bb855e721b1d57ae9e854fb16bf0250ca3fd784c2eb0b9a5fb4a3ec3f030166ab6d83fb8799ab60902
|
data/README.md
CHANGED
@@ -6,6 +6,7 @@ About
|
|
6
6
|
This project is a Ruby SDK that allows developers to create apps that use Knuverse's Knufactor Cloud APIs.
|
7
7
|
|
8
8
|
Documentation for the API can be found [here](https://cloud.knuverse.com/docs/)
|
9
|
+
Full documentation for this SDK can be found [here](http://www.rubydoc.info/gems/knuverse-knufactor/)
|
9
10
|
|
10
11
|
Note that this SDK isn't a direct port of the [Python SDK](https://github.com/KnuVerse/knuverse-sdk-python), though it is based heavily on the work done there. This SDK uses a Object-Oriented pattern, which is likely more familiar to Ruby developers than a collection of functions may be.
|
11
12
|
|
@@ -3,6 +3,31 @@ module KnuVerse
|
|
3
3
|
module Helpers
|
4
4
|
# Simple helper class methods for Resource
|
5
5
|
module ResourceClass
|
6
|
+
# Determine a list of names to use to access a resource entity attribute
|
7
|
+
# @param original_name [String,Symbol] the name of the underlying attribute
|
8
|
+
# @param opts [Hash] property options as defined in a {Resource} subclass
|
9
|
+
# @return [Array<Symbol>] the list of names
|
10
|
+
def determine_getter_names(original_name, opts)
|
11
|
+
names = []
|
12
|
+
names << (opts[:type] == :boolean ? "#{original_name}?" : original_name)
|
13
|
+
if opts[:as]
|
14
|
+
Array(opts[:as]).each do |new_name|
|
15
|
+
names << (opts[:type] == :boolean ? "#{new_name}?" : new_name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
names.map(&:to_sym).uniq
|
19
|
+
end
|
20
|
+
|
21
|
+
# Determine a list of names to use to set a resource entity attribute
|
22
|
+
# @param original_name [String,Symbol] the name of the underlying attribute
|
23
|
+
# @param opts [Hash] property options as defined in a {Resource} subclass
|
24
|
+
# @return [Array<Symbol>] the list of names
|
25
|
+
def determine_setter_names(original_name, opts)
|
26
|
+
names = ["#{original_name}="]
|
27
|
+
names.concat Array(opts[:as]).map { |new_name| "#{new_name}=" } if opts[:as]
|
28
|
+
names.map(&:to_sym).uniq
|
29
|
+
end
|
30
|
+
|
6
31
|
# Produce a more human-readable representation of {#i18n_key}
|
7
32
|
# @note ActiveRecord ActiveModel::Name compatibility method
|
8
33
|
# @return [String]
|
@@ -37,6 +37,8 @@ module KnuVerse
|
|
37
37
|
end
|
38
38
|
|
39
39
|
# Set the URI path for a resource method
|
40
|
+
# @param kind [Symbol] how to refer to the URI
|
41
|
+
# @param uri [String] an API URI to refer to later
|
40
42
|
def self.path(kind, uri)
|
41
43
|
paths[kind.to_sym] = uri
|
42
44
|
end
|
@@ -53,29 +55,35 @@ module KnuVerse
|
|
53
55
|
end
|
54
56
|
|
55
57
|
def self.gen_getter_method(name, opts)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
determine_getter_names(name, opts).each do |method_name|
|
59
|
+
define_method(method_name) do
|
60
|
+
name_as_string = name.to_s
|
61
|
+
reload if @lazy && !@entity.key?(name_as_string)
|
62
|
+
|
63
|
+
# Casting values based on type
|
64
|
+
case opts[:type]
|
65
|
+
when :time
|
66
|
+
if @entity[name_as_string] && !@entity[name_as_string].to_s.empty?
|
67
|
+
Time.parse(@entity[name_as_string].to_s).utc
|
68
|
+
end
|
69
|
+
else
|
70
|
+
@entity[name_as_string]
|
65
71
|
end
|
66
|
-
else
|
67
|
-
@entity[name_as_string]
|
68
72
|
end
|
69
73
|
end
|
70
74
|
end
|
71
75
|
|
72
76
|
def self.gen_setter_method(name, opts)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
determine_setter_names(name, opts).each do |method_name|
|
78
|
+
define_method(method_name) do |value|
|
79
|
+
raise Exceptions::ImmutableModification if immutable?
|
80
|
+
if opts[:validate]
|
81
|
+
raise Exceptions::InvalidArguments unless send("validate_#{name}".to_sym, value)
|
82
|
+
end
|
83
|
+
@entity[name.to_s] = opts[:type] == :time ? Time.parse(value.to_s).utc : value
|
84
|
+
@tainted = true
|
85
|
+
@modified_properties << name.to_sym
|
86
|
+
end
|
79
87
|
end
|
80
88
|
end
|
81
89
|
|
@@ -3,6 +3,7 @@ module KnuVerse
|
|
3
3
|
module Resources
|
4
4
|
# The Knufactor Client resource
|
5
5
|
# rubocop:disable Style/ExtraSpacing
|
6
|
+
# rubocop:disable Metrics/LineLength
|
6
7
|
class Client < Resource
|
7
8
|
property :bypass_expiration
|
8
9
|
property :bypass_limit
|
@@ -19,25 +20,37 @@ module KnuVerse
|
|
19
20
|
property :enroll_deadline_remaining_minutes
|
20
21
|
property :has_password, type: :boolean, read_only: true
|
21
22
|
property :has_pin, type: :boolean, read_only: true
|
22
|
-
property :has_verified, type: :boolean, read_only: true
|
23
|
+
property :has_verified, type: :boolean, read_only: true, as: :verified
|
23
24
|
property :help_tip, read_only: true
|
24
|
-
property :is_disabled, type: :boolean
|
25
|
-
property :is_gauth, type: :boolean, read_only: true
|
26
|
-
property :is_tenant_client, type: :boolean, read_only: true
|
25
|
+
property :is_disabled, type: :boolean, as: :disabled
|
26
|
+
property :is_gauth, type: :boolean, read_only: true, as: :gauth
|
27
|
+
property :is_tenant_client, type: :boolean, read_only: true, as: :tenant_client
|
27
28
|
property :last_verification_date, type: :time, read_only: true
|
28
29
|
property :name, read_only: true
|
29
30
|
property :notification, read_only: true
|
30
31
|
property :password, write_only: true
|
31
|
-
property :password_lock, type: :boolean
|
32
|
+
property :password_lock, type: :boolean, as: :password_locked, validate: true
|
32
33
|
property :phone_number_last, read_only: true
|
33
34
|
property :pin_rev, read_only: true
|
34
35
|
property :role
|
35
36
|
property :role_rationale
|
36
37
|
property :row_doubling
|
37
38
|
property :state, read_only: true
|
38
|
-
property :verification_lock, type: :boolean
|
39
|
+
property :verification_lock, type: :boolean, as: :verification_locked, validate: true
|
39
40
|
property :verification_speed
|
40
41
|
property :verification_speed_floor, read_only: true
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# Used to validate {#password_lock} on set
|
46
|
+
def validate_password_lock(value)
|
47
|
+
value == false # only `false` is valid
|
48
|
+
end
|
49
|
+
|
50
|
+
# Used to validate {#password_lock} on set
|
51
|
+
def validate_verification_lock(value)
|
52
|
+
value == false # only `false` is valid
|
53
|
+
end
|
41
54
|
end
|
42
55
|
end
|
43
56
|
end
|