parse-stack 1.5.1 → 1.5.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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/Changes.md +15 -1
  3. data/Gemfile.lock +10 -10
  4. data/README.md +23 -9
  5. data/bin/console +3 -0
  6. data/lib/parse/api/analytics.rb +1 -1
  7. data/lib/parse/api/objects.rb +1 -1
  8. data/lib/parse/api/users.rb +1 -1
  9. data/lib/parse/client.rb +77 -40
  10. data/lib/parse/client/caching.rb +9 -5
  11. data/lib/parse/client/protocol.rb +47 -0
  12. data/lib/parse/client/request.rb +66 -37
  13. data/lib/parse/client/response.rb +39 -21
  14. data/lib/parse/model/acl.rb +4 -9
  15. data/lib/parse/model/associations/belongs_to.rb +97 -9
  16. data/lib/parse/model/associations/collection_proxy.rb +89 -29
  17. data/lib/parse/model/associations/has_many.rb +301 -28
  18. data/lib/parse/model/associations/has_one.rb +98 -4
  19. data/lib/parse/model/associations/pointer_collection_proxy.rb +48 -16
  20. data/lib/parse/model/associations/relation_collection_proxy.rb +61 -36
  21. data/lib/parse/model/bytes.rb +11 -5
  22. data/lib/parse/model/classes/installation.rb +50 -3
  23. data/lib/parse/model/classes/role.rb +7 -2
  24. data/lib/parse/model/classes/session.rb +21 -4
  25. data/lib/parse/model/classes/user.rb +122 -22
  26. data/lib/parse/model/core/actions.rb +7 -3
  27. data/lib/parse/model/core/properties.rb +14 -13
  28. data/lib/parse/model/core/querying.rb +16 -10
  29. data/lib/parse/model/core/schema.rb +2 -3
  30. data/lib/parse/model/date.rb +18 -12
  31. data/lib/parse/model/file.rb +77 -19
  32. data/lib/parse/model/geopoint.rb +70 -12
  33. data/lib/parse/model/model.rb +84 -8
  34. data/lib/parse/model/object.rb +225 -94
  35. data/lib/parse/model/pointer.rb +94 -13
  36. data/lib/parse/model/push.rb +76 -4
  37. data/lib/parse/query.rb +356 -41
  38. data/lib/parse/query/constraints.rb +399 -29
  39. data/lib/parse/query/ordering.rb +21 -8
  40. data/lib/parse/stack.rb +1 -0
  41. data/lib/parse/stack/version.rb +2 -1
  42. data/lib/parse/webhooks.rb +0 -24
  43. data/lib/parse/webhooks/payload.rb +54 -1
  44. data/lib/parse/webhooks/registration.rb +13 -2
  45. metadata +2 -2
@@ -1,17 +1,30 @@
1
1
  # encoding: UTF-8
2
2
  # frozen_string_literal: true
3
3
 
4
- # Ordering is implemented similarly as constraints in which we add
5
- # special methods to the Symbol class. The developer can then pass one
6
- # or an array of fields (as symbols) and call the particular ordering
7
- # polarity (ex. :name.asc would create a Parse::Order where we want
8
- # things to be sortd by the name field in ascending order)
9
- # For more information about the query design pattern from DataMapper
10
- # that inspired this, see http://datamapper.org/docs/find.html
4
+
11
5
  module Parse
6
+ # This class adds support for describing ordering for Parse queries. You can
7
+ # either order by ascending (asc) or descending (desc) order.
8
+ #
9
+ # Ordering is implemented similarly to constraints in which we add
10
+ # special methods to the Symbol class. The developer can then pass one
11
+ # or an array of fields (as symbols) and call the particular ordering
12
+ # polarity (ex. _:name.asc_ would create a Parse::Order where we want
13
+ # things to be sortd by the name field in ascending order)
14
+ # For more information about the query design pattern from DataMapper
15
+ # that inspired this, see http://datamapper.org/docs/find.html'
16
+ # @example
17
+ # :name.asc # => Parse::Order by ascending :name
18
+ # :like_count.desc # => Parse::Order by descending :like_count
19
+ #
12
20
  class Order
