hopo-ruby 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b34282ca742a9099545aca5a1a6b78fc27e2f4ae
4
- data.tar.gz: 481f7a504f2c52b2441a8cff252afad40a502387
3
+ metadata.gz: 2a1171c029073f7bd9dd0c198fcf082464aaa9ab
4
+ data.tar.gz: fe0af2b14fb32d5bbd6cdba0bee43f808b9f5ccf
5
5
  SHA512:
6
- metadata.gz: 0a60da54656a03fe9f2b971672129820b532d17a5f0f4059b1d67c1ec499645fa4f57a523dcf4d34c2fe656fdd07910694cbd4e14961bf029acb6b0bc045fbe8
7
- data.tar.gz: b6944e1d8bf643cad2ea7284fafa56a81961a7607db00320ae431de716ff04c70d8dbe4e700dda40ab5cd602ec0602ecb9c8d5b75fe8ab4464f077ce44c84145
6
+ metadata.gz: c314e73105864c252eef83d7b1fa65fb10521e4c73b25ef59290dbabead48569c81c95f1fff4347630eb201766574419e547787b8f41aaea903bd5cfc5a6564f
7
+ data.tar.gz: beb9e29be275621beaa6910c7c1f117c538871c3bb2af95ba9d6ae607f0422891c8f47d01e274f09d7ec268f486e2d920b014b0fff117d9b184d9ec4733c5aad
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
-
2
1
  # hopo-ruby
