Class: PI::Client

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

Defined Under Namespace

Classes: AuthError, BadResponse, BadTarget, HTTPException, NotFound, TargetError

Constant Summary collapse

PI_HTTP_ERROR_CODES =

Error codes

[ 400, 500 ]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_urls = PI::DEFAULT_TARGET, auth_token = nil) ⇒ Client

Returns a new instance of Client.



29
30
31
32
33
34
# File 'lib/pi/client.rb', line 29

def initialize(target_urls=PI::DEFAULT_TARGET, auth_token=nil)
  target_urls = "http://#{target_urls}" unless /^https?/ =~ target_urls
  target_urls = target_urls.gsub(/\/+$/, '')
  @target =  target_urls
  @auth_token = auth_token
end

Instance Attribute Details

#auth_tokenObject (readonly)

Returns the value of attribute auth_token.



14
15
16
# File 'lib/pi/client.rb', line 14

def auth_token
  @auth_token
end

#hostObject (readonly)

Returns the value of attribute host.



14
15
16
# File 'lib/pi/client.rb', line 14

def host
  @host
end

#targetObject (readonly)

Returns the value of attribute target.



14
15
16
# File 'lib/pi/client.rb', line 14

def target
  @target
end

#traceObject

Returns the value of attribute trace.



15
16
17
# File 'lib/pi/client.rb', line 15

def trace
  @trace
end

Class Method Details

.versionObject



10
11
12
# File 'lib/pi/client.rb', line 10

def self.version
  PI::VERSION
end

Instance Method Details

#admin_domainsObject

administration



254
255
256
# File 'lib/pi/client.rb', line 254

def admin_domains
  json_get("#{PI::ADMIN_PATH}/domains")
end

#admin_users(domainid) ⇒ Object



258
259
260
# File 'lib/pi/client.rb', line 258

def admin_users(domainid)
  json_get("#{PI::ADMIN_PATH}/users?query=domain_id%3D#{domainid}")
end

#app_dns(appname) ⇒ Object



238
239
240
# File 'lib/pi/client.rb', line 238

def app_dns(appname)
  json_get("#{PI::APP_PATH}/url/mapped?appName=#{appname}")
end

#app_env(appname) ⇒ Object



190
191
192
# File 'lib/pi/client.rb', line 190

def app_env(appname)
  json_get("#{PI::APP_PATH}/env/list?appName=#{appname}")
end

#app_get_byid(appid) ⇒ Object



150
151
152
# File 'lib/pi/client.rb', line 150

def app_get_byid(appid)
  json_get("#{PI::APP_PATH}/get?appId=#{appid}")
end

#app_get_byname(appname) ⇒ Object



146
147
148
# File 'lib/pi/client.rb', line 146

def app_get_byname(appname)
  json_get("#{PI::APP_PATH}/get?appName=#{appname}")
end

#app_log(appid, filepath, instanceindex) ⇒ Object



206
207
208
# File 'lib/pi/client.rb', line 206

def app_log(appid,filepath,instanceindex)
  http_get("#{PI::APP_PATH}/logs?appId=#{appid}&filePath=#{filepath}&instanceIndex=#{instanceindex}")
end

#app_message(appname, message) ⇒ Object



162
163
164
# File 'lib/pi/client.rb', line 162

def app_message(appname,message)
  json_get("#{PI::APP_PATH}/message?appName=#{appname}&eventName=#{message}")
end

#app_service(appname) ⇒ Object



218
219
220
# File 'lib/pi/client.rb', line 218

def app_service(appname)
  json_get("#{PI::APP_PATH}/service/binded?appName=#{appname}")
end

#app_sum(projectid) ⇒ Object



142
143
144
# File 'lib/pi/client.rb', line 142

def app_sum(projectid)
  http_get("#{PI::APP_PATH}/sum?projectId=#{projectid}")
end

#apps(projectid, queryParam = nil) ⇒ Object

applications



137
138
139
140
# File 'lib/pi/client.rb', line 137

def apps(projectid, queryParam = nil)    
  queryParam = { :pageNum => -1, :NumPerPage => -1} unless queryParam
  json_get("#{PI::APP_PATH}/list?projectId=#{projectid}&pageNum=#{queryParam[:pageNum]}&numPerPage=#{queryParam[:NumPerPage]}")
