parse-stack 1.5.3 → 1.6.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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/parse-ruby-sdk.png +0 -0
  3. data/Changes.md +25 -1
  4. data/Gemfile.lock +4 -4
  5. data/README.md +37 -31
  6. data/bin/console +3 -0
  7. data/lib/parse/api/all.rb +2 -1
  8. data/lib/parse/api/apps.rb +12 -0
  9. data/lib/parse/api/config.rb +5 -1
  10. data/lib/parse/api/files.rb +1 -0
  11. data/lib/parse/api/hooks.rb +1 -0
  12. data/lib/parse/api/objects.rb +4 -1
  13. data/lib/parse/api/push.rb +1 -0
  14. data/lib/parse/api/{schemas.rb → schema.rb} +7 -0
  15. data/lib/parse/api/server.rb +44 -0
  16. data/lib/parse/api/sessions.rb +1 -0
  17. data/lib/parse/api/users.rb +4 -1
  18. data/lib/parse/client.rb +109 -73
  19. data/lib/parse/client/authentication.rb +2 -1
  20. data/lib/parse/client/batch.rb +9 -1
  21. data/lib/parse/client/body_builder.rb +16 -1
  22. data/lib/parse/client/caching.rb +15 -13
  23. data/lib/parse/client/protocol.rb +27 -15
  24. data/lib/parse/client/response.rb +26 -8
  25. data/lib/parse/model/acl.rb +1 -1
  26. data/lib/parse/model/associations/belongs_to.rb +18 -19
  27. data/lib/parse/model/associations/collection_proxy.rb +6 -0
  28. data/lib/parse/model/associations/has_many.rb +5 -6
  29. data/lib/parse/model/bytes.rb +4 -1
  30. data/lib/parse/model/classes/user.rb +46 -44
  31. data/lib/parse/model/core/actions.rb +508 -460
  32. data/lib/parse/model/core/builder.rb +75 -0
  33. data/lib/parse/model/core/errors.rb +9 -0
  34. data/lib/parse/model/core/fetching.rb +42 -38
  35. data/lib/parse/model/core/properties.rb +46 -27
  36. data/lib/parse/model/core/querying.rb +231 -228
  37. data/lib/parse/model/core/schema.rb +76 -74
  38. data/lib/parse/model/date.rb +10 -2
  39. data/lib/parse/model/file.rb +16 -2
  40. data/lib/parse/model/geopoint.rb +9 -2
  41. data/lib/parse/model/model.rb +38 -7
  42. data/lib/parse/model/object.rb +60 -19
  43. data/lib/parse/model/pointer.rb +22 -1
  44. data/lib/parse/model/push.rb +6 -2
  45. data/lib/parse/query.rb +57 -11
  46. data/lib/parse/query/constraint.rb +5 -2
  47. data/lib/parse/query/constraints.rb +588 -589
  48. data/lib/parse/query/ordering.rb +2 -2
  49. data/lib/parse/stack.rb +1 -0
  50. data/lib/parse/stack/version.rb +1 -1
  51. data/lib/parse/webhooks.rb +30 -29
  52. data/lib/parse/webhooks/payload.rb +181 -168
  53. data/lib/parse/webhooks/registration.rb +1 -1
  54. data/parse-stack.gemspec +9 -9
  55. metadata +9 -12
@@ -6,6 +6,7 @@ module Parse
6
6
  module API
7
7
  # Defines the Session class interface for the Parse REST API
8
8
  module Sessions
9
+ # @!visibility private
9
10
  SESSION_PATH_PREFIX = "sessions"
10
11
 
11
12
  # Fetch a session record for a given session token.
@@ -8,10 +8,13 @@ module Parse
8
8
  module API
9
9
  # Defines the User class interface for the Parse REST API
10
10
  module Users
11
-
11
+ # @!visibility private
12
12
  USER_PATH_PREFIX = "users"
13
+ # @!visibility private
13
14
  LOGOUT_PATH = "logout"
15
+ # @!visibility private
14
16
  LOGIN_PATH = "login"
17
+ # @!visibility private
15
18
  REQUEST_PASSWORD_RESET = "requestPasswordReset"
