yao 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: da4cbfc5d9e7c25ca43e5ae65d409b6932e6c6c5
4
- data.tar.gz: 2af6c4274cc2af3a46fd9b84e705c880ea3b9e43
2
+ SHA256:
3
+ metadata.gz: e1789686116892938a28b82e269c12b5f5ef72c49c1e9f5135f24e98351d208a
4
+ data.tar.gz: c2c470d8474707f81999cc6fa7f1a470315a2dd7d7ccc525c321ce5c5457d63b
5
5
  SHA512:
6
- metadata.gz: 071b7b04433f864f04dad54a41d836ee5391bde791bdd3bcf4f6b0db502f794ccb263eb30d6227539d355034a6a3052c8f2acdc21c4ad8b4d4fd6fe5252a451b
7
- data.tar.gz: 36794af6d54fc929b72ef4ea4d22cf9113fc6841d43036504c28f11da4a919128daa8d8032d48127719cd81b26bc20f1db2a11a74d816d53b9beeb055c4e7653
6
+ metadata.gz: 2cd63d1b7243beb3593f63ff2f9fd5869a61bf77887c9e8217c7a90cb460968221afa3cf639916c940cce4ec68b1a9372cb006b60e7bc979dda010e4ee49db92
7
+ data.tar.gz: aee7a7cbf7e888bd0cd2c6cb6e0a2a78e206526c3140fd914426b6a794077e537238845fea29ef7eb0324ced1eee26e9ddce9b7dd35d0a9593a5c74d063e6c7d
@@ -20,15 +20,15 @@ module Yao::Resources
20
20
  end
21
21
  attr_reader :service
22
22
 
23
+ def api_version
24
+ @api_version || ''
25
+ end
26
+
23
27
  def api_version=(v)
24
28
  raise("Set api_version after service is declared") unless service
25
29
  @api_version = v
26
- if cli = client
27
- cli.url_prefix.path += "/#{api_version}" unless cli.url_prefix.to_s.include?("/#{api_version}")
28
- end
29
30
  api_version
30
31
  end
31
- attr_reader :api_version
32
32
 
33
33
  def admin=(bool)
34
34
  @admin = bool
@@ -76,7 +76,7 @@ module Yao::Resources
76
76
 
77
77
  # restful methods
78
78
  def list(query={})
79
- json = GET(resources_path, query).body
79
+ json = GET(create_url([api_version, resources_path]), query).body
80
80
  if @return_single_on_querying && !query.empty?
81
81
  return_resource(resource_from_json(json))
82
82
  else
@@ -88,7 +88,7 @@ module Yao::Resources
88
88
  res = if id_or_name_or_permalink.start_with?("http://", "https://")
89
89
  GET(id_or_name_or_permalink, query)
90
90
  elsif uuid?(id_or_name_or_permalink)
91
- GET([resources_path, id_or_name_or_permalink].join("/"), query)
91
+ GET(create_url([api_version, resources_path, id_or_name_or_permalink]), query)
92
92
  else
93
93
  get_by_name(id_or_name_or_permalink, query)
94
94
  end
@@ -105,7 +105,7 @@ module Yao::Resources
105
105
  params = {
106
106
  resource_name_in_json => resource_params
107
107
  }
108
- res = POST(resources_path) do |req|
108
+ res = POST(create_url([api_version, resources_path])) do |req|
109
109
  req.body = params.to_json
110
110
  req.headers['Content-Type'] = 'application/json'
111
111
  end
@@ -116,7 +116,7 @@ module Yao::Resources
116
116
  params = {
117
117
  resource_name_in_json => resource_params
118
118
  }
119
- res = PUT([resources_path, id].join("/")) do |req|
119
+ res = PUT(create_url([api_version, resources_path, id])) do |req|
120
120
  req.body = params.to_json
121
121
  req.headers['Content-Type'] = 'application/json'
122
122
  end
@@ -124,11 +124,15 @@ module Yao::Resources
124
124
  end
125
125
 
126
126
  def destroy(id)
127
- res = DELETE([resources_path, id].join("/"))
127
+ res = DELETE(create_url([api_version, resources_path, id]))
128
128
  res.body
129
129
  end
130
130
 
131
131
  private
132
+ def create_url(paths)
133
+ paths.select{|s| s != ''}.join('/')
134
+ end
135
+
132
136
  def resource_name_in_json
133
137
  @_resource_name_in_json ||= resource_name.sub(/^os-/, "").tr("-", "_")
134
138
  end
@@ -157,13 +161,13 @@ module Yao::Resources
157
161
  def get_by_name(name, query={})
158
162
  # At first, search by ID. If nothing is found, search by name.
159
163
  begin
160
- GET([resources_path, name].join("/"), query)
164
+ GET(create_url([api_version, resources_path, name]), query)
161
165
  rescue Yao::ItemNotFound
162
166
  item = find_by_name(name)
163
167
  if item.size > 1
164
168
  raise Yao::TooManyItemFonud.new("More than one resource exists with the name '#{name}'")
165
169
  end
166
- GET([resources_path, item.first.id].join("/"), query)
170
+ GET(create_url([api_version, resources_path, item.first.id]), query)
167
171
  end
168
172
  end
169
173
  end
data/lib/yao/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yao
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yao
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio, KONDO
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-16 00:00:00.000000000 Z
11
+ date: 2018-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -263,7 +263,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
263
  version: '0'
264
264
  requirements: []
265
265
  rubyforge_project:
266
- rubygems_version: 2.6.13
266
+ rubygems_version: 2.7.6
267
267
  signing_key:
268
268
  specification_version: 4
269
269
  summary: Yet Another OpenStack API Wrapper that rocks!!