Module: FellowshipOne
- Includes:
- Enumerable
- Defined in:
- lib/common.rb,
lib/api/fund.rb,
lib/auto_load.rb,
lib/api/person.rb,
lib/api/search.rb,
lib/api/status.rb,
lib/api/fund_list.rb,
lib/api/household.rb,
lib/api/api_object.rb,
lib/fellowship_one.rb,
lib/api/person_list.rb,
lib/api/status_list.rb,
lib/api/contribution.rb,
lib/api/communication.rb,
lib/api/sub_fund_list.rb,
lib/api/household_list.rb,
lib/readers/api_reader.rb,
lib/writers/api_writer.rb,
lib/readers/fund_reader.rb,
lib/api/contribution_list.rb,
lib/readers/person_reader.rb,
lib/readers/status_reader.rb,
lib/writers/person_writer.rb,
lib/readers/fund_list_reader.rb,
lib/readers/household_reader.rb,
lib/writers/household_writer.rb,
lib/api/member_household_list.rb,
lib/api/mergeable_person_list.rb,
lib/readers/person_list_reader.rb,
lib/readers/status_list_reader.rb,
lib/readers/contribution_reader.rb,
lib/writers/contribution_writer.rb,
lib/api/mergeable_household_list.rb,
lib/readers/communication_reader.rb,
lib/readers/sub_fund_list_reader.rb,
lib/writers/communication_writer.rb,
lib/readers/household_list_reader.rb,
lib/readers/contribution_list_reader.rb,
lib/readers/member_household_list_reader.rb
Defined Under Namespace
Classes: Api, ApiObject, ApiReader, ApiWriter, Communication, CommunicationReader, CommunicationWriter, Contribution, ContributionList, ContributionListReader, ContributionReader, ContributionWriter, Fund, FundList, FundListReader, FundReader, Household, HouseholdList, HouseholdListReader, HouseholdReader, HouseholdWriter, MemberHouseholdList, MemberHouseholdListReader, MergeableHouseholdList, MergeablePersonList, Person, PersonAddress, PersonCommunication, PersonList, PersonListReader, PersonReader, PersonWriter, Search, Status, StatusList, StatusListReader, StatusReader, SubFundList, SubFundListReader
Class Method Summary
collapse
Class Method Details
._oauth_request_get(method, path, params, body) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/common.rb', line 39
def self._oauth_request_get(method, path, params, body)
consumer_env = FellowshipOne::Api.is_production ? '' : '.staging'
base_url = "https://#{FellowshipOne::Api.church_code}#{consumer_env}.fellowshiponeapi.com"
url = base_url + path
if method == :get
url_params = params.collect { |k, v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
url_params = nil if url_params.empty?
url = [url, url_params].compact.join('?')
params = {}
end
consumer = OAuth::Consumer.new(FellowshipOne::Api.consumer_key,
FellowshipOne::Api.consumer_secret,
:site => base_url,
:http_method => method)
access_token = OAuth::AccessToken.new(consumer, FellowshipOne::Api.api_token, FellowshipOne::Api.api_secret)
options = {:params => params, :method => method, :body => body}
oauth_params = {:consumer => consumer, :token => access_token}
hydra = Typhoeus::Hydra.new
req = Typhoeus::Request.new(url, options)
req.options[:headers].merge!({'Content-Type' => 'application/json'})
oauth_helper = OAuth::Client::Helper.new(req, oauth_params.merge(:request_uri => url))
req.options[:headers].merge!({"Authorization" => oauth_helper.})
hydra.queue(req)
hydra.run
req.response
end
|
.api_request(method, path, params = {}, body = '') ⇒ Object
5
6
7
8
9
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
|
# File 'lib/common.rb', line 5
def self.api_request(method, path, params = {}, body = '')
response = self._oauth_request_get(method, path, params, body)
unless response.success?
puts response.inspect
if response.code > 0
raise FellowshipOneExceptions::UnableToConnectToFellowshipOne.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 FellowshipOneExceptions::UnknownErrorConnectingToFellowshipOne.new("Unknown error when connecting to FellowshipOne API. #{response_code_desc}")
else
raise FellowshipOneExceptions::FellowshipOneResponseError.new(error_messages)
end
end
end
response
end
|