kiva_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65cd1ab8ebc34a3b117354afecae696bb6051d29
4
+ data.tar.gz: d4d4b75f3c048e8241e897ca369d6f58b67b1a68
5
+ SHA512:
6
+ metadata.gz: 748cd3db64581809c5297ce33fb01183c413d9f18a3eab61860479b5ebd87198e034b45041ed1ef40092469b8b5a028b376a4af9194e90b537bfe739c577a17e
7
+ data.tar.gz: 9d9b731618c74f28d737aea4ff1a8e45607eea78c2d508fbbae9c3e74905fb10f01ec0ab7a8735ec4d97b2a0814747564bfcf690e06393bc81a71134a51b746d
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in kiva_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Steven Magelowitz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # KivaApi
2
+
3
+ Get Loan data from Kiva's API
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'kiva_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install kiva_api
20
+
21
+ ## Usage
22
+
23
+ ### Initializing the object
24
+
25
+ When initializing the KivaApi::Loan object, you can optionally add the loan ID
26
+ to the initialization.
27
+
28
+
29
+ ```ruby
30
+ require 'kiva_api'
31
+
32
+ loan_api = KivaApi::Loan.new(92464)
33
+ # => #<KivaApi::Loan:0x007ff09b9daa88 @host="https://api.kivaws.org/v2", @loan_number=92464>
34
+
35
+ loan_api.get_data # this will hit the @host on Kiva for the loan number that you specify
36
+
37
+ loan_response = loan_api.response
38
+ loan_response.parsed_body
39
+ # => {"class"=>["Loan_Partner", "Loan"], "properties"=>{"id"=>92464...
40
+ loan_response.state
41
+ # => :ended
42
+ loan_response.loan_amount
43
+ # => "825.00"
44
+ loan_response.funded_amount
45
+ # => "825.00"
46
+ loan_response.basket_amount
47
+ # => "0.00"
48
+ loan_response.paid_amount
49
+ # => "825.00"
50
+
51
+ terms = loan_api.terms_response
52
+ terms.expected_payments
53
+ # => [{:amount=>"35.87", :effective_date=>"2009-04-08T07:00:00Z", :due_to_kiva_date=>"2009-06-01T07:00:00Z"}, ...]
54
+ ```
55
+
56
+ ### Bad Responses
57
+
58
+ ```ruby
59
+ loan_api = KivaApi::Loan.new(1)
60
+ loan_api.get_data
61
+ # => #<HTTParty::Response:0x7fa2ab088658 parsed_response={"class"=>["error", "SirenE....
62
+ ```
63
+
64
+ ## Contributing
65
+
66
+ 1. Fork it ( https://github.com/stevepm/kiva_api/fork )
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kiva_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/kiva_api.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kiva_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kiva_api"
8
+ spec.version = KivaApi::VERSION
9
+ spec.authors = ["Steven Magelowitz"]
10
+ spec.email = ["steven.magelowitz@gmail.com"]
11
+
12
+ spec.summary = %q{Get Loan data from Kiva's API}
13
+ spec.description = %q{Get Loan data from Kiva's API}
14
+ spec.homepage = "https://github.com/kiva/Kiva-API-Ruby-Gem"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'httparty', '~> 0.13.5'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.9"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.3.0"
27
+ spec.add_development_dependency "vcr", "~> 2.9.3"
28
+ spec.add_development_dependency "webmock", "~> 1.21.0"
29
+ end
@@ -0,0 +1,28 @@
1
+ require 'httparty'
2
+
3
+ class KivaApi::Loan
4
+ attr :host, :loan_number
5
+ attr_reader :response, :terms_response
6
+ DEFAULT_HOST = 'https://api.kivaws.org/v2'
7
+
8
+ def initialize(loan_number = nil, host = nil)
9
+ set_host(host)
10
+ if loan_number
11
+ @loan_number = loan_number
12
+ end
13
+ end
14
+
15
+ def get_data
16
+ @response = KivaApi::LoanResponse.new(HTTParty.get("#{@host}/loan/#{@loan_number}/"))
17
+ @terms_response = KivaApi::TermsResponse.new(HTTParty.get("#{@host}/loan/#{@loan_number}/terms"))
18
+ end
19
+
20
+ private
21
+ def set_host(host)
22
+ if host
23
+ @host = host
24
+ else
25
+ @host = DEFAULT_HOST
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,51 @@
1
+ class KivaApi::LoanResponse
2
+ attr_reader :response
3
+
4
+ STATES = {
5
+ 'deleted' => 'deleted',
6
+ 'refunded' => 'refunded',
7
+ 'inactive' => 'hidden',
8
+ 'inactive_expired' => 'hidden',
9
+ 'fundRaising' => 'fundraising',
10
+ 'expired' => 'expired',
11
+ 'raised' => 'raised',
12
+ 'payingBack' => 'paying_back',
13
+ 'ended' => 'ended',
14
+ 'reviewed' => 'review',
15
+ 'issue' => 'review',
16
+ 'defaulted' => 'paying_back_defaulted'
17
+ }
18
+
19
+ def initialize(response)
20
+ @response = response
21
+ end
22
+
23
+ def parsed_body
24
+ @response.parsed_response
25
+ end
26
+
27
+ def state
28
+ kiva_state_to_zip(parsed_body['properties']['status'])
29
+ end
30
+
31
+ def loan_amount
32
+ parsed_body['properties']['loanAmount']['amount']
33
+ end
34
+
35
+ def funded_amount
36
+ parsed_body['properties']['fundedAmount']['amount']
37
+ end
38
+
39
+ def basket_amount
40
+ parsed_body['properties']['basketAmount']['amount']
41
+ end
42
+
43
+ def paid_amount
44
+ parsed_body['properties']['paidAmount']['amount']
45
+ end
46
+
47
+ private
48
+ def kiva_state_to_zip(state)
49
+ STATES[state].to_sym
50
+ end
51
+ end
@@ -0,0 +1,19 @@
1
+ class KivaApi::TermsResponse
2
+ attr_reader :response
3
+
4
+ def initialize(response)
5
+ @response = response
6
+ end
7
+
8
+ def expected_payments
9
+ payments = []
10
+ response['properties']['expectedPayments'].each do |payment|
11
+ payments << {
12
+ amount: payment['amount']['amount'],
13
+ effective_date: payment['effectiveDate'],
14
+ due_to_kiva_date: payment['dueToKivaDate']
15
+ }
16
+ end
17
+ payments
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module KivaApi
2
+ VERSION = "0.1.0"
3
+ end
data/lib/kiva_api.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "kiva_api/version"
2
+ require 'kiva_api/loan'
3
+ require 'kiva_api/loan_response'
4
+ require 'kiva_api/terms_response'
5
+
6
+ module KivaApi
7
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kiva_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Steven Magelowitz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.13.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.13.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.9.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.9.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.21.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.21.0
97
+ description: Get Loan data from Kiva's API
98
+ email:
99
+ - steven.magelowitz@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - kiva_api.gemspec
115
+ - lib/kiva_api.rb
116
+ - lib/kiva_api/loan.rb
117
+ - lib/kiva_api/loan_response.rb
118
+ - lib/kiva_api/terms_response.rb
119
+ - lib/kiva_api/version.rb
120
+ homepage: https://github.com/kiva/Kiva-API-Ruby-Gem
121
+ licenses:
122
+ - MIT
123
+ metadata: {}
124
+ post_install_message:
125
+ rdoc_options: []
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ requirements: []
139
+ rubyforge_project:
140
+ rubygems_version: 2.4.6
141
+ signing_key:
142
+ specification_version: 4
143
+ summary: Get Loan data from Kiva's API
144
+ test_files: []