Class: UnAPI::Service
- Inherits:
-
Object
- Object
- UnAPI::Service
- Defined in:
- lib/unapi/service.rb
Overview
a class that represents the UnAPI Service
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #formats ⇒ Object
- #formats_for_uri(uri) ⇒ Object
- #get_uri_in_format(uri, format) ⇒ Object
-
#initialize(url) ⇒ Service
constructor
A new instance of Service.
Constructor Details
#initialize(url) ⇒ Service
Returns a new instance of Service.
12 13 14 |
# File 'lib/unapi/service.rb', line 12 def initialize(url) @url = url end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
10 11 12 |
# File 'lib/unapi/service.rb', line 10 def content_type @content_type end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
10 11 12 |
# File 'lib/unapi/service.rb', line 10 def document @document end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code.
10 11 12 |
# File 'lib/unapi/service.rb', line 10 def status_code @status_code end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/unapi/service.rb', line 10 def url @url end |
Instance Method Details
#formats ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/unapi/service.rb', line 16 def formats() @status_code, @document, @content_type = Utils.get_document(@url) return [] if ! @document formats = [] @document.elements.each('.//formats/format') do |e| formats << Format.new_from_element(e) end return formats end |
#formats_for_uri(uri) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/unapi/service.rb', line 27 def formats_for_uri(uri) formats = [] uri_esc = CGI.escape(uri) @status_code, @document, @content_type = Utils.get_document(@url + "?uri=#{uri_esc}") @document.elements.each('.//formats/format') do |e| formats << Format.new_from_element(e) end return formats end |
#get_uri_in_format(uri, format) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/unapi/service.rb', line 38 def get_uri_in_format(uri, format) uri_esc = CGI.escape(uri) format_esc = CGI.escape(format) @document = nil @status_code, body, @content_type = Utils.get(@url + "?uri=#{uri_esc}&format=#{format_esc}") return body end |