Git Product home page Git Product logo

parse_resource's Introduction

ParseResource

Maintainer needed

Unfortunately, I haven't been able to give this library the time it deserves. If you'd like to be a maintainer, please let me know.

Build Status Code Climate

ParseResource makes it easy to interact with Parse.com's REST API. It adheres to the ActiveRecord pattern. ParseResource is fully ActiveModel compliant, meaning you can use validations and Rails forms.

Ruby/Rails developers should feel right at home.

If you're used to Post.create(:title => "Hello, world", :author => "Octocat"), then this is for you.

Features

  • ActiveRecord-like API, almost no learning curve
  • Validations
  • Rails forms and scaffolds just work

Use cases

  • Build a custom admin dashboard for your Parse.com data
  • Use the same database for your web and native apps
  • Pre-collect data for use in iOS and Android apps

Installation

Include in your Gemfile:

gem "kaminari" # optional for pagination support
gem "parse_resource", "~> 1.8.0"

Or just gem install:

gem install kaminari # optional for pagination support
gem install parse_resource

Create an account at Parse.com. Then create an application and copy the app_id and master_key into a file called parse_resource.yml. If you're using a Rails app, place this file in the config folder.

development:
  app_id: 1234567890
  master_key: abcdefgh

test:
  app_id: 1234567890
  master_key: abcdefgh

production:
  app_id: 1234567890
  master_key: abcdefgh

If you keep parse_resource.yml in .gitignore, ParseResource will alternatively look for the api keys in environment variables. If using Heroku you can easily set your api keys in the Heroku environment using:

heroku config:set PARSE_RESOURCE_APPLICATION_ID=1234567890
heroku config:set PARSE_RESOURCE_MASTER_KEY=abcdefgh

You can create separate Parse databases if you want. If not, include the same info for each environment.

In a non-Rails app, include this somewhere (preferable in an initializer):

ParseResource::Base.load!("your_app_id", "your_master_key")

Usage

Create a model:

class Post < ParseResource::Base
  fields :title, :author, :body

  validates_presence_of :title
end

If you are using version 1.5.11 or earlier, subclass to just ParseResource--or just update to the most recent version.

Creating, updating, and deleting:

p = Post.new

# validations
p.valid? #=> false 
p.errors #=> #<ActiveModel::Errors:0xab71998 ... @messages={:title=>["can't be blank"]}> 
p.title = "Introducing ParseResource" #=> "Introducing ParseResource" 
p.valid? #=> true 

# setting more attributes, then saving
p.author = "Alan deLevie" 
p.body = "Ipso Lorem"
p.date = Time.now
p.save #=> true

# checking the id generated by Parse's servers
p.id #=> "QARfXUILgY" 
p.updated_at #=> nil 
p.created_at #=> "2011-09-19T01:32:04.973Z" # does anybody want this to be a DateTime object? Let me know.

# updating
p.title = "[Update] Introducing ParseResource"
p.save #=> true
p.updated_at #=> "2011-09-19T01:32:37.930Z" # more magic from Parse's servers

# destroying an object
p.destroy #=> true 
p.title #=> nil

Finding:

posts = Post.where(:author => "Arrington")
# the query is lazy loaded
# nothing gets sent to the Parse server until you run #all, #count, or any Array method on the query 
# (e.g. #first, #each, or #map)

posts.each do |post|
  "#{post.title}, by #{post.author}"
end

posts.map {|p| p.title} #=> ["Unpaid blogger", "Uncrunched"]

id = "DjiH4Qffke"
p = Post.find(id) #simple find by id

# ActiveRecord style find commands
Post.find_by(:title => "Uncrunched") #=> A Post object
Post.find_by_title("Uncrunched") #=> A Post object
Post.find_all_by_author("Arrington") #=> An Array of Posts

# batch save an array of objects
Post.save_all(array_of_objects)

# destroy all objects, updated to use Parse batch destroy
Post.destroy_all(array_of_objects)

# you can chain method calls, just like in ActiveRecord
Post.where(:param1 => "foo").where(:param2 => "bar").all


# limit the query
posts = Post.limit(5).where(:foo => "bar")
posts.length #=> 5

