ansible_tower_client 0.5.0 → 0.6.0

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
2
  SHA1:
3
- metadata.gz: b745ac89684afcf6633ca64b8a8e8e16615c22c9
4
- data.tar.gz: 5bad31a0e9ad53ff33c2e25d59d474638dae7a16
3
+ metadata.gz: f98b1405077eafacead17dc58b4ee20535e263dd
4
+ data.tar.gz: 9a1043e6af5bd81554f5c1f499b2b0a5b5bd7265
5
5
  SHA512:
6
- metadata.gz: 0eb05bf1f05c2091be7034346c0b4d400348b21adbafa6ede16e13ca1d7b8c43c6fdc59c7fba23299db3aae90f574cf298ca6f2fd8ba61a921d7a992388f90f9
7
- data.tar.gz: de27338f770e7153fe5926a2824c187143ae6d6b672ba6d68e48a5af1fa5bca82b660ddf183fc3cc0d9d182138b08c399043ce0170afef1dd34f78a9c9166d70
6
+ metadata.gz: c7ed7d56555c0b60b8590d5455eba86aa53ca65c083b3ebd331acd1c627dbe99b38f06a99782d8e9d7c7cb9b9f16cd103fca955bf3996b6cc626d6d497a3f19e
7
+ data.tar.gz: 807c37a2d965f77c1f9ddbe0cec24e7c26ba2f5c53f48b9b37d4b710e1bdbc95747c59425117a62731474952c32399c1dbacd8f28ab778a96fb3a2de9f048c5e
@@ -0,0 +1,16 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ This project adheres to [Semantic Versioning](http://semver.org/).
5
+
6
+ ## [0.6.0] - 2017-02-02
7
+ ### Added
8
+ - Refactor `#endpoint` [(#64)](https://github.com/ansible/ansible_tower_client_ruby/pull/64)
9
+ - Expose playbooks off of projects [(#62)](https://github.com/ansible/ansible_tower_client_ruby/pull/62)
10
+
11
+ ### Changed
12
+ - Allow for alternative resource paths [(#66)](https://github.com/ansible/ansible_tower_client_ruby/pull/66)
13
+ - Raise UnlicensedFeatureError when we receive HTTP 402 [(#65)](https://github.com/ansible/ansible_tower_client_ruby/pull/65)
14
+
15
+ ### Fixed
16
+ - Adjusted project_spec to test on a Project [(#63)](https://github.com/ansible/ansible_tower_client_ruby/pull/63)
@@ -69,6 +69,8 @@ module AnsibleTowerClient
69
69
 
70
70
  def method_missing(method_name, *args, &block)
71
71
  if instance.respond_to?(method_name)
72
+ path = build_path_to_resource(args.shift)
73
+ args.unshift(path)
72
74
  logger.debug { "#{self.class.name} Sending <#{method_name}> with <#{args.inspect}>" }
73
75
  instance.send(method_name, *args, &block).tap do |response|
74
76
  logger.debug { "#{self.class.name} Response:\n#{JSON.parse(response.body).pretty_inspect}" }
@@ -143,5 +145,13 @@ module AnsibleTowerClient
143
145
  def project_class
144
146
  @project_class ||= AnsibleTowerClient::Project
145
147
  end
148
+
149
+ private
150
+
151
+ def build_path_to_resource(original)
152
+ return original unless %r{\/?api\/v1\/(.*)} =~ original
153
+ return original if instance.url_prefix.path == "/"
154
+ File.join(instance.url_prefix.path, Regexp.last_match[1])
155
+ end
146
156
  end
147
157
  end
@@ -6,6 +6,10 @@ module AnsibleTowerClient
6
6
  superclass == AnsibleTowerClient::BaseModel ? self : superclass.base_class
7
7
  end
8
8
 
9
+ def self.endpoint
10
+ base_class.to_s.split(/::/)[1].tableize.to_s.freeze
11
+ end
12
+
9
13
  # Constructs and returns a new JSON wrapper class. Pass in a plain
10
14
  # JSON string and it will automatically give you accessor methods
11
15
  # that make it behave like a typical Ruby object. You may also pass
@@ -3,9 +3,5 @@ module AnsibleTowerClient
3
3
  def relaunch
4
4
  api.post("#{url}relaunch/")
5
5
  end
6
-
7
- def self.endpoint
8
- "ad_hoc_commands".freeze
9
- end
10
6
  end
11
7
  end
@@ -1,7 +1,4 @@
1
1
  module AnsibleTowerClient
2
2
  class Credential < BaseModel
3
- def self.endpoint
4
- "credentials".freeze
5
- end
6
3
  end
7
4
  end
@@ -1,9 +1,5 @@
1
1
  module AnsibleTowerClient
2
2
  class Group < BaseModel
3
- def self.endpoint
4
- "groups".freeze
5
- end
6
-
7
3
  def children
8
4
  Collection.new(api).find_all_by_url(related["children"])
9
5
  end
@@ -1,9 +1,5 @@
1
1
  module AnsibleTowerClient
2
2
  class Host < BaseModel
3
- def self.endpoint
4
- "hosts".freeze
5
- end
6
-
7
3
  def groups
8
4
  Collection.new(api).find_all_by_url(related["groups"])
9
5
  end
@@ -1,9 +1,5 @@
1
1
  module AnsibleTowerClient
2
2
  class Inventory < BaseModel
3
- def self.endpoint
4
- "inventories".freeze
5
- end
6
-
7
3
  def inventory_sources
8
4
  Collection.new(api).find_all_by_url(related['inventory_sources'])
9
5
  end
@@ -1,9 +1,5 @@
1
1
  module AnsibleTowerClient
2
2
  class InventorySource < BaseModel
3
- def self.endpoint
4
- "inventory_sources".freeze
5
- end
6
-
7
3
  def can_update?
8
4
  response = api.get(related['update'].to_s).body
9
5
 
@@ -1,7 +1,4 @@
1
1
  module AnsibleTowerClient
2
2
  class InventoryUpdate < BaseModel
3
- def self.endpoint
4
- "inventory_updates".freeze
5
- end
6
3
  end
7
4
  end
@@ -1,9 +1,5 @@
1
1
  module AnsibleTowerClient
2
2
  class Job < BaseModel
3
- def self.endpoint
4
- "jobs".freeze
5
- end
6
-
7
3
  def extra_vars_hash
8
4
  extra_vars.empty? ? {} : hashify(:extra_vars)
9
5
  end
@@ -11,6 +11,7 @@ module AnsibleTowerClient
11
11
  spec_url = related['survey_spec']
12
12
  return nil unless spec_url
13
13
  api.get(spec_url).body
14
+ rescue AnsibleTowerClient::UnlicensedFeatureError
14
15
  end
15
16
 
16
17
  def survey_spec_hash
@@ -20,9 +21,5 @@ module AnsibleTowerClient
20
21
  def extra_vars_hash
21
22
  extra_vars.empty? ? {} : hashify(:extra_vars)
22
23
  end
23
-
24
- def self.endpoint
25
- "job_templates".freeze
26
- end
27
24
  end
28
25
  end
@@ -1,7 +1,7 @@
1
1
  module AnsibleTowerClient
2
2
  class Project < BaseModel
3
- def self.endpoint
4
- "projects".freeze
3
+ def playbooks
4
+ Collection.new(api).find_all_by_url(related['playbooks'])
5
5
  end
6
6
  end
7
7
  end
@@ -47,17 +47,22 @@ module AnsibleTowerClient
47
47
  def fetch_more_results(next_page, get_options)
48
48
  return if next_page.nil?
49
49
  body = parse_response(api.get(next_page, get_options))
50
- parse_result_set(body["results"])
51
-
52
- body["next"]
50
+ parse_result_set(body)
53
51
  end
54
52
 
55
53
  def parse_response(response)
56
54
  JSON.parse(response.body)
57
55
  end
58
56
 
59
- def parse_result_set(results)
60
- results.each { |result| @collection << build_object(result) }
57
+ def parse_result_set(body)
58
+ case body.class.name
59
+ when "Array" then
60
+ @collection = body
61
+ nil
62
+ when "Hash" then
63
+ body["results"].each { |result| @collection << build_object(result) }
64
+ body["next"]
65
+ end
61
66
  end
62
67
 
63
68
  def build_object(result)
@@ -1,6 +1,7 @@
1
1
  module AnsibleTowerClient
2
2
  class Error < Exception; end
3
+ class ClientError < Error; end
3
4
  class ConnectionError < Error; end
4
5
  class NoMethodError < Error; end
5
- class ClientError < Error; end
6
+ class UnlicensedFeatureError < Error; end
6
7
  end
@@ -5,6 +5,8 @@ module AnsibleTowerClient
5
5
 
6
6
  def on_complete(env)
7
7
  case env[:status]
8
+ when 402
9
+ raise AnsibleTowerClient::UnlicensedFeatureError
8
10
  when 404
9
11
  raise Faraday::Error::ResourceNotFound, response_values(env)
10
12
  when 407
@@ -1,3 +1,3 @@
1
1
  module AnsibleTowerClient
2
- VERSION = "0.5.0".freeze
2
+ VERSION = "0.6.0".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ansible_tower_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dunne
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-01-18 00:00:00.000000000 Z
12
+ date: 2017-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -136,6 +136,7 @@ files:
136
136
  - ".rubocop.yml"
137
137
  - ".rubocop_local.yml"
138
138
  - ".travis.yml"
139
+ - CHANGELOG.md
139
140
  - Gemfile
140
141
  - LICENSE.txt
141
142
  - README.md