ocean-rails 3.4.0 → 3.5.0
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/config/initializers/_zeromq_logger.rb +2 -0
- data/lib/ocean/api.rb +2 -2
- data/lib/ocean/api_remote_resource.rb +17 -4
- data/lib/ocean/ocean_application_controller.rb +2 -0
- data/lib/ocean/version.rb +1 -1
- data/lib/ocean/zeromq_logger.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a20a0b667cf8116ca4b9f5636927ee1e363484b
|
4
|
+
data.tar.gz: 63f9521d2df37e1dfa8aaee5eecbb3f40e3959c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05d47be29854d4388b6299b578911fb901541d408341ccb1f22ef5b3976d012a3c23ba057c797a97ed1251f0b3eed5641aeec7519946cf05b8b358a35494ae7c
|
7
|
+
data.tar.gz: bebf3921bfb685b956a4d2cc865bfbdfa6fcf4299a2854ba418ea9ed94b3ef7172433c01c5dadac554cef3d4b8531c1a8447daf172226cd157d0a4e06fc16411
|
@@ -49,12 +49,14 @@ if Rails.env == 'production' && ENV['NO_ZEROMQ_LOGGING'].blank?
|
|
49
49
|
data[:filter] = Thread.current[:filter] if Thread.current[:filter]
|
50
50
|
data[:token] = Thread.current[:x_api_token] if Thread.current[:x_api_token].present?
|
51
51
|
data[:username] = Thread.current[:username] if Thread.current[:username].present?
|
52
|
+
data[:metadata] = Thread.current[:metadata] if Thread.current[:metadata].present?
|
52
53
|
|
53
54
|
Thread.current[:logdata] = data
|
54
55
|
Thread.current[:filter] = nil
|
55
56
|
Thread.current[:x_api_token] = nil
|
56
57
|
Thread.current[:username] = nil
|
57
58
|
Thread.current[:cache_control] = nil
|
59
|
+
Thread.current[:metadata] = nil
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
data/lib/ocean/api.rb
CHANGED
@@ -155,8 +155,8 @@ class Api
|
|
155
155
|
#
|
156
156
|
# The backoff time is increased after each wait period by the product of itself and
|
157
157
|
# backoff_rate. The backoff time is capped by backoff_max. The default time and rate
|
158
|
-
# settings will generate the progression 1, 1.9, 3.61, 6.859, 13.0321, 24.76099,
|
159
|
-
# To disable waiting between retries, set +backoff_time+ to zero.
|
158
|
+
# settings will generate the progression 1, 1.9, 3.61, 6.859, 13.0321, 24.76099, 30, 30,
|
159
|
+
# 30, etc. To disable waiting between retries entirely, set +backoff_time+ to zero.
|
160
160
|
#
|
161
161
|
def self.request(url, http_method, args: nil, headers: {}, body: nil,
|
162
162
|
credentials: nil,
|
@@ -4,7 +4,6 @@ class Api
|
|
4
4
|
# This class represents an Ocean resource accessed by a URI.
|
5
5
|
#
|
6
6
|
# The resource is read lazily. Retries and back off properties are available.
|
7
|
-
# Conditional GETs are used whenever possible.
|
8
7
|
#
|
9
8
|
# thing = Api::RemoteResource.new("http://api.example.com/things/1")
|
10
9
|
# thing.present? => false
|
@@ -53,8 +52,8 @@ class Api
|
|
53
52
|
#
|
54
53
|
# If get or get! retrieve an Ocean collection, they will return an array of RemoteResources.
|
55
54
|
#
|
56
|
-
#
|
57
|
-
#
|
55
|
+
# +thing.get!+ returns the RemoteResource if successful. If not, raises an exception.
|
56
|
+
# +thing.get+ does the same, but always returns the RemoteResource. The remote resource
|
58
57
|
# can be examined to see its status.
|
59
58
|
#
|
60
59
|
# Exceptions:
|
@@ -76,7 +75,21 @@ class Api
|
|
76
75
|
# }
|
77
76
|
#
|
78
77
|
# The above is a Thing resource, wrapped with its type. Attributes should appear in the inner
|
79
|
-
# hash, which must have at least a _links hyperlink attribute with a href and a content type.
|
78
|
+
# hash, which must have at least a +_links+ hyperlink attribute with a href and a content type.
|
79
|
+
#
|
80
|
+
# To refresh a resource using a conditional GET:
|
81
|
+
#
|
82
|
+
# +thing.refresh+
|
83
|
+
# +thing.refresh!+
|
84
|
+
#
|
85
|
+
# NB: this class can also be used to fetch any JSON data. E.g.:
|
86
|
+
#
|
87
|
+
# Api::RemoteResource.get("http://example.com/anything").raw
|
88
|
+
#
|
89
|
+
# +#raw+ will return any raw data received, even if it wasn't recognised as an Ocean resource
|
90
|
+
# and +JsonIsNoResource+ was raised. The +.get+ will suppress any exceptions. If +#raw+ returns
|
91
|
+
# +nil+, you can always chack +#status+, +#status_message+, and/or +#headers+ to determine what
|
92
|
+
# went wrong. After fetching non-resource data, +#present?+ will always be false.
|
80
93
|
#
|
81
94
|
class RemoteResource
|
82
95
|
|
@@ -31,6 +31,8 @@ module OceanApplicationController
|
|
31
31
|
return true if ENV['NO_OCEAN_AUTH']
|
32
32
|
@x_api_token = request.headers['X-API-Token']
|
33
33
|
Thread.current[:x_api_token] = @x_api_token
|
34
|
+
@x_metadata = request.headers['X-Metadata']
|
35
|
+
Thread.current[:metadata] = @x_metadata
|
34
36
|
return true if @x_api_token.present?
|
35
37
|
logger.info "X-API-Token missing"
|
36
38
|
render_api_error 400, "X-API-Token missing"
|
data/lib/ocean/version.rb
CHANGED
data/lib/ocean/zeromq_logger.rb
CHANGED
@@ -84,6 +84,7 @@ class ZeromqLogger
|
|
84
84
|
data[:username] = Thread.current[:username] if Thread.current[:username].present?
|
85
85
|
data[:msg] = msg if msg.is_a?(String)
|
86
86
|
data[:timestamp] = (Time.now.utc.to_f * 1000).to_i unless data[:timestamp]
|
87
|
+
data[:metadata] = Thread.current[:metadata] if Thread.current[:metadata].present?
|
87
88
|
data = data.merge msg if msg.is_a?(Hash)
|
88
89
|
@logger.log data
|
89
90
|
true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ocean-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Bengtson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|