parse-stack 1.6.4 → 1.6.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fe3974386a315a6858707bdfe4c70ad41d9757e
4
- data.tar.gz: ae7f69099d57799341027a1f1776529be848740b
3
+ metadata.gz: 1d377fe92fad8444768b9e99dd1ef19b9e5e224c
4
+ data.tar.gz: 777cf72734c0bf6bd6ea2f59873d541b8879e792
5
5
  SHA512:
6
- metadata.gz: 943d2a2607014404c125680ad77b75b95edb46fa310bb4185e7945eb090003a09abb1c3165e2b229ba0691293386d25249b34ba0d2ebe68b80ee47210362c914
7
- data.tar.gz: 00a8dcfb89c494f21d2763bc7fb6305b65b80e51bfd701e9d73293c9e86902db1faa3a92557b782d6c52b98b6bd5c59522f3c29cc9cb8cd03ba3e577d63c26b4
6
+ metadata.gz: 19a5167c66db9a160c6203306d40d2fa4eb90c75025c17579f93efa7ed6dfbaf4295a4e4604a8c8622a5d1e336dd581d882ce2952633eb1d244d481fa1411659
7
+ data.tar.gz: d70d4514928179ccc896a8c99f93374605bd00ed83d47b76dc0e3396b24ec3d4fea3a275d0578153985cb77a8094778d25bd972b72519374b1893608a05f5877
data/Changes.md CHANGED
@@ -1,5 +1,18 @@
1
1
  ## Parse-Stack Changelog
2
2
 
3
+ ### 1.6.5
4
+ - Client handles HTTP Status 429 (RetryLimitExceeded)
5
+ - Role class does not automatically set default ACLs for Roles. You can restore
6
+ previous behavior by using `before_save :apply_default_acls`.
7
+ - Fixed minor issue to Parse::User.signup when merging username into response.
8
+ - NEW: Adds Parse::Product core class.
9
+ - NEW: Rake task to list registered webhooks. `rake parse:webhooks:list`
10
+ - Experimental support for beforeFind and afterFind - though webhook support not
11
+ yet fully available in open source Parse Server.
12
+ - Removes HTTPS requirement on webhooks.
13
+ - FIXES: Issue with WEBHOOK_KEY not being properly validated when set.
14
+ - beforeSaves now return empty hash instead of true on noop changes.
15
+
3
16
  ### 1.6.4
4
17
  - Fixes #20: All temporary headers values are strings.
5
18
  - Reduced cache storage consumption by only storing response body and headers.
data/Gemfile CHANGED
@@ -12,4 +12,7 @@ group :test, :development do
12
12
  gem 'pry'
13
13
  gem 'pry-stack_explorer'
14
14
  gem 'pry-nav'
15
+ gem 'yard'
16
+ gem 'redcarpet'
17
+ gem 'thin'
15
18
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parse-stack (1.6.4)
4
+ parse-stack (1.6.5)
5
5
  active_model_serializers (>= 0.9, < 1)
6
6
  activemodel (>= 4.2.1, < 6)
7
7
  activesupport (>= 4.2.1, < 6)
@@ -14,15 +14,15 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- actionpack (5.0.0.1)
18
- actionview (= 5.0.0.1)
19
- activesupport (= 5.0.0.1)
17
+ actionpack (5.0.1)
18
+ actionview (= 5.0.1)
19
+ activesupport (= 5.0.1)
20
20
  rack (~> 2.0)
21
21
  rack-test (~> 0.6.3)
22
22
  rails-dom-testing (~> 2.0)
23
23
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
- actionview (5.0.0.1)
25
- activesupport (= 5.0.0.1)
24
+ actionview (5.0.1)
25
+ activesupport (= 5.0.1)
26
26
  builder (~> 3.1)
27
27
  erubis (~> 2.7.0)
28
28
  rails-dom-testing (~> 2.0)
@@ -31,9 +31,9 @@ GEM
31
31
  actionpack (>= 4.1, < 6)
32
32
  activemodel (>= 4.1, < 6)
33
33
  jsonapi (= 0.1.1.beta2)
34
- activemodel (5.0.0.1)
35
- activesupport (= 5.0.0.1)
36
- activesupport (5.0.0.1)
34
+ activemodel (5.0.1)
35
+ activesupport (= 5.0.1)
36
+ activesupport (5.0.1)
37
37
  concurrent-ruby (~> 1.0, >= 1.0.2)
38
38
  i18n (~> 0.7)
39
39
  minitest (~> 5.1)
@@ -43,11 +43,13 @@ GEM
43
43
  builder (3.2.2)
