fera-api 0.1.3 → 0.2.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/Gemfile +3 -5
- data/Gemfile.lock +31 -15
- data/lib/fera/api/version.rb +1 -1
- data/lib/fera/api.rb +13 -15
- data/lib/fera/models/base.rb +47 -1
- data/lib/fera/models/concerns/has_timestamp_action.rb +52 -0
- data/lib/fera/models/order.rb +3 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 350de7865e484558dd53c2c4e4635b679baf32d9fbf11619e19995e2add14eae
|
|
4
|
+
data.tar.gz: c758c1e080ef27a9ece0f88edb515f9ece137b1158986a216f98444ea38f3e7c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b833c34953d53e50618cdbaebfd217b6532dd6adbe4f0947ac26a00e95ddf8483ea09f6abb557b91f06c014411f264cc7fecb8d4c9d64cfd757c3161f1291d0b
|
|
7
|
+
data.tar.gz: 8c00efeddbdf2280b524f0ae536e5d4c76814dda70f7b0bda5d47abe62029e4ad2bd3b3dd2ae4873f04f9d8a692fb1509e36fcae3b9ab4ece486eeb31d740bcd
|
data/Gemfile
CHANGED
|
@@ -6,12 +6,10 @@ source "https://rubygems.org"
|
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
8
|
group :development, :test do
|
|
9
|
-
gem "pry"
|
|
10
|
-
gem "pry-byebug"
|
|
11
9
|
gem "pry-rails"
|
|
12
10
|
gem "pry-remote"
|
|
13
11
|
gem "pry-rescue"
|
|
14
|
-
gem "
|
|
15
|
-
gem "rubocop"
|
|
16
|
-
gem "
|
|
12
|
+
gem "rubocop", "~> 1.35"
|
|
13
|
+
gem "rubocop-rspec", "~> 2.12"
|
|
14
|
+
gem "spellr", "~> 0.11"
|
|
17
15
|
end
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
fera-api (0.
|
|
4
|
+
fera-api (0.2.2)
|
|
5
5
|
activemodel (>= 4)
|
|
6
6
|
activeresource (>= 6)
|
|
7
7
|
activesupport (>= 4.0)
|
|
@@ -11,8 +11,8 @@ PATH
|
|
|
11
11
|
GEM
|
|
12
12
|
remote: https://rubygems.org/
|
|
13
13
|
specs:
|
|
14
|
-
activemodel (7.0.
|
|
15
|
-
activesupport (= 7.0.
|
|
14
|
+
activemodel (7.0.4)
|
|
15
|
+
activesupport (= 7.0.4)
|
|
16
16
|
activemodel-serializers-xml (1.0.2)
|
|
17
17
|
activemodel (> 5.x)
|
|
18
18
|
activesupport (> 5.x)
|
|
@@ -21,7 +21,7 @@ GEM
|
|
|
21
21
|
activemodel (>= 6.0)
|
|
22
22
|
activemodel-serializers-xml (~> 1.0)
|
|
23
23
|
activesupport (>= 6.0)
|
|
24
|
-
activesupport (7.0.
|
|
24
|
+
activesupport (7.0.4)
|
|
25
25
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
26
26
|
i18n (>= 1.6, < 2)
|
|
27
27
|
minitest (>= 5.1)
|
|
@@ -30,7 +30,7 @@ GEM
|
|
|
30
30
|
public_suffix (>= 2.0.2, < 5.0)
|
|
31
31
|
aes_key_wrap (1.1.0)
|
|
32
32
|
ast (2.4.2)
|
|
33
|
-
bindata (2.4.
|
|
33
|
+
bindata (2.4.14)
|
|
34
34
|
binding_of_caller (1.0.0)
|
|
35
35
|
debug_inspector (>= 0.0.1)
|
|
36
36
|
builder (3.2.4)
|
|
@@ -41,17 +41,25 @@ GEM
|
|
|
41
41
|
rexml
|
|
42
42
|
debug_inspector (1.1.0)
|
|
43
43
|
diff-lcs (1.5.0)
|
|
44
|
+
faraday (2.5.2)
|
|
45
|
+
faraday-net_http (>= 2.0, < 3.1)
|
|
46
|
+
ruby2_keywords (>= 0.0.4)
|
|
47
|
+
faraday-follow_redirects (0.3.0)
|
|
48
|
+
faraday (>= 1, < 3)
|
|
49
|
+
faraday-net_http (3.0.0)
|
|
50
|
+
fast_ignore (0.17.4)
|
|
44
51
|
hashdiff (1.0.1)
|
|
45
|
-
httpclient (2.8.3)
|
|
46
52
|
i18n (1.12.0)
|
|
47
53
|
concurrent-ruby (~> 1.0)
|
|
48
54
|
interception (0.5)
|
|
55
|
+
jaro_winkler (1.5.4)
|
|
49
56
|
json (2.6.2)
|
|
50
|
-
json-jwt (1.
|
|
57
|
+
json-jwt (1.16.1)
|
|
51
58
|
activesupport (>= 4.2)
|
|
52
59
|
aes_key_wrap
|
|
53
60
|
bindata
|
|
54
|
-
|
|
61
|
+
faraday (~> 2.0)
|
|
62
|
+
faraday-follow_redirects
|
|
55
63
|
method_source (1.0.0)
|
|
56
64
|
minitest (5.16.3)
|
|
57
65
|
parallel (1.22.1)
|
|
@@ -92,7 +100,7 @@ GEM
|
|
|
92
100
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
93
101
|
rspec-support (~> 3.11.0)
|
|
94
102
|
rspec-support (3.11.0)
|
|
95
|
-
rubocop (1.35.
|
|
103
|
+
rubocop (1.35.1)
|
|
96
104
|
json (~> 2.3)
|
|
97
105
|
parallel (~> 1.10)
|
|
98
106
|
parser (>= 3.1.2.1)
|
|
@@ -104,22 +112,29 @@ GEM
|
|
|
104
112
|
unicode-display_width (>= 1.4.0, < 3.0)
|
|
105
113
|
rubocop-ast (1.21.0)
|
|
106
114
|
parser (>= 3.1.1.0)
|
|
107
|
-
rubocop-rspec (2.
|
|
108
|
-
rubocop (~> 1.
|
|
115
|
+
rubocop-rspec (2.13.1)
|
|
116
|
+
rubocop (~> 1.33)
|
|
109
117
|
ruby-progressbar (1.11.0)
|
|
118
|
+
ruby2_keywords (0.0.5)
|
|
110
119
|
slop (3.6.0)
|
|
120
|
+
spellr (0.11.0)
|
|
121
|
+
fast_ignore (>= 0.11.0)
|
|
122
|
+
jaro_winkler
|
|
123
|
+
parallel (~> 1.0)
|
|
111
124
|
to_bool (2.0.0)
|
|
112
125
|
tzinfo (2.0.5)
|
|
113
126
|
concurrent-ruby (~> 1.0)
|
|
114
|
-
unicode-display_width (2.
|
|
127
|
+
unicode-display_width (2.3.0)
|
|
115
128
|
webmock (3.18.0)
|
|
116
129
|
addressable (>= 2.8.0)
|
|
117
130
|
crack (>= 0.3.2)
|
|
118
131
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
119
132
|
|
|
120
133
|
PLATFORMS
|
|
134
|
+
ruby
|
|
121
135
|
x86_64-darwin-18
|
|
122
136
|
x86_64-darwin-20
|
|
137
|
+
x86_64-darwin-21
|
|
123
138
|
x86_64-linux
|
|
124
139
|
|
|
125
140
|
DEPENDENCIES
|
|
@@ -131,10 +146,11 @@ DEPENDENCIES
|
|
|
131
146
|
pry-rescue
|
|
132
147
|
pry-stack_explorer
|
|
133
148
|
rspec (>= 3.0)
|
|
134
|
-
rubocop
|
|
135
|
-
rubocop-rspec
|
|
149
|
+
rubocop (~> 1.35)
|
|
150
|
+
rubocop-rspec (~> 2.12)
|
|
151
|
+
spellr (~> 0.11)
|
|
136
152
|
to_bool
|
|
137
153
|
webmock (>= 3.0)
|
|
138
154
|
|
|
139
155
|
BUNDLED WITH
|
|
140
|
-
2.3.
|
|
156
|
+
2.3.15
|
data/lib/fera/api/version.rb
CHANGED
data/lib/fera/api.rb
CHANGED
|
@@ -19,23 +19,18 @@ module Fera
|
|
|
19
19
|
##
|
|
20
20
|
# @param api_key [String] Public API key, Secret API key or Auth Token (if app)
|
|
21
21
|
# @return [Object, ::Fera::API] Result of the block operation if given, otherwise self
|
|
22
|
-
def self.configure(api_key, api_url: nil, strict_mode: false, debug_mode: false)
|
|
23
|
-
previous_base_site = Base.site
|
|
24
|
-
previous_base_headers = Base.headers
|
|
22
|
+
def self.configure(api_key, api_url: nil, strict_mode: false, debug_mode: false, api_type: nil)
|
|
23
|
+
previous_base_site = Base.site.dup
|
|
24
|
+
previous_base_headers = Base.headers.dup
|
|
25
|
+
previous_debug_mode = @debug_mode
|
|
25
26
|
|
|
26
27
|
api_url ||= 'https://api.fera.ai'
|
|
27
|
-
|
|
28
|
+
api_type ||= api_key.include?('sk_') ? 'private' : 'public'
|
|
29
|
+
Base.site = "#{ api_url.chomp('/') }/v3/#{ api_type }"
|
|
28
30
|
|
|
29
31
|
@debug_mode = debug_mode
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
Base.headers['Secret-Key'] = api_key
|
|
33
|
-
elsif api_key =~ /^pk_/
|
|
34
|
-
Base.headers['Public-Key'] = api_key
|
|
35
|
-
else
|
|
36
|
-
Base.headers['Authorization'] = "Bearer #{ api_key }"
|
|
37
|
-
end
|
|
38
|
-
|
|
33
|
+
Base.api_key = api_key
|
|
39
34
|
Base.headers['Strict-Mode'] = strict_mode if strict_mode
|
|
40
35
|
|
|
41
36
|
if block_given?
|
|
@@ -43,9 +38,8 @@ module Fera
|
|
|
43
38
|
result = yield
|
|
44
39
|
ensure
|
|
45
40
|
Base.site = previous_base_site
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
end
|
|
41
|
+
Base.headers = previous_base_headers
|
|
42
|
+
@debug_mode = previous_debug_mode
|
|
49
43
|
end
|
|
50
44
|
|
|
51
45
|
result
|
|
@@ -56,6 +50,10 @@ module Fera
|
|
|
56
50
|
|
|
57
51
|
def self.debug_mode?; @debug_mode; end
|
|
58
52
|
|
|
53
|
+
##
|
|
54
|
+
# @option client_id [String] Fera app Client ID
|
|
55
|
+
# @option client_secret [String] Fera app Client secret
|
|
56
|
+
# @option auth_token [String] Auth token you wish to revoke access for.
|
|
59
57
|
def self.revoke_token!(client_id:, client_secret:, auth_token:)
|
|
60
58
|
previous_site = Base.site
|
|
61
59
|
|
data/lib/fera/models/base.rb
CHANGED
|
@@ -8,6 +8,52 @@ module Fera
|
|
|
8
8
|
self.site ||= "https://api.fera.ai/v3/private"
|
|
9
9
|
|
|
10
10
|
class << self
|
|
11
|
+
##
|
|
12
|
+
# Sets the header API key for subsequent requests
|
|
13
|
+
# @param api_key [String] Secret Key, Public Key or OAuth Access Token.
|
|
14
|
+
def api_key=(api_key)
|
|
15
|
+
if api_key.blank?
|
|
16
|
+
self.headers.delete('Secret-Key')
|
|
17
|
+
self.headers.delete('Public-Key')
|
|
18
|
+
self.headers.delete('Authorization')
|
|
19
|
+
elsif api_key =~ /^sk_/
|
|
20
|
+
self.headers['Secret-Key'] = api_key
|
|
21
|
+
elsif api_key =~ /^pk_/
|
|
22
|
+
self.headers['Public-Key'] = api_key
|
|
23
|
+
else
|
|
24
|
+
self.headers['Authorization'] = "Bearer #{ api_key }"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
# Sets all the headers for subsequent requests
|
|
30
|
+
# @param new_headers [Hash] Hash of new headers to set
|
|
31
|
+
def headers=(new_headers)
|
|
32
|
+
new_headers.to_h.each do |key, value|
|
|
33
|
+
self.headers[key] = value
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
self.headers.to_h.each do |key, _|
|
|
37
|
+
self.headers.delete(key) unless new_headers.key?(key)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def api_key
|
|
42
|
+
self.headers['Secret-Key'] || self.headers['Public-Key'] || self.headers['Authorization'].to_s.split.last.presence
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
##
|
|
46
|
+
# Returns sorted results.
|
|
47
|
+
# @note This only works from the root, not with scoped results (`Fera::Review.order(created_at: :asc)`)
|
|
48
|
+
# @param sorts [Hash, String, Symbol]
|
|
49
|
+
def order(sorts)
|
|
50
|
+
sorts = { sorts.to_s => :desc.to_s } if sorts.is_a?(String) || sorts.is_a?(Symbol)
|
|
51
|
+
sort_by = sorts.map do |column, direction|
|
|
52
|
+
"#{ column }:#{ direction.presence || :desc }"
|
|
53
|
+
end.join(",")
|
|
54
|
+
where(sort_by: sort_by)
|
|
55
|
+
end
|
|
56
|
+
|
|
11
57
|
def belongs_to(name, options = {})
|
|
12
58
|
@belongs_tos = @belongs_tos.to_h.merge(name => options)
|
|
13
59
|
end
|
|
@@ -285,7 +331,7 @@ module Fera
|
|
|
285
331
|
end
|
|
286
332
|
|
|
287
333
|
#
|
|
288
|
-
# Method missing adapters to define
|
|
334
|
+
# Method missing adapters to define is_* methods for boolean attributes
|
|
289
335
|
#
|
|
290
336
|
|
|
291
337
|
def method_missing(method_name, *args, &block)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
require 'active_support/concern'
|
|
2
|
+
|
|
3
|
+
module Fera
|
|
4
|
+
module HasTimestampAction
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
module ClassMethods
|
|
8
|
+
# define API actions that set a timestamp on the model
|
|
9
|
+
# @example
|
|
10
|
+
# class Order < Fera::Base
|
|
11
|
+
# include HasTimestampAction
|
|
12
|
+
#
|
|
13
|
+
# timestamp_action deliver: :delivered
|
|
14
|
+
# end
|
|
15
|
+
#
|
|
16
|
+
# routes to `PUT /orders/1/deliver`
|
|
17
|
+
#
|
|
18
|
+
# order = Order.find(1)
|
|
19
|
+
# order.delivered? # => false
|
|
20
|
+
# order.deliver!(Time.now)
|
|
21
|
+
# order.delivered? # => true
|
|
22
|
+
# order.delivered_at # => 2018-01-01 00:00:00 UTC
|
|
23
|
+
#
|
|
24
|
+
# or
|
|
25
|
+
#
|
|
26
|
+
# Fera::Order.deliver!(1, Time.now.utc)
|
|
27
|
+
#
|
|
28
|
+
# @param [Array<Symbol>] actions
|
|
29
|
+
def timestamp_action(args)
|
|
30
|
+
args.each do |action, state|
|
|
31
|
+
define_method("#{ action }!") do |at = nil|
|
|
32
|
+
changed_attributes = { "#{ state }_at": at.presence || Time.now.utc }
|
|
33
|
+
|
|
34
|
+
put(action, changed_attributes)
|
|
35
|
+
|
|
36
|
+
load(changed_attributes)
|
|
37
|
+
|
|
38
|
+
true
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
define_method("#{ state }?") do
|
|
42
|
+
send("#{ state }_at?")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
define_singleton_method("#{ action }!") do |id, at = nil|
|
|
46
|
+
find(id).send("#{ action }!", at)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
data/lib/fera/models/order.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fera-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Fera Commerce Inc
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-11-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activemodel
|
|
@@ -201,6 +201,7 @@ files:
|
|
|
201
201
|
- lib/fera/models/concerns/has_many_submissions.rb
|
|
202
202
|
- lib/fera/models/concerns/has_media.rb
|
|
203
203
|
- lib/fera/models/concerns/has_subject.rb
|
|
204
|
+
- lib/fera/models/concerns/has_timestamp_action.rb
|
|
204
205
|
- lib/fera/models/customer.rb
|
|
205
206
|
- lib/fera/models/media.rb
|
|
206
207
|
- lib/fera/models/order.rb
|