# get a count
Post.where(:bar => "foo").count #=> 1337

Pagination with kaminari:

# get second page of results (default is 25 per page)
Post.page(2).where(:foo => "bar")

# get second page with 100 results per page
Post.page(2).per(100).where(:foo => "bar")

Users

Note: Because users are special in the Parse API, you must name your class User if you want to subclass ParseUser.

# app/models/user.rb
class User < ParseUser
  # no validations included, but feel free to add your own
  validates_presence_of :username
  
  # you can add fields, like any other kind of Object...
  fields :name, :bio
  
  # but note that email is a special field in the Parse API.
  fields :email
end

# create a user
user = User.new(:username => "adelevie")
user.password = "asecretpassword"
user.save #=> true
# after saving, the password is automatically hashed by Parse's server
# user.password will return the unhashed password when the original object is in memory
# from a new session, User.where(:username => "adelevie").first.password will return nil

# check if a user is logged in
User.authenticate("adelevie", "foooo") #=> false
User.authenticate("adelevie", "asecretpassword") #=> #<User...>


# A simple controller to authenticate users
class SessionsController < ApplicationController
  def new
  end
  
  def create
    user = User.authenticate(params[:username], params[:password])
    if user
      session[:user_id] = user.id
      redirect_to root_url, :notice => "logged in !"
    else
      flash.now.alert = "Invalid username or password"
      render "new"
    end
  end
  
  def destroy
    session[:user_id] = nil
    redirect_to root_url, :notice => "Logged out!"
  end

end

If you want to use parse_resource to back a simple authentication system for a Rails app, follow this tutorial, and make some simple modifications.

Installations

Note: Because Installations, are special in the Parse API, you must name your class Installation if you want to manipulate installation objects.

class Installation < ParseResource::Base
  fields :appName, :appVersion, :badge, :channels, :deviceToken, :deviceType,
         :installationId, :parseVersion, :timeZone
end

GeoPoints

class Place < ParseResource::Base
  fields :location
end

place = Place.new
place.location = ParseGeoPoint.new :latitude => 34.09300844216167, :longitude => -118.3780094460731
place.save
place.location.inspect #=> #<ParseGeoPoint:0x007fb4f39c7de0 @latitude=34.09300844216167, @longitude=-118.3780094460731>


place = Place.new
place.location = ParseGeoPoint.new
place.location.latitude = 34.09300844216167
place.location.longitude = -118.3780094460731
place.save
place.location.inspect #=> #<ParseGeoPoint:0x007fb4f39c7de0 @latitude=34.09300844216167, @longitude=-118.3780094460731>

server_place = Place.find(place.objectId)
server_place.location.inspect #=> #<ParseGeoPoint:0x007fb4f39c7de0 @latitude=34.09300844216167, @longitude=-118.3780094460731>
server_place.location.latitude #=> 34.09300844216167
server_place.location.longitude #=> -118.3780094460731

Querying by GeoPoints

Place.near(:location, [34.09300844216167, -118.3780094460731], :maxDistanceInMiles => 10).all
Place.near(:location, [34.09300844216167, -118.3780094460731], :maxDistanceInKilometers => 10).all
Place.near(:location, [34.09300844216167, -118.3780094460731], :maxDistanceInRadians => 10/3959).all
Place.within_box(:location, [33.81637559726026, -118.3783150233789], [34.09300844216167, -118.3780094460731]).all

DEPRECATED Associations

class Post < ParseResource::Base
  # As with ActiveRecord, associations names can differ from class names...
  belongs_to :author, :class_name => 'User'
  fields :title, :body
end

class User < ParseUser
  # ... but on the other end, use :inverse_of to complete the link.
  has_many :posts, :inverse_of => :author
  field :name
end

author = Author.create(:name => "RL Stine")
post1 = Post.create(:title => "Goosebumps 1")
post2 = Post.create(:title => "Goosebumps 2")

# assign from parent class
author.posts << post1
author.posts << post2 

# or assign from child class
post3 = Post.create(:title => "Goosebumps 3")
post3.author = author
post3.save #=> true

# relational queries
posts = Post.include_object(:author).all
posts.each do |post|
	puts post.author.name
	# because you used Post#include_object, calling post.title won't execute a new query
	# this is similar to ActiveRecord's eager loading
