parse-stack 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +5 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +40 -80
  5. data/lib/parse/api/all.rb +7 -0
  6. data/lib/parse/api/analytics.rb +8 -3
  7. data/lib/parse/api/apps.rb +29 -1
  8. data/lib/parse/api/batch.rb +14 -129
  9. data/lib/parse/api/cloud_functions.rb +9 -0
  10. data/lib/parse/api/config.rb +10 -1
  11. data/lib/parse/api/files.rb +7 -2
  12. data/lib/parse/api/hooks.rb +45 -2
  13. data/lib/parse/api/objects.rb +43 -6
  14. data/lib/parse/api/push.rb +6 -1
  15. data/lib/parse/api/schemas.rb +15 -1
  16. data/lib/parse/api/sessions.rb +5 -0
  17. data/lib/parse/api/users.rb +64 -5
  18. data/lib/parse/client/authentication.rb +25 -8
  19. data/lib/parse/client/batch.rb +206 -0
  20. data/lib/parse/client/body_builder.rb +12 -6
  21. data/lib/parse/client/caching.rb +42 -10
  22. data/lib/parse/client/protocol.rb +51 -46
  23. data/lib/parse/client/response.rb +1 -47
  24. data/lib/parse/client.rb +171 -42
  25. data/lib/parse/model/acl.rb +184 -39
  26. data/lib/parse/model/associations/belongs_to.rb +1 -0
  27. data/lib/parse/model/classes/role.rb +7 -1
  28. data/lib/parse/model/classes/session.rb +7 -3
  29. data/lib/parse/model/classes/user.rb +107 -0
  30. data/lib/parse/model/core/actions.rb +166 -115
  31. data/lib/parse/model/core/fetching.rb +105 -0
  32. data/lib/parse/model/core/properties.rb +40 -13
  33. data/lib/parse/model/core/querying.rb +123 -39
  34. data/lib/parse/model/core/schema.rb +22 -32
  35. data/lib/parse/model/object.rb +26 -20
  36. data/lib/parse/model/pointer.rb +1 -0
  37. data/lib/parse/query/constraint.rb +65 -27
  38. data/lib/parse/query/constraints.rb +0 -3
  39. data/lib/parse/query/operation.rb +33 -22
  40. data/lib/parse/query/ordering.rb +10 -5
  41. data/lib/parse/stack/generators/rails.rb +5 -1
  42. data/lib/parse/stack/generators/templates/model_installation.rb +1 -1
  43. data/lib/parse/stack/generators/templates/model_role.rb +1 -1
  44. data/lib/parse/stack/generators/templates/model_session.rb +2 -2
  45. data/lib/parse/stack/generators/templates/model_user.rb +1 -1
  46. data/lib/parse/stack/generators/templates/parse.rb +0 -1
  47. data/lib/parse/stack/railtie.rb +1 -0
  48. data/lib/parse/stack/tasks.rb +3 -1
  49. data/lib/parse/stack/version.rb +3 -1
  50. data/lib/parse/webhooks/registration.rb +3 -3
  51. data/lib/parse/webhooks.rb +88 -7
  52. metadata +5 -3
@@ -8,23 +8,29 @@ require_relative 'protocol'
8
8
  require 'active_support'
9
9
  require 'active_support/core_ext'
10
10
  require 'active_model_serializers'
11
- # This middleware takes an incoming response (after an outgoing request)
12
- # and creates a Parse::Response object.
11
+
13
12
  module Parse
14
13
  module Middleware
14
+ # This middleware takes an incoming Parse response, after an outgoing request,
15
+ # and creates a Parse::Response object.
15
16
  class BodyBuilder < Faraday::Middleware
17
+ include Parse::Protocol
18
+ HTTP_OVERRIDE = 'X-Http-Method-Override'
19
+
16
20
  class << self
21
+ # Allows logging. Set to `true` to enable logging, `false` to disable.
22
+ # You may specify `:debug` for additional verbosity.
23
+ # @return [Boolean]
17
24
  attr_accessor :logging
18
25
  end
19
26
 