44
44
  byebug (9.0.6)
45
45
  coderay (1.1.1)
46
- concurrent-ruby (1.0.2)
46
+ concurrent-ruby (1.0.4)
47
+ daemons (1.2.4)
47
48
  debug_inspector (0.0.2)
48
49
  dotenv (2.1.1)
49
50
  erubis (2.7.0)
50
- faraday (0.10.0)
51
+ eventmachine (1.2.1)
52
+ faraday (0.10.1)
51
53
  multipart-post (>= 1.2, < 3)
52
54
  faraday_middleware (0.10.1)
53
55
  faraday (>= 0.7.4, < 1.0)
@@ -62,7 +64,7 @@ GEM
62
64
  minitest (5.10.1)
63
65
  moneta (0.8.1)
64
66
  multipart-post (2.0.0)
65
- nokogiri (1.6.8.1)
67
+ nokogiri (1.7.0)
66
68
  mini_portile2 (~> 2.1.0)
67
69
  parallel (1.10.0)
68
70
  pry (0.10.4)
@@ -77,17 +79,23 @@ GEM
77
79
  rack (2.0.1)
78
80
  rack-test (0.6.3)
79
81
  rack (>= 1.0)
80
- rails-dom-testing (2.0.1)
82
+ rails-dom-testing (2.0.2)
81
83
  activesupport (>= 4.2.0, < 6.0)
82
- nokogiri (~> 1.6.0)
84
+ nokogiri (~> 1.6)
83
85
  rails-html-sanitizer (1.0.3)
84
86
  loofah (~> 2.0)
85
87
  rake (12.0.0)
88
+ redcarpet (3.4.0)
86
89
  redis (3.3.2)
87
90
  slop (3.6.0)
91
+ thin (1.7.0)
92
+ daemons (~> 1.0, >= 1.0.9)
93
+ eventmachine (~> 1.0, >= 1.0.4)
94
+ rack (>= 1, < 3)
88
95
  thread_safe (0.3.5)
89
96
  tzinfo (1.2.2)
90
97
  thread_safe (~> 0.1)
98
+ yard (0.9.5)
91
99
 
92
100
  PLATFORMS
93
101
  ruby
@@ -101,7 +109,10 @@ DEPENDENCIES
101
109
  pry-nav
102
110
  pry-stack_explorer
103
111
  rake
112
+ redcarpet
104
113
  redis
114
+ thin
115
+ yard
105
116
 
106
117
  BUNDLED WITH
107
118
  1.13.6