16
19
 
17
20
  # Fetch a {Parse::User} for a given objectId.
data/lib/parse/client.rb CHANGED
@@ -18,15 +18,24 @@ require_relative "client/caching"
18
18
  require_relative "api/all"
19
19
 
20
20
  module Parse
21
-
22
- class ConnectionError < StandardError; end;
23
- class TimeoutError < StandardError; end;
24
- class ProtocolError < StandardError; end;
25
- class ServerError < StandardError; end;
26
- class ServiceUnavailableError < StandardError; end;
27
- class AuthenticationError < StandardError; end;
28
- class RequestLimitExceededError < StandardError; end;
29
- class InvalidSessionTokenError < StandardError; end;
21
+ class Error < StandardError
22
+ # An error when a general connection occurs.
23
+ class ConnectionError < Error; end;
24
+ # An error when a connection timeout occurs.
25
+ class TimeoutError < Error; end;
26
+ # An error when there is an Parse REST API protocol error.
27
+ class ProtocolError < Error; end;
28
+ # An error when the Parse server returned invalid code.
29
+ class ServerError < Error; end;
30
+ # An error when a Parse server responds with HTTP 500.
31
+ class ServiceUnavailableError < Error; end;
32
+ # An error when the authentication credentials in the request are invalid.
33
+ class AuthenticationError < Error; end;
34
+ # An error when the burst limit has been exceeded.
35
+ class RequestLimitExceededError < Error; end;
36
+ # An error when the session token provided in the request is invalid.
37
+ class InvalidSessionTokenError < Error; end;
38
+ end
30
39
 
31
40
  # Retrieve the App specific Parse configuration parameters. The configuration
32
41
  # for a connection is cached after the first request. Use the bang version to
@@ -86,19 +95,30 @@ module Parse
86
95
  # Faraday, which means it is open to add any additional middleware for
87
96
  # features you'd like to implement.
88
97
  class Client
89
- include Parse::API::Objects
98
+ include Parse::API::Analytics
99
+ include Parse::API::Apps
100
+ include Parse::API::Batch
101
+ include Parse::API::CloudFunctions
90
102
  include Parse::API::Config
91
103
  include Parse::API::Files
92
- include Parse::API::CloudFunctions
93
- include Parse::API::Users
94
- include Parse::API::Sessions
95
104
  include Parse::API::Hooks
96
- include Parse::API::Apps
97
- include Parse::API::Batch
105
+ include Parse::API::Objects
98
106
  include Parse::API::Push
99
107
  include Parse::API::Schema
100
- RETRY_COUNT = 2
101
- RETRY_DELAY = 2 #seconds
108
+ include Parse::API::Server
109
+ include Parse::API::Sessions
110
+ include Parse::API::Users
111
+ # The user agent header key.
112
+ USER_AGENT_HEADER = "User-Agent".freeze
113
+ # The value for the User-Agent header.
114
+ USER_AGENT_VERSION = "Parse-Stack v#{Parse::Stack::VERSION}".freeze
115
+ # The default retry count
116
+ DEFAULT_RETRIES = 2
117
+ # The wait time in seconds between retries
118
+ RETRY_DELAY = 1.5
119
+
120
+ # An error when a general response error occurs when communicating with Parse server.
121
+ class ResponseError < Parse::Error; end;
102
122
 
103
123
  # @!attribute cache
104
124
  # The underlying cache store for caching API requests.
@@ -117,7 +137,11 @@ module Parse
117
137
  # The Parse server url that will be receiving these API requests. By default
118
138
  # this will be {Parse::Protocol::SERVER_URL}.
119
139
  # @return [String]
120
- attr_accessor :cache
140
+ # @!attribute retry_limit
141
+ # The default retry count for the client when a specific request timesout or
142
+ # the service is unavailable. Defaults to {DEFAULT_RETRIES}.
143
+ # @return [String]
144
+ attr_accessor :cache, :retry_limit
121
145
  attr_reader :application_id, :api_key, :master_key, :server_url
122
146
  alias_method :app_id, :application_id