end

# fetch users through a relation on posts named commenters
post = Post.first
users = User.related_to(post, :commenters)

File Upload

  @post = Post.first()
  result = Post.upload(uploaded_file.tempfile, uploaded_file.original_filename, content_type: uploaded_file.content_type)
  @post.thumbnail = {"name" => result["name"], "__type" => "File", "url" => result["url"]}

Custom Getters and Setters

  def name
    val = get_attribute("name")
    # custom getter actions here
    val
  end

  def name=(val)
    # custom setter actions to val here
    set_attribute("name", val)
  end

Documentation

Here

To-do

  • User authentication
  • Better documentation
  • Associations
  • Callbacks
  • Push notifications
  • Better type-casting
  • HTTP request error handling

User authentication is my top priority feature. Several people have specifically requested it, and Parse just began exposing User objects in the REST API.

Let me know of any other features you want.

Contributing to ParseResource

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Create parse_resource.yml in the root of the gem folder. Using the same format as parse_resource.yml in the instructions (except only creating a test environment, add your own API keys.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright (c) 2013 Alan deLevie. See LICENSE.txt for further details.

parse_resource's People

Contributors

adelevie avatar anamba avatar arcticleo avatar awakia avatar chytreg avatar cpjolicoeur avatar emcmanus avatar epicdraws avatar ericreid avatar jamonholmgren avatar jdmaresco avatar joekain avatar kevinvangelder avatar lenart avatar luvtechno avatar lynnagara avatar nankrah avatar qixotic avatar sbonami avatar seanabrahams avatar tjalil avatar yulolimum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parse_resource's Issues

Error when saving a new user

When I attempt to save a new user, I get an error:

TypeError in UsersController#create

class or module required for rescue clause

parse_resource (1.8.0) lib/parse_resource/base.rb:401:in `rescue in save'
parse_resource (1.8.0) lib/parse_resource/base.rb:390:in `save'
app/controllers/users_controller.rb:9:in `create'

The user class is pretty simple:

class User < ParseUser
  alias :email :username
  fields :email, :first_name, :last_name
end

I've tried to dig into things, and it appears to be that I'm getting 401 Unauthorized, however, when I do this in the console:

irb(main):005:0> u=User.new
=> #<User:0x007fd314251f40 @unsaved_attributes={}, @attributes={}, @error_instances=[]>
irb(main):006:0> u.email='[email protected]'
=> "[email protected]"
irb(main):007:0> u.username='[email protected]'
=> "[email protected]"
irb(main):008:0> u.password='password'
=> "password"

u.resource
=> #<RestClient::Resource:0x007fd31584d358 @url="https://api.parse.com/1/users", @block=nil, @options={:user=>"<AppID Removed>", :password=>"<API Key Removed>"}>
irb(main):006:0> u.create
RuntimeError: Parse error : Unknown Error unauthorized

The user and password fields seem correct. I've tried with both the REST API Key and the Master API Key, but in both cases, calling create brings up the error.

Using the standard parse-ruby-client gem works fine, so I know I've got the keys right.

Problems with date objects

When I try to get date object, it returns me nil. But if I call "attributes" method in output i see that there is not nil date object.

Query Issue

Hi guys. I'm using this and tried to create a CRUD application to manage data from parse.com. When I fetch data it only returns 100 rows, but should be more than that. What am I missing?

Thanks

GeoPoints support

Implementation of GeoPoints support in line with the published REST API is missing. I think we could mimic the Android API with equivalent constructors and methods:

Constructors

ParseGeoPoint()
ParseGeoPoint(double latitude, double longitude)

Methods

double distanceInKilometersTo(ParseGeoPoint point)
double distanceInMilesTo(ParseGeoPoint point)
double distanceInRadiansTo(ParseGeoPoint point)
double getLatitude()
double getLongitude()
void setLatitude(double latitude)
void setLongitude(double longitude)

Receive bad Request when creating new User in Rails 3

Hi Alan,

First of all many thanks for all your contribution with this gem it is very helpfull for us!!!

In my Rails 3 app, I'm trying to create a User (ParseUser) but received a 400 Bad Request (trace below)
Therefore, when I create a new one directly from the rails console it works (I can see it on my class in Parse.com) .
From my Rails application when I edit an existing user it works too.

Any suggestion?

Cheers,

Philippe

RestClient::BadRequest in UsersController#create

400 Bad Request
Rails.root: /Users/saigonaut/Work/Projects/RoR/parsetest

Application Trace | Framework Trace | Full Trace
app/controllers/users_controller.rb:46:in block in create' app/controllers/users_controller.rb:45:increate'
Request

Parameters:

{"utf8"=>"✓",
"authenticity_token"=>"wNzLZQ7j56RQTUbjV6BkcCb4k2rGNHe5+tE292iXXQw=",
"user"=>{"name"=>"Toto",
"username"=>"toto",
"email"=>"toto"},
"commit"=>"Create User"}

Why were associations deprecated?

I can't find any discussion threads (and didn't go back through the commit history) on why associations were deprecated. Not having them is really messing up my code.

Naming a ParseUser a different class name doesn't work

If you name a ParseUser class a name other than "User" it will attempt to persist to Parse using that name, and not make the special Parse "User" class. In other words, it creates a generic class, which doesn't have auth capabilities.

Issue with Sessions (find_by_email) and Query strings

I'm using the parse-resource gem to use Parse along with my Rails App. I am running into two issues:

I just changed my db/server from Heroku to Parse to allow for a mobile app to talk to my Rails app and although I can create users with a regular sign up form written in HTML, I can't use a query string to link 2 models together.

I have a User model that belongs_to a Partner and a Partner has_many Users. The User model also has a foreign key, called :partner_id which is an integer. (But Parse stores it as a string, but I changed it to a number which I don't know matters or not?). I am trying to get Users to sign up via a new user form via a query string:

localhost:3000/users/new?partner_id=1

But when I sign up a user via this link, it doesn't get saved to a db. If I use:

localhost:3000/users/new

the user gets saved successfully.

Is there a limitation in Parse or the resource gem which is causing this?

One more issue:

I also noted that when I sign up a user without the query string, a new session is created. But if I sign out and then sign in, a session is not created. I have been using the bcrypt gem for Rails so far and just transferred by db from Heroku to Parse. Is this potentially because of bcrypt? Do I need to remove it and if so, how?

I am creating a new session with :email and :password.

def create
# user = User.find_by_email("params[:email]") ------- old Rails code - when using Parse, find_by_email does NOT work.
# user && user.authenticate(params[:password]) ---------old Rails code

    user = User.authenticate(params[:email], params[:password])    #------using parse-resource code and replacing username with email since that what users sign in with
     if user
      session[:uid] = user.id
      redirect_to pictures_url, notice: "Welcome #{user.name}!"
    else
      flash[:notice] = "Unknown email or password"
      render :new
    end
end

I get an error "Unknown email and password".

Thanks for your help!

Unauthorized error when no auth required

Error output in console:

$ rc                                                                                                                                          Loading development environment (Rails 3.2.11)
irb(main):001:0> Exercise
=> Exercise
irb(main):002:0> Exercise.first
RestClient::Unauthorized: 401 Unauthorized: {"error":"unauthorized"}
... rest of stack trace

Model class:

class Exercise < ParseResource::Base
    fields :workout, :step, :instruction, :repetitions

end

Parse credentials loaded in an initializer from ENV vars (which I confirmed via echo $VAR in Terminal):

ParseResource::Base.load!(ENV["PARSE_APP_KEY"], ENV["PARSE_JS_KEY"])

Memcache?

Hey there,

Has anyone looked into using memcache to temporarily cache objects from parse_resource? Marshal.dump & Marshal.load seem to work fine on objects, so it should just be a matter of wrapping things, but I figured I'd ask before going off on my own.

Thanks!

Need to set class name for Parse object if different from model name

I'm building a Rails app that integrates with an existing Parse.com database. The class names in Parse are already set and are coded into the mobile app that uses the database. The naming convention for the Parse classes is in some cases incompatible with standard Rails model names -- "userInfo", for example.

It would be super handy if there was a way to specify the Parse class name in a Parse resource model file, just as you can specify the table name for an ActiveRecord model if it differs from the model name.

I hunted through the source to see if this feature was already enabled but it didn't appear to be.

validates_uniqueness_of

Is the validation not supported?

validates_uniqueness_of
or
validates :email, uniqueness: true

Some Objects don't return an ID

On some calls id is not properly set on an object

ruby-1.9.2-p180 :003 > line = Line.find('PgnYYDiIpY')
=> #<Line:0x0000010295bfe8 @unsaved_attributes={}, @attributes={"scriptId"=>"ERzRstMbzl", "character"=>"ESTRAGON", "line"=>"Am I?", "gender"=>"female", "createdAt"=>"2012-03-21T00:39:08.895Z", "updatedAt"=>"2012-03-21T00:39:08.895Z", "objectId"=>"PgnYYDiIpY"}>
ruby-1.9.2-p180 :012 > line.id
=> nil

This only happens on some objects, other objects will produce line.id fine?!

REST API key

Is it possible to use the REST API key instead of the master key?
I've tried changing the keys in my app initializer as well as the .yml file to no avail.

Looks like the X-Parse-REST-API-Key header needs to be set - possible to do just by changing keys, or does this header need to be added in the base.rb file?

Thank you.

updating ParseGeoPoint doesn't work.

Once geopoints are set it seems to be impossible to change them.

2.0.0 (main):0 > c.location
=> #<ParseGeoPoint:0x007feb334134a0 @latitude=-33.9034209, @longitude=151.1799153>
2.0.0 (main):0 > c.location = ParseGeoPoint.new :latitude => 35.2046666, :longitude => -101.856855
=> #<ParseGeoPoint:0x007feb33438f70 @latitude=35.2046666, @longitude=-101.856855>
2.0.0 (main):0 > c.save

It seems to work on save, but when I reload the record, changes were not made. ;-(

c=Place.find("zKpVS3IyxT")
2.0.0 (main):0 > c.location
=> #<ParseGeoPoint:0x007feb34654768 @latitude=-33.9034209, @longitude=151.1799153>

RSpec in Parse-Resource

Hi guys,

your parse-resource is pretty good,I like it.

and I have found that it is like ActiveRecord,but it is NOT ActiveRecord,and when I use RSpec to test user model,I found some validates can not be used.

fox example:If I use validate like this user model:
validates :username, presence:true, format: { with: VALID_EMAIL_REGEX }, uniqueness:true

it will give me a error,it said that .rvm/gems/ruby-2.0.0-p0/gems/activemodel-3.2.13/lib/active_model/validations/validates.rb:96:in `rescue in block in validates': Unknown validator: 'UniquenessValidator' (ArgumentError)

so if I want to use RSpec to test,how should I test user model's uniqueness?

Thanks in advance!
Blues

Parse Image Uploading

Do you have any plans to add Parse Image Uploading? I may try to do it myself but I would have to spend a lot more time familiarizing myself with your code and the gems you are using than you would.

default_scope

I want to enable a default scope in model, just like ActiveRecord, query, create and update will do in the scope, do you know where to change is better? Thanks.

how to save Array column type? without having "backslash"

The right array format store in parse.com
[{"file_id":"waqGsH5Auu","file_type":"image","user_id":"Vj2Dvz00sK","username":"John"}]

But when I use this below
personal.MAFiles = Array({"file_id"=>"waqGsH5Auu","file_type"=>"image","user_id"=>"Vj2Dvz00sK","username"=>"John"}.to_json)

it save in parse.com as
["{"file_id":"waqGsH5Auu","file_type":"image","user_id":"Vj2Dvz00sK","username":"John"}"]

It save in the parse.com with additional "/" how do I remove the "/" when saving?

Ability to save an object relation

I notice in the README that associations are deprecated, does this mean there is no way to save a relationship currently. If so is this a planned feature?

Devise support

Is it possible for parse_resource work with devise? Thanks.

integrate with squeel where statement

Hi

Have you ever use squeel before? It is a convenient way to write where clause.

However, it cannot work with parse_resource. Do you think parse_resource can use where statement like that? It also seems good for searching something nil or not empty.

Twitter bootstrap generator fails due to columns method being missing from class

I'm trying to use twitter-bootstrap-rails to generate Bootstrap themed views, but as ParseResource::Base is missing ActiveRecord::Base class methods, the generation fails:

rails g bootstrap:themed Articles
...
`method_missing': undefined method `columns' for Article:Class (NoMethodError)

Is there anyway to add column 'faking' to ParseResouce::Base to allow thrid-party generators to work?

test_to_date_object failing

test_to_date_object fails in master. Is this happening only for me? I'm guessing it's something with timezone (I live in timezone of UTC+9 and ran the test at 15:00 pm). Let me know if I can help anything.

     test_to_date_object                                       0:00:01.028 FAIL
        Failed assertion, no message given.
        Assertion at:
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:200:in `assert'
        test/test_parse_resource.rb:349:in `block in test_to_date_object'
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/vcr-2.4.0/lib/vcr/util/variable_args_block_caller.rb:9:in `call'
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/vcr-2.4.0/lib/vcr/util/variable_args_block_caller.rb:9:in `call_block'
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/vcr-2.4.0/lib/vcr.rb:173:in `use_cassette'
        test/test_parse_resource.rb:344:in `test_to_date_object'
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1301:in `run'
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:867:in `_run_anything'
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1060:in `run_tests'
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1047:in `block in _run'
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1046:in `each'
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1046:in `_run'
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1035:in `run'
        ~/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:789:in `block in autorun'

Using ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.4.1] on OSX

