Module: ShelbyArena
- Defined in:
- lib/common.rb,
lib/api/fund.rb,
lib/auto_load.rb,
lib/api/family.rb,
lib/api/person.rb,
lib/api/address.rb,
lib/shelby_arena.rb,
lib/api/fund_list.rb,
lib/api/api_object.rb,
lib/api/person_list.rb,
lib/api/contribution.rb,
lib/api/shelby_session.rb,
lib/readers/api_reader.rb,
lib/writers/api_writer.rb,
lib/readers/fund_reader.rb,
lib/api/contribution_list.rb,
lib/readers/family_reader.rb,
lib/readers/person_reader.rb,
lib/writers/person_writer.rb,
lib/readers/fund_list_reader.rb,
lib/readers/person_list_reader.rb,
lib/readers/contribution_reader.rb,
lib/readers/contribution_list_reader.rb
Defined Under Namespace
Classes: Address, Api, ApiObject, ApiReader, ApiWriter, Contribution, ContributionList, ContributionListReader, ContributionReader, Family, FamilyReader, Fund, FundList, FundListReader, FundReader, Person, PersonList, PersonListReader, PersonReader, PersonWriter, ShelbySession
Class Method Summary
collapse
Class Method Details
._generate_api_signature(path, params) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/common.rb', line 57
def self._generate_api_signature(path, params)
get_vars = ''
if params.to_a.size > 0
get_vars = '?' + params.to_a.sort.collect { |kv_pair| "#{kv_pair[0]}=#{kv_pair[1].to_s}" }.join('&').downcase
end
utoken = get_vars.empty? ? '?' : '&'
Digest::MD5.hexdigest("#{ShelbyArena::Api.api_secret}_#{path.downcase}#{get_vars}#{utoken}api_session=#{ShelbyArena::Api.session_key}")
end
|
._xml2json(xml) ⇒ Object
49
50
51
52
53
54
|
# File 'lib/common.rb', line 49
def self._xml2json(xml)
XmlSimple.xml_in(xml, {KeepRoot: true, ForceArray: false, SuppressEmpty: true})
end
|
.api_request(method, path, params = {}, body = nil) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/common.rb', line 10
def self.api_request(method, path, params = {}, body = nil)
url = [ShelbyArena::Api.service_url, path].join('/')
mparams = params.merge({api_session: ShelbyArena::Api.session_key})
mparams = mparams.merge({api_sig: self._generate_api_signature(path, params)})
response =
case method
when :post
raise 'Shelby POST not tested yet'
when :get
Typhoeus::Request.get(url, params: mparams)
when :put
raise 'Shelby PUT not tested yet'
when :delete
raise 'Shelby DELETE not tested yet'
end
if !response.success?
if response.code > 0
raise ShelbyArenaExceptions::UnableToConnectToShelbyArena.new(response.body)
else
begin
error_messages = JSON.parse(response.body)['error_message']
rescue
response_code_desc = response..partition("\r\n")[0].sub(/^\S+/, '') rescue nil
raise ShelbyArenaExceptions::UnknownErrorConnectingToShelbyArena.new("Unknown error when connecting to Shelby Arena.#{response_code_desc}")
else
raise ShelbyArenaExceptions::ShelbyArenaResponseError.new(error_messages)
end
end
end
response
end
|
.attr_underscore(str) ⇒ Object
68
69
70
71
72
73
74
|
# File 'lib/common.rb', line 68
def self.attr_underscore(str)
str.gsub(/::/, '/')
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
.tr("-", "_")
.downcase
end
|
.request_session ⇒ Object