123
147
  # The client can support multiple sessions. The first session created, will be placed
@@ -169,16 +193,13 @@ module Parse
169
193
  # @param opts [Hash] a set of connection options to configure the client.
170
194
  # @option opts [String] :server_url The server url of your Parse Server if you
171
195
  # are not using the hosted Parse service. By default it will use
172
- # PARSE_SERVER_URL environment variable available or fall back to
173
- # https://api.parse.com/1/ if not specified.
174
- # @option opts [String] :app_id The Parse application id. By default it will
175
- # use PARSE_APP_ID environment variable if not specified.
176
- # @option opts [String] :api_key The Parse REST API Key. By default it will
177
- # use PARSE_API_KEY environment variable if not specified.
196
+ # ENV["PARSE_SERVER_URL"] if available, otherwise fallback to {Parse::Protocol::SERVER_URL}.
197
+ # @option opts [String] :app_id The Parse application id. Defaults to
198
+ # ENV['PARSE_APP_ID'] or ENV['PARSE_APPLICATION_ID'].
199
+ # @option opts [String] :api_key The Parse REST API Key. Defaults to ENV['PARSE_REST_API_KEY'].
178
200
  # @option opts [String] :master_key The Parse application master key (optional).
179
201
  # If this key is set, it will be sent on every request sent by the client
180
- # and your models. By default it will use PARSE_MASTER_KEY environment
181
- # variable if not specified.
202
+ # and your models. Defaults to ENV['PARSE_MASTER_KEY'].
182
203
  # @option opts [Boolean] :logging It provides you additional logging information
183
204
  # of requests and responses. If set to the special symbol of *:debug*, it
184
205
  # will provide additional payload data in the log messages. This option affects
@@ -201,6 +222,7 @@ module Parse
201
222
  # cache using the clear_cache! method on your Parse::Client instance.
202
223
  # @option opts [Hash] :faraday You may pass a hash of options that will be
203
224
  # passed to the Faraday constructor.
225
+ # @raise Parse::Error::ConnectionError if the client was not properly configured with required keys or url.
204
226
  # @raise ArgumentError if the cache instance passed to the :cache option is not of Moneta::Transformer.
205
227
  # @see Parse::Middleware::BodyBuilder
206
228
  # @see Parse::Middleware::Caching
@@ -208,13 +230,13 @@ module Parse
208
230
  # @see Parse::Protocol
209
231
  def initialize(opts = {})
210
232
  @server_url = opts[:server_url] || ENV["PARSE_SERVER_URL"] || Parse::Protocol::SERVER_URL
211
- @application_id = opts[:application_id] || opts[:app_id] || ENV["PARSE_APP_ID"] || ENV['PARSE_SERVER_APPLICATION_ID']
212
- @api_key = opts[:api_key] || opts[:rest_api_key] || ENV["PARSE_API_KEY"] || ENV["PARSE_REST_API_KEY"]
213
- @master_key = opts[:master_key] || ENV["PARSE_MASTER_KEY"] || ENV['PARSE_SERVER_MASTER_KEY']
233
+ @application_id = opts[:application_id] || opts[:app_id] || ENV["PARSE_APP_ID"] || ENV['PARSE_APPLICATION_ID']
234
+ @api_key = opts[:api_key] || opts[:rest_api_key] || ENV["PARSE_REST_API_KEY"] || ENV["PARSE_API_KEY"]
235
+ @master_key = opts[:master_key] || ENV["PARSE_MASTER_KEY"]
214
236
  opts[:adapter] ||= Faraday.default_adapter
215
237
  opts[:expires] ||= 3
216
- if @application_id.nil? || ( @api_key.nil? && @master_key.nil? )
217
- raise "Please call Parse.setup(application_id:, api_key:) to setup a client"
238
+ if @server_url.nil? || @application_id.nil? || ( @api_key.nil? && @master_key.nil? )
239
+ raise Parse::Error::ConnectionError, "Please call Parse.setup(server_url:, application_id:, api_key:) to setup a client"
218
240
  end
219
241
  @server_url += '/' unless @server_url.ends_with?('/')
