parse-stack 1.0.3 → 1.0.4

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: 51e6999d35378d6ca78b0fa9dee414a514399bcf
4
- data.tar.gz: 69d850f4bcc6dd881ddefe78046b9e28f029eb01
3
+ metadata.gz: 7b2f443ea3100a01208cc85a71fdc0b6ec2724c0
4
+ data.tar.gz: 253a1845c48fe6a9ffbdd728660efbab38bea5a1
5
5
  SHA512:
6
- metadata.gz: 73838aeea4e18427b0d8ba59dec9dd540f1a2c1f21b12fa53d44902a2027d1d83d79fde141752cb3a41f3fc29d8f713b92d2b2f2f3ef5a1ceca658b095e79a56
7
- data.tar.gz: c54006ff84b0caaea0c6a31732d666cb52a93de78fc6d5ceb9800cc9f0d0ee9c8edaf5b8c94f80483e0b6b893cec03e53eb0740d60cf4a5310f6b890e9e279b3
6
+ metadata.gz: e083d6466f4dc40f2d207c192966027f6a0adf8e928183f129c6be81d569c6ed51a9eb4b5ff4e909ba46465d74fa818bd24025a52ef756c1b14e0235986d40d5
7
+ data.tar.gz: cfc551f79913f5fe87f29e642fcf22bdd51652b2b15db71650cd3727b0e62103e767e29e128b246dea5b5b4febd9eb28cff4e3ff639ec7e2441ae25928b936c9
data/Changes.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Parse-Stack Changes
2
2
 
3
+ 1.0.4
4
+ -----------
5
+ - Fixes minor issue when storing and retrieving objects from the cache.
6
+ - Support for providing :server_url as a connection option for those migrating hosting
7
+ their own parse-server.
8
+
3
9
  1.0.3
4
10
  -----------
5
11
  - Fixes minor issue when passing `nil` to the class `find` method.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parse-stack (1.0.3)
4
+ parse-stack (1.0.4)
5
5
  active_model_serializers (>= 0.9, < 1)
6
6
  activemodel (>= 4, < 5)
7
7
  activesupport (>= 4, < 5)