DateTime attributes are not supported

Setting a DateTime attribute on an object results in a 400 response from Parse on create and save methods.

I'm taking a look at the code to try and identify why this would happen, but I'm more of a Objective-C programmer than Ruby, so I haven't found anything yet.

User email field inaccessible

In the documentation you say:
# you can add fields, like any other kind of Object...
fields :name, :bio
# but note that email is a special field in the Parse API.
fields :email
but you don't say what is special about it or how to access it. Additionally, the documentation on Parse.com does not indicate there is anything special about emails or accessing them. Can you make the email field accessible and/or update your documentation?

Thanks!

Use .where() on DateTime fields

I've tried several variations on how I imagine I would construct the where clause to include DateTime fields but I can't seem to make anything work. I'd like to be able to get all Posts, for example, where the object creation date is greater than a certain DateTime value. Is there any way to do this? If not, I'll fork and experiment...

model generator

Is there a model generator for parse_resource? I skipped the active record when creating project. Now generating scaffold is a big problem. Will fail in orm missing.

uninitialized constant ParseGeoPoint

Hi guys,

Im trying to use use the class ParseGeoPoint in a controller like the next one:

  1. require 'parse_resource'
  2. class HomeController < ApplicationController
    
  3. def index
    
  4.   ParseResource::Base.load!("app_id", "master_key")
    
  5.   place = Place.new
    
  6.   place.name = "Office"
    
  7.   place.location = ParseGeoPoint.new  
    
  8. end
    11.
    12.end

