Class: OptaSD::Core
Direct Known Subclasses
Constant Summary collapse
- PARAMETERS =
YAML::load(File.open(File.('../../../config/parameters.yml', __FILE__)))
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#get ⇒ Object
Build the Request and get the Data.
-
#initialize ⇒ Core
constructor
The Initialize.
-
#parse_data(response) ⇒ Object
Parse The Response.
-
#parse_json(response) ⇒ Object
Parse JSON Response.
-
#parse_xml(response) ⇒ Object
Parse XML Response.
Constructor Details
#initialize ⇒ Core
The Initialize
9 10 11 12 |
# File 'lib/opta_sd/core.rb', line 9 def initialize set_configuration @params = Hash.new end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/opta_sd/core.rb', line 6 def data @data end |
Instance Method Details
#get ⇒ Object
Build the Request and get the Data
15 16 17 18 19 |
# File 'lib/opta_sd/core.rb', line 15 def get response = Net::HTTP.get(build_uri) @data = parse_data(response) self end |
#parse_data(response) ⇒ Object
Parse The Response
22 23 24 25 26 27 |
# File 'lib/opta_sd/core.rb', line 22 def parse_data(response) case @params[:_fmt] when 'json' then parse_json(response) when 'xml' then parse_xml(response) else response end end |
#parse_json(response) ⇒ Object
Parse JSON Response
30 31 32 33 34 |
# File 'lib/opta_sd/core.rb', line 30 def parse_json(response) data = JSON.parse(response) fail OptaSD::Error.new(data), ErrorMessage.(data['errorCode'].to_i) if data['errorCode'] data end |
#parse_xml(response) ⇒ Object
Parse XML Response
37 38 39 40 41 |
# File 'lib/opta_sd/core.rb', line 37 def parse_xml(response) data = Nokogiri::XML(response) do |config| config.strict.noblanks end fail OptaSD::Error.new(xml_error_to_hast(data)), ErrorMessage.(data.children.first.content.to_i) if data.css('errorCode').first.present? data end |