Class: PayPal::Common::Request

Inherits:
Request
  • Object
show all
Defined in:
lib/paypal/common/request.rb

Constant Summary

Constants inherited from Request

Request::CA_FILE

Instance Attribute Summary

Attributes inherited from Request

#uri

Instance Method Summary collapse

Methods inherited from Request

#api_methods, #normalize_params, #post, #prepare_headers, #prepare_params

Instance Method Details

#apiObject



4
5
6
# File 'lib/paypal/common/request.rb', line 4

def api
  PayPal::Api
end

#build_action_type(value) ⇒ Object



41
42
43
# File 'lib/paypal/common/request.rb', line 41

def build_action_type(value)
  ACTION_TYPES.fetch(value.to_sym, value) if value
end

#build_json(json) ⇒ Object



32
33
34
# File 'lib/paypal/common/request.rb', line 32

def build_json(json)
  json.is_a?(Hash) ? build_json(json) : json
end

#default_headersObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/paypal/common/request.rb', line 8

def default_headers
  super.merge(
    {
      'X-PAYPAL-SECURITY-USERID'      => api.username,
      'X-PAYPAL-SECURITY-PASSWORD'    => api.password,
      'X-PAYPAL-SECURITY-SIGNATURE'   => api.signature,
      'X-PAYPAL-REQUEST-DATA-FORMAT'  => api.request_data_format,
      'X-PAYPAL-RESPONSE-DATA-FORMAT' => api.response_data_format,
      'X-PAYPAL-APPLICATION-ID'       => api.app_id
    }
  )
end

#method_endpoint(method) ⇒ Object

Returns the actual api endpoint base on method



23
24
25
# File 'lib/paypal/common/request.rb', line 23

def method_endpoint(method)
  api.api_endpoint
end

#prepare_json(json) ⇒ Object



27
28
29
30
# File 'lib/paypal/common/request.rb', line 27

def prepare_json(json)
  json[:requestEnvelope] = PayPal::Common::RequestEnvelope.new.to_hash unless json[:requestEnvelope]
  json
end

#run(method, json = {}) ⇒ Object



36
37
38
39
# File 'lib/paypal/common/request.rb', line 36

def run(method, json = {})
  self.uri = method_endpoint(method)
  post(MultiJson.dump(prepare_json(json)), default_headers)
end