But im getting the next error:

NameError (uninitialized constant HomeController::ParseGeoPoint):
app/controllers/home_controller.rb:9:in `index'

Is there any problem with this code?

parse-ruby-client -- quick question.

Alan,

Can you quickly outline your goals for integrating parse-ruby-client into parse_resource? Does it make sense to do at this point? I don't know parse-ruby-client very well, so I'm not quite sure what jobs it would take on internally and it would be nice to get a sense for how things would change on the parse_resource API as well as the internal code.

Jamon

get_attribute and set_attribute

I just wanted to ask if get_attribute and set_attribute are supported (they're listed in the docs), but I get:
undefined method `set_attribute' for #Spot:0x007fd04451ef70

Also when I create a method for some field, like

def address=(val)
  #something
end

it doesn't seem to get executed at all :s

Thank you!

.save returns nil instead of updated object

On running a simple change to an object and saving I'm getting nil back instead of #<Store>. I've verified that I'm running the latest version and I'm pretty sure my models are correctly inheriting ParseResource::Base. Am I doing something wrong or is there an error in the Base?

jamons-imac:bigdaywebapp.dev kvg$ rails c
Loading development environment (Rails 3.2.6)
1.9.3p194 :001 > s = Store.find_by_name("Amazon Test2")
 => #<Store:0x007ff28af50698 @unsaved_attributes={}, @attributes={"affiliateLink"=>"http://www.amazon.com/?tag=bigdaysho-20", "category"=>"", "mobileOptimized"=>true, "name"=>"Amazon Test2", "createdAt"=>"2012-09-12T18:57:27.007Z", "updatedAt"=>"2012-09-14T21:20:25.702Z", "objectId"=>"M5XZ7ldArX"}>