20
- include Parse::Protocol
21
- HTTP_OVERRIDE = 'X-Http-Method-Override'
22
-
23
27
  # thread-safety
28
+ # @!visibility private
24
29
  def call(env)
25
30
  dup.call!(env)
26
31
  end
27
32
 
33
+ # @!visibility private
28
34
  def call!(env)
29
35
  # the maximum url size is ~2KB, so if we request a Parse API url greater than this
30
36
  # (which is most likely a very complicated query), we need to override the request method
@@ -55,7 +61,7 @@ module Parse
55
61
  @app.call(env).on_complete do |response_env|
56
62
  # on a response, create a new Parse::Response and replace the :body
57
63
  # of the env
58
- # TODO: CHECK FOR HTTP STATUS CODES
64
+ # @todo CHECK FOR HTTP STATUS CODES
59
65
  if self.class.logging
60
66
  puts "[[Response #{response_env[:status]}]] ----------------------------------"
61
67
  puts response_env.body
@@ -5,13 +5,20 @@ require 'faraday'
5
5
  require 'faraday_middleware'
6
6
  require 'moneta'
7
7
  require_relative 'protocol'
8
- # This is a caching middleware for Parse queries using Moneta.
8
+
9
9
  module Parse
10
10
  module Middleware
11
11
  class CachingError < StandardError; end;
12
+ # This is a caching middleware for Parse queries using Moneta. The caching
13
+ # middleware will cache all GET requests made to the Parse REST API as long
14
+ # as the API responds with a successful non-empty result payload.
15
+ #
16
+ # Whenever an object is created or updated, the corresponding entry in the cache
17
+ # when fetching the particular record (using the specific non-Query based API)
18
+ # will be cleared.
12
19
  class Caching < Faraday::Middleware
13
20
  include Parse::Protocol
14
- # Cache-Control: no-cache
21
+
15
22
  # Internal: List of status codes that can be cached:
16
23
  # * 200 - 'OK'
17
24
  # * 203 - 'Non-Authoritative Information'
@@ -20,30 +27,53 @@ module Parse
20
27
  # * 302 - 'Found'
21
28
  # * 404 - 'Not Found' - removed
22
29
  # * 410 - 'Gone' - removed
23
- CACHEABLE_HTTP_CODES = [200, 203, 300, 301, 302]
30
+
31
+ CACHEABLE_HTTP_CODES = [200, 203, 300, 301, 302].freeze
24
32
  CACHE_CONTROL = 'Cache-Control'
25
- CONTENT_LENGTH_KEY = "content-length"
26
- CACHE_RESPONSE_HEADER = "X-Cache-Response"
33
+ CONTENT_LENGTH_KEY = 'content-length'
34
+ CACHE_RESPONSE_HEADER = 'X-Cache-Response'
27
35
  CACHE_EXPIRES_DURATION = 'X-Parse-Stack-Cache-Expires'
28
36
 
29
37
  class << self
30
- attr_accessor :enabled, :logging
38
+ # @!attribute enabled
39
+ # @return [Boolean] whether the caching middleware should be enabled.
40
+ attr_accessor :enabled
41
+
42
+ # @!attribute logging
43
+ # @return [Boolean] whether the logging should be enabled.
44
+ attr_accessor :logging
31
45
 
32
46
  def enabled
33
47
  @enabled = true if @enabled.nil?
34
48
  @enabled
35
49
  end
36
50
 
51
+ # @return [Boolean] whether caching is enabled.
37
52
  def caching?
38
53
  @enabled
39
54
  end
40
55
 
41
56
  end
42
57
 
