kiva_api 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65cd1ab8ebc34a3b117354afecae696bb6051d29
4
- data.tar.gz: d4d4b75f3c048e8241e897ca369d6f58b67b1a68
3
+ metadata.gz: 245421fc53b4e783d890b0da38d26b885b0cf500
4
+ data.tar.gz: bed30fd8a7c2e5f91166713ee92b5652759d5a99
5
5
  SHA512:
6
- metadata.gz: 748cd3db64581809c5297ce33fb01183c413d9f18a3eab61860479b5ebd87198e034b45041ed1ef40092469b8b5a028b376a4af9194e90b537bfe739c577a17e
7
- data.tar.gz: 9d9b731618c74f28d737aea4ff1a8e45607eea78c2d508fbbae9c3e74905fb10f01ec0ab7a8735ec4d97b2a0814747564bfcf690e06393bc81a71134a51b746d
6
+ metadata.gz: 73847da2413e66ea3d804e832c92c34b5d5fcf9739f57cd3a65bfe3e90053062dbf6bd440738b71871acad7d2cc5c6bac7e979f84fa7ca0480980f527170df4c
7
+ data.tar.gz: c3c386c6da60756e6bd57979b41961d091b72b1c9c1cbbb5d29edefea54cf365cda0fd245e5e9d5dc913ef8f44d2e1117327eafd3bc68ec3149dcff19d3a45c5
@@ -0,0 +1,31 @@
1
+ class KivaApi::CommentsResponse
2
+ attr_reader :response
3
+
4
+ def initialize(response)
5
+ @response = response.parsed_response
6
+ end
7
+
8
+ def comments
9
+ if @response["entities"]
10
+ comments = []
11
+ @response["entities"].each do |comment|
12
+ comments << {
13
+ body: comment["properties"]["body"],
14
+ date: comment["properties"]["date"],
15
+ author: comment["properties"]["authorName"]
16
+ }
17
+ end
18
+ comments
19
+ else
20
+ []
21
+ end
22
+ end
23
+
24
+ def comment_count
25
+ if @response["properties"].is_a?(Hash)
26
+ @response["properties"]["count"]
27
+ else
28
+ 0
29
+ end
30
+ end
31
+ end
data/lib/kiva_api/loan.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require 'httparty'
2
2
 
3
3
  class KivaApi::Loan
4
- attr :host, :loan_number
5
- attr_reader :response, :terms_response
4
+ attr_accessor :host, :loan_number
5
+ attr_reader :response, :terms_response, :comments
6
6
  DEFAULT_HOST = 'https://api.kivaws.org/v2'
7
7
 
8
8
  def initialize(loan_number = nil, host = nil)
@@ -15,6 +15,7 @@ class KivaApi::Loan
15
15
  def get_data
16
16
  @response = KivaApi::LoanResponse.new(HTTParty.get("#{@host}/loan/#{@loan_number}/"))
17
17
  @terms_response = KivaApi::TermsResponse.new(HTTParty.get("#{@host}/loan/#{@loan_number}/terms"))
18
+ @comments = KivaApi::CommentsResponse.new(HTTParty.get("#{@host}/loan/#{@loan_number}/comments"))
18
19
  end
19
20
 
20
21
  private
@@ -1,3 +1,3 @@
1
1
  module KivaApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/kiva_api.rb CHANGED
@@ -2,6 +2,7 @@ require "kiva_api/version"
2
2
  require 'kiva_api/loan'
3
3
  require 'kiva_api/loan_response'
4
4
  require 'kiva_api/terms_response'
5
+ require 'kiva_api/comments_response'
5
6
 
6
7
  module KivaApi
7
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kiva_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Magelowitz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-12 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -113,6 +113,7 @@ files:
113
113
  - bin/setup
114
114
  - kiva_api.gemspec
115
115
  - lib/kiva_api.rb
116
+ - lib/kiva_api/comments_response.rb
116
117
  - lib/kiva_api/loan.rb
117
118
  - lib/kiva_api/loan_response.rb
118
119
  - lib/kiva_api/terms_response.rb