oldbill 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../../spec_helper", __FILE__)
3
+ require File.expand_path('../../vcr_enabled', __FILE__)
4
+
5
+ describe "Session caching on" do
6
+ use_vcr_cassette 'share', :record => :new_episodes
7
+
8
+ before(:each) do
9
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
10
+ end
11
+
12
+ describe "Cache" do
13
+ before(:each) do
14
+ @service = @session.service
15
+ end
16
+
17
+ it "should create the cache key from the request" do
18
+ @session.forces
19
+ @session.cache.should_not be_empty
20
+ @session.cache.keys.should include("/forces/")
21
+ end
22
+
23
+ it "should give exactly the same response as the first request" do
24
+ response1 = @session.forces
25
+ response2 = @session.cache["/forces/"]
26
+ response1.should == response2
27
+ response2.should == @session.forces
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+ describe "Session caching off" do
34
+ use_vcr_cassette 'share', :record => :new_episodes
35
+ before(:each) do
36
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"], :caching => false)
37
+ end
38
+
39
+ describe "Cache" do
40
+ before(:each) do
41
+ @service = @session.service
42
+ end
43
+
44
+ it "should not create the cache key from the request" do
45
+ @session.forces
46
+ @session.cache.should be_nil
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+ describe "Session expiration" do
53
+ use_vcr_cassette 'share', :record => :new_episodes
54
+
55
+ before(:each) do
56
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"], :expires_in => 1)
57
+ end
58
+
59
+ describe "Cache" do
60
+ before(:each) do
61
+ @service = @session.service
62
+ end
63
+
64
+ it "should create the cache" do
65
+ @session.forces
66
+ @session.cache.should_not be_empty
67
+ end
68
+
69
+ it "should expire when the time as gone passed expiration" do
70
+ @session.forces
71
+ @time_now = Time.parse("Feb 24 2100")
72
+ Time.stub!(:now).and_return(@time_now)
73
+ @session.cache["/forces/"].should be_nil
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,28 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "Session" do
4
+ describe "when creating, .create" do
5
+ it "should be cool when supplying an api key" do
6
+ OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
7
+ end
8
+
9
+ it "should have the defaults" do
10
+ session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
11
+ session.server.should == "policeapi2.rkh.co.uk/api"
12
+ session.api_version.should == 2
13
+ session.logging.should be_false
14
+ session.caching.should be_true
15
+ end
16
+
17
+ it "should allow defaults to be changed when creating" do
18
+ session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"], :api_version => 3, :logging => false, :server => "beans")
19
+ session.server.should == "beans"
20
+ session.logging.should be_false
21
+ session.api_version.should == 3
22
+ end
23
+
24
+ it "should raise Argument error if no api key is supplied; with message 'need API to save the planet!'" do
25
+ lambda{OldBill::Session.create}.should raise_error(ArgumentError)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,121 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../../spec_helper", __FILE__)
3
+ require File.expand_path('../../vcr_enabled', __FILE__)
4
+
5
+ describe "crime api" do
6
+ use_vcr_cassette 'share', :record => :new_episodes
7
+ context "#forces" do
8
+ before(:each) do
9
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
10
+ end
11
+
12
+ it "should be cool in getting some forces" do
13
+ lambda{@session.forces}.should_not raise_error
14
+ end
15
+
16
+ it "should include bedfordshire as one of its forces do" do
17
+ forces = @session.forces
18
+ forces.detect{|force| force.id == "bedfordshire"}.should_not be_nil
19
+ end
20
+
21
+ it "should have each force with a name and an id" do
22
+ @session.forces.each do |force|
23
+ force.should respond_to(:id)
24
+ force.should respond_to(:name)
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ context "#force" do
31
+ before(:each) do
32
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
33
+ end
34
+
35
+ it "should be cool a call force" do
36
+ lambda{@session.force("bedfordshire")}.should_not raise_error
37
+ end
38
+
39
+ it "should be cool to get bedfordshire" do
40
+ @session.force("bedfordshire").should_not be_nil
41
+ end
42
+
43
+ it "should have some engagement-methods" do
44
+ force = @session.force("bedfordshire")
45
+ force.engagement_methods.should_not be_empty
46
+ end
47
+
48
+ it "should have engagement_methods as a hashie mash" do
49
+ force = @session.force("bedfordshire")
50
+ force.engagement_methods[0].class.should eq(Hashie::Mash)
51
+ end
52
+
53
+ it "should have engagement_methods with title url description" do
54
+ force = @session.force("bedfordshire")
55
+ force.engagement_methods.each do |engagement_method|
56
+ engagement_method.should respond_to(:title)
57
+ engagement_method.should respond_to(:url)
58
+ engagement_method.should respond_to(:description)
59
+ end
60
+ end
61
+ end
62
+
63
+ context "#crimes_by_month" do
64
+ before(:each) do
65
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
66
+ end
67
+
68
+ it "should cool to call crimes_by_month" do
69
+ lambda{@session.crimes_by_month("leicestershire", "C01")}.should_not raise_error
70
+ end
71
+
72
+ it "should bring back empty array when no data" do
73
+ @session.crimes_by_month("bedfordshire", "C01").should be_empty
74
+ end
75
+
76
+ it "should create a nice looking crime by month object" do
77
+ crime_by_month = @session.crimes_by_month("leicestershire", "C01")[0]
78
+ crime_by_month.month.should_not be_empty
79
+ crime_by_month.burglary.should_not be_empty
80
+ end
81
+ end
82
+
83
+ context "#street_level_crimes" do
84
+ before(:each) do
85
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
86
+ end
87
+
88
+ it "should cool to call street_level_crimes" do
89
+ lambda{@session.street_level_crimes(51, 48)}.should_not raise_error
90
+ end
91
+
92
+ it "should bring back empty array when no data" do
93
+ @session.street_level_crimes(0, 0).should be_empty
94
+ end
95
+
96
+ it "should create a nice looking street_level_crimes object" do
97
+ street_crimes = @session.street_level_crimes(52.6397278, -1.1322921)
98
+ street_crime = street_crimes[0]
99
+ street_crime.category.should_not be_nil
100
+ street_crime.month.should_not be_nil
101
+ street_crime.location.should_not be_nil
102
+ street_crime.location.street.name.should_not be_nil
103
+ end
104
+ end
105
+
106
+ context "#crime_categories" do
107
+ before(:each) do
108
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
109
+ end
110
+
111
+ it "should be cool to call crime_categories" do
112
+ lambda{@session.crime_categories}.should_not raise_error
113
+ end
114
+
115
+ it "should include bulgary as one of its categories" do
116
+ categories = @session.crime_categories
117
+ categories.detect{|category| category.url == "burglary"}.should_not be_nil
118
+ end
119
+ end
120
+
121
+ end
@@ -0,0 +1,131 @@
1
+ # encoding: utf-8
2
+ require File.expand_path("../../spec_helper", __FILE__)
3
+ require File.expand_path('../../vcr_enabled', __FILE__)
4
+
5
+ describe "crime api" do
6
+ use_vcr_cassette 'share', :record => :new_episodes
7
+
8
+ context "#neighbourhoods" do
9
+ before(:each) do
10
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
11
+ end
12
+
13
+ it "should be cool to call neighbourhoods" do
14
+ lambda{@session.neighbourhoods("leicestershire")}.should_not raise_error
15
+ end
16
+
17
+ it "should give me some cool neighbourhoods" do
18
+ neighbourhood = @session.neighbourhoods("leicestershire")[0]
19
+ neighbourhood.name.should_not be_nil
20
+ neighbourhood.id.should_not be_nil
21
+ neighbourhood.should_not be_fully_loaded
22
+ end
23
+
24
+ it "should be able to come fully_loaded" do
25
+ neighbourhood = @session.neighbourhoods("leicestershire")[0]
26
+ neighbourhood.fully_loaded!
27
+ neighbourhood.centre.latitude.should_not be_nil
28
+ end
29
+
30
+ it "should raise 404 when random force" do
31
+ lambda{@session.neighbourhoods("random")}.should raise_error(OldBill::NotFoundError)
32
+ end
33
+ end
34
+
35
+ context "#neighbourhood" do
36
+ before(:each) do
37
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
38
+ end
39
+
40
+ it "should be cool to call neighbourhoods" do
41
+ lambda{@session.neighbourhood("leicestershire", "C01")}.should_not raise_error
42
+ end
43
+
44
+ it "should give me a cool neighbourhood" do
45
+ neighbourhood = @session.neighbourhoods("leicestershire")[0]
46
+ neighbourhood.fully_loaded!
47
+ neighbourhood.centre.latitude.should_not be_nil
48
+ neighbourhood.contact_details.should_not be_empty
49
+ neighbourhood.contact_details.email.should_not be_nil
50
+ end
51
+
52
+ it "should be cool to get some crimes" do
53
+ neighbourhood = @session.neighbourhoods("leicestershire")[0]
54
+ neighbourhood.street_level_crimes.should_not be_empty
55
+ neighbourhood.street_level_crimes[0].category.should_not be_empty
56
+ end
57
+ end
58
+
59
+ context "#events" do
60
+ before(:each) do
61
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
62
+ end
63
+
64
+ it "should be cool to call events" do
65
+ lambda{@session.events("leicestershire", "C01")}.should_not raise_error
66
+ end
67
+
68
+ it "should give me a cool event" do
69
+ event = @session.events("leicestershire", "C01")[0]
70
+ event.start_date.should_not be_nil
71
+ event.start_date.should be_a(Date)
72
+ event.description.should_not be_nil
73
+ end
74
+ end
75
+
76
+ context "#police_officers" do
77
+ before(:each) do
78
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
79
+ end
80
+
81
+ it "should be cool to call events" do
82
+ lambda{@session.police_officers("leicestershire", "C01")}.should_not raise_error
83
+ end
84
+
85
+ it "should give me a cool event" do
86
+ police_officer = @session.police_officers("leicestershire", "C01")[0]
87
+ police_officer.bio.should_not be_nil
88
+ police_officer.name.should.should_not be_nil
89
+ police_officer.rank.should.should_not be_nil
90
+ end
91
+ end
92
+
93
+ context "#locate" do
94
+ before(:each) do
95
+ @session = OldBill::Session.create(:username => ENV["OLD_BILL_USERNAME"], :password => ENV["OLD_BILL_PASSWORD"])
96
+ end
97
+
98
+ it "should be cool to call events" do
99
+ lambda{@session.locate(52.6397278, -1.1322921)}.should_not raise_error
100
+ end
101
+
102
+ it "should bring back nil when no location found" do
103
+ @session.locate(33, -1).should be_nil
104
+ end
105
+
106
+ it "should give me a cool locator" do
107
+ locator = @session.locate(52.6397278, -1.1322921)
108
+ locator.neighbourhood.should_not be_nil
109
+ locator.force.should_not be_nil
110
+ end
111
+
112
+ it "should be cool to get crimes_by_month" do
113
+ locator = @session.locate(52.6397278, -1.1322921)
114
+ locator.crimes_by_month.should_not be_empty
115
+ locator.crimes_by_month[0].month.should_not be_nil
116
+ end
117
+
118
+
119
+ it "should be cool to get police_officers" do
120
+ locator = @session.locate(52.6397278, -1.1322921)
121
+ locator.police_officers.should_not be_empty
122
+ locator.police_officers[0].rank.should_not be_nil
123
+ end
124
+
125
+ it "should be cool to get events" do
126
+ locator = @session.locate(52.6397278, -1.1322921)
127
+ locator.events.should_not be_empty
128
+ locator.events[0].description.should_not be_nil
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,19 @@
1
+ require "bundler"
2
+ Bundler.setup
3
+
4
+ # get the calculated gem and bundle in the test group
5
+ require "oldbill"
6
+ Bundler.require(:test)
7
+
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ Rspec.configure do |config|
11
+ config.before(:suite) do
12
+ raise Exception, "You need to set you old bill mate" unless ENV["OLD_BILL_USERNAME"] && ENV["OLD_BILL_PASSWORD"]
13
+ end
14
+
15
+ config.before(:each) do
16
+ end
17
+
18
+ config.mock_with :rspec
19
+ end
@@ -0,0 +1,11 @@
1
+ require 'vcr'
2
+ require 'webmock'
3
+
4
+ VCR.config do |c|
5
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
6
+ c.stub_with :webmock # :fakeweb
7
+ end
8
+
9
+ RSpec.configure do |c|
10
+ c.extend VCR::RSpec::Macros
11
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oldbill
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - hookercookerman
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-23 00:00:00 +00:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activesupport
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 3
30
+ - 0
31
+ - 5
32
+ version: 3.0.5
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: i18n
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 5
46
+ version: "0.5"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: httparty
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ - 7
60
+ - 4
61
+ version: 0.7.4
62
+ type: :runtime
63
+ version_requirements: *id003
64
+ - !ruby/object:Gem::Dependency
65
+ name: hashie
66
+ prerelease: false
67
+ requirement: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 1
74
+ - 0
75
+ - 0
76
+ version: 1.0.0
77
+ type: :runtime
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: moneta
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ - 6
90
+ - 0
91
+ version: 0.6.0
92
+ type: :runtime
93
+ version_requirements: *id005
94
+ - !ruby/object:Gem::Dependency
95
+ name: tzinfo
96
+ prerelease: false
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ~>
101
+ - !ruby/object:Gem::Version
102
+ segments:
103
+ - 0
104
+ - 3
105
+ - 22
106
+ version: 0.3.22
107
+ type: :runtime
108
+ version_requirements: *id006
109
+ description: ruby wrapper for the police API
110
+ email:
111
+ - hookercookerman@gmail.com
112
+ executables: []
113
+
114
+ extensions: []
115
+
116
+ extra_rdoc_files: []
117
+
118
+ files:
119
+ - .gitignore
120
+ - .rspec
121
+ - Gemfile
122
+ - README.rdoc
123
+ - Rakefile
124
+ - autotest/discover.rb
125
+ - lib/oldbill.rb
126
+ - lib/oldbill/api/crime.rb
127
+ - lib/oldbill/api/neighbourhood.rb
128
+ - lib/oldbill/errors.rb
129
+ - lib/oldbill/service.rb
130
+ - lib/oldbill/session.rb
131
+ - lib/oldbill/v2/crime_by_month.rb
132
+ - lib/oldbill/v2/crimes/location.rb
133
+ - lib/oldbill/v2/crimes/street_level.rb
134
+ - lib/oldbill/v2/force.rb
135
+ - lib/oldbill/v2/neighbourhood.rb
136
+ - lib/oldbill/v2/neighbourhoods/event.rb
137
+ - lib/oldbill/v2/neighbourhoods/location.rb
138
+ - lib/oldbill/v2/neighbourhoods/locator.rb
139
+ - lib/oldbill/v2/neighbourhoods/police_officer.rb
140
+ - lib/oldbill/version.rb
141
+ - oldbill.gemspec
142
+ - spec/fixtures/vcr_cassettes/share.yml
143
+ - spec/session/cache_spec.rb
144
+ - spec/session/create_spec.rb
145
+ - spec/session/crime_spec.rb
146
+ - spec/session/neighbourhoods_spec.rb
147
+ - spec/spec_helper.rb
148
+ - spec/vcr_enabled.rb
149
+ has_rdoc: true
150
+ homepage: ""
151
+ licenses: []
152
+
153
+ post_install_message:
154
+ rdoc_options: []
155
+
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ segments:
164
+ - 0
165
+ version: "0"
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ requirements: []
175
+
176
+ rubyforge_project: oldbill
177
+ rubygems_version: 1.3.7
178
+ signing_key:
179
+ specification_version: 3
180
+ summary: ruby wrapper for the police API
181
+ test_files:
182
+ - spec/fixtures/vcr_cassettes/share.yml
183
+ - spec/session/cache_spec.rb
184
+ - spec/session/create_spec.rb
185
+ - spec/session/crime_spec.rb
186
+ - spec/session/neighbourhoods_spec.rb
187
+ - spec/spec_helper.rb
188
+ - spec/vcr_enabled.rb