here_places 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in here_places.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Prem Pillai
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # HerePlaces
2
+ A wafer-thin Ruby wrapper for accessing Nokia's Here Maps Places API.
3
+ Read more about the official API here: <http://developer.here.net/>
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'here_places'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install here_places
19
+
20
+ * * *
21
+
22
+ ## Getting Started
23
+
24
+ The aim of this gem is to provide a ruby wrapper around the REST APIs that **Here** provides. Read more about the APIs here: <http://developer.here.net/docs/places/topics/resources.html>
25
+
26
+ To start using the APIs, register for a Nokia Developer Account <http://developer.here.net/> to get your APP\_ID and APP\_CODE
27
+
28
+ * * *
29
+
30
+ ### Discover API
31
+
32
+ #### Searching <http://developer.here.net/docs/places/topics/resource-search.html>
33
+
34
+ The search resource represent sets of places that match a user's search term in a specific location context (such as near a given location, around a user's current position or on the currently visible map).
35
+
36
+ require 'here_places'
37
+ app_id = "YOUR_APP_ID"
38
+ app_code = "YOUR_APP_CODE"
39
+ data = {
40
+ q: 'Cafe',
41
+ at: '40.74917,-73.98529',
42
+ }
43
+ api = HerePlaces::Discover.new(app_id, app_code)
44
+ a = api.search(data)
45
+
46
+ #### Exploring <http://developer.here.net/docs/places/topics/resource-explore.html>
47
+
48
+ The explore resource represent sets of popular places within a specific location context. The explore resource allows users to explore places without typing search queries. An explore resource's location context might be an explicitly given location or implicitly defined by a user's current position or the currently visible map. Optionally, the places may be restricted to a given set of categories.
49
+ `at` and `in` parameter are mutually exclusive and can't be passed at the same time
50
+
51
+ require 'here_places'
52
+ app_id = "YOUR_APP_ID"
53
+ app_code = "YOUR_APP_CODE"
54
+ data = {
55
+ cat: 'natural-geographical',
56
+ at: '40.74917,-73.98529',
57
+ }
58
+ api = HerePlaces::Discover.new(app_id, app_code)
59
+ a = api.explore(data)
60
+
61
+ #### Here <http://developer.here.net/docs/places/topics/resource-discover-here.html>
62
+
63
+ The discover here resource represent sets of places within a specific location context. The Discover Here resource allows users to request places near to a given point, based on a location precision parameter which must be provided. If the precision is high, the places around that point are returned in order of proximity. Otherwise, a set of recommended places in the area is returned.
64
+
65
+ require 'here_places'
66
+ app_id = "YOUR_APP_ID"
67
+ app_code = "YOUR_APP_CODE"
68
+ data = {
69
+ cat: 'natural-geographical',
70
+ at: '40.7063,-73.9971;u=0',
71
+ }
72
+ api = HerePlaces::Discover.new(app_id, app_code)
73
+ a = api.here(data)
74
+
75
+ * * *
76
+
77
+ ### Places
78
+
79
+ #### The Place Resource <http://developer.here.net/docs/places/topics/resource-discover-here.html>
80
+
81
+ The place resource represent places on earth.
82
+ Examples for places include:
83
+ Places of (public) interest (POI)
84
+ Addresses of buildings (Locations)
85
+ Named areas and regions
86
+ Each place is referenced by an identifier, called a placeId.
87
+
88
+ require 'here_places'
89
+ app_id = "YOUR_APP_ID"
90
+ app_code = "YOUR_APP_CODE"
91
+ id = '840dr5rs-5c0f37fabdc643938dd4f47db00d4ae8'
92
+ api = HerePlaces::Place.new(app_id, app_code)
93
+ a = api.places(id)
94
+
95
+ * * *
96
+
97
+ ### Suggestions
98
+
99
+ #### The Search Suggestion Resource <http://developer.here.net/docs/places/topics/resource-suggest.html>
100
+
101
+ The search suggestions resource represents lists of suggested search terms related to a given (partial) search term and location context.
102
+
103
+ require 'here_places'
104
+ app_id = "YOUR_APP_ID"
105
+ app_code = "YOUR_APP_CODE"
106
+ data = {
107
+ q: 'restaur',
108
+ at: '40.7063,-73.9971',
109
+ }
110
+ api = HerePlaces::Suggest.new(app_id, app_code)
111
+ a = api.suggest(data)
112
+
113
+ * * *
114
+
115
+ ### Categories
116
+
117
+ #### The Category Graph Resource <http://developer.here.net/docs/places/topics/resource-category-graph.html>
118
+
119
+ The category graph resource represents sets of locally relevant categories that are organized in a graph-like hierarchy. The category graph may change at any point in the future and may be different depending on the location of the request. A set of permanent, top-level, categories can be found [here](http://developer.here.net/docs/places/topics/categories.html).
120
+
121
+ require 'here_places'
122
+ app_id = "YOUR_APP_ID"
123
+ app_code = "YOUR_APP_CODE"
124
+ data = {
125
+ at: '40.7063,-73.9971',
126
+ }
127
+ api = HerePlaces::Category.new(app_id, app_code)
128
+ a = api.places(data)
129
+
130
+ * * *
131
+
132
+ ## Contributing
133
+
134
+ 1. Fork it
135
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
136
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
137
+ 4. Push to the branch (`git push origin my-new-feature`)
138
+ 5. Create new Pull Request
139
+
140
+ * * *
141
+
142
+ ## License
143
+
144
+ MIT License
145
+
146
+ Permission is hereby granted, free of charge, to any person obtaining
147
+ a copy of this software and associated documentation files (the
148
+ "Software"), to deal in the Software without restriction, including
149
+ without limitation the rights to use, copy, modify, merge, publish,
150
+ distribute, sublicense, and/or sell copies of the Software, and to
151
+ permit persons to whom the Software is furnished to do so, subject to
152
+ the following conditions:
153
+
154
+ The above copyright notice and this permission notice shall be
155
+ included in all copies or substantial portions of the Software.
156
+
157
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
158
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
159
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
160
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
161
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
162
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
163
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'here_places/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "here_places"
8
+ gem.version = HerePlaces::VERSION
9
+ gem.authors = ["Prem Pillai"]
10
+ gem.email = ["prem.pillai@gmail.com"]
11
+ gem.description = %q{A wafer-thin Ruby Wrapper for Nokia's Here Places API}
12
+ gem.summary = %q{A wafer-thin Ruby Wrapper for Nokia's Here Places API}
13
+ gem.homepage = "https://github.com/premjg/here_places"
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features|helper)/})
19
+ gem.require_paths = ["lib"]
20
+ gem.add_development_dependency 'rspec', '~>2.1'
21
+ gem.add_development_dependency 'fakeweb', '~>1.3'
22
+ gem.add_dependency 'faraday', '~>0.8.4'
23
+ end
@@ -0,0 +1,41 @@
1
+ module HerePlaces
2
+ class Base
3
+ @@base_url = 'http://places.nlp.nokia.com/'
4
+ @@api_prefix = 'places/v1'
5
+
6
+ attr_reader :conn
7
+
8
+ def initialize(app_id, app_code, log=false)
9
+ @app_id = app_id
10
+ @app_code = app_code
11
+ @log = log
12
+ setup()
13
+ end
14
+
15
+ def setup
16
+ @conn = Faraday.new(:url => @@base_url) do |faraday|
17
+ faraday.request :url_encoded
18
+ faraday.response :logger if @log
19
+ faraday.adapter Faraday.default_adapter
20
+ end
21
+ end
22
+
23
+ def api(url_fragment, data={})
24
+ result = @conn.get do |req|
25
+ req.url url_fragment
26
+ req.params['app_id'] = @app_id
27
+ req.params['app_code'] = @app_code
28
+ data.each do |key,value|
29
+ req.params[key] = value
30
+ end
31
+ end
32
+
33
+ parsed_result = JSON.parse(result.body)
34
+ if parsed_result["status"]
35
+ raise HerePlaces::APIError.new(parsed_result), parsed_result['message']
36
+ else
37
+ parsed_result
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,10 @@
1
+ module HerePlaces
2
+ class Category < HerePlaces::Base
3
+ @@resource = 'categories'
4
+
5
+ def places(data)
6
+ url = @@api_prefix + '/' + @@resource + '/' + 'places'
7
+ api(url, data)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module HerePlaces
2
+ class Discover < HerePlaces::Base
3
+ @@resource = 'discover'
4
+ %w(search explore here).each do |meth|
5
+ define_method(meth) do |data|
6
+ url = @@api_prefix + '/' + @@resource + '/' + meth
7
+ api(url, data)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ module HerePlaces
2
+ class APIError < StandardError
3
+ attr_accessor :status, :error_message
4
+
5
+ def initialize(error)
6
+ self.status = error["status"].to_i rescue 500
7
+ self.error_message = error["error_message"] || 'Unknown Error'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module HerePlaces
2
+ class Place < HerePlaces::Base
3
+ @@resource = 'places'
4
+
5
+ def places(id)
6
+ url = @@api_prefix + '/' + @@resource + '/' + id.to_s
7
+ api(url)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module HerePlaces
2
+ class Suggest < HerePlaces::Base
3
+ @@resource = 'suggest'
4
+
5
+ def suggest(data)
6
+ url = @@api_prefix + '/' + @@resource
7
+ api(url, data)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module HerePlaces
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,15 @@
1
+ require "faraday"
2
+ require "json"
3
+ require_relative './here_places/base'
4
+ require_relative './here_places/category'
5
+ require_relative './here_places/discover'
6
+ require_relative './here_places/error'
7
+ require_relative './here_places/place'
8
+ require_relative './here_places/suggest'
9
+
10
+ # /discover/search?q=...&[at=...]
11
+ # /discover/explore?[cat=...]&[(at|in)=...]
12
+ # /discover/here?[at=...]
13
+ # /places/{placeId}
14
+ # /suggest?q=...&[at=...]
15
+ # /categories/places?[at=...]
data/spec/base_spec.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe HerePlaces::Base do
4
+ before(:each) do
5
+ @app_id = 'APP_ID'
6
+ @app_code = 'APP_CODE'
7
+ end
8
+
9
+ context "after initialize" do
10
+ it 'calls the setup method' do
11
+ HerePlaces::Base.any_instance.stub(:setup)
12
+ HerePlaces::Base.any_instance.should_receive(:setup)
13
+ @h = HerePlaces::Base.new(@app_id, @app_code)
14
+ end
15
+ end
16
+
17
+ context "the setup method" do
18
+ it "correctly sets up the Faraday connection object" do
19
+ @h = HerePlaces::Base.new(@app_id, @app_code)
20
+ @h.conn.should be_an_instance_of(Faraday::Connection)
21
+ end
22
+ end
23
+
24
+ context "api method" do
25
+ before(:each) do
26
+ @url_fragment = 'some/url/fragment'
27
+ @data = {test: 'stuff'}
28
+ end
29
+
30
+ after(:each) do
31
+ FakeWeb.clean_registry
32
+ end
33
+
34
+ it "correctly constructs the API URL and makes calls" do
35
+ @h = HerePlaces::Base.new(@app_id, @app_code)
36
+ FakeWeb.register_uri(:get, %r|^http:\/\/places\.nlp\.nokia\.com\/.*|, :body => {stuff: 'test'}.to_json)
37
+ @h.api(@url_fragment, @data)
38
+ @parametrized_data = URI.encode_www_form(@data)
39
+ FakeWeb.last_request.path.should eq("/#{@url_fragment}?app_id=#{@app_id}&app_code=#{@app_code}&#{@parametrized_data}")
40
+ end
41
+
42
+ it "flips out and raises error when it receives an API error" do
43
+ @h = HerePlaces::Base.new(@app_id, @app_code)
44
+ FakeWeb.register_uri(:get, %r|^http:\/\/places\.nlp\.nokia\.com\/.*|, :body => {status: 400, stuff: 'test'}.to_json)
45
+ expect {@h.api(@url_fragment, @data)}.to raise_error(HerePlaces::APIError)
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe HerePlaces::Category do
4
+ before(:each) do
5
+ app_id = 'APP_ID'
6
+ app_code = 'APP_CODE'
7
+ @data = {test: 'stuff'}
8
+ @h = HerePlaces::Category.new(app_id, app_code)
9
+ @h.stub!(:api)
10
+ end
11
+
12
+ it 'responds correctly to places method and delegates to the api call' do
13
+ resource_url = "#{API_PREFIX}/categories/places"
14
+ @h.should respond_to(:places)
15
+ @h.should_receive(:api).with(resource_url, @data)
16
+ @h.places(@data)
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe HerePlaces::Discover do
4
+ before(:each) do
5
+ app_id = 'APP_ID'
6
+ app_code = 'APP_CODE'
7
+ @data = {test: 'stuff'}
8
+ @h = HerePlaces::Discover.new(app_id, app_code)
9
+ @h.stub!(:api)
10
+ end
11
+
12
+ %w(search explore here).each do |meth|
13
+ it "responds correctly to #{meth} and delegates to the api call" do
14
+ resource_url = "#{API_PREFIX}/discover/#{meth}"
15
+ @h.should respond_to(meth.to_sym)
16
+ @h.should_receive(:api).with(resource_url, @data)
17
+ @h.send(meth.to_sym, @data)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe HerePlaces::Place do
4
+ before(:each) do
5
+ app_id = 'APP_ID'
6
+ app_code = 'APP_CODE'
7
+ @id = '123asdfa'
8
+ @h = HerePlaces::Place.new(app_id, app_code)
9
+ @h.stub!(:api)
10
+ end
11
+
12
+ it 'responds correctly to places method and delegates to the api call' do
13
+ resource_url = "#{API_PREFIX}/places/#{@id}"
14
+ @h.should respond_to(:places)
15
+ @h.should_receive(:api).with(resource_url)
16
+ @h.places(@id)
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'rspec'
4
+ require 'fakeweb'
5
+ require 'here_places'
6
+
7
+ BASE_URL = 'http://places.nlp.nokia.com/'
8
+ API_PREFIX = 'places/v1'
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe HerePlaces::Suggest do
4
+ before(:each) do
5
+ app_id = 'APP_ID'
6
+ app_code = 'APP_CODE'
7
+ @data = {test: 'stuff'}
8
+ @h = HerePlaces::Suggest.new(app_id, app_code)
9
+ @h.stub!(:api)
10
+ end
11
+
12
+ it 'responds correctly to suggest method and delegates to the api call' do
13
+ resource_url = "#{API_PREFIX}/suggest"
14
+ @h.should respond_to(:suggest)
15
+ @h.should_receive(:api).with(resource_url, @data)
16
+ @h.suggest(@data)
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: here_places
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Prem Pillai
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.1'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fakeweb
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: faraday
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 0.8.4
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.8.4
62
+ description: A wafer-thin Ruby Wrapper for Nokia's Here Places API
63
+ email:
64
+ - prem.pillai@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - here_places.gemspec
75
+ - lib/here_places.rb
76
+ - lib/here_places/base.rb
77
+ - lib/here_places/category.rb
78
+ - lib/here_places/discover.rb
79
+ - lib/here_places/error.rb
80
+ - lib/here_places/place.rb
81
+ - lib/here_places/suggest.rb
82
+ - lib/here_places/version.rb
83
+ - spec/base_spec.rb
84
+ - spec/category_spec.rb
85
+ - spec/discover_spec.rb
86
+ - spec/place_spec.rb
87
+ - spec/spec_helper.rb
88
+ - spec/suggest_spec.rb
89
+ homepage: https://github.com/premjg/here_places
90
+ licenses:
91
+ - MIT
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.23
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: A wafer-thin Ruby Wrapper for Nokia's Here Places API
114
+ test_files:
115
+ - spec/base_spec.rb
116
+ - spec/category_spec.rb
117
+ - spec/discover_spec.rb
118
+ - spec/place_spec.rb
119
+ - spec/spec_helper.rb
120
+ - spec/suggest_spec.rb
121
+ has_rdoc: