Module: ChurchCommunityBuilder

Includes:
Enumerable
Defined in:
lib/ccb_api.rb,
lib/common.rb,
lib/api/fund.rb,
lib/api/batch.rb,
lib/auto_load.rb,
lib/api/campus.rb,
lib/api/search.rb,
lib/api/address.rb,
lib/api/fund_list.rb,
lib/api/api_object.rb,
lib/api/batch_list.rb,
lib/api/individual.rb,
lib/api/campus_list.rb,
lib/api/transaction.rb,
lib/readers/api_reader.rb,
lib/writers/api_writer.rb,
lib/api/individual_list.rb,
lib/writers/user_writer.rb,
lib/api/transaction_list.rb,
lib/api/valid_individual.rb,
lib/readers/batch_reader.rb,
lib/readers/fund_list_reader.rb,
lib/api/valid_individual_list.rb,
lib/readers/batch_list_reader.rb,
lib/readers/individual_reader.rb,
lib/readers/campus_list_reader.rb,
lib/api/mergeable_individual_list.rb,
lib/api/mergeable_transaction_list.rb,
lib/readers/individual_list_reader.rb

Overview

This class is meant to be a wrapper ChurchCommunityBuilder API

Defined Under Namespace

Classes: Address, Api, ApiObject, ApiReader, ApiWriter, Batch, BatchList, BatchListReader, BatchReader, Campus, CampusList, CampusListReader, Fund, FundList, FundListReader, Individual, IndividualList, IndividualListReader, IndividualReader, MergeableIndividualList, MergeableTransactionList, Search, Transaction, TransactionList, UserWriter, ValidIndividual, ValidIndividualList

Class Method Summary collapse

Class Method Details

.admin_request(method, params = {}, body = nil) ⇒ 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
37
38
39
40
41
42
43
44
45
46
# File 'lib/common.rb', line 5

def self.admin_request(method, params = {}, body = nil)
  url = "https://#{ChurchCommunityBuilder::Api.api_subdomain}.ccbchurch.com/api.php"
  username = ChurchCommunityBuilder::Api.api_username
  password = ChurchCommunityBuilder::Api.api_password

  response =
  case method
  when :post
    Typhoeus::Request.post(url, {:headers => headers, :body => body})
  when :get
    Typhoeus::Request.get(url, params: params, userpwd: username+":"+password)
  when :put
    Typhoeus::Request.put(url, {:headers => headers, :body => body})
  when :delete
    Typhoeus::Request.delete(url, {:headers => headers, :params => params})
  end    

  # Need to account for this
  # {"ccb_api"=>{"request"=>{"parameters"=>{"argument"=>[{"name"=>"srv", "value"=>"batch_profiles_in_date_range"}, 
  #   {"name"=>"date_start", "value"=>"2013-03-11"}, {"name"=>"date_end", "value"=>"2013-04-10"}]}}, 
  #   "response"=>{"error"=>{"number"=>"005", "type"=>"Service Permission", "content"=>"Query limit of '10000' reached, please try again tomorrow."}}}}
  if response.body.include?('Query limit of \'10000\' reached, please try again tomorrow.')
    raise ChurchCommunityBuilderExceptions::ChurchCommunityBuilderResponseError.new("Query limit of 10000 reached, please try again tomorrow.")
  elsif response.body.include?('You do not have permission to use this service.')
    raise ChurchCommunityBuilderExceptions::ChurchCommunityBuilderResponseError.new("You do not have permission to use this service.")      
  elsif !response.success?
    if response.code > 0
      raise ChurchCommunityBuilderExceptions::UnableToConnectToChurchCommunityBuilder.new(response.body)
    else
      begin
        error_messages = JSON.parse(response.body)['error_message']
      rescue
        response_code_desc = response.headers.partition("\r\n")[0].sub(/^\S+/, '') rescue nil
        raise ChurchCommunityBuilderExceptions::UnknownErrorConnectingToChurchCommunityBuilder.new("Unknown error when connecting to The City.#{response_code_desc}")
      else
        raise ChurchCommunityBuilderExceptions::ChurchCommunityBuilderResponseError.new(error_messages)
      end
    end
  end   
  
  response
end