Class: Sonycam::DeviceDescription
- Inherits:
-
Object
- Object
- Sonycam::DeviceDescription
- Defined in:
- lib/sonycam/device_description.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Instance Method Summary collapse
-
#api_url(type = :camera) ⇒ Object
type: :camera, :system, :guide.
-
#initialize(document) ⇒ DeviceDescription
constructor
A new instance of DeviceDescription.
Constructor Details
#initialize(document) ⇒ DeviceDescription
Returns a new instance of DeviceDescription.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sonycam/device_description.rb', line 8 def initialize document @doc = REXML::Document.new(open(document)) @camera_name = REXML::XPath.first(@doc, "//xmlns:friendlyName").text @api_url_hash = {} REXML::XPath.each(@doc, '//av:X_ScalarWebAPI_Service') do |element| type = REXML::XPath.first(element, 'av:X_ScalarWebAPI_ServiceType').text url = REXML::XPath.first(element, 'av:X_ScalarWebAPI_ActionList_URL').text @api_url_hash[type.to_sym] = url end end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
6 7 8 |
# File 'lib/sonycam/device_description.rb', line 6 def doc @doc end |
Instance Method Details
#api_url(type = :camera) ⇒ Object
type: :camera, :system, :guide
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sonycam/device_description.rb', line 20 def api_url type = :camera # Hush, it's a secret, don't tell anyone. if @camera_name == 'DSC-RX100M2' url = @api_url_hash[type].sub('sony', 'camera') puts "DSC-RX100M2 detected, API URL \"#{url}\" is used insteadly." return url end if action_list_url = @api_url_hash[type] then "#{action_list_url}/#{type}" else raise "Can not find service type \"#{type}\"." end end |