ocean-rails 3.4.0 → 3.5.0

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: e35b6a26426816dec30071f7fd2c87272e4530d7
4
- data.tar.gz: ac1e42b243d0985e4aba91f2b2939ec0e3b3d0c4
3
+ metadata.gz: 9a20a0b667cf8116ca4b9f5636927ee1e363484b
4
+ data.tar.gz: 63f9521d2df37e1dfa8aaee5eecbb3f40e3959c6
5
5
  SHA512:
6
- metadata.gz: 00265cc72834b55c5c5c9e4e4d2f672dddd14ebbbd20baf65c9d28d2898138054d7fd9f08a36c5eacfdc025a04cda1f83373ffe0cda7306fd195cd6db8dde6f1
7
- data.tar.gz: 191b0d669a58c0efcac288da5a6605f6d97fcbc62d89a650333f4083fec9da7938fe2b037412a1b20a28f4d2c03ec55582064ceb3855ac820ae71e118f064b9f
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
 
@@ -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, etc.
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
- # <tt>thing.get!</tt> returns the Api::RemoteResource if successful. If not, raises an exception.
57
- # <tt>thing.get</tt> does the same, but always returns the Api::RemoteResource. The remote resource
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"
@@ -1,3 +1,3 @@
1
1
  module Ocean
2
- VERSION = "3.4.0"
2
+ VERSION = "3.5.0"
3
3
  end
@@ -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.0
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-27 00:00:00.000000000 Z
11
+ date: 2014-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus