Class: ApigeeCli::ResourceFile
- Inherits:
-
Base
- Object
- Base
- ApigeeCli::ResourceFile
show all
- Defined in:
- lib/apigee_cli/resource_file.rb
Constant Summary
collapse
- RESOURCE_FILE_KEY =
'resourceFile'
- DEFAULT_RESOURCE_TYPE =
'jsc'
Instance Attribute Summary
Attributes inherited from Base
#environment, #org
Instance Method Summary
collapse
Methods inherited from Base
#delete, #get, #initialize, #post, #put, #response_error, #upload_file
Instance Method Details
#all ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/apigee_cli/resource_file.rb', line 11
def all
response = get(base_url)
if response.status != 200
response_error(response)
else
JSON.parse(response.body)
end
end
|
#base_url ⇒ Object
7
8
9
|
# File 'lib/apigee_cli/resource_file.rb', line 7
def base_url
"https://api.enterprise.apigee.com/v1/organizations/#{org}/resourcefiles"
end
|
#create(name, resource_type, file) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/apigee_cli/resource_file.rb', line 32
def create(name, resource_type, file)
url = "#{base_url}?name=#{name}&type=#{resource_type}"
response = upload_file(url, file)
if response.status != 201
response_error(response)
else
JSON.parse(response.body)
end
end
|
#read(name, resource_type) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/apigee_cli/resource_file.rb', line 20
def read(name, resource_type)
url = [base_url,resource_type,name].join('/')
response = get(url)
if response.status == 404
nil
elsif response.status != 200
response_error(response)
else
response.body
end
end
|
#remove(name, resource_type) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/apigee_cli/resource_file.rb', line 42
def remove(name, resource_type)
url = [base_url,resource_type,name].join('/')
response = delete(url)
if response.status != 200
response_error(response)
else
JSON.parse(response.body)
end
end
|
#upload(name, resource_type, file) ⇒ Object
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/apigee_cli/resource_file.rb', line 52
def upload(name, resource_type, file)
if read(name, resource_type)
result = :overwritten
remove(name, resource_type)
else
result = :new_file
end
create(name, resource_type, file)
result
end
|