data/README.md CHANGED
@@ -86,6 +86,7 @@ Parse::Stack is a full stack framework that utilizes several ideas behind [DataM
86
86
  require 'parse/stack'
87
87
 
88
88
  Parse.setup application_id: APP_ID, api_key: REST_API_KEY
89
+ # you may pass `server_url` as an option. Defaults to `https://api.parse.com/1/`
89
90
 
90
91
  # Object Mapper
91
92
  class Song < Parse::Object
@@ -99,9 +100,6 @@ class Song < Parse::Object
99
100
  has_many :likes, as: :user, through: :relation
100
101
  end
101
102
 
102
- # Optional schema updates (requires master key)
103
- Song.auto_upgrade!
104
-
105
103
  artist = Artist.first(:name.like => /Sinatra/, :genres.in => ['swing'])
106
104
 
107
105
  song = Song.new name: "Fly Me to the Moon"
@@ -7,7 +7,7 @@ module Parse
7
7
  module Analytics
8
8
 
9
9
  def send_analytics(event_name, data = {})
10
- request :post, "/1/events/#{event_name}", body: data
10
+ request :post, "events/#{event_name}", body: data
11
11
  end
12
12
 
13
13
  end
@@ -9,25 +9,25 @@ module Parse
9
9
  def fetch_app_keys(appid, email, password)
10
10
  headers = {}
11
11
  headers.merge!( { 'X-Parse-Email' => email, 'X-Parse-Password' => password } )
12
- request :get, "/1/apps/#{appid}", headers: headers
12
+ request :get, "apps/#{appid}", headers: headers
13
13
  end
14
14
 
15
15
  def fetch_apps(email, password)
16
16
  headers = {}
17
17
  headers.merge!( { 'X-Parse-Email' => email, 'X-Parse-Password' => password } )
18
- request :get, "/1/apps", headers: headers
18
+ request :get, "apps", headers: headers
19
19
  end
20
20
 
21
21
  def create_app(opts, email, password)
22
22
  headers = {}
23
23
  headers.merge!( { 'X-Parse-Email' => email, 'X-Parse-Password' => password } )
24
- request :post, "/1/apps", body: opts, headers: headers
24
+ request :post, "apps", body: opts, headers: headers
25
25
  end
26
26
 
27
27
  def update_app(appid, opts, email, password)
28
28
  headers = {}
29
29
  headers.merge!( { 'X-Parse-Email' => email, 'X-Parse-Password' => password } )
30
- request :put, "/1/apps/#{appid}", body: opts, headers: headers
30
+ request :put, "apps/#{appid}", body: opts, headers: headers
31
31
  end
32
32
 
33
33
 
@@ -47,7 +47,7 @@ module Parse
47
47
  end
48
48
 
49
49
  class BatchOperation
50
- MAX_REQ_SEC = 30
50
+ MAX_REQ_SEC = 40
51
51
 
52
52
  attr_accessor :requests, :responses
53
53
  include Enumerable
@@ -139,7 +139,7 @@ module Parse
139
139
  unless batch_operations.is_a?(Parse::BatchOperation)
140
140
  batch_operations = Parse::BatchOperation.new batch_operations
141
141
  end
142
- response = request(:post, "/1/batch", body: batch_operations.as_json)
142
+ response = request(:post, "batch", body: batch_operations.as_json)
143
143
  response.success? && response.batch? ? response.batch_responses : response
144
144
  end
145
145
 
@@ -5,11 +5,11 @@ module Parse
5
5
  module CloudFunctions
6
6
 
7
7
  def call_function(name, body = {})
8
- request :post, "/1/functions/#{name}", body: body
8
+ request :post, "functions/#{name}", body: body
9
9
  end
10
10
 
11
11
  def trigger_job(name, body = {})
12
- request :post, "/1/jobs/#{name}", body: body
12
+ request :post, "jobs/#{name}", body: body
13
13
  end
14
14
 
15
15
  end
@@ -8,7 +8,7 @@ module Parse
8
8
 
9
9
  def config
10
10
  if @config.nil?
11
- response = request :get, "/1/config".freeze
11
+ response = request :get, "config"
12
12
  unless response.error?
13
13
  @config = response.result["params"]
14
14
  end
@@ -9,7 +9,7 @@ module Parse
9
9
  def create_file(fileName, data = {}, content_type = nil)
10
10
  headers = {}
11
11
  headers.merge!( { Parse::Protocol::CONTENT_TYPE => content_type.to_s } ) if content_type.present?
12
- response = request :post, "/1/files/#{fileName}", body: data, headers: headers
12
+ response = request :post, "files/#{fileName}", body: data, headers: headers
13
13
  response.parse_class = "_File".freeze
14
14
  response
15
15
  end
@@ -6,7 +6,7 @@ module Parse
6
6
 
7
7
  module API
8
8
  module Hooks
9
- HOOKS_PREFIX = "/1/hooks/".freeze
9
+ HOOKS_PREFIX = "hooks/".freeze
10
10
  TRIGGER_NAMES = [:beforeSave, :afterSave, :beforeDelete, :afterDelete].freeze
11
11
  def _verify_trigger(triggerName)
12
12
  triggerName = triggerName.to_s.camelize(:lower).to_sym
@@ -5,7 +5,7 @@ module Parse
5
5
  #object fetch methods
6
6
  module Objects
7
7
 
8
- CLASS_PATH_PREFIX = "/1/classes/".freeze
8
+ CLASS_PATH_PREFIX = "classes/".freeze
9
9
  PREFIX_MAP = { installation: "installations", _installation: "installations",
10
10
  user: "users", _user: "users",
11
11
  role: "roles", _role: "roles",
@@ -25,7 +25,7 @@ module Parse
25
25
  uri = "#{CLASS_PATH_PREFIX}#{className}"
26
26
  class_prefix = className.downcase.to_sym
27
27
  if PREFIX_MAP.has_key?(class_prefix)
28
- uri = "/1/#{PREFIX_MAP[class_prefix]}/"
28
+ uri = "#{PREFIX_MAP[class_prefix]}/"
29
29
  end
30
30
  id.present? ? "#{uri}/#{id}" : uri
31
31
  end
@@ -6,7 +6,7 @@ module Parse
6
6
  module Push
7
7
 
8
8
  def push(payload = {})
9
- request :post, "/1/push".freeze, body: payload.as_json
9
+ request :post, "push".freeze, body: payload.as_json
10
10
  end
11
11
 
12
12
  end
@@ -5,7 +5,7 @@ module Parse
5
5
  module API
6
6
  #object fetch methods
7
7
  module Schema
8
- SCHEMA_PREFIX = "/1/schemas/".freeze
8
+ SCHEMA_PREFIX = "schemas/".freeze
9
9
  def schema(className)
10
10
  request :get, "#{SCHEMA_PREFIX}#{className}"
11
11
  end
@@ -6,7 +6,7 @@ module Parse
6
6
  module Users
7
7
  # Note that Parse::Objects mainly use the objects.rb API since we can
8
8
  # detect class names to proper URI handlers
9
- USER_PATH_PREFIX = "/1/users".freeze
9
+ USER_PATH_PREFIX = "users".freeze
10
10
  USER_CLASS = "_User".freeze
11
11
  def fetch_user(id)
12
12
  request :get, "#{USER_PATH_PREFIX}/#{id}"
data/lib/parse/client.rb CHANGED
@@ -26,7 +26,7 @@ module Parse
26
26
  include Parse::API::Schema
27
27
 
28
28
  attr_accessor :session, :cache
29
- attr_reader :application_id, :api_key, :master_key, :version, :host
29
+ attr_reader :application_id, :api_key, :master_key, :server_url
30
30
  # The client can support multiple sessions. The first session created, will be placed
31
31
  # under the default session tag. The :default session will be the default client to be used
32
32
  # by the other classes including Parse::Query and Parse::Objects
@@ -59,10 +59,9 @@ module Parse
59
59
  # :cache - Moneta::Transformer - if set, it should be a Moneta store instance
60
60
  # :expires - Integer - if set, it should be a Moneta store instance
61
61
  # :adapter - the HTTP adapter to use with Faraday, defaults to Faraday.default_adapter
62
- # :host - defaults to Parse::Protocol::Host (api.parse.com)
62
+ # :host - defaults to Parse::Protocol::SERVER_URL (https://api.parse.com/1/)
63
63
  def initialize(opts = {})
64
- @host = Parse::Protocol::HOST
65
- @version = 1
64
+ @server_url = opts[:server_url] || ENV["PARSE_SERVER_URL"] || Parse::Protocol::SERVER_URL
66
65
  @application_id = opts[:application_id] || ENV["PARSE_APP_ID"]
67
66
  @api_key = opts[:api_key] || ENV["PARSE_API_KEY"]
68
67
  @master_key = opts[:master_key] || ENV["PARSE_MASTER_KEY"]
@@ -71,9 +70,11 @@ module Parse
71
70
  if @application_id.nil? || ( @api_key.nil? && @master_key.nil? )
72
71
  raise "Please call Parse.setup(application_id:, api_key:) to setup a session"
73
72
  end
74
- @version_prefix = "/1/".freeze
73
+ @server_url += '/' unless @server_url.ends_with?('/')
75
74
  #Configure Faraday
76
- @session = Faraday.new("https://#{@host}", opts[:faraday]) do |conn|
75
+ opts[:faraday] ||= {}
76
+ opts[:faraday].merge!(:url => @server_url)
77
+ @session = Faraday.new(opts[:faraday]) do |conn|
77
78
  #conn.request :json
78
79
 
79
80
  conn.response :logger if opts[:logging]
@@ -138,11 +139,10 @@ module Parse
138
139
  # http method
139
140
  method = method.downcase.to_sym
140
141
  # set the User-Agent
141
- headers["User-Agent".freeze] = "Parse-Ruby-Mapper v#{Parse::Stack::VERSION}".freeze
142
+ headers["User-Agent"] = "Parse-Ruby-Client v#{Parse::Stack::VERSION}"
142
143
  #if it is a :get request, then use query params, otherwise body.
143
144
  params = (method == :get ? query : body) || {}
144
145
  # if the path does not start with the '/1/' prefix, then add it to be nice.
145
- uri.replace(@version_prefix + uri) unless uri.start_with?(@version_prefix)
146
146
  # actually send the request and return the body
147
147
  @session.send(method, uri, params, headers).body
148
148
  rescue Faraday::Error::ClientError => e
@@ -64,7 +64,8 @@ module Parse
64
64
  if method == :get && url.present? && @store.key?(url)
65
65
  puts("[Parse::Cache] >>> #{url}") if self.class.logging.present?
66
66
  response = Faraday::Response.new
67
- body = @store[url].body
67
+ res_env = @store[url] # previous cached response
68
+ body = res_env.respond_to?(:body) ? res_env.body : nil
68
69
  if body.present?
69
70
  response.finish({status: 200, response_headers: {}, body: body })
70
71
  return response
@@ -77,12 +78,12 @@ module Parse
77
78
  # request for the same '/1/classes/Artist/<objectId>' where objectId are equivalent
78
79
  @store.delete url
79
80
  end
80
- rescue Exception => e
81
+ rescue Errno::EINVAL, Redis::CannotConnectError => e
81
82
  # if the cache store fails to connect, catch the exception but proceed
82
83
  # with the regular request, but turn off caching for this request. It is possible
83
84
  # that the cache connection resumes at a later point, so this is temporary.
84
85
  cache_enabled = false
85
- warn "[Parse::Cache Error] Cache store connection failed. #{e}"
86
+ warn "[Parse::Cache Error] #{e}"
86
87
  end
87
88
 
88
89
 
@@ -4,6 +4,7 @@ module Parse
4
4
 
5
5
  module Protocol
6
6
  HOST = "api.parse.com".freeze
7
+ SERVER_URL = "https://api.parse.com/1/".freeze
7
8
  APP_ID = 'X-Parse-Application-Id'.freeze
8
9
  API_KEY = 'X-Parse-REST-API-Key'.freeze
9
10
  MASTER_KEY = 'X-Parse-Master-Key'.freeze
@@ -1,5 +1,5 @@
1
1
  module Parse
2
2
  module Stack
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
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.0.3
4
+ version: 1.0.4
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-02-03 00:00:00.000000000 Z
12
+ date: 2016-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel