Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #58 from qixotic/installation

Add support for _Installation objects.
  • Loading branch information...
commit e84491438cf1893821c103869b5c7195d8ead6ce 2 parents d8cf434 + e1cdf59
@adelevie authored
View
11 README.md
@@ -203,6 +203,17 @@ end
If you want to use parse_resource to back a simple authentication system for a Rails app, follow this [tutorial](http://asciicasts.com/episodes/250-authentication-from-scratch), and make some simple modifications.
+Installations
+
+Note: Because [Installations](https://parse.com/docs/rest#installations), are special in the Parse API, you must name your class Installation if you want to manipulate installation objects.
+
+```ruby
+class Installation < ParseResource::Base
+ fields :appName, :appVersion, :badge, :channels, :deviceToken, :deviceType,
+ :installationId, :parseVersion, :timeZone
+end
+```
+
GeoPoints
```ruby
View
4 lib/parse_resource/base.rb
@@ -89,6 +89,7 @@ def self.belongs_to(parent, options = {})
def to_pointer
klass_name = self.class.model_name
klass_name = "_User" if klass_name == "User"
+ klass_name = "_Installation" if klass_name == "Installation"
{"__type" => "Pointer", "className" => klass_name, "objectId" => self.id}
end
@@ -181,6 +182,8 @@ def self.resource
if model_name == "User" #https://parse.com/docs/rest#users-signup
base_uri = "https://api.parse.com/1/users"
+ elsif model_name == "Installation" #https://parse.com/docs/rest#installations
+ base_uri = "https://api.parse.com/1/installations"
else
base_uri = "https://api.parse.com/1/classes/#{model_name}"
end
@@ -388,6 +391,7 @@ def get_attribute(k)
when Hash
klass_name = attrs[k]["className"]
klass_name = "User" if klass_name == "_User"
+ klass_name = "Installation" if klass_name == "_Installation"
case attrs[k]["__type"]
when "Pointer"
result = klass_name.constantize.find(attrs[k]["objectId"])
View
38 test/test_parse_installation.rb
@@ -0,0 +1,38 @@
+require 'helper'
+require 'parse_resource'
+
+ParseResource::Base.load!(ENV["PARSE_RESOURCE_APPLICATION_ID"], ENV["PARSE_RESOURCE_MASTER_KEY"])
+
+
+class Installation < ParseResource::Base
+end
+
+class TestParseUser < Test::Unit::TestCase
+ #def setup
+ # User.destroy_all
+ #end
+
+ #def teardown
+ # User.destroy_all
+ #end
+
+ def test_creation
+ Installation.destroy_all
+ i = Installation.create(:deviceType => "ios",
+ :deviceToken => "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
+ :channels => [""])
+ assert_not_nil(i.id)
+ assert i.errors.empty?
+ end
+
+ def test_creation_validation_check
+ Installation.destroy_all
+ # missing deviceType
+ i = Installation.create(:deviceToken => "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
+ :channels => [""])
+ assert_equal false, i.errors.empty?
+ # TODO: actually check for the parse error code 135, once ParseError is
+ # fixed to actually represent parse error codes.
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.