KivaApi
Get Loan data from Kiva's API
Installation
Add this line to your application's Gemfile:
gem 'kiva_api', '~> 0.1.11'
And then execute:
$ bundle
Or install it yourself as:
$ gem install kiva_api
Usage
Initializing the object
When initializing the KivaApi::Loan object, you can optionally add the loan ID to the initialization.
require 'kiva_api'
loan_api = KivaApi::Loan.new(92464)
# => #<KivaApi::Loan:0x007ff09b9daa88 @host="https://api.kivaws.org/v2", @loan_number=92464>
loan_api.get_data # this will hit the @host on Kiva for the loan number that you specify
loan_response = loan_api.loan
loan_response.parsed_body
# => {"class"=>["Loan_Partner", "Loan"], "properties"=>{"id"=>92464...
loan_response.state
# => "ended"
loan_response.loan_amount
# => 825.00
loan_response.funded_amount
# => 825.00
loan_response.basket_amount
# => 0.00
loan_response.paid_amount
# => 825.00
loan_response.privately_fundraising?
# => false
loan_response.required_pfp_lenders
# => 7
loan_response.purchased_amount
# => 825.00
loan_response.loan_amount_left_to_purchase
# => 0.00
loan_response.percent_purchased
# => 100.00
loan_response.delinquent?
# => false
loan_response.expiration_date
# => "2015-09-15T16:47:02Z"
loan_response.business_name
# => "Ellen: A-1 Grooming Too"
terms = loan_api.terms
terms.expected_payments
# => [{:amount=>35.87, :effective_date=>"2009-04-08T07:00:00Z", :due_to_kiva_date=>"2009-06-01T07:00:00Z"}, ...]
comments = loan_api.comments
comments.comment_count
# => 0
# If there are comments this would be the comments response
comments.comments
# => [{body: "Comment body", author: "Steve", date: "2012-09-19T18:55:20Z"}, ...]
lenders = loan_api.lenders
lenders.lender_count
# => 6
Bad Responses
loan_api = KivaApi::Loan.new(1)
loan_api.get_data
# => #<HTTParty::Response:0x7fa2ab088658 parsed_response={"class"=>["error", "SirenE....
Contributing
- Fork it ( https://github.com/stevepm/kiva_api/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request