parse-stack 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a515a094fadb46b58f8acbefd80f8188e265b22
4
- data.tar.gz: 64702d47c7a395c9ae754374aa9cf8b9fec048a4
3
+ metadata.gz: 308c8dffe7b01440e9682f44d06455e63342a73b
4
+ data.tar.gz: 8da41ba790a1676ba268bde0058687f8757762a6
5
5
  SHA512:
6
- metadata.gz: 8402485e10d774c12325542f3a4aabcf24a10f7626a6dc1d32b76f47df9283408a796e5440642d6f84b0a58ebf777637a77fa94cb52e78f5027ae0a625fdd2c8
7
- data.tar.gz: e080d1f9665dd80694eb5802162ab67a0b6bd72f8b8c6b9e4b8e0aa1ed348ce5c5dbceb21c89f1355b5769c4021fe7067458bef624e34caeb388da67da15e1c3
6
+ metadata.gz: 5875ce8bfce69516990b0fda62b0ccb6b1ef4a72f153f1a71bb6af4a193b918f0df8e7ced88626df5b3194a6202ca53d02867574b4b152847aa8a6e39635849c
7
+ data.tar.gz: 3f560e954fe65a9ef6f17977e929b99c10896f7b90806d476e954abb482859801fa28116fb6eed506af3a631fce63011711ce98843e425ff29fddc6d840fd78f
data/Changes.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Parse-Stack Changes
2
2
 
3
+ 1.3.1
4
+ -----------
5
+ - Parse::Query now supports `:cache` and `:use_master_key` option. (experimental)
6
+ - Minimum ruby version set to 1.9.3 (same as ActiveModel 4.2.1)
7
+ - Support for Rails 5.0+ and Rack 2.0+
8
+
3
9
  1.3.0
4
10
  -----------
5
11
  - **IMPORTANT**: __Raising an error no longer sends an error response back to
data/Gemfile.lock CHANGED
@@ -1,50 +1,49 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parse-stack (1.3.0)
4
+ parse-stack (1.3.1)
5
5
  active_model_serializers (>= 0.9, < 1)
6
- activemodel (>= 4.2.1, < 5)
7
- activesupport (>= 4.2.1, < 5)
6
+ activemodel (>= 4.2.1, < 6)
7
+ activesupport (>= 4.2.1, < 6)
8
8
  faraday (>= 0.8, < 1)
9
9
  faraday_middleware (>= 0.9, < 1)
10
10
  moneta (>= 0.7, < 1)
11
11
  parallel (>= 1.6, < 2)
12
- rack (< 2)
12
+ rack (< 3)
13
13
 
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- actionpack (4.2.6)
18
- actionview (= 4.2.6)
19
- activesupport (= 4.2.6)
20
- rack (~> 1.6)
21
- rack-test (~> 0.6.2)
22
- rails-dom-testing (~> 1.0, >= 1.0.5)
17
+ actionpack (5.0.0)
18
+ actionview (= 5.0.0)
19
+ activesupport (= 5.0.0)
20
+ rack (~> 2.0)
21
+ rack-test (~> 0.6.3)
22
+ rails-dom-testing (~> 2.0)
23
23
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
- actionview (4.2.6)
25
- activesupport (= 4.2.6)
24
+ actionview (5.0.0)
25
+ activesupport (= 5.0.0)
26
26
  builder (~> 3.1)
27
27
  erubis (~> 2.7.0)
28
- rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-dom-testing (~> 2.0)
29
29
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
30
- active_model_serializers (0.10.1)
30
+ active_model_serializers (0.10.2)
31
31
  actionpack (>= 4.1, < 6)
32
32
  activemodel (>= 4.1, < 6)
33
33
  jsonapi (~> 0.1.1.beta2)
34
34
  railties (>= 4.1, < 6)
35
- activemodel (4.2.6)
36
- activesupport (= 4.2.6)
37
- builder (~> 3.1)
38
- activesupport (4.2.6)
35
+ activemodel (5.0.0)
36
+ activesupport (= 5.0.0)
37
+ activesupport (5.0.0)
38
+ concurrent-ruby (~> 1.0, >= 1.0.2)
39
39
  i18n (~> 0.7)
40
- json (~> 1.7, >= 1.7.7)
41
40
  minitest (~> 5.1)
42
- thread_safe (~> 0.3, >= 0.3.4)
43
41
  tzinfo (~> 1.1)
44
42
  binding_of_caller (0.7.2)
45
43
  debug_inspector (>= 0.0.1)
46
44
  builder (3.2.2)
47
45
  coderay (1.1.1)
46
+ concurrent-ruby (1.0.2)
48
47
  debug_inspector (0.0.2)
49
48
  dotenv (2.1.1)
50
49
  erubis (2.7.0)
@@ -77,20 +76,18 @@ GEM
77
76
  pry-stack_explorer (0.4.9.2)
78
77
  binding_of_caller (>= 0.7)
79
78
  pry (>= 0.9.11)
80
- rack (1.6.4)
79
+ rack (2.0.1)
81
80
  rack-test (0.6.3)
82
81
  rack (>= 1.0)
83
- rails-deprecated_sanitizer (1.0.3)
84
- activesupport (>= 4.2.0.alpha)
85
- rails-dom-testing (1.0.7)
86
- activesupport (>= 4.2.0.beta, < 5.0)
82
+ rails-dom-testing (2.0.1)
83
+ activesupport (>= 4.2.0, < 6.0)
87
84
  nokogiri (~> 1.6.0)
88
- rails-deprecated_sanitizer (>= 1.0.1)
89
85
  rails-html-sanitizer (1.0.3)
90
86
  loofah (~> 2.0)
91
- railties (4.2.6)
92
- actionpack (= 4.2.6)
93
- activesupport (= 4.2.6)
87
+ railties (5.0.0)
88
+ actionpack (= 5.0.0)
89
+ activesupport (= 5.0.0)
90
+ method_source
94
91
  rake (>= 0.8.7)
95
92
  thor (>= 0.18.1, < 2.0)
96
93
  rake (10.5.0)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Parse::Stack
