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.
-
#last_url ⇒ Object
readonly
Returns the value of attribute last_url.
-
#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_id(id) ⇒ Object
- #get_id_in_format(id, 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 |
#last_url ⇒ Object (readonly)
Returns the value of attribute last_url.
10 11 12 |
# File 'lib/unapi/service.rb', line 10 def last_url @last_url 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 26 |
# 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 @last_url = @url return formats end |
#formats_for_id(id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/unapi/service.rb', line 28 def formats_for_id(id) formats = [] request_url = @url + "?id=#{CGI.escape(id)}" @status_code, @document, @content_type = Utils.get_document request_url @document.elements.each('.//formats/format') do |e| formats << Format.new_from_element(e) end @last_url = request_url return formats end |
#get_id_in_format(id, format) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/unapi/service.rb', line 39 def get_id_in_format(id, format) id_esc = CGI.escape(id) format_esc = CGI.escape(format) request_url = @url + "?id=#{id_esc}&format=#{format_esc}" @document = nil @status_code, body, @content_type = Utils.get request_url @last_url = request_url return body end |