Class: DmLiveResources::DMSheet
- Inherits:
-
Object
- Object
- DmLiveResources::DMSheet
- Includes:
- HTTParty
- Defined in:
- lib/dm_live_resources/dm_sheet.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#resource_hash ⇒ Object
readonly
Returns the value of attribute resource_hash.
Instance Method Summary collapse
- #add_resource ⇒ Object
- #find_resource_id ⇒ Object
-
#initialize(args = {}) ⇒ DMSheet
constructor
A new instance of DMSheet.
- #list_resources ⇒ Object
- #request_options ⇒ Object
- #update_resource ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ DMSheet
Returns a new instance of DMSheet.
8 9 10 11 12 13 14 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 8 def initialize(args = {}) @api_key = args[:dm_api_key] @file = args[:file] @description = args[:description] @name = args[:name] ||= "#{description}.xlsx" @id = args[:dm_id] ||= find_resource_id end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
5 6 7 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 5 def api_key @api_key end |
#auth ⇒ Object (readonly)
Returns the value of attribute auth.
5 6 7 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 5 def auth @auth end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
5 6 7 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 5 def content_type @content_type end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 5 def description @description end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 5 def file @file end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 5 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 5 def name @name end |
#resource_hash ⇒ Object (readonly)
Returns the value of attribute resource_hash.
5 6 7 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 5 def resource_hash @resource_hash end |
Instance Method Details
#add_resource ⇒ Object
57 58 59 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 57 def add_resource self.class.post('https://www.devicemagic.com/api/resources.json', ) end |
#find_resource_id ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 47 def find_resource_id resources = list_resources resources.each do |resource| if resource['original_filename'] == name && resource['description'] == description id = resource['id'] return id end end end |
#list_resources ⇒ Object
40 41 42 43 44 45 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 40 def list_resources = { basic_auth: auth } response = self.class.get('https://www.devicemagic.com/api/resources.json', ) resources = response['resources'] return resources end |
#request_options ⇒ Object
30 31 32 33 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 30 def @request_options = { basic_auth: auth, body: {"resource" => resource_hash }} @request_options end |
#update_resource ⇒ Object
61 62 63 |
# File 'lib/dm_live_resources/dm_sheet.rb', line 61 def update_resource self.class.put("https://www.devicemagic.com/api/resources/#{id}.json", ) end |