220
242
  #Configure Faraday
@@ -260,6 +282,14 @@ module Parse
260
282
  Parse::Client.clients[:default] ||= self
261
283
  end
262
284
 
285
+ # If set, returns the current retry count for this instance. Otherwise,
286
+ # returns {DEFAULT_RETRIES}. Set to 0 to disable retry mechanism.
287
+ # @return [Integer] the current retry count for this client.
288
+ def retry_limit
289
+ return DEFAULT_RETRIES if @retry_limit.nil?
290
+ @retry_limit
291
+ end
292
+
263
293
  # @return [String] the url prefix of the Parse Server url.
264
294
  def url_prefix
265
295
  @conn.url_prefix
@@ -295,21 +325,21 @@ module Parse
295
325
  # - *:retry* [Integer] The number of retrties to perform if the service is unavailable.
296
326
  # Set to false to disable the retry mechanism. When performing request retries, the
297
327
  # client will sleep for a number of seconds ({Parse::Client::RETRY_DELAY}) between requests.
298
- # The default value is {Parse::Client::RETRY_COUNT}.
299
- # @raise Parse::AuthenticationError when HTTP response status is 401 or 403
300
- # @raise Parse::TimeoutError when HTTP response status is 400 or
328
+ # The default value is {Parse::Client::DEFAULT_RETRIES}.
329
+ # @raise Parse::Error::AuthenticationError when HTTP response status is 401 or 403
330
+ # @raise Parse::Error::TimeoutError when HTTP response status is 400 or
301
331
  # 408, and the Parse code is 143 or {Parse::Response::ERROR_TIMEOUT}.
302
- # @raise Parse::ConnectionError when HTTP response status is 404 is not an object not found error.
332
+ # @raise Parse::Error::ConnectionError when HTTP response status is 404 is not an object not found error.
303
333
  # - This will also be raised if after retrying a request a number of times has finally failed.
304
- # @raise Parse::ProtocolError when HTTP response status is 405 or 406
305
- # @raise Parse::ServiceUnavailableError when HTTP response status is 500 or 503.
334
+ # @raise Parse::Error::ProtocolError when HTTP response status is 405 or 406
335
+ # @raise Parse::Error::ServiceUnavailableError when HTTP response status is 500 or 503.
306
336
  # - This may also happen when the Parse Server response code is any
307
337
  # number less than {Parse::Response::ERROR_SERVICE_UNAVAILABLE}.
308
- # @raise Parse::ServerError when the Parse response code is less than 100
309
- # @raise Parse::RequestLimitExceededError when the Parse response code is {Parse::Response::ERROR_EXCEEDED_BURST_LIMIT}.
338
+ # @raise Parse::Error::ServerError when the Parse response code is less than 100
339
+ # @raise Parse::Error::RequestLimitExceededError when the Parse response code is {Parse::Response::ERROR_EXCEEDED_BURST_LIMIT}.
310
340
  # - This usually means you have exceeded the burst limit on requests, which will mean you will be throttled for the
311
341
  # next 60 seconds.
312
- # @raise Parse::InvalidSessionTokenError when the Parse response code is 209.
342
+ # @raise Parse::Error::InvalidSessionTokenError when the Parse response code is 209.
313
343
  # - This means the session token that was sent in the request seems to be invalid.
314
344
  # @return [Parse::Response] the response for this request.
315
345
  # @see Parse::Middleware::BodyBuilder
@@ -318,12 +348,12 @@ module Parse
318
348
  # @see Parse::Protocol
319
349
  # @see Parse::Request
320
350
  def request(method, uri = nil, body: nil, query: nil, headers: nil, opts: {})
321
- retry_count ||= RETRY_COUNT
351
+ _retry_count ||= self.retry_limit
322
352
 
323
353
  if opts[:retry] == false
324
- retry_count = 0
354
+ _retry_count = 0
325
355
  elsif opts[:retry].to_i > 0
326
- retry_count = opts[:retry]
356
+ _retry_count = opts[:retry]
327
357
  end
328
358
 
329
359
  headers ||= {}
@@ -343,7 +373,7 @@ module Parse
343
373
  # http method
