Class: Atlas::BoxProvider
- Defined in:
- lib/atlas/box_provider.rb
Overview
Representation and handling of Box Provider objects.
Constant Summary
Constants inherited from Resource
Resource::INTERNAL_ATTRIBUTE_KEYS
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
#attributes, date_accessor, date_writer, #inspect, #to_hash, #update_with_response
Methods included from Validations
Constructor Details
#initialize(tag, hash = {}) ⇒ BoxProvider
Initialize a provider from a tag and object hash.
47 48 49 50 51 |
# File 'lib/atlas/box_provider.rb', line 47 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.
33 34 35 36 37 38 |
# File 'lib/atlas/box_provider.rb', line 33 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.
17 18 19 20 21 22 |
# File 'lib/atlas/box_provider.rb', line 17 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.
84 85 86 |
# File 'lib/atlas/box_provider.rb', line 84 def delete Atlas.client.delete(url_builder.box_provider_url) end |
#save ⇒ Hash
Save the provider.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/atlas/box_provider.rb', line 56 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.
72 73 74 75 76 77 78 79 |
# File 'lib/atlas/box_provider.rb', line 72 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 |