evvnt 0.2.0 → 0.2.1
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/README.md +1 -0
- data/bin/setup +17 -1
- data/lib/evvnt/class_template_methods.rb +4 -19
- data/lib/evvnt/path_helpers.rb +32 -56
- data/lib/evvnt/version.rb +1 -1
- 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: 99fdbaa6f393f35458b29e4d3e762f7809cd006f5d88672c98aae7b1456f4dc4
|
4
|
+
data.tar.gz: df9178a3183b63df38d5867a4ab05a5d9c1e78b22c399e7ea25c3b5536acff8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d501b651e0698f4819a9e4f8d991be01a90f33682475ae4af3309aa219e047b0f2d58226f14c2f0b512067162c17b31b4150f07878c7af752cc86f7daf6fce47
|
7
|
+
data.tar.gz: 42eb5835948b69a83d99a1beb74691b334fd0c6132d403e58a7cf6cf150abba8d1cbe279c5c571be43207184e5c34d40c0e0c7410fb95aceb200da18b321346d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -37,6 +37,7 @@ To configure the gem, create an initializer and define the following block:
|
|
37
37
|
``` ruby
|
38
38
|
# config/initializers/evvnt.rb
|
39
39
|
Evvnt.configure do |config|
|
40
|
+
config.environment = Rails.env.production? ? :live : :sandbox
|
40
41
|
# Print out useful logger info to the Rails log
|
41
42
|
config.logger = Rails.logger
|
42
43
|
config.debug = Rails.env.development?
|
data/bin/setup
CHANGED
@@ -1,8 +1,24 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
2
|
set -euo pipefail
|
3
3
|
IFS=$'\n\t'
|
4
|
-
set -vx
|
4
|
+
# set -vx
|
5
5
|
|
6
|
+
# Install local gem dependencies
|
6
7
|
bundle install
|
7
8
|
|
8
9
|
# Do any other automated setup that you need to do here
|
10
|
+
|
11
|
+
# Create .env file if it doesn't already exist...
|
12
|
+
if [ ! -f ./.env ]; then
|
13
|
+
printf "Creating local .env file..."
|
14
|
+
touch .env
|
15
|
+
echo "API_KEY=username" >> .env
|
16
|
+
echo "API_SECRET=secret" >> .env
|
17
|
+
fi
|
18
|
+
printf "
|
19
|
+
# ========
|
20
|
+
# = NOTE =
|
21
|
+
# ========
|
22
|
+
|
23
|
+
Add your own API key and secret to .env if you haven't already done so.
|
24
|
+
"
|
@@ -16,11 +16,7 @@ module Evvnt
|
|
16
16
|
#
|
17
17
|
# Returns {Evvnt::Base} subclass
|
18
18
|
def create(**params)
|
19
|
-
path =
|
20
|
-
nest_path_within_parent(plural_resource_path, params)
|
21
|
-
else
|
22
|
-
plural_resource_path
|
23
|
-
end
|
19
|
+
path = nest_path_within_parent(plural_resource_path, params)
|
24
20
|
api_request(:post, path, params: params)
|
25
21
|
end
|
26
22
|
|
@@ -31,18 +27,7 @@ module Evvnt
|
|
31
27
|
# Returns Array
|
32
28
|
def index(**params)
|
33
29
|
params.stringify_keys!
|
34
|
-
|
35
|
-
path = plural_resource_path.call
|
36
|
-
path.match(PARAM_REGEX) do |segment|
|
37
|
-
value = params.delete(segment.to_s[1..-1])
|
38
|
-
path = path.gsub!(/#{segment}/, value.to_s)
|
39
|
-
end
|
40
|
-
else
|
41
|
-
path = plural_resource_path
|
42
|
-
end
|
43
|
-
if params_include_parent_resource_id?(params)
|
44
|
-
path = nest_path_within_parent(path, params)
|
45
|
-
end
|
30
|
+
path = nest_path_within_parent(plural_resource_path, params)
|
46
31
|
api_request(:get, path, params: params)
|
47
32
|
end
|
48
33
|
|
@@ -56,7 +41,7 @@ module Evvnt
|
|
56
41
|
if record_id.nil? && !singular_resource?
|
57
42
|
raise ArgumentError, "record_id cannot be nil"
|
58
43
|
end
|
59
|
-
path = singular_path_for_record(record_id, params)
|
44
|
+
path = nest_path_within_parent(singular_path_for_record(record_id, params), params)
|
60
45
|
api_request(:get, path, params: params)
|
61
46
|
end
|
62
47
|
|
@@ -70,7 +55,7 @@ module Evvnt
|
|
70
55
|
if record_id.nil? && !singular_resource?
|
71
56
|
raise ArgumentError, "record_id cannot be nil"
|
72
57
|
end
|
73
|
-
path = singular_path_for_record(record_id, params)
|
58
|
+
path = nest_path_within_parent(singular_path_for_record(record_id, params), params)
|
74
59
|
api_request(:put, path, params: params)
|
75
60
|
end
|
76
61
|
|
data/lib/evvnt/path_helpers.rb
CHANGED
@@ -12,23 +12,39 @@ module Evvnt
|
|
12
12
|
@singular_resource == true
|
13
13
|
end
|
14
14
|
|
15
|
+
# The name for this class's corresponding resource on the API.
|
16
|
+
def resource_name
|
17
|
+
@resource_name || default_resource_name
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
15
23
|
# Declare this class as a singular resource
|
16
24
|
#
|
17
25
|
def singular_resource!
|
18
26
|
@singular_resource = true
|
19
|
-
resource_name
|
27
|
+
self.resource_name = name.split("::").last.underscore.singularize
|
20
28
|
end
|
21
29
|
|
22
|
-
|
30
|
+
def resource_name=(value)
|
31
|
+
@resource_name = value
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
# The default name of this resource on the API (e.g. "users")
|
23
37
|
#
|
24
|
-
#
|
38
|
+
# Returns String
|
39
|
+
def default_resource_name
|
40
|
+
@default_resource_name || name.split("::").last.underscore.pluralize
|
41
|
+
end
|
42
|
+
|
43
|
+
# The default path of this resource on the API (e.g. "/users")
|
25
44
|
#
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
else
|
30
|
-
@resource_name || default_resource_name
|
31
|
-
end
|
45
|
+
# Returns String
|
46
|
+
def default_resource_path
|
47
|
+
resource_name
|
32
48
|
end
|
33
49
|
|
34
50
|
# Nest a given resource path within a parent resource.
|
@@ -42,6 +58,7 @@ module Evvnt
|
|
42
58
|
#
|
43
59
|
# Returns String
|
44
60
|
def nest_path_within_parent(path, params)
|
61
|
+
return path unless params_include_parent_resource_id?(params)
|
45
62
|
params.symbolize_keys!
|
46
63
|
parent_resource = parent_resource_name(params)
|
47
64
|
parent_id = params.delete(parent_resource_param(params)).try(:to_s)
|
@@ -52,40 +69,12 @@ module Evvnt
|
|
52
69
|
#
|
53
70
|
# Returns String
|
54
71
|
def singular_resource_path
|
55
|
-
if singular_resource?
|
56
|
-
|
57
|
-
else
|
58
|
-
"#{resource_name}/:id"
|
59
|
-
end
|
72
|
+
return resource_name if singular_resource?
|
73
|
+
"#{resource_name}/:id"
|
60
74
|
end
|
61
75
|
|
62
|
-
|
63
|
-
|
64
|
-
# Returns String
|
65
|
-
def default_resource_name
|
66
|
-
name.split("::").last.underscore.pluralize
|
67
|
-
end
|
68
|
-
|
69
|
-
# The defined path of this resource on the API (e.g. "/users")
|
70
|
-
#
|
71
|
-
# new_path - A String with the new default value for the plural_resource_path
|
72
|
-
# block - A Proc object for defining dynamic resource_paths
|
73
|
-
#
|
74
|
-
# Returns String
|
75
|
-
# Returns Proc
|
76
|
-
def plural_resource_path(new_path = nil, &block)
|
77
|
-
if new_path || block_given?
|
78
|
-
@plural_resource_path = (new_path || block)
|
79
|
-
else
|
80
|
-
@plural_resource_path || default_resource_path
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# The default path of this resource on the API (e.g. "/users")
|
85
|
-
#
|
86
|
-
# Returns String
|
87
|
-
def default_resource_path
|
88
|
-
resource_name
|
76
|
+
def plural_resource_path
|
77
|
+
@plural_resource_path ||= default_resource_path
|
89
78
|
end
|
90
79
|
|
91
80
|
# Template method for fetching _mine_ records from the API.
|
@@ -94,21 +83,8 @@ module Evvnt
|
|
94
83
|
# params - A Hash of parameters to send to the API.
|
95
84
|
#
|
96
85
|
# Returns String
|
97
|
-
def singular_path_for_record(record_id,
|
98
|
-
|
99
|
-
path = singular_resource_path.call
|
100
|
-
path.match(PARAM_REGEX) do |segment|
|
101
|
-
value = params.delete(segment.to_s[1..-1])
|
102
|
-
path = path.gsub!(/#{segment}/, value.to_s)
|
103
|
-
end
|
104
|
-
else
|
105
|
-
path = singular_resource_path
|
106
|
-
end
|
107
|
-
path = path.gsub(/\:id/, record_id.to_s)
|
108
|
-
if params_include_parent_resource_id?(params)
|
109
|
-
path = nest_path_within_parent(path, params)
|
110
|
-
end
|
111
|
-
path
|
86
|
+
def singular_path_for_record(record_id, _params)
|
87
|
+
singular_resource_path.gsub(/\:id/, record_id.to_s)
|
112
88
|
end
|
113
89
|
end
|
114
90
|
end
|
data/lib/evvnt/version.rb
CHANGED