Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a series of shortcuts methods to instantiate objects from the client #167

Merged
merged 2 commits into from
Jun 8, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add a series of shortcuts methods to instantiate objects from the client
  • Loading branch information
Lawrence Oluyede committed Jun 8, 2015
commit 39cd3ae61b4f28d47aa44f8a99e92619f9eec7e6
25 changes: 24 additions & 1 deletion lib/parse/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
require 'parse/util'

require 'logger'
module Parse

module Parse
# A class which encapsulates the HTTPS communication with the Parse
# API server.
class Client
Expand Down Expand Up @@ -87,6 +87,29 @@ def delete(uri)
request(uri, :delete)
end

def batch
Parse::Batch.new(self)
end

def cloud_function(function_name)
Parse::Cloud::Function.new(function_name, self)
end

def file(data)
Parse::File.new(data, self)
end

def object(class_name, data = nil)
Parse::Object.new(class_name, data, self)
end

def push(data, channel = '')
Parse::Push.new(data, channel, self)
end

def query(class_name)
Parse::Query.new(class_name, self)
end
end


Expand Down
41 changes: 41 additions & 0 deletions test/test_client_create.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
require 'helper'

class TestClientShortcuts < ParseTestCase
def test_batch
batch = @client.batch
assert batch.is_a? Parse::Batch
assert_equal @client, batch.client
end

def test_cloud_function
cloud_function = @client.cloud_function('whatever')
assert cloud_function.is_a? Parse::Cloud::Function
assert_equal @client, cloud_function.client
end

def test_file
file = @client.file({
:body => "Hello World!",
:local_filename => "hello.txt",
:content_type => "text/plain"})
assert file.is_a? Parse::File
assert_equal @client, file.client
end

def test_object
object = @client.object('Post')
assert object.is_a? Parse::Object
assert_equal @client, object.client
end

def test_push
push = @client.push({:alert => 'message'})
assert push.is_a? Parse::Push
assert_equal @client, push.client
end

def test_query
query = @client.query('Post')
assert query.is_a? Parse::Query
assert_equal @client, query.client
end
end

class TestClientCreate < ParseTestCase

def stubbed_client(&block)
Expand Down