Class: Yatran::API
- Inherits:
-
Object
- Object
- Yatran::API
- Defined in:
- lib/yatran/api.rb
Class Method Summary collapse
Class Method Details
.request(method, args = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/yatran/api.rb', line 31 def self.request(method, args = {}) url = URI.parse("#{YATRAN_URL}#{method}") response = Net::HTTP.post_form(url, args).body begin response = JSON(response) rescue raise Error response end if response['code'] code = response['code'].to_i if ERROR_CODES.key?(code) raise Error.new(ERROR_CODES[code]) end end response end |