Class: K2Client

Inherits:
Object
  • Object
show all
Defined in:
lib/k2-connect-ruby/k2_services/client/k2_client.rb

Overview

TODO: Uncomment the checking of the request scheme

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_secret_key) ⇒ K2Client

Initialize method

Raises:

  • (ArgumentError)


8
9
10
11
# File 'lib/k2-connect-ruby/k2_services/client/k2_client.rb', line 8

def initialize(api_secret_key)
  raise ArgumentError, 'No Secret Key Given!' if api_secret_key.blank?
  @api_secret_key = api_secret_key
end

Instance Attribute Details

#api_secret_keyObject

Returns the value of attribute api_secret_key.



3
4
5
# File 'lib/k2-connect-ruby/k2_services/client/k2_client.rb', line 3

def api_secret_key
  @api_secret_key
end

#hash_bodyObject

Returns the value of attribute hash_body.



3
4
5
# File 'lib/k2-connect-ruby/k2_services/client/k2_client.rb', line 3

def hash_body
  @hash_body
end

#k2_signatureObject

Returns the value of attribute k2_signature.



3
4
5
# File 'lib/k2-connect-ruby/k2_services/client/k2_client.rb', line 3

def k2_signature
  @k2_signature
end

Instance Method Details

#parse_request(the_request) ⇒ Object

Method for parsing the Entire Request. Come back to it later to trim. L8r call it set_client_variables

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
21
22
23
# File 'lib/k2-connect-ruby/k2_services/client/k2_client.rb', line 14

def parse_request(the_request)
  raise ArgumentError, 'Nil Request Parameter Input!' if the_request.blank?

  # The Response Body.
  @hash_body = Yajl::Parser.parse(the_request.body.read.as_json)
  # The Response Header
  hash_header = Yajl::Parser.parse(the_request.env.select { |k, _| k =~ /^HTTP_/ }.to_json)
  # The K2 Signature
  @k2_signature = hash_header['HTTP_X_KOPOKOPO_SIGNATURE']
end