43
- attr_accessor :store, :expires
44
-
45
- def initialize(app, store, opts = {})
46
- super(app)
58
+ # @!attribute [rw] store
59
+ # The internal moneta cache store instance.
60
+ # @return [Moneta::Transformer]
61
+ attr_accessor :store
62
+
63
+ # @!attribute [rw] expires
64
+ # The expiration time in seconds for this particular request.
65
+ # @return [Integer]
66
+ attr_accessor :expires
67
+
68
+ # Creates a new caching middleware.
69
+ # @param adapter [Faraday::Adapter] An instance of the Faraday adapter
70
+ # used for the connection. Defaults Faraday::Adapter::NetHttp.
71
+ # @param store [Moneta] An instance of the Moneta cache store to use.
72
+ # @param opts [Hash] additional options.
73
+ # @option opts [Integer] :expires the default expiration for a cache entry.
74
+ # @raise Parse::Middleware::CachingError, if `store` is not a Moneta::Transformer instance.
75
+ def initialize(adapter, store, opts = {})
76
+ super(adapter)
47
77
  @store = store
48
78
  @opts = {expires: 0}
49
79
  @opts.merge!(opts) if opts.is_a?(Hash)
@@ -55,10 +85,12 @@ module Parse
55
85
 
56
86
  end
57
87
 
88
+ # @!visibility private
58
89
  def call(env)
59
90
  dup.call!(env)
60
91
  end
61
92
 
93
+ # @!visibility private
62
94
  def call!(env)
63
95
  @request_headers = env[:request_headers]
64
96
 
@@ -1,9 +1,9 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- # A module to contain all the main constants.
5
- module Parse
6
4
 
5
+ module Parse
6
+ # Set of Parse protocol constants.
7
7
  module Protocol
8
8
  HOST = 'api.parse.com'
9
9
  SERVER_URL = 'https://api.parse.com/1/'
@@ -19,51 +19,56 @@ module Parse
19
19
  CONTENT_TYPE_FORMAT = 'application/json; charset=utf-8'
20
20
  end
21
21
 
22
+ # All Parse error codes.
23
+ # @todo Implement all error codes as StandardError
24
+ #
25
+ # List of error codes.
26
+ # OtherCause -1 Error code indicating that an unknown error or an error unrelated to Parse occurred.
27
+ # InternalServerError 1 Error code indicating that something has gone wrong with the server. If you get this error code, it is Parse's fault. Please report the bug to https://parse.com/help.
28
+ # ConnectionFailed 100 Error code indicating the connection to the Parse servers failed.
29
+ # ObjectNotFound 101 Error code indicating the specified object doesn't exist.
30
+ # InvalidQuery 102 Error code indicating you tried to query with a datatype that doesn't support it, like exact matching an array or object.
31
+ # InvalidClassName 103 Error code indicating a missing or invalid classname. Classnames are case-sensitive. They must start with a letter, and a-zA-Z0-9_ are the only valid characters.
32
+ # MissingObjectId 104 Error code indicating an unspecified object id.
33
+ # InvalidKeyName 105 Error code indicating an invalid key name. Keys are case-sensitive. They must start with a letter, and a-zA-Z0-9_ are the only valid characters.
34
+ # InvalidPointer 106 Error code indicating a malformed pointer. You should not see this unless you have been mucking about changing internal Parse code.
35
+ # InvalidJSON 107 Error code indicating that badly formed JSON was received upstream. This either indicates you have done something unusual with modifying how things encode to JSON, or the network is failing badly.
36
+ # CommandUnavailable 108 Error code indicating that the feature you tried to access is only available internally for testing purposes.
37
+ # NotInitialized 109 You must call Parse.initialize before using the Parse library.
38
+ # IncorrectType 111 Error code indicating that a field was set to an inconsistent type.
39
+ # InvalidChannelName 112 Error code indicating an invalid channel name. A channel name is either an empty string (the broadcast channel) or contains only a-zA-Z0-9_ characters and starts with a letter.
40
+ # PushMisconfigured 115 Error code indicating that push is misconfigured.
41
+ # ObjectTooLarge 116 Error code indicating that the object is too large.
42
+ # OperationForbidden 119 Error code indicating that the operation isn't allowed for clients.
43
+ # CacheMiss 120 Error code indicating the result was not found in the cache.
44
+ # InvalidNestedKey 121 Error code indicating that an invalid key was used in a nested JSONObject.
45
+ # InvalidFileName 122 Error code indicating that an invalid filename was used for ParseFile. A valid file name contains only a-zA-Z0-9_. characters and is between 1 and 128 characters.
46
+ # InvalidACL 123 Error code indicating an invalid ACL was provided.
47
+ # Timeout 124 Error code indicating that the request timed out on the server. Typically this indicates that the request is too expensive to run.
48
+ # InvalidEmailAddress 125 Error code indicating that the email address was invalid.
49
+ # DuplicateValue 137 Error code indicating that a unique field was given a value that is already taken.
50
+ # InvalidRoleName 139 Error code indicating that a role's name is invalid.
51
+ # ExceededQuota 140 Error code indicating that an application quota was exceeded. Upgrade to resolve.
52
+ # ScriptFailed 141 Error code indicating that a Cloud Code script failed.
53
+ # ValidationFailed 142 Error code indicating that a Cloud Code validation failed.
54
+ # FileDeleteFailed 153 Error code indicating that deleting a file failed.
55
+ # RequestLimitExceeded 155 Error code indicating that the application has exceeded its request limit.
56
+ # InvalidEventName 160 Error code indicating that the provided event name is invalid.
57
+ # UsernameMissing 200 Error code indicating that the username is missing or empty.
58
+ # PasswordMissing 201 Error code indicating that the password is missing or empty.
59
+ # UsernameTaken 202 Error code indicating that the username has already been taken.
60
+ # EmailTaken 203 Error code indicating that the email has already been taken.
61
+ # EmailMissing 204 Error code indicating that the email is missing, but must be specified.
62
+ # EmailNotFound 205 Error code indicating that a user with the specified email was not found.
63
+ # SessionMissing 206 Error code indicating that a user object without a valid session could not be altered.
64
+ # MustCreateUserThroughSignup 207 Error code indicating that a user can only be created through signup.
65
+ # AccountAlreadyLinked 208 Error code indicating that an an account being linked is already linked to another user.
66
+ # InvalidSessionToken 209 Error code indicating that the current session token is invalid.
67
+ # LinkedIdMissing 250 Error code indicating that a user cannot be linked to an account because that account's id could not be found.
68
+ # InvalidLinkedSession 251 Error code indicating that a user with a linked (e.g. Facebook) account has an invalid session.
69
+ # UnsupportedService 252 Error code indicating that a service being linked (e.g. Facebook or Twitter) is unsupported.
22
70
  module ErrorCodes