13
- # We only support ascending and descending
21
+ # The Parse operators to indicate ordering direction.
14
22
  ORDERING = {asc: '', desc: '-'}.freeze
23
+ # @!attribute [rw] field
24
+ # @return [Symbol] the name of the field
25
+ # @!attribute [rw] direction
26
+ # The direction of the sorting. This is either `:asc` or `:desc`.
27
+ # @return [Symbol]
15
28
  attr_accessor :field, :direction
16
29
 
17
30
  def initialize(field, order = :asc)
data/lib/parse/stack.rb CHANGED
@@ -7,6 +7,7 @@ require_relative 'query'
7
7
  require_relative 'model/object'
8
8
  require_relative 'webhooks'
9
9
 
10
+
10
11
  module Parse
11
12
  module Stack
12
13
 
@@ -2,7 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Parse
5
+ # @author Anthony Persaud
5
6
  module Stack
6
- VERSION = "1.5.1"
7
+ VERSION = "1.5.2"
7
8
  end
8
9
  end
@@ -14,30 +14,6 @@ require_relative 'model/object'
14
14
  require_relative 'webhooks/payload'
15
15
  require_relative 'webhooks/registration'
16
16
 
17
-
18
- =begin
19
- Some methods take a block, and this pattern frequently appears for a block:
20
-
21
- {|x| x.foo}
22
- and people would like to write that in a more concise way. In order to do that,
23
- a symbol, the method Symbol#to_proc, implicit class casting, and & operator
24
- are used in combination. If you put & in front of a Proc instance in the
25
- argument position, that will be interpreted as a block. If you combine
26
- something other than a Proc instance with &, then implicit class casting
27
- will try to convert that to a Proc instance using to_proc method defined on
28
- that object if there is any. In case of a Symbol instance, to_proc works in
29
- this way:
30
-
31
- :foo.to_proc # => ->x{x.foo}
32
-
33
- For example, suppose you write like this:
34
-
35
- bar(&:foo)
36
- The & operator is combined with :foo, which is not a Proc instance, so implicit class cast applies Symbol#to_proc to it, which gives ->x{x.foo}. The & now applies to this and is interpreted as a block, which gives:
37
-
38
- bar{|x| x.foo}
39
- =end
40
-
41
17
  module Parse
42
18
 
43
19
  class Object
@@ -10,7 +10,12 @@ require 'active_support/core_ext'
10
10
  require 'active_model_serializers'
11
11
 
12
12
  module Parse
13
-
13
+ # Represents the data structure that Parse server sends to a registered webhook.
14
+ # Parse Parse allows you to receive Cloud Code webhooks on your own hosted
15
+ # server. The `Parse::Webhooks` class is a lightweight Rack application that
16
+ # routes incoming Cloud Code webhook requests and payloads to locally
17
+ # registered handlers. The payloads are `Parse::Payload` type of objects that
18
+ # represent that data that Parse sends webhook handlers.
14
19
  class Payload
15
20
  ATTRIBUTES = { master: nil, user: nil,
16
21
  installationId: nil, params: nil,
@@ -18,6 +23,31 @@ module Parse
18
23
  original: nil, update: nil,
19
24
  triggerName: nil }.freeze
20
25
  include ::ActiveModel::Serializers::JSON
