Skip to content

Commit

Permalink
Merge pull request #58 from qixotic/installation
Browse files Browse the repository at this point in the history
Add support for _Installation objects.
  • Loading branch information
adelevie committed Jan 15, 2013
2 parents d8cf434 + e1cdf59 commit e844914
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/parse_resource/base.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"])
Expand Down
38 changes: 38 additions & 0 deletions 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

0 comments on commit e844914

Please sign in to comment.