Class: Atlas::BoxProvider
- Defined in:
- lib/atlas/box_provider.rb
Overview
Representation and handling of Box Provider objects.
Instance Attribute Summary collapse
-
#download_url ⇒ Object
Returns the value of attribute download_url.
-
#name ⇒ Object
Returns the value of attribute name.
Attributes inherited from Resource
Class Method Summary collapse
-
.create(box_version_tag, attr = {}) ⇒ Object
Create a new Provider.
-
.find(tag) ⇒ Provider
Find a provider by it’s tag.
Instance Method Summary collapse
-
#delete ⇒ Hash
Delete the provider.
-
#initialize(tag, hash = {}) ⇒ BoxProvider
constructor
Initialize a provider from a tag and object hash.
-
#save ⇒ Hash
Save the provider.
Methods inherited from Resource
#inspect, #to_hash, #update_with_response
Constructor Details
#initialize(tag, hash = {}) ⇒ BoxProvider
Initialize a provider from a tag and object hash.
44 45 46 47 48 |
# File 'lib/atlas/box_provider.rb', line 44 def initialize(tag, hash = {}) hash[:url] = hash[:download_url] super(tag, hash) end |
Instance Attribute Details
#download_url ⇒ Object
Returns the value of attribute download_url.
7 8 9 |
# File 'lib/atlas/box_provider.rb', line 7 def download_url @download_url end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/atlas/box_provider.rb', line 7 def name @name end |
Class Method Details
.create(box_version_tag, attr = {}) ⇒ Object
Create a new Provider.
30 31 32 33 34 35 |
# File 'lib/atlas/box_provider.rb', line 30 def self.create(box_version_tag, attr = {}) tag = "#{box_version_tag}/#{attr[:name]}" provider = new(tag, attr) provider.save provider end |
.find(tag) ⇒ Provider
Find a provider by it’s tag.
14 15 16 17 18 19 |
# File 'lib/atlas/box_provider.rb', line 14 def self.find(tag) url_builder = UrlBuilder.new tag response = Atlas.client.get(url_builder.box_provider_url) new(tag, JSON.parse(response.body)) end |
Instance Method Details
#delete ⇒ Hash
Delete the provider.
69 70 71 72 73 |
# File 'lib/atlas/box_provider.rb', line 69 def delete response = Atlas.client.delete(url_builder.box_provider_url) JSON.parse(response.body) end |
#save ⇒ Hash
Save the provider.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/atlas/box_provider.rb', line 53 def save body = { provider: to_hash } begin response = Atlas.client.put(url_builder.box_provider_url, body: body) rescue Excon::Errors::NotFound response = Atlas.client.post("#{url_builder.box_version_url}/providers", body: body) end update_with_response(response.body) end |