Class: Avod::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/avod/client.rb

Constant Summary collapse

BASE_URL =
"https://cn.avoscloud.com/"
VERSION_CODE =
"1"
API_URL =
BASE_URL + VERSION_CODE + "/"
API_OBJECT_URL =
API_URL + "classes/"
API_USER_URL =
API_URL + "users"
API_INSTALLIIONS_URL =
API_URL + "installations"

Instance Method Summary collapse

Constructor Details

#initialize(app_id, app_key, master_key) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
# File 'lib/avod/client.rb', line 16

def initialize(app_id, app_key, master_key)
	@app_id = app_id
	@app_key = app_key
	@master_key = master_key
end

Instance Method Details

#create_object(class_name, object) ⇒ Object



34
35
36
# File 'lib/avod/client.rb', line 34

def create_object(class_name, object)
	post API_OBJECT_URL + class_name, object.to_json
end

#delete_object(class_name, object_id) ⇒ Object



46
47
48
# File 'lib/avod/client.rb', line 46

def delete_object(class_name, object_id)
	delete API_OBJECT_URL + class_name + "/" + object_id
end

#delete_user(user_id, session) ⇒ Object

untest



98
99
100
101
102
103
104
105
106
# File 'lib/avod/client.rb', line 98

def delete_user(user_id, session) #untest
	url = API_USER_URL + user_id
	result =  RestClient.delete url ,
	:"content-type" => "application/json", 
	:"X-AVOSCloud-Application-Id" => @app_id,
	:"X-AVOSCloud-Application-Key" => @app_key,
	:"X-AVOSCloud-Session-Token" => session
	result.code == 200
end

#get_all_object(name) ⇒ Object



30
31
32
# File 'lib/avod/client.rb', line 30

def get_all_object(name)
	get API_OBJECT_URL + name
end

#get_all_usersObject



73
74
75
# File 'lib/avod/client.rb', line 73

def get_all_users 
	get API_USER_URL
end

#get_install(object_id) ⇒ Object



151
152
153
# File 'lib/avod/client.rb', line 151

def get_install(object_id) 
	get API_INSTALLIIONS_URL + "/" + object_id
end

#get_installationsObject

URL HTTP 功能 /1/installations POST 上传安装数据 /1/installations/<objectId> GET 获取安装数据 /1/installations/<objectId> PUT 更新安装数据 /1/installations GET 查询安装数据 /1/installations/<objectId> DELETE 删除安装数据



147
148
149
# File 'lib/avod/client.rb', line 147

def get_installations
	private_get  API_INSTALLIIONS_URL 
end

#get_object(class_name, object_id) ⇒ Object



38
39
40
# File 'lib/avod/client.rb', line 38

def get_object(class_name, object_id)
	get  API_OBJECT_URL + class_name + "/"  + object_id
end

#get_user(object_id) ⇒ Object



77
78
79
# File 'lib/avod/client.rb', line 77

def get_user(object_id)  
	get API_USER_URL + "/" +  object_id
end

#register_user(username, password, email, *opt) ⇒ Object

untest



81
82
83
84
85
86
87
88
89
90
# File 'lib/avod/client.rb', line 81

def register_user(username, password, email, *opt) #untest
	if opt 
		params = opt
	else	
		params = Hash.new
	end
	params[:password] = password
	params[:username] = username			
	post API_USER_URL, params
end

#reset_email(email) ⇒ Object

faild



108
109
110
111
112
113
114
115
116
117
# File 'lib/avod/client.rb', line 108

def reset_email(email) #faild
	url = "https://cn.avoscloud.com/1/requestPasswordReset"
	params = {"email" => email}
	result =  RestClient.post url , params, 
	:"content-type" => "application/json", 
	:"X-AVOSCloud-Application-Id" => @app_id,
	:"X-AVOSCloud-Application-Key" => @app_key,
	:"X-AVOSCloud-Master-Key" => @master_key
	result.code == 200
end

#rest_password(email) ⇒ Object

untest



93
94
95
96
# File 'lib/avod/client.rb', line 93

def  rest_password(email) #untest
	params = {"email" => email}
	post API_URL + "requestPasswordReset", params
end

#update_install(object_id, params) ⇒ Object

untest



155
156
157
# File 'lib/avod/client.rb', line 155

def update_install(object_id, params) #untest
	put API_INSTALLIIONS_URL + "/" + params["objectId"], params
end

#update_object(class_name, object_id, object) ⇒ Object



42
43
44
# File 'lib/avod/client.rb', line 42

def update_object(class_name, object_id, object)
	put API_OBJECT_URL + class_name + "/" + object_id, object.to_json
end

#update_user(user_id, params, session) ⇒ Object

URL HTTP 功能 /1/users POST 用户注册 用户连接 /1/login GET 用户登录 /1/users/<objectId> GET 获取用户 /1/users/<objectId> PUT 更新用户 用户连接 验证Email /1/users GET 查询用户 /1/users/<objectId> DELETE 删除用户 /1/requestPasswordReset POST 请求密码重设



63
64
65
66
67
68
69
70
71
# File 'lib/avod/client.rb', line 63

def update_user(user_id, params, session) #untest
	url = API_USER_URL + user_id
	result =  RestClient.put url , params,
	:"content-type" => "application/json", 
	:"X-AVOSCloud-Application-Id" => @app_id,
	:"X-AVOSCloud-Application-Key" => @app_key,
	:"X-AVOSCloud-Session-Token" => session
	return to_json(params)
end