glide 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/glide.gemspec +0 -1
- data/lib/glide.rb +29 -32
- data/lib/glide/version.rb +1 -1
- data/spec/glide_spec.rb +9 -1
- metadata +12 -12
data/glide.gemspec
CHANGED
@@ -15,7 +15,6 @@ Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
18
|
s.require_paths = ["lib"]
|
20
19
|
|
21
20
|
# specify any dependencies here; for example:
|
data/lib/glide.rb
CHANGED
@@ -1,47 +1,44 @@
|
|
1
|
-
require "glide/version"
|
2
1
|
require 'timeout'
|
3
2
|
require 'httparty'
|
4
3
|
require 'json'
|
5
4
|
|
5
|
+
require "glide/version"
|
6
|
+
|
6
7
|
module Glide
|
7
|
-
|
8
|
+
GLIDE_HUMAN_NAME = {"elec" => "Electricity", "tv_license" => "TV License"}
|
8
9
|
|
9
|
-
def self.api_key
|
10
|
-
@@api_key ||= ""
|
11
|
-
end
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
11
|
+
class << self
|
12
|
+
attr_accessor :api_key
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
def get_quote(services = ['elec'], extra = {}, period = 6, tenants = 1)
|
15
|
+
quotes = {}
|
16
|
+
services.each do |service|
|
17
|
+
quotes[service] = get_service_quote(service, extra[service], period, tenants)
|
18
|
+
quotes[service]["human_name"] = insert_human_name(service)
|
19
|
+
end
|
20
|
+
calculate_totals(quotes)
|
22
21
|
end
|
23
|
-
calculate_totals(quotes)
|
24
|
-
end
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def self.insert_human_name(service)
|
36
|
-
HUMAN_NAME[service] || service.capitalize
|
37
|
-
end
|
23
|
+
def get_service_quote(service, extra, period, tenants)
|
24
|
+
res = Timeout::timeout(5) { HTTParty.get("https://api.glide.uk.com/signup/servicePrice.json", :query => {:service => service, :period => period, :extra => extra, :tenants => tenants, :key => api_key}) }
|
25
|
+
JSON.parse(res.body)["results"]
|
26
|
+
rescue Timeout::Error => e
|
27
|
+
{"message" => "A timeout error has occured", "error" => 2}
|
28
|
+
rescue
|
29
|
+
{"message" => "An error has occured", "error" => 3}
|
30
|
+
end
|
38
31
|
|
39
|
-
|
40
|
-
|
41
|
-
["tenant_week", "tenant_month", "monthly_fee"].each do |k|
|
42
|
-
quotes["total"][k] = "%.2f" % quotes.map { |e| e[1][k].to_f }.reduce(:+)
|
32
|
+
def insert_human_name(service)
|
33
|
+
GLIDE_HUMAN_NAME[service] || service.capitalize
|
43
34
|
end
|
44
35
|
|
45
|
-
quotes
|
36
|
+
def calculate_totals(quotes)
|
37
|
+
quotes["total"] = {}
|
38
|
+
["tenant_week", "tenant_month", "monthly_fee"].each do |k|
|
39
|
+
quotes["total"][k] = "%.2f" % quotes.map { |e| e[1][k].to_f }.reduce(:+)
|
40
|
+
end
|
41
|
+
quotes
|
42
|
+
end
|
46
43
|
end
|
47
44
|
end
|
data/lib/glide/version.rb
CHANGED
data/spec/glide_spec.rb
CHANGED
@@ -26,7 +26,7 @@ describe Glide do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "get_service_quote" do
|
29
|
-
|
29
|
+
|
30
30
|
it 'should respond with HTTParty response and convert to json' do
|
31
31
|
HTTParty.should_receive(:get).and_return(response_elec)
|
32
32
|
# HTTParty.should_receive(:get) do |args|
|
@@ -55,6 +55,14 @@ describe Glide do
|
|
55
55
|
rt["total"]["tenant_week"].should eql("13.94")
|
56
56
|
rt["total"]["tenant_month"].should eql("60.40")
|
57
57
|
end
|
58
|
+
|
59
|
+
it "should return 0.00 when nil values are summed" do
|
60
|
+
quotes = {"elec" => {"message" => "A timeout error has occured", "error" => 2}, "water" => {"message" => "An error has occured", "error" => 3}}
|
61
|
+
rt = Glide.calculate_totals(quotes)
|
62
|
+
rt["total"]["monthly_fee"].should eql("0.00")
|
63
|
+
rt["total"]["tenant_week"].should eql("0.00")
|
64
|
+
rt["total"]["tenant_month"].should eql("0.00")
|
65
|
+
end
|
58
66
|
end
|
59
67
|
|
60
68
|
describe "insert_human_name" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glide
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement: &
|
16
|
+
requirement: &5590320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *5590320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: json
|
27
|
-
requirement: &
|
27
|
+
requirement: &5589620 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *5589620
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rake
|
38
|
-
requirement: &
|
38
|
+
requirement: &5588400 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *5588400
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &5613340 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *5613340
|
58
58
|
description: allows you to get quotes from the glide api for the services required
|
59
59
|
in one go and sum up the totals
|
60
60
|
email:
|
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
88
88
|
version: '0'
|
89
89
|
segments:
|
90
90
|
- 0
|
91
|
-
hash:
|
91
|
+
hash: 4300868938252812644
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
93
|
none: false
|
94
94
|
requirements:
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
segments:
|
99
99
|
- 0
|
100
|
-
hash:
|
100
|
+
hash: 4300868938252812644
|
101
101
|
requirements: []
|
102
102
|
rubyforge_project: glide
|
103
103
|
rubygems_version: 1.8.15
|