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.
-
#original_url ⇒ Object
Returns the value of attribute original_url.
-
#url ⇒ Object
Returns the value of attribute url.
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.
-
#upload(file) ⇒ Object
Upload a .box file for this provider.
Methods inherited from Resource
date_accessor, date_writer, #inspect, #to_hash, #update_with_response
Constructor Details
#initialize(tag, hash = {}) ⇒ BoxProvider
Initialize a provider from a tag and object hash.
45 46 47 48 49 |
# File 'lib/atlas/box_provider.rb', line 45 def initialize(tag, hash = {}) hash[:url] = hash[:download_url] unless hash.key? :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 |
#original_url ⇒ Object
Returns the value of attribute original_url.
7 8 9 |
# File 'lib/atlas/box_provider.rb', line 7 def original_url @original_url end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/atlas/box_provider.rb', line 7 def url @url end |
Class Method Details
.create(box_version_tag, attr = {}) ⇒ Object
Create a new Provider.
31 32 33 34 35 36 |
# File 'lib/atlas/box_provider.rb', line 31 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.
15 16 17 18 19 20 |
# File 'lib/atlas/box_provider.rb', line 15 def self.find(tag) url_builder = UrlBuilder.new tag response = Atlas.client.get(url_builder.box_provider_url) new(tag, response) end |
Instance Method Details
#delete ⇒ Hash
Delete the provider.
82 83 84 |
# File 'lib/atlas/box_provider.rb', line 82 def delete Atlas.client.delete(url_builder.box_provider_url) end |
#save ⇒ Hash
Save the provider.
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/atlas/box_provider.rb', line 54 def save body = { provider: to_hash } begin response = Atlas.client.put(url_builder.box_provider_url, body: body) rescue Atlas::Errors::NotFoundError response = Atlas.client.post("#{url_builder.box_version_url}/providers", body: body) end update_with_response(response) end |
#upload(file) ⇒ Object
Upload a .box file for this provider.
70 71 72 73 74 75 76 77 |
# File 'lib/atlas/box_provider.rb', line 70 def upload(file) # get the path for upload response = Atlas.client.get("#{url_builder.box_provider_url}/upload") # upload the file upload_url = response['upload_path'] Excon.put(upload_url, body: file) end |