glide 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ Gemfile.lock
3
+ pkg/*
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ coverage
8
+ InstalledFiles
9
+ lib/bundler/man
10
+ pkg
11
+ rdoc
12
+ spec/reports
13
+ test/tmp
14
+ test/version_tmp
15
+ tmp
16
+
17
+ # YARD artifacts
18
+ .yardoc
19
+ _yardoc
20
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in glide.gemspec
4
+ gemspec
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2012 Volker Pacher
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,70 @@
1
+ # Glide
2
+
3
+ The glide gem is a simple wrapper around the Glide UK api to retrieve quotes for the individual services you require in one go and sum up the totals.
4
+
5
+ # Installation
6
+
7
+ ## with bundler:
8
+
9
+ gem 'glide'
10
+
11
+ ## without bundler:
12
+
13
+ sudo gem install 'glide'
14
+
15
+ # Usage
16
+
17
+ ## Set your API access key:
18
+
19
+ Glide::api_key = "YourKeyGoesHere"
20
+
21
+ ## Do a query:
22
+
23
+ quotes = Glide.get_quote(["elec", "water", "gas"], {"water" => "SW1 0AA"}, 6, 1)
24
+
25
+ where the paramaters are as follows:
26
+
27
+ Glide.get_quote(service, extra, period, tenants)
28
+
29
+ service: Can be one or any combination of elec, water, gas, telephone, broadband and tv_license
30
+ extra: required additional information for certain services:
31
+ for elec 'green', 'nogas' or 'green,nogas' is optional
32
+ for water postcode is required
33
+ for broadband llu24s for standard broadband or llu24p for premium broadband is required
34
+
35
+ # Submitting an Issue
36
+ We use the [GitHub issue tracker][issues] to track bugs and features. Before
37
+ submitting a bug report or feature request, check to make sure it hasn't
38
+ already been submitted. When submitting a bug report, please include a [Gist][]
39
+ that includes a stack trace and any details that may be necessary to reproduce
40
+ the bug, including your gem version, Ruby version, and operating system.
41
+ Ideally, a bug report should include a pull request with failing specs.
42
+
43
+ [gist]: https://gist.github.com/
44
+
45
+ # Submitting a Pull Request
46
+ 1. [Fork the repository.][fork]
47
+ 2. [Create a topic branch.][branch]
48
+ 3. Add specs for your unimplemented feature or bug fix.
49
+ 4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
50
+ 5. Implement your feature or bug fix.
51
+ 6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
52
+ 7. Run `open coverage/index.html`. If your changes are not completely covered
53
+ by your tests, return to step 3.
54
+ 8. Add documentation for your feature or bug fix.
55
+ 9. Run `bundle exec rake yard`. If your changes are not 100% documented, go
56
+ back to step 8.
57
+ 10. Add, commit, and push your changes.
58
+ 11. [Submit a pull request.][pr]
59
+
60
+ [fork]: http://help.github.com/fork-a-repo/
61
+ [branch]: http://learn.github.com/p/branching.html
62
+ [pr]: http://help.github.com/send-pull-requests/
63
+
64
+ ## Copyright
65
+ Copyright (c) 2012 Volker Pacher
66
+ See [LICENSE][] for details.
67
+
68
+ [license]: https://github.com/vpacher/glide/blob/master/LICENSE.md
69
+
70
+ =====
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "glide/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "glide"
7
+ s.version = Glide::VERSION
8
+ s.authors = ["Volker Pacher"]
9
+ s.email = ["volker.pacher@gmail.com"]
10
+ s.homepage = "https://github.com/vpacher/glide"
11
+ s.summary = %q{a wrapper of the Glide Uk api}
12
+ s.description = %q{allows you to get quotes from the glide api for the services required in one go and sum up the totals}
13
+
14
+ s.rubyforge_project = "glide"
15
+
16
+ s.files = `git ls-files`.split("\n")
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
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_runtime_dependency "httparty"
23
+ s.add_runtime_dependency "json"
24
+ s.add_development_dependency "rake"
25
+ s.add_development_dependency "rspec"
26
+ end
@@ -0,0 +1,43 @@
1
+ require "glide/version"
2
+ require 'timeout'
3
+ require 'httparty'
4
+ require 'json'
5
+
6
+ module Glide
7
+
8
+ @@api_key = ""
9
+
10
+ def self.api_key
11
+ @@api_key
12
+ end
13
+
14
+ def self.api_key=(key)
15
+ @@api_key = key
16
+ end
17
+
18
+ def self.get_qote(services = ['elec'], extra = {}, period = 6, tenants = 1)
19
+ quotes = {}
20
+ services.each do |service|
21
+ quotes[service] = get_service_quote(service, extra[service], period, tenants)
22
+ end
23
+ calculate_totals(quotes)
24
+ end
25
+
26
+ def self.get_service_quote(service, extra, period, tenants)
27
+ 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}) }
28
+ JSON.parse(res.body)["results"]
29
+ rescue Timeout::Error => e
30
+ {"message" => "A timeout error has occured", "error" => 2}
31
+ rescue
32
+ {"message" => "An error has occured", "error" => 3}
33
+ end
34
+
35
+ def self.calculate_totals(quotes)
36
+ quotes["total"] = {}
37
+ quotes["total"]["tenant_week"] = quotes.map { |e| e[1]["tenant_week"].to_f }.reduce(:+).to_s
38
+ quotes["total"]["tenant_month"] = quotes.map { |e| e[1]["tenant_month"].to_f }.reduce(:+).to_s
39
+ quotes["total"]["monthly_fee"] = quotes.map { |e| e[1]["monthly_fee"].to_f }.reduce(:+).to_s
40
+
41
+ quotes
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Glide
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,55 @@
1
+ require 'glide'
2
+
3
+ describe Glide do
4
+
5
+ # RESPONSE
6
+ # "\004\bo:\027HTTParty::Response\n:\r@headerso: HTTParty::Response::Headers\006:\f@header{\017\"\vserver[\006\"\vApache\"\tdate[\006\"\"Sun, 06 May 2012 16:19:40 GMT\"\fexpires[\006\"\"Thu, 19 Nov 1981 08:52:00 GMT\"\vpragma[\006\"\rno-cache\"\023content-length[\006\"\b113\"\021content-type[\006\"\025application/json\"\017connection[\006\"\nclose\"\017set-cookie[\a\"9symfony=2n594frr1c83aldiloljk7erq3; path=/; HttpOnly\"9symfony=6pvq9hfd8elj5n8j2m5ij9kkp7; path=/; HttpOnly\"\022cache-control[\006\"\rno-cache\"\vx-farm[\006\"\nHTTPS:\025@parsed_response{\a\"\fversion\"\rv3.1.1.5\"\fresults{\t\"\020monthly_fee\"\n30.20\"\020tenant_week\"\t6.97\"\nnotes0\"\021tenant_month\"\n30.20:\r@requesto:\026HTTParty::Request\v:\016@last_urio:\017URI::HTTPS\017:\016@fragment0:\n@porti\002\273\001:\n@path\"\036/signup/servicePrice.json:\016@registry0:\016@password0:\f@opaque0:\n@user0:\v@query\"\002/\001key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@host\"\025api.glide.uk.com:\f@scheme\"\nhttps:\r@options{\n:\025follow_redirectsT:\023default_params{\000:\vparserc\025HTTParty::Parser:\nquery{\n:\bkey\"%1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z:\nextra0:\vperiodi\v:\fservice\"\telec:\ftenantsi\006:\nlimiti\n;\020@4:\021@raw_requesto:\023Net::HTTP::Get\f:\021@body_stream0;\020\"j/signup/servicePrice.json?key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@body0;\b{\a\"\017connection[\006\"\nclose\"\thost[\006\"\025api.glide.uk.com:\027@response_has_bodyT:\026@request_has_bodyF:\f@method\"\bGET:\021@http_methodc\023Net::HTTP::Get:\023@last_responseo:\020Net::HTTPOK\r:\022@http_version\"\b1.1:\020@body_existT:\f@socket0;&\"v{\"results\":{\"monthly_fee\":\"30.20\",\"tenant_week\":\"6.97\",\"tenant_month\":\"30.20\",\"notes\":null},\"version\":\"v3.1.1.5\"};\b{\017@\b@\t@\024@\025@\021@\022@\016@\017@\v@\f@\027@\030@\032@\e@!@\"@\035@\036@$@%:\r@message\"\aOK:\n@code\"\b200:\n@readT;&@L:\016@response@J"
7
+
8
+ before do
9
+ Glide::api_key = "ABC"
10
+ end
11
+
12
+ describe "get_quote" do
13
+
14
+ it 'should return a hash' do
15
+ HTTParty.should_receive(:get).exactly(6).times.and_return(Marshal.load("\004\bo:\027HTTParty::Response\n:\r@headerso: HTTParty::Response::Headers\006:\f@header{\017\"\vserver[\006\"\vApache\"\tdate[\006\"\"Sun, 06 May 2012 16:19:40 GMT\"\fexpires[\006\"\"Thu, 19 Nov 1981 08:52:00 GMT\"\vpragma[\006\"\rno-cache\"\023content-length[\006\"\b113\"\021content-type[\006\"\025application/json\"\017connection[\006\"\nclose\"\017set-cookie[\a\"9symfony=2n594frr1c83aldiloljk7erq3; path=/; HttpOnly\"9symfony=6pvq9hfd8elj5n8j2m5ij9kkp7; path=/; HttpOnly\"\022cache-control[\006\"\rno-cache\"\vx-farm[\006\"\nHTTPS:\025@parsed_response{\a\"\fversion\"\rv3.1.1.5\"\fresults{\t\"\020monthly_fee\"\n30.20\"\020tenant_week\"\t6.97\"\nnotes0\"\021tenant_month\"\n30.20:\r@requesto:\026HTTParty::Request\v:\016@last_urio:\017URI::HTTPS\017:\016@fragment0:\n@porti\002\273\001:\n@path\"\036/signup/servicePrice.json:\016@registry0:\016@password0:\f@opaque0:\n@user0:\v@query\"\002/\001key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@host\"\025api.glide.uk.com:\f@scheme\"\nhttps:\r@options{\n:\025follow_redirectsT:\023default_params{\000:\vparserc\025HTTParty::Parser:\nquery{\n:\bkey\"%1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z:\nextra0:\vperiodi\v:\fservice\"\telec:\ftenantsi\006:\nlimiti\n;\020@4:\021@raw_requesto:\023Net::HTTP::Get\f:\021@body_stream0;\020\"j/signup/servicePrice.json?key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@body0;\b{\a\"\017connection[\006\"\nclose\"\thost[\006\"\025api.glide.uk.com:\027@response_has_bodyT:\026@request_has_bodyF:\f@method\"\bGET:\021@http_methodc\023Net::HTTP::Get:\023@last_responseo:\020Net::HTTPOK\r:\022@http_version\"\b1.1:\020@body_existT:\f@socket0;&\"v{\"results\":{\"monthly_fee\":\"30.20\",\"tenant_week\":\"6.97\",\"tenant_month\":\"30.20\",\"notes\":null},\"version\":\"v3.1.1.5\"};\b{\017@\b@\t@\024@\025@\021@\022@\016@\017@\v@\f@\027@\030@\032@\e@!@\"@\035@\036@$@%:\r@message\"\aOK:\n@code\"\b200:\n@readT;&@L:\016@response@J"))
16
+ quotes = Glide.get_qote(services = ["elec", "water", "gas", "telephone", "broadband", "tv_license"])
17
+ quotes.should be_an_instance_of(Hash)
18
+ quotes["elec"]["monthly_fee"].should eql("30.20")
19
+ quotes["water"]["tenant_month"].should eql("30.20")
20
+ quotes["total"]["monthly_fee"].should eql("181.2")
21
+ quotes["total"]["tenant_week"].should eql("41.82")
22
+ quotes["total"]["tenant_month"].should eql("181.2")
23
+ end
24
+
25
+ end
26
+
27
+ describe "get_service_quote" do
28
+
29
+ it 'should respond with HTTParty response and convert to json' do
30
+ HTTParty.should_receive(:get).and_return(Marshal.load("\004\bo:\027HTTParty::Response\n:\r@headerso: HTTParty::Response::Headers\006:\f@header{\017\"\vserver[\006\"\vApache\"\tdate[\006\"\"Sun, 06 May 2012 16:19:40 GMT\"\fexpires[\006\"\"Thu, 19 Nov 1981 08:52:00 GMT\"\vpragma[\006\"\rno-cache\"\023content-length[\006\"\b113\"\021content-type[\006\"\025application/json\"\017connection[\006\"\nclose\"\017set-cookie[\a\"9symfony=2n594frr1c83aldiloljk7erq3; path=/; HttpOnly\"9symfony=6pvq9hfd8elj5n8j2m5ij9kkp7; path=/; HttpOnly\"\022cache-control[\006\"\rno-cache\"\vx-farm[\006\"\nHTTPS:\025@parsed_response{\a\"\fversion\"\rv3.1.1.5\"\fresults{\t\"\020monthly_fee\"\n30.20\"\020tenant_week\"\t6.97\"\nnotes0\"\021tenant_month\"\n30.20:\r@requesto:\026HTTParty::Request\v:\016@last_urio:\017URI::HTTPS\017:\016@fragment0:\n@porti\002\273\001:\n@path\"\036/signup/servicePrice.json:\016@registry0:\016@password0:\f@opaque0:\n@user0:\v@query\"\002/\001key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1&key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@host\"\025api.glide.uk.com:\f@scheme\"\nhttps:\r@options{\n:\025follow_redirectsT:\023default_params{\000:\vparserc\025HTTParty::Parser:\nquery{\n:\bkey\"%1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z:\nextra0:\vperiodi\v:\fservice\"\telec:\ftenantsi\006:\nlimiti\n;\020@4:\021@raw_requesto:\023Net::HTTP::Get\f:\021@body_stream0;\020\"j/signup/servicePrice.json?key=1O3N6dk0jENDVGIO44WDUbLT7AIG8W6Z&period=6&extra=&service=elec&tenants=1:\n@body0;\b{\a\"\017connection[\006\"\nclose\"\thost[\006\"\025api.glide.uk.com:\027@response_has_bodyT:\026@request_has_bodyF:\f@method\"\bGET:\021@http_methodc\023Net::HTTP::Get:\023@last_responseo:\020Net::HTTPOK\r:\022@http_version\"\b1.1:\020@body_existT:\f@socket0;&\"v{\"results\":{\"monthly_fee\":\"30.20\",\"tenant_week\":\"6.97\",\"tenant_month\":\"30.20\",\"notes\":null},\"version\":\"v3.1.1.5\"};\b{\017@\b@\t@\024@\025@\021@\022@\016@\017@\v@\f@\027@\030@\032@\e@!@\"@\035@\036@$@%:\r@message\"\aOK:\n@code\"\b200:\n@readT;&@L:\016@response@J"))
31
+ Glide.get_service_quote("elec", nil, 6, 1).should eql({"monthly_fee"=>"30.20", "tenant_week"=>"6.97", "notes"=>nil, "tenant_month"=>"30.20"})
32
+ end
33
+
34
+ it 'should handle timeout errors' do
35
+ HTTParty.should_receive(:get).and_raise(Timeout::Error)
36
+ Glide.get_service_quote("elec", nil, 6, 1).should eql({"message" => "A timeout error has occured", "error" => 2})
37
+ end
38
+
39
+ it 'should handle errors' do
40
+ HTTParty.should_receive(:get).and_raise(ZeroDivisionError)
41
+ Glide.get_service_quote("water", nil, 6, 1).should eql({"message" => "An error has occured", "error" => 3})
42
+ end
43
+ end
44
+
45
+ describe "calculate_totals" do
46
+ it "should return totals as new element in hash" do
47
+ quotes = {"elec" => {"monthly_fee"=>"30.20", "tenant_week"=>"6.97", "notes"=>nil, "tenant_month"=>"30.20"}, "water" => {"monthly_fee"=>"30.20", "tenant_week"=>"6.97", "notes"=>nil, "tenant_month"=>"30.20"}}
48
+ rt = Glide.calculate_totals(quotes)
49
+ rt["total"]["monthly_fee"].should eql("60.4")
50
+ rt["total"]["tenant_week"].should eql("13.94")
51
+ rt["total"]["tenant_month"].should eql("60.4")
52
+ end
53
+ end
54
+
55
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glide
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Volker Pacher
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-05-08 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ prerelease: false
31
+ requirement: *id001
32
+ type: :runtime
33
+ name: httparty
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ prerelease: false
45
+ requirement: *id002
46
+ type: :runtime
47
+ name: json
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ prerelease: false
59
+ requirement: *id003
60
+ type: :development
61
+ name: rake
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ prerelease: false
73
+ requirement: *id004
74
+ type: :development
75
+ name: rspec
76
+ description: allows you to get quotes from the glide api for the services required in one go and sum up the totals
77
+ email:
78
+ - volker.pacher@gmail.com
79
+ executables: []
80
+
81
+ extensions: []
82
+
83
+ extra_rdoc_files: []
84
+
85
+ files:
86
+ - .gitignore
87
+ - Gemfile
88
+ - LICENSE.md
89
+ - README.md
90
+ - Rakefile
91
+ - glide.gemspec
92
+ - lib/glide.rb
93
+ - lib/glide/version.rb
94
+ - spec/glide_spec.rb
95
+ homepage: https://github.com/vpacher/glide
96
+ licenses: []
97
+
98
+ post_install_message:
99
+ rdoc_options: []
100
+
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ hash: 3
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project: glide
124
+ rubygems_version: 1.8.15
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: a wrapper of the Glide Uk api
128
+ test_files: []
129
+