Skip to content

Commit edff115

Browse files
committed
First commit
0 parents  commit edff115

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1184
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spec/dummy/log/*.log
2+
spec/dummy/tmp/*
3+
.DS_Store
4+
.bundle

.rvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rvm use 1.9.3-p0@sensis

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source "http://rubygems.org"
2+
3+
# gem's dependencies in sensis.gemspec
4+
gemspec

Gemfile.lock

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
PATH
2+
remote: .
3+
specs:
4+
sensis (0.0.1)
5+
6+
GEM
7+
remote: http://rubygems.org/
8+
specs:
9+
actionpack (3.1.1)
10+
activemodel (= 3.1.1)
11+
activesupport (= 3.1.1)
12+
builder (~> 3.0.0)
13+
erubis (~> 2.7.0)
14+
i18n (~> 0.6)
15+
rack (~> 1.3.2)
16+
rack-cache (~> 1.1)
17+
rack-mount (~> 0.8.2)
18+
rack-test (~> 0.6.1)
19+
sprockets (~> 2.0.2)
20+
activemodel (3.1.1)
21+
activesupport (= 3.1.1)
22+
builder (~> 3.0.0)
23+
i18n (~> 0.6)
24+
activesupport (3.1.1)
25+
multi_json (~> 1.0)
26+
archive-tar-minitar (0.5.2)
27+
builder (3.0.0)
28+
columnize (0.3.4)
29+
diff-lcs (1.1.3)
30+
erubis (2.7.0)
31+
hike (1.2.1)
32+
i18n (0.6.0)
33+
json (1.6.1)
34+
linecache19 (0.5.12)
35+
ruby_core_source (>= 0.1.4)
36+
multi_json (1.0.3)
37+
nokogiri (1.5.0)
38+
rack (1.3.5)
39+
rack-cache (1.1)
40+
rack (>= 0.4)
41+
rack-mount (0.8.3)
42+
rack (>= 1.0.0)
43+
rack-ssl (1.3.2)
44+
rack
45+
rack-test (0.6.1)
46+
rack (>= 1.0)
47+
railties (3.1.1)
48+
actionpack (= 3.1.1)
49+
activesupport (= 3.1.1)
50+
rack-ssl (~> 1.3.2)
51+
rake (>= 0.8.7)
52+
rdoc (~> 3.4)
53+
thor (~> 0.14.6)
54+
rake (0.9.2.2)
55+
rcov (0.9.11)
56+
rdoc (3.11)
57+
json (~> 1.4)
58+
rspec (2.7.0)
59+
rspec-core (~> 2.7.0)
60+
rspec-expectations (~> 2.7.0)
61+
rspec-mocks (~> 2.7.0)
62+
rspec-core (2.7.1)
63+
rspec-expectations (2.7.0)
64+
diff-lcs (~> 1.1.2)
65+
rspec-mocks (2.7.0)
66+
rspec-rails (2.7.0)
67+
actionpack (~> 3.0)
68+
activesupport (~> 3.0)
69+
railties (~> 3.0)
70+
rspec (~> 2.7.0)
71+
ruby-debug-base19 (0.11.25)
72+
columnize (>= 0.3.1)
73+
linecache19 (>= 0.5.11)
74+
ruby_core_source (>= 0.1.4)
75+
ruby-debug19 (0.11.6)
76+
columnize (>= 0.3.1)
77+
linecache19 (>= 0.5.11)
78+
ruby-debug-base19 (>= 0.11.19)
79+
ruby_core_source (0.1.5)
80+
archive-tar-minitar (>= 0.5.2)
81+
sprockets (2.0.3)
82+
hike (~> 1.2)
83+
rack (~> 1.0)
84+
tilt (~> 1.1, != 1.3.0)
85+
thor (0.14.6)
86+
tilt (1.3.3)
87+
tzinfo (0.3.31)
88+
89+
PLATFORMS
90+
ruby
91+
92+
DEPENDENCIES
93+
json
94+
nokogiri
95+
rcov
96+
rspec-core
97+
rspec-rails
98+
ruby-debug19
99+
sensis!
100+
tzinfo

MIT-LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2011 Ben Wiseley [email protected]
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.markdown

+178
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Sensis Search
2+
This is a pretty basic api wrapper for Sensis searching.
3+
4+
For more information on Sensis see their developer site: http://developers.sensis.com.au/
5+
6+
## Install
7+
8+
gem install sensis
9+
10+
## Usage
11+
You can get a free api key at http://developers.sensis.com.au/
12+
13+
Note - all methods (search, get_listing_by_id and report) all take an additional key: :test => true/false. This decides if the test endpoint or the production endpoint will be used. It defaults to test.
14+
15+
All results can be accessed by their hash values or by method names... example:
16+
17+
res["code"] == res.code
18+
res["results"].size == res.results.size
19+
20+
### Search
21+
22+
res = Sensis.search(:key => "your api key", :query => "poker")
23+
24+
Sensis.search takes a hash of options defined here: http://developers.sensis.com.au/docs/endpoint_reference/Search
25+
26+
Sample Search result set: see http://developers.sensis.com.au/docs/endpoint_reference for more information
27+
28+
{
29+
"results": [
30+
{
31+
"id": "999",
32+
"name": "Bob's Hairdresser",
33+
"categories": [
34+
{
35+
"name": "Hairdressers"
36+
}
37+
],
38+
"primaryAddress" {
39+
"addressLine": "123 Fitzroy Street",
40+
...
41+
}
42+
...
43+
}
44+
...
45+
],
46+
...
47+
"count": 20,
48+
"totalResults": 19791,
49+
"executedQuery": "hairdresser",
50+
"originalQuery": "hairdresser",
51+
"date": "2011-02-28T12:01:02.345+1000",
52+
"time": 10,
53+
"code": 200,
54+
"message": "OK"
55+
}
56+
57+
So - you could do something like:
58+
59+
res.results.first.name == res["results"][0]["name"]
60+
61+
#### Search paging
62+
63+
res = Sensis.search(:key => "your api key", :query => "poker")
64+
pages = res.totalResults.to_i / 20
65+
pages.each do |page|
66+
res = Sensis.search(:key => "your api key", :query => "poker", :page => page.to_s)
67+
end
68+
69+
More on paging in the docs http://developers.sensis.com.au/docs/using_endpoints/Pagination
70+
71+
### Get Listing By ID
72+
73+
res = Sensis.get_listing_by_id(:key => "your api key", :query => "999")
74+
75+
Sample result set: see for more information
76+
77+
{
78+
"results": [
79+
{
80+
"businessId": "999",
81+
"businessName": "Hairdresser",
82+
"categories": [
83+
{
84+
"name": "Hairdressers"
85+
}
86+
],
87+
"primaryAddress": {
88+
"addressLine": "123 Fitzroy Street",
89+
},
90+
...
91+
}
92+
],
93+
"count": 1,
94+
"totalResults": 1,
95+
"executedQuery": "999",
96+
"originalQuery": "999",
97+
"date": "2011-02-28T12:01:02.345+1000",
98+
"time": 10,
99+
"code": 200,
100+
"message": "OK"
101+
}
102+
103+
### Report
104+
105+
res = Sensis.report(:key => "your api key", :userIp => "192.1.2.3", :userAgent => "Mozilla Firefox",
106+
:userSessionId => "123467890",
107+
:id => "VyY2UiOiJZRUxMT1ciLCJwcm9kdWN0SWQiOiIxMjM0IiwicHJvZHVjdFZlcnNpb24iOiI1Njc4In0")
108+
109+
You can also include multiple ID's by passing an array
110+
111+
res = Sensis.report(:key => "your api key", :userIp => "192.1.2.3", :userAgent => "Mozilla Firefox",
112+
:userSessionId => "123467890",
113+
:id => ["1","2","3","4"])
114+
115+
116+
Sample report result set: see http://developers.sensis.com.au/docs/endpoint_reference/Report for more information
117+
118+
{
119+
"results": [
120+
{
121+
"id": "999",
122+
"name": "Bob's Hairdresser",
123+
"categories": [
124+
{
125+
"name": "Hairdressers"
126+
}
127+
],
128+
"reportingId":"VyY2UiOiJZRUxMT1ciLCJwcm9kdWN0SWQiOiIx ⤶
129+
MjM0IiwicHJvZHVjdFZlcnNpb24iOiI1Njc4In0",
130+
...
131+
},
132+
{
133+
"id": "1000",
134+
"name": "Jill's Hairdresser",
135+
"categories": [
136+
{
137+
"name": "Hairdressers"
138+
}
139+
],
140+
"reportingId":"eyJib29rSWQiOiJTMDBXIiwibGlzdGluZ05hbW ⤶
141+
UiOiJzdWJzY3JpYmVyTmFtZSIsInNvdXJjZSI6",
142+
...
143+
}
144+
...
145+
],
146+
...
147+
"count": 20,
148+
"totalResults": 19791,
149+
"executedQuery": "hairdresser",
150+
"originalQuery": "hairdresser",
151+
"date": "2011-02-28T12:01:02.345+1000",
152+
"time": 10,
153+
"code": 200,
154+
"message": "OK"
155+
}
156+
157+
## TODO
158+
* add more tests
159+
* add better examples for Get Listing By ID and Report. Haven't really used these yet.
160+
161+
## Testing
162+
1. clone the code: git clone git://github.com/wiseleyb/Sensis.git
163+
2. gem install bundler
164+
3. bundle install
165+
4. bundle exec rspec spec
166+
167+
## Console
168+
If you're working on the gem you can muck around in console by
169+
170+
cd spec/dummy
171+
bundle execute rails c
172+
173+
### Credits
174+
175+
Thank you to jdunwoody for some sample sensis code https://github.com/jdunwoody/SensisSearchApp/blob/master/lib/search_command.rb
176+
177+
Thank you to mikedemers for some cool json -> class method code (class ResponseData) https://github.com/mikedemers/rbing/blob/master/lib/rbing.rb
178+

Rakefile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
require 'rake'
2+
require 'rake/testtask'
3+
require 'rdoc/task'
4+
5+
desc 'Default: run unit tests.'
6+
task :default => :test
7+
8+
desc 'Test the zemanta_fu plugin.'
9+
Rake::TestTask.new(:test) do |t|
10+
t.libs << 'lib'
11+
t.libs << 'test'
12+
t.pattern = 'test/**/*_test.rb'
13+
t.verbose = true
14+
end
15+
16+
desc 'Generate documentation for the zemanta_fu plugin.'
17+
RDoc::Task.new(:rdoc) do |rdoc|
18+
rdoc.rdoc_dir = 'rdoc'
19+
rdoc.title = 'ZemantaFu'
20+
rdoc.options << '--line-numbers' << '--inline-source'
21+
rdoc.rdoc_files.include('README')
22+
rdoc.rdoc_files.include('lib/**/*.rb')
23+
end

init.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Include hook code here

install.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Install hook code here

0 commit comments

Comments
 (0)