Class: TrailAPI::Donor

Inherits:
Base
  • Object
show all
Defined in:
lib/trail_api/donor.rb

Class Method Summary collapse

Methods inherited from Base

api_path_for, auth, hashize, #initialize, url_options

Constructor Details

This class inherits a constructor from TrailAPI::Base

Class Method Details

.all(organization_id) ⇒ Object



7
8
9
# File 'lib/trail_api/donor.rb', line 7

def self.all(organization_id )
 hashize get( api_path_for.api_v1_organization_donors_path( organization_id ) )
end

.create(organization_id, new_params) ⇒ Object



29
30
31
32
33
# File 'lib/trail_api/donor.rb', line 29

def self.create( organization_id, new_params )
  new_params[:donor].merge! :organization_id => organization_id
  params =  Hashie::Mash.new(new_params).stringify_keys!.to_hash
  hashize post( api_path_for.api_v1_organization_donors_path( organization_id), :body => ActiveSupport::JSON.encode(params) )
end

.destroy(organization_id, donor_id) ⇒ Object



35
36
37
# File 'lib/trail_api/donor.rb', line 35

def self.destroy( organization_id, donor_id )
  hashize delete( api_path_for.api_v1_organization_donor_path( organization_id , donor_id) )
end

.purchase(organization_id, donor_id, fund_info) ⇒ Object



39
40
41
42
# File 'lib/trail_api/donor.rb', line 39

def self.purchase( organization_id, donor_id, fund_info )
  params = Hashie::Mash.new(fund_info).stringify_keys!.to_hash
  hashize post( api_path_for.api_v1_organization_donor_purchase_path( organization_id, donor_id) , :body => ActiveSupport::JSON.encode( params ))
end

.show(organization_id, donor_id) ⇒ Object



11
12
13
# File 'lib/trail_api/donor.rb', line 11

def self.show( organization_id , donor_id )
  hashize get( api_path_for.api_v1_organization_donor_path( organization_id , donor_id))
end

.update(organization_id, donor_id, new_params) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/trail_api/donor.rb', line 15

def self.update( organization_id, donor_id , new_params )
  params =  Hashie::Mash.new(new_params).stringify_keys!.to_hash
  # This is such a crazy mess -- httparty/rails really mangles the PUT process
  # So we're building what HTTParty SHOULD be building. Because this works excellent. 
  #
  hashize HTTParty::Request.new( Net::HTTP::Put, 
                             "http://" + TrailAPI.uri + api_path_for.api_v1_organization_donor_path( organization_id , donor_id), 
                             :body => ActiveSupport::JSON.encode(params),
                             :basic_auth => default_options[:basic_auth],
                             :headers => {'Accept' => 'application/json', 'Content-Type' => 'application/json'},
                             :format => :json).perform

end