Coder Social home page Coder Social logo

parse-ruby-client's Introduction

Build Status

The original creator of parse-ruby-client, aalpern, has decided to stop work on the project. I'm going to give the project new life, first by maintaining the project as a gem, and second by eventually making it power parse_resource under the hood.

Ruby Client for parse.com REST API

This file implements a simple Ruby client library for using Parse's REST API. Rather than try to implement an ActiveRecord-compatible library, it tries to match the structure of the iOS and Android SDKs from Parse.

So far it supports simple GET, PUT, and POST operations on objects. Enough to read & write simple data.

New in 0.1.1

  • query ordering
  • reserved keys no longer deleted on update

Dependencies

This currently depends on the gems 'json' and 'patron' for JSON support and HTTP, respectively.

Getting Started

Installation

gem "parse-ruby-client", "~> 0.1.1"


To get started, load the parse.rb file and call Parse.init to initialize the client object with your application ID and API key values, which you can obtain from the parse.com dashboard.

require 'parse-ruby-client'

Parse.init :application_id => "<your_app_id>",
           :api_key        => "<your_api_key>"

If you don't like pasting this stuff in every time you fire up irb, save your api keys to .bash_profile or similar:

export PARSE_APPLICATION_ID="12345678"
export PARSE_REST_API_KEY="ABCDEFGH"

Now you can just do this:

Parse.init

The test folder assumes this naming convention for environment variables, so if you want to run the tests, you must do this. But it's easy. And good for you, too.

Creating and Saving Objects

Create an instance of Parse::Object with your class name supplied as a string, set some keys, and call save().

game_score = Parse::Object.new "GameScore"
game_score["score"] 		= 1337
game_score["playerName"]	= "Sean Plott"
game_score["cheatMode"] 	= false
game_score.save

Alternatively, you can initialize the object's initial values with a hash.

game_score = Parse::Object.new "GameScore", {
	"score" => 1337, "playerName" => "Sean Plott", "cheatMode" => false
}

Or if you prefer, you can use symbols for the hash keys - they will be converted to strings by Parse::Object.initialize().

game_score = Parse::Object.new "GameScore", {
		:score => 1337, :playerName => "Sean Plott", :cheatMode => false
}

Retrieving Objects

Individual objects can be retrieved with a single call to Parse.get() supplying the class and object id.

game_score = Parse.get "GameScore", "xWMyZ4YEGZ"

All the objects in a given class can be retrieved by omitting the object ID. Use caution if you have lots and lots of objects of that class though.

all_scores = Parse.get "GameScore"

Queries

Queries are supported by the Parse::Query class.

# Create some simple objects to query
(1..100).each { |i|
  score = Parse::Object.new "GameScore"
  score["score"] = i
  score.save
}

# Retrieve all scores between 10 & 20 inclusive
Parse::Query.new("GameScore")   \
  .greater_eq("score", 10)      \
  .less_eq("score", 20)         \
  .get

# Retrieve a set of specific scores
Parse::Query.new("GameScore")           \
  .value_in("score", [10, 20, 30, 40])  \
  .get

Push Notifications

push = Parse::Push.new({"alert" => "I'm sending this push to all my app users!"})
push.save

TODO

  • Add some form of debug logging
  • Support for Date, Pointer, and Bytes API data types
  • ACLs
  • Login

Resources

parse-ruby-client's People

Contributors

aalpern avatar adelevie avatar ericcj avatar ifuller avatar jeiting avatar lsiqueira avatar tikhon avatar

Stargazers

 avatar

Watchers

 avatar

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.