1.9.3p194 :002 > s.name = "Amazon"
 => "Amazon"
1.9.3p194 :003 > save = s.save
 => nil
1.9.3p194 :004 > save
 => nil
1.9.3p194 :005 > s = Store.find_by_name("Amazon")
 => #<Store:0x007ff28ae17f10 @unsaved_attributes={}, @attributes={"affiliateLink"=>"http://www.amazon.com/?tag=bigdaysho-20", "category"=>"", "mobileOptimized"=>true, "name"=>"Amazon", "createdAt"=>"2012-09-12T18:57:27.007Z", "updatedAt"=>"2012-09-14T21:20:46.377Z", "objectId"=>"M5XZ7ldArX"}>
1.9.3p194 :006 >

Order doesn't take a direction

Order should take an argument for ASC or DESC like ActiveRecord. Maybe you could implement this when you rewrite the order method?

Getting a 401 unauthorized error.

  1. Fresh install of Ruby on Rails
  2. Using the Gem
  3. Using the following code for Parse login:
    ParseResource::Base.load!("myappid", "mymasterkey")
  4. Created a User model
  5. Any calls to the database result in the 401 error:
    RestClient::Unauthorized: 401 Unauthorized: {"error":"unauthorized"}

Cannot create resource on class with number column

My scheme has some columns of number type, give them string will fail with message "@messages={:f=>["i"]}". But all params from a form is in string. Currently I have to convert them in controller, that's very tedious. In other ORM like Mongoid and Datamapper, I can set field type for each field, and they will convert it automatically. Is there a good way to let parse resource has this feature?