26
+ # @!attribute [rw] master
27
+ # @return [Boolean] whether the master key was used for this request.
28
+ # @!attribute [rw] user
29
+ # @return [Parse::User] the user who performed this request or action.
30
+ # @!attribute [rw] installation_id
31
+ # @return [String] The identifier of the device that submitted the request.
32
+ # @!attribute [rw] params
33
+ # @return [Hash] The list of function arguments submitted for a function request.
34
+ # @!attribute [rw] function_name
35
+ # @return [String] the name of the function.
36
+ # @!attribute [rw] object
37
+ # In a beforeSave, this attribute is the final object that will be persisted.
38
+ # @return [Hash] the object hash related to a webhook trigger request.
39
+ # @see #parse_object
40
+ # @!attribute [rw] trigger_name
41
+ # @return [String] the name of the trigger (ex. beforeSave, afterSave, etc.)
42
+ # @!attribute [rw] original
43
+ # In a beforeSave, for previously saved objects, this attribute is the Parse::Object
44
+ # that was previously in the persistent store.
45
+ # @return [Hash] the object hash related to a webhook trigger request.
46
+ # @see #parse_object
47
+ # @!attribute [rw] raw
48
+ # @return [Hash] the raw payload from Parse server.
49
+ # @!attribute [rw] update
50
+ # @return [Hash] the update payload in the request.
21
51
  attr_accessor :master, :user, :installation_id, :params, :function_name, :object, :trigger_name
22
52
 
23
53
  attr_accessor :original, :update, :raw
@@ -25,6 +55,9 @@ module Parse
25
55
  alias_method :functionName, :function_name
26
56
  alias_method :triggerName, :trigger_name
27
57
 
58
+ # You would normally never create a Parse::Payload object since it is automatically
59
+ # provided to you when using Parse::Webhooks.
60
+ # @see Parse::Webhooks
28
61
  def initialize(hash = {})
29
62
  hash = JSON.parse(hash) if hash.is_a?(String)
30
63
  hash = Hash[hash.map{ |k, v| [k.to_s.underscore.to_sym, v] }]
@@ -33,6 +66,7 @@ module Parse
33
66
  @user = Parse::User.new hash[:user] if hash[:user].present?
34
67
  @installation_id = hash[:installation_id]
35
68
  @params = hash[:params]
69
+ @params = @params.with_indifferent_access if @params.is_a?(Hash)
36
70
  @function_name = hash[:function_name]
37
71
  @object = hash[:object]
38
72
  @trigger_name = hash[:trigger_name]
@@ -40,61 +74,80 @@ module Parse
40
74
  @update = hash[:update] || {} #it comes as an update hash
41
75
  end
42
76
 
77
+ # @return [Hash]
43
78
  def attributes
44
79
  ATTRIBUTES
45
80
  end
46
81
 
82
+ # true if this is a webhook function request.
47
83
  def function?
48
84
  @function_name.present?
49
85
  end
50
86
 
87
+ # @return [String] the name of the Parse class for this request.
51
88
  def parse_class
52
89
  return nil unless @object.present?
53
90
  @object[Parse::Model::KEY_CLASS_NAME] || @object[:className]
54
91
  end
55
92
 
93
+ # @return [String] the objectId in this request.
56
94
  def parse_id
57
95
  return nil unless @object.present?
58
96
  @object[Parse::Model::OBJECT_ID] || @object[:objectId]
59
97
  end; alias_method :objectId, :parse_id
60
98
 
99
+ # true if this is a webhook trigger request.
61
100
  def trigger?
62
101
  @trigger_name.present?
63
102
  end
64
103
 
104
+ # true if this is a beforeSave or beforeDelete webhook trigger request.
65
105
  def before_trigger?
66
106
  before_save? || before_delete?
67
107
  end
68
108
 
109
+ # true if this is a afterSave or afterDelete webhook trigger request.
69
110
  def after_trigger?
70
111
  after_save? || after_delete?
71
112
  end
72
113
 
114
+ # true if this is a beforeSave webhook trigger request.
73
115
  def before_save?
74
116
  trigger? && @trigger_name.to_sym == :beforeSave
75
117
  end
76
118
 
119
+ # true if this is a afterSave webhook trigger request.
77
120
  def after_save?
78
121
  trigger? && @trigger_name.to_sym == :afterSave
79
122
  end
80
123
 
124
+ # true if this is a beforeDelete webhook trigger request.
81
125
  def before_delete?
82
126
  trigger? && @trigger_name.to_sym == :beforeDelete
83
127
  end
84
128
 
129
+ # true if this is a afterDelete webhook trigger request.
85
130
  def after_delete?
86
131
  trigger? && @trigger_name.to_sym == :afterDelete
87
132
  end
88
133
 
134
+ # true if this request is a trigger that contains an object.
89
135
  def object?
90
136
  trigger? && @object.present?
91
137
  end
92
138
 
139
+ # @return [Parse::Object] a Parse::Object from the original object
93
140
  def original_parse_object
94
141
  return nil unless @original.is_a?(Hash)
95
142
  Parse::Object.build(@original)
96
143
  end
97
144
 
145
+ # This method returns a Parse::Object by combining the original object, if was provided,
146
+ # with the final object. This will return a dirty tracked Parse::Object subclass,
147
+ # that will have information on which fields have changed between the previous state
148
+ # in the persistent store and the one about to be saved.
149
+ # @param pristine [Boolean] whether the object should be returned without dirty tracking.
150
+ # @return [Parse::Object] a dirty tracked Parse::Object subclass instance
98
151
  def parse_object(pristine = false)
99
152
  return nil unless object?
100
153
  return Parse::Object.build(@object) if pristine
@@ -15,7 +15,7 @@ module Parse
15
15
 
16
16
  ALLOWED_HOOKS = Parse::API::Hooks::TRIGGER_NAMES + [:function]
17
17
 
18
-
18
+ # removes all registered webhook functions with Parse Server.
19
19
  def remove_all_functions!
20
20
 
21
21
  client.functions.results.sort_by { |f| f['functionName'] }.each do |f|
@@ -25,6 +25,7 @@ module Parse
25
25
  end
26
26
  end
27
27
 
28
+ # removes all registered webhook triggers with Parse Server.
28
29
  def remove_all_triggers!
29
30
 
30
31
  client.triggers.results.sort_by { |f| [f['triggerName'],f['className']] }.each do |f|
@@ -37,6 +38,8 @@ module Parse
37
38
 
38
39
  end
39
40
 
41
+ # Registers all webhook functions registered with Parse::Stack with Parse server.
42
+ # @param endpoint [String] a https url that points to the webhook server.
40
43
  def register_functions!(endpoint)
41
44
 
42
45
  unless endpoint.present? && endpoint.starts_with?('https://')
@@ -62,6 +65,9 @@ module Parse
62
65
 
63
66
  end
64
67
 
68
+ # Registers all webhook triggers registered with Parse::Stack with Parse server.
69
+ # @param endpoint [String] a https url that points to the webhook server.
70
+ # @param include_wildcard [Boolean] Allow wildcard registrations
65
71
  def register_triggers!(endpoint, include_wildcard: false)
66
72
 
67
73
  unless endpoint.present? && endpoint.starts_with?('https://')
@@ -87,7 +93,7 @@ module Parse
87
93
  classNames = routes[trigger].keys.dup
88
94
  if include_wildcard && classNames.include?('*') #then create the list for all classes
89
95
  classNames.delete '*' #delete the wildcard before we expand it
90
- classNames = classNames + Parse.registered_classes
96
+ classNames = classNames + Parse.registered_classes - ['_Session']
91
97
  classNames.uniq!
92
98
  end
93
99
 
@@ -106,6 +112,11 @@ module Parse
106
112
  end
107
113
  end
108
114
 
115
+ # Registers a webhook trigger with a given endpoint url.
116
+ # @param trigger [Symbol] Trigger type based on Parse::API::Hooks::TRIGGER_NAMES or :function.
117
+ # @param name [String] the name of the webhook.
118
+ # @param url [String] the https url endpoint that will handle the request.
119
+ # @see Parse::API::Hooks::TRIGGER_NAMES
109
120
  def register_webhook!(trigger, name, url)
110
121
  trigger = trigger.to_s.camelize(:lower).to_sym
111
122
  raise ArgumentError, "Invalid hook trigger #{trigger}" unless ALLOWED_HOOKS.include?(trigger)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Persaud
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2016-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel