Class: NCMB::Script

Inherits:
Object
  • Object
show all
Includes:
NCMB
Defined in:
lib/ncmb/script.rb

Constant Summary

Constants included from NCMB

API_VERSION, DOMAIN, SCRIPT_API_VERSION, SCRIPT_DOMAIN

Instance Method Summary collapse

Methods included from NCMB

CurrentUser, initialize

Constructor Details

#initialize(name) ⇒ Script

Returns a new instance of Script.



6
7
8
9
# File 'lib/ncmb/script.rb', line 6

def initialize(name)
  @name = name
  @params = {}
end

Instance Method Details

#body(params) ⇒ Object



42
43
44
45
# File 'lib/ncmb/script.rb', line 42

def body(params)
  @params[:body] = params
  self
end

#delete(params = {}) ⇒ Object



23
24
25
26
# File 'lib/ncmb/script.rb', line 23

def delete(params = {})
  self.set(params)
  @@client.delete 
end

#execute(method) ⇒ Object



52
53
54
# File 'lib/ncmb/script.rb', line 52

def execute(method)
  @@client.send(method, "/#{@@client.script_api_version}/script/#{@name}", (@params[:query] || {}).merge(@params[:body] || {}), @params[:header])
end

#get(params = {}) ⇒ Object



11
12
13
# File 'lib/ncmb/script.rb', line 11

def get(params = {})
  self.set(params).execute('get')
end

#header(params) ⇒ Object



37
38
39
40
# File 'lib/ncmb/script.rb', line 37

def header(params)
  @params[:header] = params
  self
end

#post(params = {}) ⇒ Object



15
16
17
# File 'lib/ncmb/script.rb', line 15

def post(params = {})
  self.set(params).execute('post')
end

#put(params = {}) ⇒ Object



19
20
21
# File 'lib/ncmb/script.rb', line 19

def put(params = {})
  self.set(params).execute('put')
end

#query(params) ⇒ Object



47
48
49
50
# File 'lib/ncmb/script.rb', line 47

def query(params)
  @params[:query] = params
  self
end

#set(params) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/ncmb/script.rb', line 28

def set(params)
  params = Hash[ params.map{ |k, v| [k.to_sym, v] } ]
  self
    .header(params[:header])
    .body(params[:body])
    .query(params[:query])
  self
end