Validations Question (I assume I'm missing something in what I'm doing)

Starting with:
class PUser < ParseResource::Base
fields :name, :email

validates_presence_of :name
end

Running:

@user = PUser.new(name: "", email: "[email protected]")
Returns:
... " @unsaved_attributes={:name=>"", :email=>"[email protected]"},
@attributes={:name=>"", :email=>"[email protected]"}>"

and ....

@user.valid?
false

then ...

@user.name = "Kim"
"Kim"
@user
@unsaved_attributes={:name=>"", :email=>"[email protected]", "name"=>"Kim"}, @attributes={:name=>"", :email=>"[email protected]", "name"=>"Kim"}, @validation_context=nil, @errors=#<ActiveModel::Errors:0x007f84f4eb7d20 @base=#<PUser:0x007f84f73364a8 ...>, @messages={:name=>["can't be blank"]}>>

But ...

@user.valid?
false

I see the "@unsaved_attributes={:name=>"" and "name"=>"Kim"}, but why is that so?

The Validation example on your readme does not see to get the same results?

/kim

Zero-bytes uploaded images

Hi,

I cannot seem to upload images successfully… my code:

  def create
    image = Image.create(params)
    uploaded_file = params[:spot][:image]
    result = Image.upload(uploaded_file.tempfile, uploaded_file.original_filename, content_type: uploaded_file.content_type)
    Image.create :file => { "name" => result["name"], "__type" => "File" }       
  end

The resulting image:
http://files.parse.com/ad1f6da6-cae0-4847-9aaf-690ef786a4be/79987359-30f0-49fc-9483-a9093e18d152-IMG_7946.JPG

is zero bytes :(

I tried this:

curl -X POST
-H "X-Parse-Application-Id: xxx"
-H "X-Parse-REST-API-Key: yyy"
-H "Content-Type: image/jpeg"
--data-binary '@aa.png'
https://api.parse.com/1/files/aa.png

and the image is uploaded ok..

Another issue: I asked about it on the Parse forum:
https://parse.com/questions/parse-error-106

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.