344
374
  method = method.downcase.to_sym
345
375
  # set the User-Agent
346
- headers["User-Agent"] = "Parse-Stack v#{Parse::Stack::VERSION}"
376
+ headers[USER_AGENT_HEADER] = USER_AGENT_VERSION
347
377
 
348
378
  if opts[:cache] == false
349
379
  headers[Parse::Middleware::Caching::CACHE_CONTROL] = "no-cache"
@@ -373,59 +403,63 @@ module Parse
373
403
 
374
404
  case response.http_status
375
405
  when 401, 403
376
- puts "[Parse:AuthenticationError] #{response}"
377
- raise Parse::AuthenticationError, response
406
+ warn "[Parse:AuthenticationError] #{response}"
407
+ raise Parse::Error::AuthenticationError, response
378
408
  when 400, 408
379
409
  if response.code == Parse::Response::ERROR_TIMEOUT || response.code == 143 #"net/http: timeout awaiting response headers"
380
- puts "[Parse:TimeoutError] #{response}"
381
- raise Parse::TimeoutError, response
410
+ warn "[Parse:TimeoutError] #{response}"
411
+ raise Parse::Error::TimeoutError, response
382
412
  end
383
413
  when 404
384
414
  unless response.object_not_found?
385
- puts "[Parse:ConnectionError] #{response}"
386
- raise Parse::ConnectionError, response
415
+ warn "[Parse:ConnectionError] #{response}"
416
+ raise Parse::Error::ConnectionError, response
387
417
  end
388
418
  when 405, 406
389
- puts "[Parse:ProtocolError] #{response}"
390
- raise Parse::ProtocolError, response
419
+ warn "[Parse:ProtocolError] #{response}"
420
+ raise Parse::Error::ProtocolError, response
391
421
  when 500, 503
392
- puts "[Parse:ServiceUnavailableError] #{response}"
393
- raise Parse::ServiceUnavailableError, response
422
+ warn "[Parse:ServiceUnavailableError] #{response}"
423
+ raise Parse::Error::ServiceUnavailableError, response
394
424
  end
395
425
 
396
426
  if response.error?
397
427
  if response.code <= Parse::Response::ERROR_SERVICE_UNAVAILABLE
398
- puts "[Parse:ServiceUnavailableError] #{response}"
399
- raise Parse::ServiceUnavailableError, response
428
+ warn "[Parse:ServiceUnavailableError] #{response}"
429
+ raise Parse::Error::ServiceUnavailableError, response
400
430
  elsif response.code <= 100
401
- puts "[Parse:ServerError] #{response}"
402
- raise Parse::ServerError, response
431
+ warn "[Parse:ServerError] #{response}"
432
+ raise Parse::Error::ServerError, response
403
433
  elsif response.code == Parse::Response::ERROR_EXCEEDED_BURST_LIMIT
404
- puts "[Parse:RequestLimitExceededError] #{response}"
405
- raise Parse::RequestLimitExceededError, response
434
+ warn "[Parse:RequestLimitExceededError] #{response}"
435
+ raise Parse::Error::RequestLimitExceededError, response
406
436
  elsif response.code == 209 # Error 209: invalid session token
407
- puts "[Parse:InvalidSessionTokenError] #{response}"
408
- raise Parse::InvalidSessionTokenError, response
437
+ warn "[Parse:InvalidSessionTokenError] #{response}"
438
+ raise Parse::Error::InvalidSessionTokenError, response
409
439
  end
410
440
  end
411
441
 
412
442
  response
413
- rescue Parse::ServiceUnavailableError => e
414
- if retry_count > 0
415
- puts "[Parse:Retry] Retries remaining #{retry_count} : #{response.request}"
416
- sleep RETRY_DELAY
417
- retry_count -= 1
443
+ rescue Parse::Error::ServiceUnavailableError => e
444
+ if _retry_count > 0
445
+ warn "[Parse:Retry] Retries remaining #{_retry_count} : #{response.request}"
446
+ _retry_count -= 1
447
+ backoff_delay = RETRY_DELAY * (self.retry_limit - _retry_count)
448
+ _retry_delay = [0,RETRY_DELAY, backoff_delay].sample
449
+ sleep _retry_delay if _retry_delay > 0
418
450
  retry
419
451
  end
420
452
  raise
421
453
  rescue Faraday::Error::ClientError, Net::OpenTimeout => e
422
- if retry_count > 0
423
- puts "[Parse:Retry] Retries remaining #{retry_count} : #{_request}"
424
- sleep RETRY_DELAY
425
- retry_count -= 1
454
+ if _retry_count > 0
455
+ warn "[Parse:Retry] Retries remaining #{_retry_count} : #{_request}"
456
+ _retry_count -= 1
457
+ backoff_delay = RETRY_DELAY * (self.retry_limit - _retry_count)
458
+ _retry_delay = [0,RETRY_DELAY, backoff_delay].sample
459
+ sleep _retry_delay if _retry_delay > 0
426
460
  retry
427
461
  end
428
- raise Parse::ConnectionError, "#{_request} : #{e.class} - #{e.message}"
462
+ raise Parse::Error::ConnectionError, "#{_request} : #{e.class} - #{e.message}"
429
463
  end
430
464
 
431
465
  # Send a GET request.
@@ -479,10 +513,12 @@ module Parse
479
513
  # Any subclass can override their `client` methods to provide a different session to use
480
514
  module Connectable
481
515
 
516
+ # @!visibility private
482
517
  def self.included(baseClass)
483
518
  baseClass.extend ClassMethods
484
519
  end
485
-
520
+ # Class methods to be added to any object that wants to have standard access to
521
+ # a the default {Parse::Client} instance.
486
522
  module ClassMethods
487
523
 
488
524
  # @return [Parse::Client] the current client for :default.
@@ -15,6 +15,7 @@ module Parse
15
15
  # Parse REST API endpoint.
16
16
  class Authentication < Faraday::Middleware
17
17
  include Parse::Protocol
18
+ # @!visibility private
18
19
  DISABLE_MASTER_KEY = "X-Disable-Parse-Master-Key".freeze
19
20
  # @return [String] the application id for this Parse endpoint.
20
21
  attr_accessor :application_id
@@ -44,7 +45,7 @@ module Parse
44
45
  @content_type = options[:content_type] || CONTENT_TYPE_FORMAT
45
46
  end
46
47
 
47
- # we dup the call for thread-safety
48
+ # Thread-safety
48
49
  # @!visibility private
49
50
  def call(env)
50
51
  dup.call!(env)
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
1
3
 
2
4
  require_relative 'request'
3
5
  require_relative 'response'
@@ -33,9 +35,15 @@ module Parse
33
35
  # @see Array.save
34
36
  # @see Array.destroy
35
37
  class BatchOperation
38
+ include Enumerable
39
+
40
+ # @!attribute requests
41
+ # @return [Array] the set of requests in this batch.
36
42
 
43
+ # @!attribute responses
44
+ # @return [Array] the set of responses from this batch.
37
45
  attr_accessor :requests, :responses
38
- include Enumerable
46
+
39
47
 
40
48
  # @return [Parse::Client] the client to be used for the request.
41
49
  def client
@@ -10,11 +10,26 @@ require 'active_support/core_ext'
10
10
  require 'active_model_serializers'
11
11
 
12
12
  module Parse
13
+
14
+ # @!attribute self.logging
15
+ # Sets {Parse::Middleware::BodyBuilder} logging.
16
+ # You may specify `:debug` for additional verbosity.
17
+ # @return (see Parse::Middleware::BodyBuilder.logging)
18
+ def self.logging
19
+ Parse::Middleware::BodyBuilder.logging
20
+ end
21
+ # @!visibility private
22
+ def self.logging=(value)
23
+ Parse::Middleware::BodyBuilder.logging = value
24
+ end
25
+
26
+ # Namespace for Parse-Stack related middleware.
13
27
  module Middleware
14
28
  # This middleware takes an incoming Parse response, after an outgoing request,
15
29
  # and creates a Parse::Response object.
16
30
  class BodyBuilder < Faraday::Middleware
