module Shapeshift::Connection
Network Layer for API Rest client
Private Instance Methods
get( url, options = {} )
click to toggle source
Make an HTTP GET request
# File lib/shapeshift/connections.rb, line 14 def get( url, options = {} ) headers = merge_headers( options[:headers] || {} ) resp = self.class.get( url, { headers: headers } ) return parse( resp ) rescue ShapeshiftError => e puts e.message end
merge_headers(input = {})
click to toggle source
# File lib/shapeshift/connections.rb, line 6 def merge_headers(input = {}) { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }.merge( input ) end
parse( resp )
click to toggle source
# File lib/shapeshift/connections.rb, line 34 def parse( resp ) if resp.code == 200 body = resp.parsed_response # Received marketplace error from Shapeshift if body.is_a?(Hash) && body.has_key?("error") raise ShapeshiftError.new( body["error"] ) elsif body.is_a?(Hash) && body.has_key?("success") return body["success"] else return body end else raise HTTPError end end
post( url, options = {} )
click to toggle source
Make an HTTP POST request
# File lib/shapeshift/connections.rb, line 23 def post( url, options = {} ) headers = merge_headers( options[:headers] || {} ) body = options[:body] resp = self.class.post( url, { body: body.to_json, headers: headers } ) return parse( resp ) rescue ShapeshiftError => e puts e.message end