data/README.md CHANGED
@@ -6,6 +6,11 @@ Parse-Stack is the [Parse Server](https://github.com/ParsePlatform/parse-server)
6
6
 
7
7
  Below is a [quick start guide](https://github.com/modernistik/parse-stack#overview), but you can also check out the full [API Reference](http://www.rubydoc.info/github/modernistik/parse-stack) for more detailed information about our Parse Server SDK.
8
8
 
9
+ Watch Getting Started: https://youtu.be/zoYSGmciDlQ
10
+
11
+ ### Parse File Migration Tool
12
+ **If you are looking for a tool to migrate your hosted Parse Files to an Amazon S3 bucket, see our [Parse File Migration tool here](https://github.com/modernistik/parse-file-migration). This should be done before January 28th, 2017**
13
+
9
14
  ### Code Status
10
15
  [![Gem Version](https://badge.fury.io/rb/parse-stack.svg)](https://badge.fury.io/rb/parse-stack)
11
16
  [![Build Status](https://travis-ci.org/modernistik/parse-stack.svg?branch=master)](https://travis-ci.org/modernistik/parse-stack)
data/Rakefile CHANGED
@@ -13,6 +13,16 @@ end
13
13
  task :default => :test
14
14
 
15
15
  task :console do
16
- exec("./bin/console")
16
+ exec './bin/console'
17
17
  end
18
18
  task :c => :console
19
+
20
+ desc 'List undocumented methods'
21
+ task 'doc:stats' do
22
+ exec 'yard stats --list-undoc'
23
+ end
24
+
25
+ desc 'Start the yard server'
26
+ task 'doc:server' do
27
+ exec 'rm -rf ./yard && yard server --reload'
28
+ end
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-midnight
@@ -10,8 +10,9 @@ module Parse
10
10
  # @!visibility private
11
11
  HOOKS_PREFIX = "hooks/"
12
12
  # The allowed set of Parse triggers.
13
- TRIGGER_NAMES = [:beforeSave, :afterSave, :beforeDelete, :afterDelete].freeze
14
-
13
+ TRIGGER_NAMES = [:afterDelete, :afterFind, :afterSave, :beforeDelete, :beforeFind, :beforeSave].freeze
14
+ # @!visibility private
15
+ TRIGGER_NAMES_LOCAL = [:after_delete, :after_find, :after_save, :before_delete, :before_find, :before_save].freeze
15
16
  # @!visibility private
16
17
  def _verify_trigger(triggerName)
17
18
  triggerName = triggerName.to_s.camelize(:lower).to_sym
@@ -13,6 +13,7 @@ module Parse
13
13
 
14
14
  # @!visibility private
15
15
  SERVER_INFO_PATH = 'serverInfo'
16
+ # @!visibility private
16
17
  SERVER_HEALTH_PATH = 'health'
17
18
  # Fetch and cache information about the Parse server configuration. This
18
19
  # hash contains information specifically to the configuration of the running
data/lib/parse/client.rb CHANGED
@@ -173,7 +173,7 @@ module Parse
173
173
  # options.
174
174
  # @example
175
175
  # Parse.setup app_id: "YOUR_APP_ID",
176
- # api_key: "YOUR_API_KEY",
176
+ # api_key: "YOUR_REST_API_KEY",
177
177
  # master_key: "YOUR_MASTER_KEY", # optional
178
178
  # server_url: 'https://api.parse.com/1/' #default
179
179
  # @param opts (see Parse::Client#initialize)
@@ -197,7 +197,7 @@ module Parse
197
197
  # ENV["PARSE_SERVER_URL"] if available, otherwise fallback to {Parse::Protocol::SERVER_URL}.
198
198
  # @option opts [String] :app_id The Parse application id. Defaults to
199
199
  # ENV['PARSE_APP_ID'] or ENV['PARSE_APPLICATION_ID'].
200
- # @option opts [String] :api_key The Parse REST API Key. Defaults to ENV['PARSE_REST_API_KEY'].
200
+ # @option opts [String] :api_key Your Parse REST API Key. Defaults to ENV['PARSE_REST_API_KEY'].
201
201
  # @option opts [String] :master_key The Parse application master key (optional).
202
202
  # If this key is set, it will be sent on every request sent by the client
203
203
  # and your models. Defaults to ENV['PARSE_MASTER_KEY'].
@@ -429,6 +429,9 @@ module Parse
429
429
  when 405, 406
430
430
  warn "[Parse:ProtocolError] #{response}"
431
431
  raise Parse::Error::ProtocolError, response
432
+ when 429 # Request over the throttle limit
433
+ warn "[Parse:RequestLimitExceededError] #{response}"
434
+ raise Parse::Error::RequestLimitExceededError, response
432
435
  when 500, 503
433
436
  warn "[Parse:ServiceUnavailableError] #{response}"
434
437
  raise Parse::Error::ServiceUnavailableError, response
@@ -451,7 +454,7 @@ module Parse
451
454
  end
452
455
 
453
456
  response
454
- rescue Parse::Error::ServiceUnavailableError => e
457
+ rescue Parse::Error::RequestLimitExceededError, Parse::Error::ServiceUnavailableError => e
455
458
  if _retry_count > 0
456
459
  warn "[Parse:Retry] Retries remaining #{_retry_count} : #{response.request}"
457
460
  _retry_count -= 1
@@ -14,6 +14,7 @@ module Parse
14
14
  class Installation < Parse::Object
15
15
 
16
16
  parse_class Parse::Model::CLASS_INSTALLATION
17
+ # @!attribute gcm_sender_id
17
18
  # This field only has meaning for Android installations that use the GCM
18
19
  # push type. It is reserved for directing Parse to send pushes to this
19
20
  # installation with an alternate GCM sender ID. This field should generally
@@ -22,49 +23,75 @@ module Parse
22
23
  # corresponding to this GCM sender ID in your Parse application’s push settings.
23
24
  # @return [String]
24
25
  property :gcm_sender_id, :string, field: :GCMSenderId
26
+
27
+ # @!attribute app_identifier
25
28
  # A unique identifier for this installation’s client application. In iOS, this is the Bundle Identifier.
26
29
  # @return [String]
27
30
  property :app_identifier
31
+
32
+ # @!attribute app_name
28
33
  # The display name of the client application to which this installation belongs.
29
34
  # @return [String]
30
35
  property :app_name
36
+
37
+ # @!attribute app_version
31
38
  # The version string of the client application to which this installation belongs.
32
39
  # @return [String]
33
40
  property :app_version
41
+
42
+ # @!attribute badge
34
43
  # A number field representing the last known application badge for iOS installations.
35
44
  # @return [Integer]
36
45
  property :badge, :integer
46
+
47
+ # @!attribute channels
37
48
  # An array of the channels to which a device is currently subscribed.
38
49
  # Note that **channelUris** (the Microsoft-generated push URIs for Windows devices) is
39
50
  # not supported at this time.
40
51
  # @return [Array]
41
52
  property :channels, :array
53
+
54
+ # @!attribute device_token
42
55
  # The Apple or Google generated token used to deliver messages to the APNs
43
56
  # or GCM push networks respectively.
44
57
  # @return [String]
45
58
  property :device_token
46
- # @return [Integer]
59
+
60
+ # @!attribute device_token_last_modified
61
+ # @return [Integer] number of seconds since token modified
47
62
  property :device_token_last_modified, :integer
63
+
64
+ # @!attribute device_type
48
65
  # The type of device, “ios”, “android”, “winrt”, “winphone”, or “dotnet” (readonly).
49
66
  # This property is implemented as a Parse::Stack enumeration.
50
67
  # @return [String]
51
68
  property :device_type, enum: [:ios, :android, :winrt, :winphone, :dotnet]
69
+
70
+ # @!attribute installation_id
52
71
  # Universally Unique Identifier (UUID) for the device used by Parse. It
53
72
  # must be unique across all of an app’s installations. (readonly).
54
73
  # @return [String]
55
74
  property :installation_id
75
+
76
+ # @!attribute locale_identifier
56
77
  # The locale for this device.
57
78
  # @return [String]
58
79
  property :locale_identifier
80
+
81
+ # @!attribute parse_version
59
82
  # The version of the Parse SDK which this installation uses.
60
83
  # @return [String]
61
84
  property :parse_version
85
+
86
+ # @!attribute push_type
62
87
  # This field is reserved for directing Parse to the push delivery network
63
88
  # to be used. If the device is registered to receive pushes via GCM, this
64
89
  # field will be marked “gcm”. If this device is not using GCM, and is
65
90
  # using Parse’s push notification service, it will be blank (readonly).
66
91
  # @return [String]
67
92
  property :push_type
93
+
94
+ # @!attribute time_zone
68
95
  # The current time zone where the target device is located. This should be an IANA time zone identifier.
69
96
  # @return [String]
70
97
  property :time_zone
@@ -0,0 +1,46 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+ require_relative '../object'
4
+ require_relative 'user'
5
+ module Parse
6
+ # This class represents the data and columns contained in the standard Parse `_Product` collection.
7
+ # These records are usually used when implementing in-app purchases in mobile applications.
8
+ class Product < Parse::Object
9
+
10
+ parse_class Parse::Model::CLASS_PRODUCT
11
+ # @!attribute download
12
+ # @return [String] the file payload for this product download.
13
+ property :download, :file
14
+
15
+ # @!attribute download_name
16
+ # @return [String] the name of this download.
17
+ property :download_name
18
+
19
+ # @!attribute icon
20
+ # An icon file representing this download. This field is required by Parse.
21
+ # @return [String]
22
+ property :icon, :file, required: true
23
+
24
+ # @!attribute order
25
+ # The product order number. This field is required by Parse.
26
+ # @return [String]
27
+ property :order, :integer, required: true
28
+
29
+ # @!attribute product_identifier
30
+ # The product identifier. This field is required by Parse.
31
+ # @return [String]
32
+ property :product_identifier, required: true
33
+
34
+ # @!attribute subtitle
35
+ # The subtitle description for this product. This field is required by Parse.
36
+ # @return [String]
37
+ property :subtitle, required: true
38
+
39
+ # @!attribute title
40
+ # The title for this product. This field is required by Parse.
41
+ # @return [String] the title for this product.
42
+ property :title, required: true
43
+
44
+ end
45
+
46
+ end
@@ -10,6 +10,7 @@ module Parse
10
10
  class Role < Parse::Object
11
11
 
12
12
  parse_class Parse::Model::CLASS_ROLE
13
+ # @!attribute name
13
14
  # @return [String] the name of this role.
14
15
  property :name
15
16
  # This attribute is mapped as a `has_many` Parse relation association with the {Parse::Role} class,
@@ -21,8 +22,9 @@ module Parse
21
22
  # This attribute is mapped as a `has_many` Parse relation association with the {Parse::User} class.
22
23
  # @return [RelationCollectionProxy<User>] a Parse relation of users belonging to this role.
23
24
  has_many :users, through: :relation
24
-
25
- before_save do
25
+
26
+ # A method to set acls for Roles to public read, and deny public write.
27
+ def apply_default_acls
26
28
  acl.everyone true, false
27
29
  end
28
30
 
@@ -12,15 +12,24 @@ module Parse
12
12
  class Session < Parse::Object
13
13
 
14
14
  parse_class Parse::Model::CLASS_SESSION
15
+
16
+ # @!attribute created_with
15
17
  # @return [Hash] data on how this Session was created.
16
18
  property :created_with, :object
19
+
20
+ # @!attribute expires_at
17
21
  # @return [Parse::Date] when the session token expires.
18
22
  property :expires_at, :date
23
+
24
+ # @!attribute installation_id
19
25
  # @return [String] The installation id from the Installation table.
20
26
  # @see Installation#installation_id
21
27
  property :installation_id
28
+
29
+ # @!attribute [r] restricted
22
30
  # @return [Boolean] whether this session token is restricted.
23
31
  property :restricted, :boolean
32
+
24
33
  # @!attribute [r] session_token
25
34
  # @return [String] the session token for this installation and user pair.
26
35
  property :session_token
@@ -128,12 +128,14 @@ module Parse
128
128
  # @return [String] The session token if this user is logged in.
129
129
  attr_accessor :session_token
130
130
 
131
+ # @!attribute auth_data
131
132
  # The auth data for this Parse::User. Depending on how this user is authenticated or
132
133
  # logged in, the contents may be different, especially if you are using another third-party
133
134
  # authentication mechanism like Facebook/Twitter.
134
135
  # @return [Hash] Auth data hash object.
135
136
  property :auth_data, :object
136
137
 
138
+ # @!attribute email
137
139
  # Emails are optional in Parse, but if set, they must be unique.
138
140
  # @return [String] The email field.
139
141
  property :email
@@ -146,6 +148,7 @@ module Parse
146
148
  # @return [String] The password you set.
147
149
  property :password
148
150
 
151
+ # @!attribute username
149
152
  # All Parse users have a username and must be globally unique.
150
153
  # @return [String] The user's username.
151
154
  property :username
@@ -155,7 +158,7 @@ module Parse
155
158
  self.clear_attribute_change!(:acl)
156
159
  end
157
160
 
158
- # True if this user is anonymous.
161
+ # @return [Boolean] true if this user is anonymous.
159
162
  def anonymous?
160
163
  anonymous_id.nil?
161
164
  end
@@ -302,7 +305,8 @@ module Parse
302
305
  def self.create(body, **opts)
303
306
  response = client.create_user(body, opts: opts)
304
307
  if response.success?
305
- return Parse::User.build response.result
308
+ body.delete :password # clear password before merging
309
+ return Parse::User.build body.merge(response.result)
306
310
  end
307
311
 
308
312
  case response.code
@@ -53,8 +53,10 @@ module Parse
53
53
  CLASS_INSTALLATION = '_Installation'
54
54
  # The collection for revocable Sessions in Parse. Used by Parse::Session.
55
55
  CLASS_SESSION = '_Session'
56
- # The collection for revocable Roles in Parse. Used by Parse::Role.
56
+ # The collection for Roles in Parse. Used by Parse::Role.
57
57
  CLASS_ROLE = '_Role'
58
+ # The collection for to store Products (in-App purchases) in Parse. Used by Parse::Product.
59
+ CLASS_PRODUCT = '_Product'
58
60
  # The type label for hashes containing file data. Used by Parse::File.
59
61
  TYPE_FILE = 'File'
60
62
  # The type label for hashes containing geopoints. Used by Parse::GeoPoint.
@@ -426,20 +426,20 @@ module Parse
426
426
  # puts "Parse::Object.build error: #{e}"
427
427
  end
428
428
 
429
- # @!attribute [rw] id
429
+ # @!attribute id
430
430
  # @return [String] the value of Parse "objectId" field.
431
+ property :id, field: :objectId
431
432
 
432
433
  # @!attribute [r] created_at
433
434
  # @return [Date] the created_at date of the record in UTC Zulu iso 8601 with 3 millisecond format.
435
+ property :created_at, :date
434
436
 
435
437
  # @!attribute [r] updated_at
436
438
  # @return [Date] the updated_at date of the record in UTC Zulu iso 8601 with 3 millisecond format.
439
+ property :updated_at, :date
437
440
 
438
- # @!attribute [rw] acl
441
+ # @!attribute acl
439
442
  # @return [ACL] the access control list (permissions) object for this record.
440
- property :id, field: :objectId
441
- property :created_at, :date
442
- property :updated_at, :date
443
443
  property :acl, :acl, field: :ACL
444
444
 
445
445
  # Alias to {created_at}
@@ -509,6 +509,7 @@ end
509
509
 
510
510
  # Load all the core classes.
511
511
  require_relative 'classes/installation'
512
+ require_relative 'classes/product'
512
513
  require_relative 'classes/role'
513
514
  require_relative 'classes/session'
514
515
  require_relative 'classes/user'
@@ -54,8 +54,8 @@ module Parse
54
54
  end
55
55
 
56
56
  endpoint = ENV['HOOKS_URL'] || ''
57
- unless endpoint.empty? || endpoint.starts_with?('https://')
58
- raise "The ENV variable HOOKS_URL must be a <https> url : '#{endpoint}'. Ex. https://12345678.ngrok.io/webhooks"
57
+ unless endpoint.starts_with?('http://') || endpoint.starts_with?('https://')
58
+ raise "The ENV variable HOOKS_URL must be a <http/s> url : '#{endpoint}'. Ex. https://12345678.ngrok.io/webhooks"
59
59
  end
60
60
 
61
61
  end
@@ -78,12 +78,44 @@ module Parse
78
78
  Rake::Task['parse:webhooks:register:triggers'].invoke
79
79
  end
80
80
 
81
- desc "Remove all locally registered webhooks from the Parse Application"
81
+ desc "List all webhooks and triggers registered with the Parse Server"
82
+ task :list => :verify_env do
83
+ Rake::Task['parse:webhooks:list:functions'].invoke
84
+ Rake::Task['parse:webhooks:list:triggers'].invoke
85
+ end
86
+
87
+ desc "Remove all locally registered webhooks from the Parse Application."
82
88
  task :remove => :verify_env do
83
89
  Rake::Task['parse:webhooks:remove:functions'].invoke
84
90
  Rake::Task['parse:webhooks:remove:triggers'].invoke
85
91
  end
86
92
 
93
+ namespace :list do
94
+ task :functions => :verify_env do
95
+ endpoint = ENV['HOOKS_URL'] || '-'
96
+ Parse.client.functions.each do |r|
97
+ name = r['functionName']
98
+ url = r['url']
99
+ star = url.starts_with?(endpoint) ? '*' : ' '
100
+ puts "[#{star}] #{name} -> #{url}"
101
+ end
102
+ end
103
+
104
+ task :triggers => :verify_env do
105
+ endpoint = ENV['HOOKS_URL'] || '-'
106
+ triggers = Parse.client.triggers.results
107
+ triggers.sort! { |x,y| [x['className'],x['triggerName']] <=> [y['className'], y['triggerName'] ] }
108
+ triggers.each do |r|
109
+ name = r['className']
110
+ trigger = r['triggerName']
111
+ url = r['url']
112
+ star = url.starts_with?(endpoint) ? '*' : ' '
113
+ puts "[#{star}] #{name}.#{trigger} -> #{url}"
114
+ end
115
+ end
116
+
117
+ end
118
+
87
119
  namespace :register do
88
120
 
89
121
  task :functions => :verify_env do
@@ -6,6 +6,6 @@ module Parse
6
6
  # The Parse Server SDK for Ruby
7
7
  module Stack
8
8
  # The current version.
9
- VERSION = "1.6.4"
9
+ VERSION = "1.6.5"
10
10
  end
11
11
  end
@@ -91,12 +91,13 @@ module Parse
91
91
  # The content type that needs to be sent back to Parse server.
92
92
  CONTENT_TYPE = "application/json"
93
93
 
94
- # @!attribute key
94
+
95
95
  # The Parse Webhook Key to be used for authenticating webhook requests.
96
- # By default this is taken from the PARSE_WEBHOOK_KEY environment variable if
97
- # present.
96
+ # See {Parse::Webhooks.key} on setting this value.
98
97
  # @return [String]
99
- attr_accessor :key
98
+ def key
99
+ self.class.key
100
+ end
100
101
 
101
102
  class << self
102
103
 
@@ -114,10 +115,9 @@ module Parse
114
115
  # `:before_delete`, `:after_delete` or `:function`.
115
116
  # @return [OpenStruct]
116
117
  def routes
117
- @routes ||= OpenStruct.new( {
118
- before_save: {}, after_save: {},
119
- before_delete: {}, after_delete: {}, function: {}
120
- })
118
+ return @routes unless @routes.nil?
119
+ r = Parse::API::Hooks::TRIGGER_NAMES_LOCAL + [:function]
120
+ @routes = OpenStruct.new( r.reduce({}) { |h,t| h[t] = {}; h; } )
121
121
  end
122
122
 
123
123
  # Internally registers a route for a specific webhook trigger or function.
@@ -192,6 +192,9 @@ module Parse
192
192
  result.run_callbacks(:destroy) { false }
193
193
  result = true
194
194
  end
195
+ elsif type == :before_save && ( result == true || result.nil? )
196
+ # Open Source Parse server does not accept true results on before_save hooks.
197
+ result = {}
195
198
  end
196
199
 
197
200
  result
@@ -211,9 +214,11 @@ module Parse
211
214
  { error: data }.to_json
212
215
  end
213
216
 
217
+ # @!attribute key
214
218
  # Returns the configured webhook key if available. By default it will use
215
219
  # the value of ENV['PARSE_WEBHOOK_KEY'] if not configured.
216
220
  # @return [String]
221
+ attr_accessor :key
217
222
  def key
218
223
  @key ||= ENV['PARSE_WEBHOOK_KEY']
219
224
  end
@@ -237,8 +242,9 @@ module Parse
237
242
  request = Rack::Request.new env
238
243
  response = Rack::Response.new
239
244
 
240
- if @key.present? && @key =! request.env[HTTP_PARSE_WEBHOOK]
241
- response.write error("Invalid Parse-Webhook Key")
245
+ if self.key.present? && self.key != request.env[HTTP_PARSE_WEBHOOK]
246
+ puts "[Parse::Webhooks] Invalid Parse-Webhook Key: #{request.env[HTTP_PARSE_WEBHOOK]}"
247
+ response.write error("Invalid Parse Webhook Key")
242
248
  return response.finish
243
249
  end
244
250
 
@@ -23,6 +23,8 @@ module Parse
23
23
  installationId: nil, params: nil,
24
24
  functionName: nil, object: nil,
25
25
  original: nil, update: nil,
26
+ query: nil, log: nil,
27
+ objects: nil,
26
28
  triggerName: nil }.freeze
27
29
  include ::ActiveModel::Serializers::JSON
28
30
  # @!attribute [rw] master
@@ -50,9 +52,20 @@ module Parse
50
52
  # @return [Hash] the raw payload from Parse server.
51
53
  # @!attribute [rw] update
52
54
  # @return [Hash] the update payload in the request.
55
+ # @!attribute [r] query
56
+ # The query request in a beforeFind trigger. Available in Parse Server 2.3.1 or later.
57
+ # @return [Parse::Query]
58
+ # @!attribute [r] objects
59
+ # The set of matching objects in an afterFind trigger. Available in Parse Server 2.3.1 or later.
60
+ # @return [<Parse::Object>]
61
+ # @!attribute [r] log
62
+ # Logging information if available. Available in Parse Server 2.3.1 or later.
63
+ # @return [Hash] the set of matching objects in an afterFind trigger.
53
64
  attr_accessor :master, :user, :installation_id, :params, :function_name, :object, :trigger_name
54
-
65
+ attr_accessor :query, :log, :objects
55
66
  attr_accessor :original, :update, :raw
67
+ # @!visibility private
68
+ attr_accessor :webhook_class
56
69
  alias_method :installationId, :installation_id
57
70
  alias_method :functionName, :function_name
58
71
  alias_method :triggerName, :trigger_name
@@ -74,6 +87,10 @@ module Parse
74
87
  @trigger_name = hash[:trigger_name]
75
88
  @original = hash[:original]
76
89
  @update = hash[:update] || {} #it comes as an update hash
90
+ # Added for beforeFind and afterFind triggers
91
+ @query = hash[:query]
92
+ @objects = hash[:objects] || []
93
+ @log = hash[:log]
77
94
  end
78
95
 
79
96
  # @return [ATTRIBUTES]
@@ -88,6 +105,7 @@ module Parse
88
105
 
89
106
  # @return [String] the name of the Parse class for this request.
90
107
  def parse_class
108
+ return @webhook_class if @webhook_class.present?
91
109
  return nil unless @object.present?
92
110
  @object[Parse::Model::KEY_CLASS_NAME] || @object[:className]
93
111
  end
@@ -105,12 +123,12 @@ module Parse
105
123
 
106
124
  # true if this is a beforeSave or beforeDelete webhook trigger request.
107
125
  def before_trigger?
108
- before_save? || before_delete?
126
+ before_save? || before_delete? || before_find?
109
127
  end
110
128
 
111
129
  # true if this is a afterSave or afterDelete webhook trigger request.
112
130
  def after_trigger?
113
- after_save? || after_delete?
131
+ after_save? || after_delete? || after_find?
114
132
  end
115
133
 
116
134
  # true if this is a beforeSave webhook trigger request.
@@ -133,6 +151,16 @@ module Parse
133
151
  trigger? && @trigger_name.to_sym == :afterDelete
134
152
  end
135
153
 
154
+ # true if this is a beforeFind webhook trigger request.
155
+ def before_find?
156
+ trigger? && @trigger_name.to_sym == :beforeFind
157
+ end
158
+
159
+ # true if this is a afterFind webhook trigger request.
160
+ def after_find?
161
+ trigger? && @trigger_name.to_sym == :afterFind
162
+ end
163
+
136
164
  # true if this request is a trigger that contains an object.
137
165
  def object?
138
166
  trigger? && @object.present?
@@ -195,6 +223,13 @@ module Parse
195
223
  raise Parse::Webhooks::ResponseError, msg
196
224
  end
197
225
 
226
+
227
+ # @return [Parse::Query] the Parse query for a beforeFind trigger.
228
+ def parse_query
229
+ return nil unless parse_class.present? && @query.is_a?(Hash)
230
+ Parse::Query.new parse_class, @query
231
+ end
232
+
198
233
  end # Payload
199
234
  end
200
235
  end
@@ -42,8 +42,8 @@ module Parse
42
42
  # @param endpoint [String] a https url that points to the webhook server.
43
43
  def register_functions!(endpoint)
44
44
 
45
- unless endpoint.present? && endpoint.starts_with?('https://')
46
- raise ArgumentError, "The HOOKS_URL must be https: '#{endpoint}''"
45
+ unless endpoint.present? && (endpoint.starts_with?('http://') || endpoint.starts_with?('https://') )
46
+ raise ArgumentError, "The HOOKS_URL must be http/s: '#{endpoint}''"
47
47
  end
48
48
  endpoint += '/' unless endpoint.ends_with?('/')
49
49
  functionsMap = {}
@@ -70,17 +70,14 @@ module Parse
70
70
  # @param include_wildcard [Boolean] Allow wildcard registrations
71
71
  def register_triggers!(endpoint, include_wildcard: false)
72
72
 
73
- unless endpoint.present? && endpoint.starts_with?('https://')
74
- raise ArgumentError, "The HOOKS_URL must be https: '#{endpoint}''"
73
+ unless endpoint.present? && (endpoint.starts_with?('http://') || endpoint.starts_with?('https://') )
74
+ raise ArgumentError, "The HOOKS_URL must be http/s: '#{endpoint}''"
75
75
  end
76
76
  endpoint += '/' unless endpoint.ends_with?('/')
77
+ all_triggers = Parse::API::Hooks::TRIGGER_NAMES_LOCAL
77
78
 
78
- current_triggers = {
79
- after_save: {},
80
- after_delete: {},
81
- before_delete: {},
82
- before_save: {}
83
- }
79
+ current_triggers = {}
80
+ all_triggers.each { |t| current_triggers[t] = {} }
84
81
 
85
82
  client.triggers.each do |t|
86
83
  next unless t["url"].present?
@@ -89,7 +86,7 @@ module Parse
89
86
  current_triggers[trigger_name][ t["className"] ] = t["url"]
90
87
  end
91
88
 
92
- [:after_delete, :after_save, :before_delete, :before_save].each do |trigger|
89
+ all_triggers.each do |trigger|
93
90
  classNames = routes[trigger].keys.dup
94
91
  if include_wildcard && classNames.include?('*') #then create the list for all classes
95
92
  classNames.delete '*' #delete the wildcard before we expand it
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.6.4
4
+ version: 1.6.5
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-12-16 00:00:00.000000000 Z
11
+ date: 2017-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -181,6 +181,7 @@ files:
181
181
  - LICENSE
182
182
  - README.md
183
183
  - Rakefile
184
+ - _config.yml
184
185
  - bin/console
185
186
  - bin/server
186
187
  - bin/setup
@@ -216,6 +217,7 @@ files:
216
217
  - lib/parse/model/associations/relation_collection_proxy.rb
217
218
  - lib/parse/model/bytes.rb
218
219
  - lib/parse/model/classes/installation.rb
220
+ - lib/parse/model/classes/product.rb
219
221
  - lib/parse/model/classes/role.rb
220
222
  - lib/parse/model/classes/session.rb
221
223
  - lib/parse/model/classes/user.rb
@@ -274,7 +276,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
274
276
  version: '0'
275
277
  requirements: []
276
278
  rubyforge_project:
277
- rubygems_version: 2.6.6
279
+ rubygems_version: 2.6.8
278
280
  signing_key:
279
281
  specification_version: 4
280
282
  summary: Parse-Server Ruby Client and Relational Mapper