23
- # OtherCause -1 Error code indicating that an unknown error or an error unrelated to Parse occurred.
24
- # InternalServerError 1 Error code indicating that something has gone wrong with the server. If you get this error code, it is Parse's fault. Please report the bug to https://parse.com/help.
25
- # ConnectionFailed 100 Error code indicating the connection to the Parse servers failed.
26
- # ObjectNotFound 101 Error code indicating the specified object doesn't exist.
27
- # InvalidQuery 102 Error code indicating you tried to query with a datatype that doesn't support it, like exact matching an array or object.
28
- # InvalidClassName 103 Error code indicating a missing or invalid classname. Classnames are case-sensitive. They must start with a letter, and a-zA-Z0-9_ are the only valid characters.
29
- # MissingObjectId 104 Error code indicating an unspecified object id.
30
- # InvalidKeyName 105 Error code indicating an invalid key name. Keys are case-sensitive. They must start with a letter, and a-zA-Z0-9_ are the only valid characters.
31
- # InvalidPointer 106 Error code indicating a malformed pointer. You should not see this unless you have been mucking about changing internal Parse code.
32
- # InvalidJSON 107 Error code indicating that badly formed JSON was received upstream. This either indicates you have done something unusual with modifying how things encode to JSON, or the network is failing badly.
33
- # CommandUnavailable 108 Error code indicating that the feature you tried to access is only available internally for testing purposes.
34
- # NotInitialized 109 You must call Parse.initialize before using the Parse library.
35
- # IncorrectType 111 Error code indicating that a field was set to an inconsistent type.
36
- # InvalidChannelName 112 Error code indicating an invalid channel name. A channel name is either an empty string (the broadcast channel) or contains only a-zA-Z0-9_ characters and starts with a letter.
37
- # PushMisconfigured 115 Error code indicating that push is misconfigured.
38
- # ObjectTooLarge 116 Error code indicating that the object is too large.
39
- # OperationForbidden 119 Error code indicating that the operation isn't allowed for clients.
40
- # CacheMiss 120 Error code indicating the result was not found in the cache.
41
- # InvalidNestedKey 121 Error code indicating that an invalid key was used in a nested JSONObject.
42
- # InvalidFileName 122 Error code indicating that an invalid filename was used for ParseFile. A valid file name contains only a-zA-Z0-9_. characters and is between 1 and 128 characters.
43
- # InvalidACL 123 Error code indicating an invalid ACL was provided.
44
- # Timeout 124 Error code indicating that the request timed out on the server. Typically this indicates that the request is too expensive to run.
45
- # InvalidEmailAddress 125 Error code indicating that the email address was invalid.
46
- # DuplicateValue 137 Error code indicating that a unique field was given a value that is already taken.
47
- # InvalidRoleName 139 Error code indicating that a role's name is invalid.
48
- # ExceededQuota 140 Error code indicating that an application quota was exceeded. Upgrade to resolve.
49
- # ScriptFailed 141 Error code indicating that a Cloud Code script failed.
50
- # ValidationFailed 142 Error code indicating that a Cloud Code validation failed.
51
- # FileDeleteFailed 153 Error code indicating that deleting a file failed.
52
- # RequestLimitExceeded 155 Error code indicating that the application has exceeded its request limit.
53
- # InvalidEventName 160 Error code indicating that the provided event name is invalid.
54
- # UsernameMissing 200 Error code indicating that the username is missing or empty.
55
- # PasswordMissing 201 Error code indicating that the password is missing or empty.
56
- # UsernameTaken 202 Error code indicating that the username has already been taken.
57
- # EmailTaken 203 Error code indicating that the email has already been taken.
58
- # EmailMissing 204 Error code indicating that the email is missing, but must be specified.
59
- # EmailNotFound 205 Error code indicating that a user with the specified email was not found.
60
- # SessionMissing 206 Error code indicating that a user object without a valid session could not be altered.
61
- # MustCreateUserThroughSignup 207 Error code indicating that a user can only be created through signup.
62
- # AccountAlreadyLinked 208 Error code indicating that an an account being linked is already linked to another user.
63
- # InvalidSessionToken 209 Error code indicating that the current session token is invalid.
64
- # LinkedIdMissing 250 Error code indicating that a user cannot be linked to an account because that account's id could not be found.
65
- # InvalidLinkedSession 251 Error code indicating that a user with a linked (e.g. Facebook) account has an invalid session.
66
- # UnsupportedService 252 Error code indicating that a service being linked (e.g. Facebook or Twitter) is unsupported.
71
+
67
72
  end