17
31
  include Parse::Protocol
32
+ # Header sent when a GET requests exceeds the limit.
18
33
  HTTP_OVERRIDE = 'X-Http-Method-Override'
19
34
 
20
35
  class << self
@@ -24,7 +39,7 @@ module Parse
24
39
  attr_accessor :logging
25
40
  end
26
41
 
27
- # thread-safety
42
+ # Thread-safety
28
43
  # @!visibility private
29
44
  def call(env)
30
45
  dup.call!(env)
@@ -8,7 +8,6 @@ require_relative 'protocol'
8
8
 
9
9
  module Parse
10
10
  module Middleware
11
- class CachingError < StandardError; end;
12
11
  # This is a caching middleware for Parse queries using Moneta. The caching
13
12
  # middleware will cache all GET requests made to the Parse REST API as long
14
13
  # as the API responds with a successful non-empty result payload.
@@ -19,19 +18,22 @@ module Parse
19
18
  class Caching < Faraday::Middleware
20
19
  include Parse::Protocol
21
20
 
22
- # Internal: List of status codes that can be cached:
23
- # * 200 - 'OK'
24
- # * 203 - 'Non-Authoritative Information'
25
- # * 300 - 'Multiple Choices'
26
- # * 301 - 'Moved Permanently'
27
- # * 302 - 'Found'
28
- # * 404 - 'Not Found' - removed
29
- # * 410 - 'Gone' - removed
30
-
21
+ # List of status codes that can be cached:
22
+ # * 200 - 'OK'
23
+ # * 203 - 'Non-Authoritative Information'
24
+ # * 300 - 'Multiple Choices'
25
+ # * 301 - 'Moved Permanently'
26
+ # * 302 - 'Found'
27
+ # * 404 - 'Not Found' - removed
28
+ # * 410 - 'Gone' - removed
31
29
  CACHEABLE_HTTP_CODES = [200, 203, 300, 301, 302].freeze
30
+ # Cache control header
32
31
  CACHE_CONTROL = 'Cache-Control'
32
+ # Request env key for the content length
33
33
  CONTENT_LENGTH_KEY = 'content-length'
34
+ # Header in response that is sent if this is a cached result
34
35
  CACHE_RESPONSE_HEADER = 'X-Cache-Response'
36
+ # Header in request to set caching information for the middleware.
35
37
  CACHE_EXPIRES_DURATION = 'X-Parse-Stack-Cache-Expires'
36
38
 
37
39
  class << self
@@ -71,7 +73,7 @@ module Parse
71
73
  # @param store [Moneta] An instance of the Moneta cache store to use.
72
74
  # @param opts [Hash] additional options.
73
75
  # @option opts [Integer] :expires the default expiration for a cache entry.
74
- # @raise Parse::Middleware::CachingError, if `store` is not a Moneta::Transformer instance.
76
+ # @raise ArgumentError, if `store` is not a Moneta::Transformer instance.
75
77
  def initialize(adapter, store, opts = {})
76
78
  super(adapter)
77
79
  @store = store
@@ -80,11 +82,12 @@ module Parse
80
82
  @expires = @opts[:expires]
81
83
 
82
84
  unless @store.is_a?(Moneta::Transformer)
83
- raise Parse::Middleware::CachingError, "Caching store object must a Moneta key/value store (Moneta::Transformer)."
85
+ raise ArgumentError, "Caching store object must a Moneta key/value store (Moneta::Transformer)."
84
86
  end
85
87
 
86
88
  end
87
89
 
90
+ # Thread-safety
88
91
  # @!visibility private
89
92
  def call(env)
90
93
  dup.call!(env)
@@ -153,7 +156,6 @@ module Parse
153
156
  puts "[Parse::Cache] Error: #{e}"
154
157
  end
155
158
 
156
- puts("[Parse::Cache::Miss] !! #{url}") if self.class.logging.present?
157
159
  @app.call(env).on_complete do |response_env|
158
160
  # Only cache GET requests with valid HTTP status codes whose content-length
159
161
  # is greater than 20. Otherwise they could be errors, successes and empty result sets.