Class: FiftyFifty

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/fiftyfifty.rb

Defined Under Namespace

Classes: BadRequest

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ FiftyFifty

Returns a new instance of FiftyFifty.



11
12
13
14
# File 'lib/fiftyfifty.rb', line 11

def initialize(api_key)
   @api_key = api_key
   self.class.base_uri "5050.gd/api/#{@api_key}"
end

Instance Method Details

#campaigner_details(campaigner_id) ⇒ Object

Show details for a specific campaigner.



54
55
56
# File 'lib/fiftyfifty.rb', line 54

def campaigner_details(campaigner_id)
  return get("/campaigners/#{campaigner_id}")
end

#campaignersObject

List all campaigners currently running projects on 50/50.



49
50
51
# File 'lib/fiftyfifty.rb', line 49

def campaigners
  return get("/campaigners/list")
end

#get(url) ⇒ Object

Get’s response for a URL request. If the status is 400, raise a BadRequest exception, otherwise, return the associated data



60
61
62
63
64
65
66
67
# File 'lib/fiftyfifty.rb', line 60

def get(url)
  response = Hashie::Mash.new(self.class.get(url))
  if response.status == 400
    raise BadRequest
  else
    return response.data
  end
end

#project_details(project_id) ⇒ Object

Show details for specific project.



26
27
28
# File 'lib/fiftyfifty.rb', line 26

def project_details(project_id)
  return get("/projects/#{project_id}")
end

#project_donations(project_id) ⇒ Object

List donations for a specific project.



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

def project_donations(project_id)
  return get("/projects/#{project_id}/donations")
end

#project_pledges(project_id) ⇒ Object

List of users who have pledged to take part in a specific project.



43
44
45
# File 'lib/fiftyfifty.rb', line 43

def project_pledges(project_id)
  return get("/projects/#{project_id}/pledges")
end

#projectsObject

Lists all current 50/50 projects.



21
22
23
# File 'lib/fiftyfifty.rb', line 21

def projects
  return get("/projects/list")
end

#register_project_donation(project_id, amount) ⇒ Object

Notify us of a new donation, i.e. one that you may have received in person, or from another online payment mechanism. Your API key must be associated with the requested project for this to be successful.



38
39
40
# File 'lib/fiftyfifty.rb', line 38

def register_project_donation(project_id, amount)
  return get("/projects/#{project_id}/donations/notify/#{amount}")
end

#statisticsObject



16
17
18
# File 'lib/fiftyfifty.rb', line 16

def statistics
  return get("/statistics")
end