Class: DataMapper::Parse::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/adapters/parse/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_id, api_key, master) ⇒ Engine

Returns a new instance of Engine.



35
36
37
38
# File 'lib/adapters/parse/engine.rb', line 35

def initialize(app_id, api_key, master)
  @app_id, @api_key, @master = app_id, api_key, master
  @client = build_client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



33
34
35
# File 'lib/adapters/parse/engine.rb', line 33

def client
  @client
end

Instance Method Details

#create(storage_name, attributes) ⇒ Object



51
52
53
# File 'lib/adapters/parse/engine.rb', line 51

def create(storage_name, attributes)
  client.post uri_for(storage_name), attributes.to_json
end

#delete(storage_name, id) ⇒ Object



47
48
49
# File 'lib/adapters/parse/engine.rb', line 47

def delete(storage_name, id)
  client.delete uri_for(storage_name, id)
end

#read(storage_name, params) ⇒ Object



40
41
42
43
44
45
# File 'lib/adapters/parse/engine.rb', line 40

def read(storage_name, params)
  query = params.inject({}) do |result, (k, v)|
    result.merge k.to_s => CGI.escape(v.to_s)
  end
  client.request uri_for(storage_name), :get, nil, query
end

#request_password_reset(email) ⇒ Object



68
69
70
# File 'lib/adapters/parse/engine.rb', line 68

def request_password_reset(email)
  client.post ::Parse::Protocol::PASSWORD_RESET_URI, {email: email}.to_json
end

#sign_in(username, password) ⇒ Object



59
60
61
# File 'lib/adapters/parse/engine.rb', line 59

def (username, password)
  client.request ::Parse::Protocol::USER_LOGIN_URI, :get, nil, { username: username, password: password }
end

#update(storage_name, id, attributes) ⇒ Object



55
56
57
# File 'lib/adapters/parse/engine.rb', line 55

def update(storage_name, id, attributes)
  client.put uri_for(storage_name, id), attributes.to_json
end

#upload_file(filename, content, content_type) ⇒ Object



63
64
65
66
# File 'lib/adapters/parse/engine.rb', line 63

def upload_file(filename, content, content_type)
  client = build_client(content_type: content_type)
  client.post ::Parse::Protocol.file_uri(URI.escape(filename)), content
end