3
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/hopo-ruby.svg)](http://badge.fury.io/rb/hopo-ruby)
4
+ [![Code Climate](https://codeclimate.com/github/mikereinmiller/hopo-ruby/badges/gpa.svg)](https://codeclimate.com/github/mikereinmiller/hopo-ruby)
5
+
4
6
  A library for using the Honest Policy API, currently supports Auto and Home Raters.
5
7
 
6
8
  ## Installation
@@ -25,6 +25,10 @@ require 'extend/object' unless defined?(::Rails)
25
25
  # General
26
26
  require 'hopo/errors'
27
27
 
28
+ # Utils
29
+ require 'hopo/utils/calculator'
30
+ require 'hopo/utils/sorter'
31
+
28
32
  # API Connections
29
33
  require 'hopo/connections/request'
30
34
  require 'hopo/connections/response'
@@ -1,15 +1,20 @@
1
1
  module Hopo
2
2
  class Rater < API
3
+ include Hopo::Utils::Calculator
4
+ include Hopo::Utils::Sorter
5
+
3
6
  attr_accessor :line, :premium_mode, :sorter
4
7
 
5
8
  BASE_URL = 'https://integral.honestpolicy.com/api'
9
+ API_VERSION = 1
10
+ API_PATH = 'rates'
6
11
 
7
- def initialize(line, premium_mode='annually', sorter='premiums-asc', version=1, path='rates')
12
+ def initialize(line, premium_mode='annually', sorter='premiums-asc')
8
13
  unless Hopo.api_key
9
14
  raise AuthenticationError, 'No API key provided. Set your API key using "Hopo.api_key = <API-KEY>".'
10
15
  end
11
16
 
12
- super(BASE_URL, "/v#{version}/#{path}", true)
17
+ super(BASE_URL, "/v#{API_VERSION}/#{API_PATH}", true)
13
18
 
14
19
  @premium_mode = premium_mode
15
20
  @sorter = sorter
@@ -28,46 +33,29 @@ module Hopo
28
33
  end
29
34
 
30
35
  def format_response(response)
31
- # TEMP Hack Until Integral API is cleaned Up....
36
+ # TEMP Hack for v1 Until Integral API is cleaned Up (v2)
32
37
  if response['status']
33
38
  hash = { :errors => [response['message']] }
34
39
 
40
+ elsif response['errors']
41
+ hash = {:errors => [response['errors']]}
42
+
35
43
  else
36
44
  hash = {}
37
45
  rates = response['results']['rates']
38
46
  errors = response['results']['errors']
39
47
  risk = response['risk']
40
48
 
41
- hash.merge!( {:rates => factor_premiums(rates) } ) unless rates.blank?
49
+ calculated_rates = factor_rates(rates, premium_mode)
50
+ sorted_rates = sort_rates(calculated_rates, sorter)
51
+
52
+ hash.merge!( {:rates => sorted_rates} ) unless rates.blank?
42
53
  hash.merge!( {:errors => errors} ) unless errors.blank?
43
54
  hash.merge!( {:risk => risk} ) unless risk.blank?
44
-
45
55
  end
46
56
 
47
57
  hash
48
58
  end
49
59
 
50
- def factor_premiums(rates)
51
- premiums = {:monthly => 12, :triannually => 3, :quarterly => 4, :biannually => 2, :annually => 1}
52
- divisor = premiums[premium_mode.to_sym] || 1
53
-
54
- rates.each do |k, v|
55
- rates[k] = v / divisor
56
- end
57
-
58
- sort_rates(rates) unless sorter.blank?
59
- end
60
-
61
- def sort_rates(rates)
62
- sort = sorter.split('-')
63
-
64
- sorted_rates =
65
- if sort[1] == 'desc'
66
- Hash[rates.sort_by {|k, v| sort[0]=='companies' ? k : v }.reverse]
67
- else
68
- Hash[rates.sort_by {|k, v| sort[0]=='companies' ? k : v }]
69
- end
70
- end
71
-
72
60
  end
73
61
  end
@@ -1,13 +1,15 @@
1
1
  module Hopo
2
2
  class AutoRater < Rater
3
3
 
4
- def initialize(premium_mode='annually', sorter='premiums-asc', version=1, path='rates')
5
- super('auto', premium_mode, sorter, version, path)
4
+ def initialize(premium_mode='annually', sorter='premiums-asc')
5
+ super('auto', premium_mode, sorter)
6
6
  end
7
7
 
8
8
  def required_fields?
9
9
  {
10
10
  :zip => 'Five diging Zip Code for location',
11
+ :num_vehicles => 'Number representing the total count of vehicles',
12
+ :num_drivers => 'Number representing the total number of drivers',
11
13
  :model_year => 'Not Required - defaults to 2012',
12
14
  :make => 'Not Required - defaults to Toyota',
13
15
  :model => 'Not Required - defaults to Camry'
@@ -1,8 +1,8 @@
1
1
  module Hopo
2
2
  class HomeRater < Rater
3
3
 
4
- def initialize(premium_mode='annually', sorter='premiums-asc', version=1, path='rates')
5
- super('home', premium_mode, sorter, version, path)
4
+ def initialize(premium_mode='annually', sorter='premiums-asc')
5
+ super('home', premium_mode, sorter)
6
6
  end
7
7
 
8
8
  def required_fields?
@@ -0,0 +1,20 @@
1
+ module Hopo
2
+ module Utils
3
+ module Calculator
4
+
5
+ def factor_rates(rates, mode)
6
+ return if rates.blank?
7
+
8
+ premiums = {:monthly => 12, :triannually => 3, :quarterly => 4, :biannually => 2, :annually => 1}
9
+ divisor = premiums[mode.to_sym] || 1
10
+
11
+ rates.each do |k, v|
12
+ rates[k] = v / divisor
13
+ end
14
+
15
+ rates
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module Hopo
2
+ module Utils
3
+ module Sorter
4
+
5
+ def sort_rates(rates, mode)
6
+ return if rates.blank?
7
+
8
+ sort = mode.split('-')
9
+
10
+ sorted_rates =
11
+ if sort[1] == 'desc'
12
+ Hash[rates.sort_by {|k, v| sort[0]=='companies' ? k : v }.reverse]
13
+ else
14
+ Hash[rates.sort_by {|k, v| sort[0]=='companies' ? k : v }]
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Hopo
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hopo-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Reinmiller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-01 00:00:00.000000000 Z
11
+ date: 2014-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,6 +77,8 @@ files:
77
77
  - lib/hopo/rater.rb
78
78
  - lib/hopo/rater/auto_rater.rb
79
79
  - lib/hopo/rater/home_rater.rb
80
+ - lib/hopo/utils/calculator.rb
81
+ - lib/hopo/utils/sorter.rb
80
82
  - lib/hopo/version.rb
81
83
  homepage: https://github.com/mikereinmiller/hopo-ruby
82
84
  licenses: