Class: SyncwiseApi::Requests::V1_0::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/syncwise_api/requests/V1_0/base.rb

Constant Summary collapse

HOST_HEADER =
'api-int.syncwise.com'
BASE_URL =
"https://#{HOST_HEADER}/rest/action"

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Base

Returns a new instance of Base.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/syncwise_api/requests/V1_0/base.rb', line 37

def initialize(params = {})
  # Add the action code to params based on the child class's name
  params[:'Action Code'] = self.unqualified_class

  # Verify we have all required params by comparing child class's required_params to the passed in params
  param_keys = params.keys.sort

  fail SyncwiseApi::Errors::InvalidParameters.new(self.class, param_keys, self.class.required_params) unless param_keys & self.class.required_params == self.class.required_params
  # remove the signing key from params and store it for use when building the HMAC signature
  @secret_key = params.delete(:secretKey)

  # @params now holds the params we need to build the header_hash
  @params = params

  build_header_hash

  # after build_header_hash returns, we have @header which holds all values needed to build the request and signature
  # and @params which now only contains the values that will be added to the JSON payload
end

Class Attribute Details

.default_header_paramsObject (readonly)

Returns the value of attribute default_header_params.



34
35
36
# File 'lib/syncwise_api/requests/V1_0/base.rb', line 34

def default_header_params
  @default_header_params
end

.host_headerObject (readonly)

Returns the value of attribute host_header.



34
35
36
# File 'lib/syncwise_api/requests/V1_0/base.rb', line 34

def host_header
  @host_header
end

.required_header_paramsObject (readonly)

Returns the value of attribute required_header_params.



34
35
36
# File 'lib/syncwise_api/requests/V1_0/base.rb', line 34

def required_header_params
  @required_header_params
end

.required_paramsObject (readonly)

Returns the value of attribute required_params.



34
35
36
# File 'lib/syncwise_api/requests/V1_0/base.rb', line 34

def required_params
  @required_params
end

Instance Method Details

#send_requestObject



57
58
59
60
61
62
63
64
# File 'lib/syncwise_api/requests/V1_0/base.rb', line 57

def send_request
  request_string = build_api_call
  body = build_body
  # TODO: send POST with Net::Http to request_string with JSON payload body
  SyncwiseApi::ServiceUtils::HTTP.post(request_string, body) do |http_response|
    SyncwiseApi::Responses::V1_0::Standard.new(http_response)
  end
end