class Coinone::Connection
Constants
- AUTH_URI
- BASE_URI
- DELETE_AUTH_URI
- REFRESH_AUTH_URI
- REQUEST_URI
Attributes
access_token[R]
secret_key[R]
Public Class Methods
factory(params)
click to toggle source
ACCESS_TOKEN = “ACESS_TOKEN” SECRET_KEY= “SECRET_KEY”
# File lib/coinone/connection.rb, line 20 def self.factory(params) # :nodoc Connection.new( access_token: params[:access_token], secret_key: params[:secret_key] ) end
new(options={})
click to toggle source
# File lib/coinone/connection.rb, line 27 def initialize(options={}) # :nodoc @access_token = options[:access_token] || nil @secret_key = options[:secret_key] || nil end
Public Instance Methods
check_for_errors(response)
click to toggle source
# File lib/coinone/connection.rb, line 76 def check_for_errors(response) # {"errorCode"=>"130", "errorMessage"=>"V2 API Nonce value must be a positive integer", "result"=>"error"} response = JSON.parse(response) case response["errorCode"].to_i when 11 then raise AccessTokenMissingError, response["errorMessage"] when 12 then raise InvalidAccessTokenError, response["errorMessage"] when 40 then raise InvalidAPIPermissionError, response["errorMessage"] when 50 then raise AuthenticateError, response["errorMessage"] when 51 then raise InvalidAPIError, response["errorMessage"] when 100 then raise SessionExpiredError, response["errorMessage"] when 101 then raise InvalidFormatError, response["errorMessage"] when 102 then raise IDMissingError, response["errorMessage"] when 103 then raise LackOfBalanceError, response["errorMessage"] when 104 then raise OrderIdMissingError, response["errorMessage"] when 105 then raise PriceNotCorrectError, response["errorMessage"] when 106 then raise LockingError, response["errorMessage"] when 107 then raise ParameterError, response["errorMessage"] when 111 then raise OrderIdMissingError, response["errorMessage"] when 112 then raise CancelFailedError, response["errorMessage"] when 113 then raise QuantityTooLowError, response["errorMessage"] when 120 then raise APIV2PayloadMissingError, response["errorMessage"] when 121 then raise APIV2SignatureMissingError, response["errorMessa ge"] when 122 then raise APIV2NonceMissingError, response["errorMessage"] when 123 then raise APIV2SignatureIsNotCorrectError, response["errorMessage"] when 130 then raise APIV2NonceValueMustBePosiveIntegerError, response["errorMessage"] when 131 then raise APIV2NonceBiggerThenLastNonceError, response["errorMessage"] when 132 then raise APIV2BodyIsCorruptedError, response["errorMessage"] when 150 then raise APIV2Call150Error, response["errorMessage"] when 151 then raise APIV2Call151Error, response["errorMessage"] when 200 then raise WalletError, response["errorMessage"] when 202 then raise Limitation202Error, response["errorMessage"] when 210 then raise Limitation210Error, response["errorMessage"] when 220 then raise Limitation220Error, response["errorMessage"] when 221 then raise Limitation221Error, response["errorMessage"] when 310 then raise MobileAuthError, response["errorMessage"] when 311 then raise NeedMobileAuthError, response["errorMessage"] when 312 then raise NameIsNotCorrectError, response["errorMessage"] when 330 then raise PhoneNumberError, response["errorMessage"] when 404 then raise PageNotFoundError, response["errorMessage"] when 405 then raise ServerError, response["errorMessage"] when 444 then raise LockingError, response["errorMessage"] when 500 then raise Email500Error, response["errorMessage"] when 501 then raise EMail501Error, response["errorMessage"] when 777 then raise MobileAuthError, response["errorMessage"] when 778 then raise PhoneNumberError, response["errorMessage"] when 1202 then raise AppNotFoundError, response["errorMessage"] when 1203 then raise AlreadyRegisteredError, response["errorMessage"] when 1204 then raise InvalidAccessError, response["errorMessage"] when 1205 then raise APIKeyError, response["errorMessage"] when 1206 then raise UserNotFound1206Error, response["errorMessage"] when 1207 then raise UserNotFound1207Error, response["errorMessage"] when 1208 then raise UserNotFound1208Error, response["errorMessage"] when 1209 then raise UserNotFound1209Error, response["errorMessage"] end end
create_coinone_payload( data )
click to toggle source
# File lib/coinone/connection.rb, line 72 def create_coinone_payload( data ) Base64.strict_encode64(data.to_json).chomp end
create_coinone_signature( payload )
click to toggle source
# File lib/coinone/connection.rb, line 68 def create_coinone_signature( payload ) OpenSSL::HMAC.hexdigest( 'sha512', @secret_key.upcase, payload) end
get( connection_uri, params = {} )
click to toggle source
# File lib/coinone/connection.rb, line 38 def get( connection_uri, params = {} ) response = resource[ connection_uri ].get params: params.merge(access_token: @access_token) check_for_errors(response.body) JSON.parse(response.body, symbolize_names: true) end
post( connection_uri, params = {} )
click to toggle source
# File lib/coinone/connection.rb, line 47 def post( connection_uri, params = {} ) params[:access_token] = @access_token params[:nonce] = Time.now.to_i payload = create_coinone_payload(params) signature = create_coinone_signature(payload) #puts "Send To : #{connection_uri}" #puts "params: #{params}" #puts "payload: #{payload}" #puts "signature: #{create_coinone_signature(payload)}" response = resource[ connection_uri ].post params, {'Content-Type': 'application/json', 'X-COINONE-PAYLOAD': payload, 'X-COINONE-SIGNATURE': signature } #puts "Response : #{response}\n\n" #puts "Response Body : #{response.body}\n\n" check_for_errors(response.body) JSON.parse(response.body, symbolize_names: true) end
resource()
click to toggle source
# File lib/coinone/connection.rb, line 34 def resource @@resouce ||= RestClient::Resource.new( BASE_URI ) end