1
+ # Parse::Stack - A Parse SDK Ruby Client and Data Mapper
2
2
  Parse::Stack is an opinionated framework for larger scale ruby applications that utilize the [Parse Platform](http://www.parse.com). It provides a client adapter, a query engine, an object relational mapper (ORM) and a Cloud Code Webhooks rack application.
3
3
 
4
4
  ## Table Of Contents
@@ -51,15 +51,15 @@ module Parse
51
51
  end
52
52
 
53
53
  # /1/classes/<className>/<objectId> GET Retrieving Objects
54
- def fetch_object(className, id)
55
- response = request :get, uri_path(className, id)
54
+ def fetch_object(className, id, opts = {})
55
+ response = request :get, uri_path(className, id), opts: opts
56
56
  response.parse_class = className if response.present?
57
57
  response
58
58
  end
59
59
 
60
60
  # /1/classes/<className> GET Queries
61
- def find_objects(className, query = {})
62
- response = request :get, uri_path(className), query: query
61
+ def find_objects(className, query = {}, opts = {})
62
+ response = request :get, uri_path(className), query: query, opts: opts
63
63
  response.parse_class = className if response.present?
64
64
  response
65
65
  end
data/lib/parse/client.rb CHANGED
@@ -138,7 +138,7 @@ module Parse
138
138
  # If you need to override or add additional headers to a specific request (ex. when uploading a Parse File), you can do so
139
139
  # with the header: paramter (also a hash).
140
140
  # This method also takes in a Parse::Request object instead of the arguments listed above.
141
- def request(method, uri = nil, body: nil, query: nil, headers: nil)
141
+ def request(method, uri = nil, body: nil, query: nil, headers: nil, opts: {})
142
142
  headers ||= {}
143
143
  # if the first argument is a Parse::Request object, then construct it
144
144
  if method.is_a?(Request)
@@ -153,14 +153,26 @@ module Parse
153
153
  # http method
154
154
  method = method.downcase.to_sym
155
155
  # set the User-Agent
156
- headers["User-Agent"] = "Parse-Ruby-Client v#{Parse::Stack::VERSION}"
156
+ headers["User-Agent".freeze] = "Parse-Stack Ruby Client v#{Parse::Stack::VERSION}".freeze
157
+
158
+ if opts[:cache] == false
159
+ headers[Parse::Middleware::Caching::CACHE_CONTROL] = "no-cache"
160
+ elsif opts[:cache].is_a?(Numeric)
161
+ # future feature
162
+ # headers[Parse::Middleware::Caching::CACHE_CONTROL] = "max-age: #{opts[:cache].to_i}"
163
+ end
164
+
165
+ if opts[:use_master_key] == false
166
+ headers[Parse::Middleware::Authentication::DISABLE_MASTER_KEY] = "true"
167
+ end
168
+
157
169
  #if it is a :get request, then use query params, otherwise body.
158
170
  params = (method == :get ? query : body) || {}
159
171
  # if the path does not start with the '/1/' prefix, then add it to be nice.
160
172
  # actually send the request and return the body
161
173
  response = @session.send(method, uri, params, headers)
162
174
  body = response.body
163
-
175
+
164
176
  case response.status
165
177
  when 401, 403
166
178
  puts "[ParseError] #{body}"
@@ -194,7 +206,7 @@ module Parse
194
206
  end
195
207
 
196
208
  body
197
- rescue Faraday::Error::ClientError => e
209
+ rescue Faraday::Error::ClientError, Net::OpenTimeout => e
198
210
  raise Parse::ConnectionError, e.message
199
211
  end
200
212
 
@@ -10,6 +10,7 @@ module Parse
10
10
 
11
11
  class Authentication < Faraday::Middleware
12
12
  include Parse::Protocol
13
+ DISABLE_MASTER_KEY = "X-Disable-Parse-Master-Key"
13
14
  attr_accessor :application_id
14
15
  attr_accessor :api_key
15
16
  attr_accessor :master_key
@@ -32,11 +33,11 @@ module Parse
32
33
  headers = {}
33
34
  raise "No Parse Application Id specified for authentication." unless @application_id.present?
34
35
  headers[APP_ID] = @application_id
35
-
36
- # Set a user agent
37
- headers["User-Agent".freeze] = "Parse-Stack v0.0.1".freeze
38
36
  headers[API_KEY] = @api_key unless @api_key.blank?
39
- headers[MASTER_KEY] = @master_key unless @master_key.blank?
37
+
38
+ unless @master_key.blank? || env[:request_headers][DISABLE_MASTER_KEY].present?
39
+ headers[MASTER_KEY] = @master_key
40
+ end
40
41
  # merge the headers with the current provided headers
41
42
  env[:request_headers].merge! headers
42
43
  # set the content type of the request if it was not provided already.
@@ -7,6 +7,7 @@ module Parse
7
7
  module Middleware
8
8
  class Caching < Faraday::Middleware
9
9
  include Parse::Protocol
10
+ # Cache-Control: no-cache
10
11
  # Internal: List of status codes that can be cached:
11
12
  # * 200 - 'OK'
12
13
  # * 203 - 'Non-Authoritative Information'
@@ -16,6 +17,7 @@ module Parse
16
17
  # * 404 - 'Not Found' - removed
17
18
  # * 410 - 'Gone' - removed
18
19
  CACHEABLE_HTTP_CODES = [200, 203, 300, 301, 302].freeze
20
+ CACHE_CONTROL = 'Cache-Control'.freeze
19
21
 
20
22
  class << self
21
23
  attr_accessor :enabled, :logging
@@ -58,21 +60,25 @@ module Parse
58
60
 
59
61
  cache_enabled = true
60
62
 
63
+ if env[:request_headers][CACHE_CONTROL] == "no-cache".freeze
64
+ cache_enabled = false
65
+ end
66
+
61
67
  url = env.url
62
68
  method = env.method
63
69
  begin
64
- if method == :get && url.present? && @store.key?(url)
70
+ if cache_enabled && method == :get && url.present? && @store.key?(url)
65
71
  puts("[Parse::Cache] >>> #{url}") if self.class.logging.present?
66
72
  response = Faraday::Response.new
67
73
  res_env = @store[url] # previous cached response
68
74
  body = res_env.respond_to?(:body) ? res_env.body : nil
69
75
  if body.present?
70
- response.finish({status: 200, response_headers: {}, body: body })
76
+ response.finish({status: 200, response_headers: { "X-Cache-Response" => true }, body: body })
71
77
  return response
72
78
  else
73
79
  @store.delete url
74
80
  end
75
- elsif url.present?
81
+ elsif cache_enabled && url.present?
76
82
  #non GET requets should clear the cache for that same resource path.
77
83
  #ex. a POST to /1/classes/Artist/<objectId> should delete the cache for a GET
78
84
  # request for the same '/1/classes/Artist/<objectId>' where objectId are equivalent
@@ -5,9 +5,9 @@ module Parse
5
5
  #This class is mainly to create a potential request - mainly for the batching API.
6
6
 
7
7
  class Request
8
- attr_accessor :method, :path, :body, :headers
8
+ attr_accessor :method, :path, :body, :headers, :opts, :cache
9
9
  attr_accessor :tag #for tracking in bulk requests
10
- def initialize(method, uri, body: nil, headers: nil)
10
+ def initialize(method, uri, body: nil, headers: nil, opts: {})
11
11
  @tag = 0
12
12
  method = method.downcase.to_sym
13
13
  raise "Invalid Method type #{method} " unless [:get,:put,:delete,:post].include?(method)
@@ -15,6 +15,7 @@ module Parse
15
15
  self.path = uri
16
16
  self.body = body
17
17
  self.headers = headers || {}
18
+ self.opts = opts || {}
18
19
  end
19
20
 
20
21
 
data/lib/parse/query.rb CHANGED
@@ -23,7 +23,7 @@ module Parse
23
23
  # You can modify the default client being used by all Parse::Query objects by setting
24
24
  # Parse::Query.client. You can override individual Parse::Query object clients
25
25
  # by changing their client variable to a different Parse::Client object.
26
- attr_accessor :table, :client, :key
26
+ attr_accessor :table, :client, :key, :cache, :use_master_key
27
27
 
28
28
  # We have a special class method to handle field formatting. This turns
29
29
  # the symbol keys in an operand from one key to another. For example, we can
@@ -99,6 +99,8 @@ module Parse
99
99
  @limit = 100
100
100
  @skip = 0
101
101
  @table = table
102
+ @cache = true
103
+ @use_master_key = true
102
104
  conditions constraints
103
105
  self # chaining
104
106
  end # initialize
@@ -117,6 +119,10 @@ module Parse
117
119
  limit value
118
120
  elsif expression == :include || expression == :includes
119
121
  includes(value)
122
+ elsif expression == :cache
123
+ self.cache = value
124
+ elsif expression == :use_master_key
125
+ self.cache = value
120
126
  else
121
127
  add_constraint(expression, value)
122
128
  end
@@ -305,7 +311,10 @@ module Parse
305
311
  end
306
312
 
307
313
  def fetch!(compiled_query)
308
- response = client.find_objects(@table, compiled_query.as_json )
314
+ opts = {}
315
+ opts[:cache] = false unless self.cache
316
+ opts[:use_mster_key] = self.use_master_key
317
+ response = client.find_objects(@table, compiled_query.as_json, opts )
309
318
  if response.error?
310
319
  puts "[ParseQuery] #{response.error}"
311
320
  end
@@ -1,5 +1,5 @@
1
1
  module Parse
2
2
  module Stack
3
- VERSION = "1.3.0"
3
+ VERSION = "1.3.1"
4
4
  end
5
5
  end
data/parse-stack.gemspec CHANGED
@@ -25,16 +25,16 @@ Gem::Specification.new do |spec|
25
25
  spec.bindir = "exe"
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
- spec.required_ruby_version = '>= 2.2'
28
+ spec.required_ruby_version = '>= 1.9.3'
29
29
 
30
- spec.add_runtime_dependency "activemodel", [">= 4.2.1", "< 5"]
31
- spec.add_runtime_dependency "activesupport", [">= 4.2.1", "< 5"]
30
+ spec.add_runtime_dependency "activemodel", [">= 4.2.1", "< 6"]
31
+ spec.add_runtime_dependency "activesupport", [">= 4.2.1", "< 6"]
32
32
  spec.add_runtime_dependency "active_model_serializers", [">= 0.9", "< 1"]
33
33
  spec.add_runtime_dependency "parallel", [">= 1.6", "< 2"]
34
34
  spec.add_runtime_dependency "faraday", [">= 0.8", "< 1"]
35
35
  spec.add_runtime_dependency "faraday_middleware", [">= 0.9", "< 1"]
36
36
  spec.add_runtime_dependency "moneta", [">= 0.7", "< 1"]
37
- spec.add_runtime_dependency "rack", ["< 2"]
37
+ spec.add_runtime_dependency "rack", ["< 3"]
38
38
 
39
39
  spec.add_development_dependency "bundler", "~> 1"
40
40
  spec.add_development_dependency "rake", "~> 10"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Persaud
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-07-03 00:00:00.000000000 Z
12
+ date: 2016-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -20,7 +20,7 @@ dependencies:
20
20
  version: 4.2.1
21
21
  - - "<"
22
22
  - !ruby/object:Gem::Version
23
- version: '5'
23
+ version: '6'
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: 4.2.1
31
31
  - - "<"
32
32
  - !ruby/object:Gem::Version
33
- version: '5'
33
+ version: '6'
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: activesupport
36
36
  requirement: !ruby/object:Gem::Requirement
@@ -40,7 +40,7 @@ dependencies:
40
40
  version: 4.2.1
41
41
  - - "<"
42
42
  - !ruby/object:Gem::Version
43
- version: '5'
43
+ version: '6'
44
44
  type: :runtime
45
45
  prerelease: false
46
46
  version_requirements: !ruby/object:Gem::Requirement
@@ -50,7 +50,7 @@ dependencies:
50
50
  version: 4.2.1
51
51
  - - "<"
52
52
  - !ruby/object:Gem::Version
53
- version: '5'
53
+ version: '6'
54
54
  - !ruby/object:Gem::Dependency
55
55
  name: active_model_serializers
56
56
  requirement: !ruby/object:Gem::Requirement
@@ -157,14 +157,14 @@ dependencies:
157
157
  requirements:
158
158
  - - "<"
159
159
  - !ruby/object:Gem::Version
160
- version: '2'
160
+ version: '3'
161
161
  type: :runtime
162
162
  prerelease: false
163
163
  version_requirements: !ruby/object:Gem::Requirement
164
164
  requirements:
165
165
  - - "<"
166
166
  - !ruby/object:Gem::Version
167
- version: '2'
167
+ version: '3'
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: bundler
170
170
  requirement: !ruby/object:Gem::Requirement
@@ -351,7 +351,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
351
351
  requirements:
352
352
  - - ">="
353
353
  - !ruby/object:Gem::Version
354
- version: '2.2'
354
+ version: 1.9.3
355
355
  required_rubygems_version: !ruby/object:Gem::Requirement
356
356
  requirements:
357
357
  - - ">="