Class: BOSSMan::REST
- Inherits:
-
Object
- Object
- BOSSMan::REST
- Defined in:
- lib/bossman/rest.rb
Class Method Summary collapse
- .get(method, query, options) ⇒ Object
- .parse_error(response_string) ⇒ Object
- .validate_parameters(options) ⇒ Object
Class Method Details
.get(method, query, options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bossman/rest.rb', line 7 def self.get(method, query, ) validate_parameters() uri = URI.parse(URI.encode("#{API_BASEURI}/#{method}/#{API_VERSION}/#{query}")) uri.query = .to_query request = Net::HTTP::Get.new(uri.request_uri) response = Net::HTTP.new(uri.host).request(request) case response when Net::HTTPSuccess return ResultSet.new(ActiveSupport::JSON.decode(response.body)) else raise BOSSError, parse_error(response.body) end end |
.parse_error(response_string) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/bossman/rest.rb', line 22 def self.parse_error(response_string) response_document = REXML::Document.new(response_string) error_code = REXML::XPath.first(response_document, '//yahoo:code').text error_description = REXML::XPath.first(response_document, '//yahoo:description').text error_detail = REXML::XPath.first(response_document, '//yahoo:detail').text return "#{error_code} #{error_description}: #{error_detail}" end |
.validate_parameters(options) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/bossman/rest.rb', line 30 def self.validate_parameters() unless BOSSMan.application_id raise MissingConfiguration, "Application ID must be set prior to making a service call." end unless [:count] > 0 raise InvalidParameter, "Invalid count. Count must be > 0." end end |