end

#bind_service(appname, manifest = nil) ⇒ Object



222
223
224
# File 'lib/pi/client.rb', line 222

def bind_service(appname, manifest=nil)
  json_post("#{PI::APP_PATH}/service/bind?appName=#{appname}",manifest)
end

#check_urlObject

Users



40
41
42
# File 'lib/pi/client.rb', line 40

def check_url
  http_get    
end

#create_app(projectid, manifest = {}) ⇒ Object



154
155
156
# File 'lib/pi/client.rb', line 154

def create_app(projectid,manifest={})
  status, body, headers = json_post("#{PI::APP_PATH}/create?projectId=#{projectid}", manifest)
end

#create_env(appname, manifest = nil) ⇒ Object



194
195
196
# File 'lib/pi/client.rb', line 194

def create_env(appname,manifest=nil)
  json_post("#{PI::APP_PATH}/env/save?appName=#{appname}",manifest)
end

#create_project(name, manifest = {}) ⇒ Object



96
97
98
# File 'lib/pi/client.rb', line 96

def create_project(name, manifest={})
  status, body, headers = json_post("#{PI::PROJECT_PATH}/create", manifest)
end

#delete_app(appid) ⇒ Object



166
167
168
# File 'lib/pi/client.rb', line 166

def delete_app(appid)
  http_delete("#{PI::APP_PATH}/delete?appId=#{appid}",'application/json')
end

#delete_env(appname, manifest = nil) ⇒ Object



198
199
200
# File 'lib/pi/client.rb', line 198

def delete_env(appname,manifest=nil)
  json_post("#{PI::APP_PATH}/env/delete?appName=#{appname}",manifest)
end

#delete_project(projectname) ⇒ Object



100
101
102
# File 'lib/pi/client.rb', line 100

def delete_project(projectname)
  http_delete("#{PI::PROJECT_PATH}/delete/#{projectname}",'application/json')
end

#env_verify(appname, name) ⇒ Object



202
203
204
# File 'lib/pi/client.rb', line 202

def env_verify(appname,name)
  http_get("#{PI::APP_PATH}/env/verify?appName=#{appname}&name=#{name}")
end

#frameworks(runtime) ⇒ Object



80
81
82
# File 'lib/pi/client.rb', line 80

def frameworks(runtime)
  json_get("#{PI::INFO_PATH}/frameworks?runtime=#{runtime}")
end

#github(manifest = {}) ⇒ Object



72
73
74
# File 'lib/pi/client.rb', line 72

def github(manifest={})
  json_post("#{PI::USER_PATH}/bind",manifest)
end

#github_infoObject



60
61
62
# File 'lib/pi/client.rb', line 60

def github_info
  json_get("#{PI::USER_PATH}/github")
end

#infoObject



52
53
54
# File 'lib/pi/client.rb', line 52

def info
  json_get(PI::INFO_PATH)
end

#login(user, password) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/pi/client.rb', line 44

def (user, password)
  status, body, headers = json_post("#{PI::TOKEN_PATH}", {:password => password,:userName => user})
  response_info = json_parse(body)
  if response_info
    @auth_token = response_info[:token]
  end
end

#map_dns(appname, manifest = nil) ⇒ Object



242
243
244
# File 'lib/pi/client.rb', line 242

def map_dns(appname, manifest=nil)
  json_post("#{PI::APP_PATH}/url/map?appName=#{appname}",manifest)
end

#password(newpassword) ⇒ Object



68
69
70
# File 'lib/pi/client.rb', line 68

def password(newpassword)
  status, body, headers = json_post("#{PI::USER_PATH}/password/#{newpassword}",{:newpass => newpassword})
end

#project_apps(projectname) ⇒ Object



121
122
123
# File 'lib/pi/client.rb', line 121

def project_apps(projectname)
  json_get("#{PI::PROJECT_PATH}/apps/#{projectname}")
end

#project_binary(projectid) ⇒ Object



125
126
127
# File 'lib/pi/client.rb', line 125

def project_binary(projectid)
  json_get("#{PI::PROJECT_PATH}/binary/list?query=project_id%3D#{projectid}")
end

#project_branchs(projectname) ⇒ Object



129
130
131
# File 'lib/pi/client.rb', line 129

def project_branchs(projectname)
  json_get("#{PI::PROJECT_PATH}/branchs/#{projectname}")
end

#project_commits(projectname, tag) ⇒ Object



117
118
119
# File 'lib/pi/client.rb', line 117

def project_commits(projectname,tag)
  json_get("#{PI::PROJECT_PATH}/commitinfo/#{projectname}/#{tag}")
end

#project_events(projectname) ⇒ Object



109
110
111
# File 'lib/pi/client.rb', line 109

def project_events(projectname)
  json_get("#{PI::PROJECT_PATH}/events/#{projectname}")
end

#project_get(projectname) ⇒ Object



92
93
94
# File 'lib/pi/client.rb', line 92

def project_get(projectname)
  json_get("#{PI::PROJECT_PATH}/get?projectName=#{projectname}")
end

#project_tags(projectname) ⇒ Object



113
114
115
# File 'lib/pi/client.rb', line 113

def project_tags(projectname)
  json_get("#{PI::PROJECT_PATH}/tags/#{projectname}")
end

#projectsObject

projects



88
89
90
# File 'lib/pi/client.rb', line 88

def projects
  json_get("#{PI::PROJECT_PATH}/list")
end

#runtimesObject



76
77
78
# File 'lib/pi/client.rb', line 76

def runtimes
  json_get("#{PI::INFO_PATH}/runtimes")
end

#scale_app(appid, instance) ⇒ Object



178
179
180
# File 'lib/pi/client.rb', line 178

def scale_app(appid,instance)
  json_get("#{PI::APP_PATH}/scale?appId=#{appid}&instance=#{instance}")
end

#start_app(appid) ⇒ Object



170
171
172
# File 'lib/pi/client.rb', line 170

def start_app(appid)
  json_get("#{PI::APP_PATH}/start?appId=#{appid}")
end

#status(appname) ⇒ Object



186
187
188
# File 'lib/pi/client.rb', line 186

def status(appname)
  json_get("#{PI::APP_PATH}/monitor?appName=#{appname}")
end

#stop_app(appid) ⇒ Object



174
175
176
# File 'lib/pi/client.rb', line 174

def stop_app(appid)
  json_get("#{PI::APP_PATH}/stop?appId=#{appid}")
end

#target_memory(targetname) ⇒ Object



158
159
160
# File 'lib/pi/client.rb', line 158

def target_memory(targetname)
  http_get("#{PI::APP_PATH}/target/memory?targetName=#{targetname}")
end

#targetsObject



64
65
66
# File 'lib/pi/client.rb', line 64

def targets
  json_get("#{PI::USER_PATH}/targets")
end

#unbind_service(appname, manifest = nil) ⇒ Object



226
227
228
# File 'lib/pi/client.rb', line 226

def unbind_service(appname, manifest=nil)
  json_post("#{PI::APP_PATH}/service/unbind?appName=#{appname}",manifest)
end

#unmap_dns(appname, manifest = nil) ⇒ Object



246
247
248
# File 'lib/pi/client.rb', line 246

def unmap_dns(appname, manifest=nil)
  json_post("#{PI::APP_PATH}/url/unmap?appName=#{appname}",manifest)
end

#update_app(appid, tag) ⇒ Object



182
183
184
# File 'lib/pi/client.rb', line 182

def update_app(appid,tag)
  json_get("#{PI::APP_PATH}/rollback?appId=#{appid}&tag=#{tag}")
end

#upload(manifest = {}) ⇒ Object



104
105
106
107
# File 'lib/pi/client.rb', line 104

def upload(manifest={})
  status, body, headers = http_post("#{PI::PROJECT_PATH}/upload", manifest)
  response_info = json_parse(body)
end

#usable_dns(appname) ⇒ Object

dns



234
235
236
# File 'lib/pi/client.rb', line 234

def usable_dns(appname)
  json_get("#{PI::APP_PATH}/url/usable?appName=#{appname}")
end

#usable_services(appname) ⇒ Object

services



214
215
216
# File 'lib/pi/client.rb', line 214

def usable_services(appname)
  json_get("#{PI::APP_PATH}/service/usable?appName=#{appname}")
end

#user_infoObject



56
57
58
# File 'lib/pi/client.rb', line 56

def 
  json_get(PI::USER_PATH)
end