class Iyzipay::IyzipayResource

Constants

AUTHORIZATION_HEADER_NAME
AUTHORIZATION_HEADER_STRING
RANDOM_CHARS
RANDOM_HEADER_NAME
RANDOM_STRING_SIZE

Public Instance Methods

calculate_hash(pki_string, random_header_value, options) click to toggle source
# File lib/iyzipay/iyzipay_resource.rb, line 38
def calculate_hash(pki_string, random_header_value, options)
  Digest::SHA1.base64digest("#{options.api_key}#{random_header_value}#{options.secret_key}#{pki_string}")
end
format_header_string(*args) click to toggle source
# File lib/iyzipay/iyzipay_resource.rb, line 42
def format_header_string(*args)
  sprintf(AUTHORIZATION_HEADER_STRING, *args)
end
get_http_header(pki_string = nil, options = nil, authorize_request = true) click to toggle source
# File lib/iyzipay/iyzipay_resource.rb, line 10
def get_http_header(pki_string = nil, options = nil, authorize_request = true)
  header = {:accept => 'application/json',
            :'content-type' => 'application/json'}

  if authorize_request
    random_header_value = random_string(RANDOM_STRING_SIZE)
    header[:'Authorization'] = "#{prepare_authorization_string(pki_string, random_header_value, options)}"
    header[:'x-iyzi-rnd'] = "#{random_header_value}"
    header[:'x-iyzi-client-version'] = 'iyzipay-ruby-1.0.45'
  end

  header
end
get_plain_http_header() click to toggle source
# File lib/iyzipay/iyzipay_resource.rb, line 24
def get_plain_http_header
  get_http_header(nil, false)
end
json_decode(response, raw_result) click to toggle source
# File lib/iyzipay/iyzipay_resource.rb, line 33
def json_decode(response, raw_result)
  json_result = JSON::parse(raw_result)
  response.from_json(json_result)
end
prepare_authorization_string(pki_string, random_header_value, options) click to toggle source
# File lib/iyzipay/iyzipay_resource.rb, line 28
def prepare_authorization_string(pki_string, random_header_value, options)
  hash_digest = calculate_hash(pki_string, random_header_value, options)
  format_header_string(options.api_key, hash_digest)
end
random_string(string_length) click to toggle source
# File lib/iyzipay/iyzipay_resource.rb, line 46
def random_string(string_length)
  random_string = ''
  string_length.times do
    random_string << RANDOM_CHARS.split('').sample
  end
  random_string
end
to_pki_string(request) click to toggle source
# File lib/iyzipay/iyzipay_resource.rb, line 54
def to_pki_string(request)
  PkiBuilder.new.append(:locale, request[:locale]).
      append(:conversationId, request[:conversationId]).
      get_request_string
end