Class: FirstGiving::Lookup

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/firstgiving/lookup.rb

Defined Under Namespace

Modules: Actions

Constant Summary

Constants included from Base

Base::DONATION_PRODUCTION_ENDPOINT, Base::DONATION_SANDBOX_ENDPOINT, Base::SEARCH_ENDPOINT

Instance Method Summary collapse

Methods included from Base

#headers_json, #headers_security, #logging

Constructor Details

#initializeLookup

Returns a new instance of Lookup.



13
14
15
16
# File 'lib/firstgiving/lookup.rb', line 13

def initialize
  @api_endpoint = DONATION_PRODUCTION_ENDPOINT
  @api_endpoint = DONATION_SANDBOX_ENDPOINT if FirstGiving.configuration.options[:use_staging]
end

Instance Method Details

#call(action, params, _headers) ⇒ Object



22
23
24
25
# File 'lib/firstgiving/lookup.rb', line 22

def call(action, params, _headers)
  response = get_call(@api_endpoint, action, params, _headers)
  parse(response.body)
end

#detail(params) ⇒ Object



27
28
29
# File 'lib/firstgiving/lookup.rb', line 27

def detail(params)
  call(Actions::TRANSACTION_DETAIL, params, headers)
end

#headersObject



18
19
20
# File 'lib/firstgiving/lookup.rb', line 18

def headers
  headers_json.merge!(headers_security)
end

#list(params) ⇒ Object



31
32
33
# File 'lib/firstgiving/lookup.rb', line 31

def list(params)
  call(Actions::TRANSACTION_LIST, params, headers)
end

#message_from(response) ⇒ Object



45
46
47
# File 'lib/firstgiving/lookup.rb', line 45

def message_from(response)
  response['firstGivingDonationApi']['firstGivingResponse']['verboseErrorMessage']
end

#params_from(response) ⇒ Object



40
41
42
43
# File 'lib/firstgiving/lookup.rb', line 40

def params_from(response)
  params = response['firstGivingDonationApi']['firstGivingResponse']['transaction']
  params ||= response['firstGivingDonationApi']['firstGivingResponse']['transactions']
end

#parse(body) ⇒ Object



49
50
51
52
# File 'lib/firstgiving/lookup.rb', line 49

def parse(body)
  response = Crack::XML.parse(body)
  response = Response.new(success_from(response), message_from(response), params_from(response))
end

#success_from(response) ⇒ Object



35
36
37
38
# File 'lib/firstgiving/lookup.rb', line 35

def success_from(response)
  ack = response['firstGivingDonationApi']['firstGivingResponse']['acknowledgement']
  ack == 'Success' ? true : false
end