68
73
 
69
74
  end
@@ -1,52 +1,6 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- # Member name Value Description
5
- # OtherCause -1 Error code indicating that an unknown error or an error unrelated to Parse occurred.
6
- # InternalServerError 1 Error code indicating that something has gone wrong with the server. If you get this error code, it is Parse's fault. Please report the bug to https://parse.com/help.
7
- # ConnectionFailed 100 Error code indicating the connection to the Parse servers failed.
8
- # ObjectNotFound 101 Error code indicating the specified object doesn't exist.
9
- # InvalidQuery 102 Error code indicating you tried to query with a datatype that doesn't support it, like exact matching an array or object.
10
- # InvalidClassName 103 Error code indicating a missing or invalid classname. Classnames are case-sensitive. They must start with a letter, and a-zA-Z0-9_ are the only valid characters.
11
- # MissingObjectId 104 Error code indicating an unspecified object id.
12
- # InvalidKeyName 105 Error code indicating an invalid key name. Keys are case-sensitive. They must start with a letter, and a-zA-Z0-9_ are the only valid characters.
13
- # InvalidPointer 106 Error code indicating a malformed pointer. You should not see this unless you have been mucking about changing internal Parse code.
14
- # InvalidJSON 107 Error code indicating that badly formed JSON was received upstream. This either indicates you have done something unusual with modifying how things encode to JSON, or the network is failing badly.
15
- # CommandUnavailable 108 Error code indicating that the feature you tried to access is only available internally for testing purposes.
16
- # NotInitialized 109 You must call Parse.initialize before using the Parse library.
17
- # IncorrectType 111 Error code indicating that a field was set to an inconsistent type.
18
- # InvalidChannelName 112 Error code indicating an invalid channel name. A channel name is either an empty string (the broadcast channel) or contains only a-zA-Z0-9_ characters and starts with a letter.
19
- # PushMisconfigured 115 Error code indicating that push is misconfigured.
20
- # ObjectTooLarge 116 Error code indicating that the object is too large.
21
- # OperationForbidden 119 Error code indicating that the operation isn't allowed for clients.
22
- # CacheMiss 120 Error code indicating the result was not found in the cache.
23
- # InvalidNestedKey 121 Error code indicating that an invalid key was used in a nested JSONObject.
24
- # InvalidFileName 122 Error code indicating that an invalid filename was used for ParseFile. A valid file name contains only a-zA-Z0-9_. characters and is between 1 and 128 characters.
25
- # InvalidACL 123 Error code indicating an invalid ACL was provided.
26
- # Timeout 124 Error code indicating that the request timed out on the server. Typically this indicates that the request is too expensive to run.
27
- # InvalidEmailAddress 125 Error code indicating that the email address was invalid.
28
- # DuplicateValue 137 Error code indicating that a unique field was given a value that is already taken.
29
- # InvalidRoleName 139 Error code indicating that a role's name is invalid.
30
- # ExceededQuota 140 Error code indicating that an application quota was exceeded. Upgrade to resolve.
31
- # ScriptFailed 141 Error code indicating that a Cloud Code script failed.
32
- # ValidationFailed 142 Error code indicating that a Cloud Code validation failed.
33
- # FileDeleteFailed 153 Error code indicating that deleting a file failed.
34
- # RequestLimitExceeded 155 Error code indicating that the application has exceeded its request limit.
35
- # InvalidEventName 160 Error code indicating that the provided event name is invalid.
36
- # UsernameMissing 200 Error code indicating that the username is missing or empty.
37
- # PasswordMissing 201 Error code indicating that the password is missing or empty.
38
- # UsernameTaken 202 Error code indicating that the username has already been taken.
39
- # EmailTaken 203 Error code indicating that the email has already been taken.
40
- # EmailMissing 204 Error code indicating that the email is missing, but must be specified.
41
- # EmailNotFound 205 Error code indicating that a user with the specified email was not found.
42
- # SessionMissing 206 Error code indicating that a user object without a valid session could not be altered.
43
- # MustCreateUserThroughSignup 207 Error code indicating that a user can only be created through signup.
44
- # AccountAlreadyLinked 208 Error code indicating that an an account being linked is already linked to another user.
45
- # InvalidSessionToken 209 Error code indicating that the current session token is invalid.
46
- # LinkedIdMissing 250 Error code indicating that a user cannot be linked to an account because that account's id could not be found.
47
- # InvalidLinkedSession 251 Error code indicating that a user with a linked (e.g. Facebook) account has an invalid session.
48
- # UnsupportedService 252 Error code indicating that a service being linked (e.g. Facebook or Twitter) is unsupported.
49
-
50
4
  require 'active_support'
51
5
  require 'active_support/json'
52
6
  # This is the model that represents a response from Parse. A Response can also
@@ -58,7 +12,7 @@ module Parse
58
12
  include Enumerable
59
13
 
60
14
  ERROR_INTERNAL = 1
61
- ERROR_SERVICE_UNAVAILALBE = 2
15
+ ERROR_SERVICE_UNAVAILABLE = 2
62
16
  ERROR_TIMEOUT = 124
63
17
  ERROR_EXCEEDED_BURST_LIMIT = 155
64
18
  ERROR_OBJECT_NOT_FOUND = 101