Class: DmLiveResources::DMSheet

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/dm_live_resources/dm_sheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_keyObject (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

#authObject (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_typeObject (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

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/dm_live_resources/dm_sheet.rb', line 5

def description
  @description
end

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/dm_live_resources/dm_sheet.rb', line 5

def file
  @file
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/dm_live_resources/dm_sheet.rb', line 5

def id
  @id
end

#nameObject (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_hashObject (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_resourceObject



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', request_options)
end

#find_resource_idObject



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_resourcesObject



40
41
42
43
44
45
# File 'lib/dm_live_resources/dm_sheet.rb', line 40

def list_resources
  options = { basic_auth: auth }
  response = self.class.get('https://www.devicemagic.com/api/resources.json', options)
  resources = response['resources']
  return resources
end

#request_optionsObject



30
31
32
33
# File 'lib/dm_live_resources/dm_sheet.rb', line 30

def request_options
  @request_options = { basic_auth: auth, body: {"resource" => resource_hash }}
  @request_options
end

#update_resourceObject



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", request_options)
end