tupalo_api_client 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ pkg/*
2
+ .rvmrc
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2011 Tupalo.com
3
+
4
+ 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:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ 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,138 @@
1
+ Tupalo API Client
2
+ ---
3
+
4
+ An interface to [Tupalo.com](Tupalo.com)'s Easy API. This allows you
5
+ to
6
+
7
+ * search for spots
8
+ * find spots within a certain area
9
+ * display detailed information about a spot
10
+ * display spots on a map
11
+ * post reviews via review widgets
12
+ * match your spots to our spots
13
+ * tell us about spots not yet in our database
14
+
15
+ Basically this allows you to build a specialized location-based site
16
+ or integrate Tupalo.com's content into your page.
17
+
18
+ API access
19
+ ---
20
+
21
+ Without an API token you will be limited to 200 requests per
22
+ month. This has to do with the way we are licensing data from our
23
+ partners. For the same reason tokenless requests will not include the
24
+ phone numbers of spots.
25
+
26
+ To get an API token please email api@tupalo.com and let us know what
27
+ kind of app you have in mind, as well as an estimate on the number of
28
+ requests you will approximately need per month.
29
+
30
+ Some more guidelines:
31
+
32
+ * Use the API for good and not for evil.
33
+ * Do not scrape us.
34
+ * Do not resell our data.
35
+ * Create something awesome.
36
+ * Have fun.
37
+
38
+ Creating an API client instance
39
+ ---
40
+
41
+ require 'tupalo_api_client'
42
+ tup = TupaloApiClient.new
43
+
44
+ Alternatively `#new` can take an options hash with the keys `:lang`
45
+ and `:token` to customize the language and supply your API token.
46
+
47
+ tup = TupaloApiClient.new(:lang => 'nl', :token => 'abc123')
48
+
49
+ Language-wise we currently support English (the default), German, Dutch,
50
+ Danish, Finnish, Polish, Swedish and French.
51
+
52
+ Spots search
53
+ ---
54
+
55
+ Used for retrieving spots in a certain area.
56
+
57
+ tup.spots(:origin => 'Schmalzhofgasse 26, Vienna, Austria',
58
+ :includecategories => 'restaurant')
59
+
60
+ This will return all restaurants within 0.3km (the default radius)
61
+ with the Tupalo.com office.
62
+
63
+ The following parameters are supported in the options hash:
64
+
65
+ * `name`: name or part of the name of a spot
66
+ * `origin`: an address string (example: "Schmalzhofgasse 26, Vienna, Austria")
67
+ * `latitude`: latitude coordinate
68
+ * `longitude`: longitude coordinate
69
+ * `spot_id`: uses the latitude and longitude of the given spot
70
+ * `radius`: search radius (default 0.3km)
71
+ * `excludecategories`: comma separated category keys
72
+ * `includecategories`: comma separated category keys
73
+ * `map_size`: size of the static map image
74
+ * `offset`: used for pagination (maximum 40, default 0)
75
+ * `limit`: number of results to return (maximum 10)
76
+ * `token`: optional access key token
77
+
78
+ The list of category keys can be found here in JSON format:
79
+
80
+ [http://tupalo.com/en/api/v1/categories/tree.json](http://tupalo.com/en/api/v1/categories/tree.json)
81
+
82
+ Spot details
83
+ ---
84
+
85
+ Returns detailed information about a spot, including reviews.
86
+
87
+ tup.spot_details(:spot_id => 'gubi')
88
+
89
+ This needs a `spot_id` which has to be retrieved via `#spots` first.
90
+
91
+ Review widget
92
+ ---
93
+
94
+ Returns an HTML partial for a Tupalo.com review widget that you can
95
+ use for embedding Tupalo.com reviews in your site.
96
+
97
+ _This token-only method is further described in the official API
98
+ documentation._
99
+
100
+ Matching
101
+ ---
102
+
103
+ Used for augmenting spot information on Tupalo.com or pushing new
104
+ spots into our database. Changes to existing information as well as
105
+ newly added spots will be manually reviewed before being added to the
106
+ site.
107
+
108
+ _This token-only method is further described in the official API
109
+ documentation._
110
+
111
+ Error handling
112
+ ---
113
+
114
+ In case something goes wrong, an `TupaloApiErrors::ClientError` (HTTP
115
+ 4xx) or a `TupaloApiErrors::ServerError` (HTTP 5xx) get raised.
116
+
117
+ A "HTTP 412 Precondition Failed" status code is returned if you go
118
+ over your API request limit.
119
+
120
+ Known problems
121
+ ---
122
+
123
+ None at the moment.
124
+
125
+ Todo
126
+ ---
127
+
128
+ This gem models the current state of Tupalo.com's Easy API.
129
+
130
+ Authors
131
+ ---
132
+
133
+ Michael Kohl <michi@tupalo.com> and Andreas Tiefenthaler <andy@tupalo.com>
134
+
135
+ License
136
+ ---
137
+
138
+ This gem is licensed under the MIT license. See the `LICENSE` file for details.
@@ -0,0 +1,35 @@
1
+ require 'rake/testtask'
2
+ require 'fileutils'
3
+ GEMSPEC = 'tupalo_api_client.gemspec'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.pattern = 'test/test_*.rb'
7
+ end
8
+
9
+ def gemspec
10
+ @gemspec ||= eval(File.read(GEMSPEC), binding, GEMSPEC)
11
+ end
12
+
13
+ namespace :gem do
14
+ desc "Build the gem"
15
+ task :build => :generate_gemspec do
16
+ sh "gem build #{GEMSPEC}"
17
+ FileUtils.mkdir_p 'pkg'
18
+ FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
19
+ end
20
+
21
+ desc "Install the gem locally (without docs)"
22
+ task :install => :build do
23
+ sh %{gem install pkg/#{gemspec.name}-#{gemspec.version} --no-rdoc --no-ri}
24
+ end
25
+
26
+ desc "Generate the gemspec"
27
+ task :generate_gemspec do
28
+ puts gemspec.to_ruby
29
+ end
30
+
31
+ desc "Validate the gemspec"
32
+ task :validate_gemspec do
33
+ gemspec.validate
34
+ end
35
+ end
@@ -0,0 +1,60 @@
1
+ require 'api_smith'
2
+ require 'uri'
3
+
4
+ require 'tupalo_api_client/spot'
5
+ require 'tupalo_api_client/review'
6
+ require 'tupalo_api_client/review_widget'
7
+ require 'tupalo_api_client/match'
8
+ require 'tupalo_api_client/import'
9
+
10
+ require 'tupalo_api_client/errors'
11
+
12
+ class TupaloApiClient
13
+
14
+ include APISmith::Client
15
+ include TupaloApiErrors
16
+
17
+ base_uri 'http://tupalo.com/'
18
+
19
+ def initialize(opts = {})
20
+ options = {
21
+ :lang => 'en',
22
+ :token => '',
23
+ :timeout => 15}.merge(opts)
24
+
25
+ add_query_options! :token => options[:token] unless options[:token].empty?
26
+ self.class.endpoint "#{options[:lang]}/api/easy/v1"
27
+ end
28
+
29
+ def spots(opts={})
30
+ get("spots/#{parameterize(opts)}", :transform => Spot)
31
+ end
32
+
33
+ def spot_details(opts={})
34
+ get("spot/#{parameterize(opts)}", :transform => Spot)
35
+ end
36
+
37
+ def review_widget(opts={})
38
+ get("review_widget/#{parameterize(opts)}", :transform => ReviewWidget)
39
+ end
40
+
41
+ def match(opts={})
42
+ transform = opts.has_key?(:spot_id) ? Match : Import
43
+ get("match/#{parameterize(opts)}", :transform => transform)
44
+ end
45
+
46
+ private
47
+
48
+ def parameterize(params)
49
+ "?#{URI.escape(params.map{|k,v| "#{k}=#{v}"}.join('&'))}"
50
+ end
51
+
52
+ def check_response_errors(response)
53
+ if response.code.to_s =~ /^(4|5)/
54
+ raise $1 == "4" ?
55
+ ClientError.new(response.headers["status"]) :
56
+ ServerError.new(response.headers["status"])
57
+ end
58
+ end
59
+
60
+ end
@@ -0,0 +1,5 @@
1
+ module TupaloApiErrors
2
+ class ClientError < StandardError; end
3
+ class ServerError < StandardError; end
4
+ end
5
+
@@ -0,0 +1,12 @@
1
+ class Import < APISmith::Smash
2
+
3
+ property :name
4
+ property :city
5
+ property :country
6
+ property :street
7
+ property :phone
8
+ property :website
9
+ property :locale
10
+ property :returntext
11
+
12
+ end
@@ -0,0 +1,6 @@
1
+ class Match < APISmith::Smash
2
+
3
+ property :url
4
+ property :changes
5
+
6
+ end
@@ -0,0 +1,8 @@
1
+ class Review < APISmith::Smash
2
+
3
+ property :rating, :transformer => :to_i
4
+ property :created_at
5
+ property :text
6
+ property :user
7
+
8
+ end
@@ -0,0 +1,6 @@
1
+ class ReviewWidget < APISmith::Smash
2
+
3
+ property :review_widget
4
+ property :spot_id
5
+
6
+ end
@@ -0,0 +1,23 @@
1
+ class Spot < APISmith::Smash
2
+
3
+ property :street
4
+ property :state
5
+ property :category
6
+ property :website_url_formatted
7
+ property :icon_url
8
+ property :zip
9
+ property :city
10
+ property :rating, :transformer => :to_f
11
+ property :google_maps_url
12
+ property :country_code
13
+ property :spot_id
14
+ property :name
15
+ property :latitude, :transformer => :to_f
16
+ property :external_url
17
+ property :longitude, :transformer => :to_f
18
+ property :image_thumbnail_url
19
+
20
+ property :reviews, :transformer => lambda { |review| review.map { |r| Review.call(r) }.flatten }
21
+
22
+ end
23
+
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'tupalo_api_client'
3
+ s.version = '1.0.1'
4
+ s.authors = ['Michael Kohl', 'Andreas Tiefenthaler']
5
+ s.email = ['michi@tupalo.com', 'andy@tupalo.com']
6
+ s.description = 'A convenient wrapper for the Tupalo.com API'
7
+ s.summary = s.description
8
+ s.homepage = 'https://github.com/tupalo/tupalo_api_client'
9
+ s.require_paths = ['lib']
10
+ s.files = `git ls-files`.split("\n")
11
+ s.add_dependency('api_smith', '~> 1.0.0')
12
+ s.has_rdoc = false
13
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tupalo_api_client
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Michael Kohl
14
+ - Andreas Tiefenthaler
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-09-23 00:00:00 +02:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: api_smith
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 23
31
+ segments:
32
+ - 1
33
+ - 0
34
+ - 0
35
+ version: 1.0.0
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ description: A convenient wrapper for the Tupalo.com API
39
+ email:
40
+ - michi@tupalo.com
41
+ - andy@tupalo.com
42
+ executables: []
43
+
44
+ extensions: []
45
+
46
+ extra_rdoc_files: []
47
+
48
+ files:
49
+ - .gitignore
50
+ - LICENSE
51
+ - README.markdown
52
+ - Rakefile
53
+ - lib/tupalo_api_client.rb
54
+ - lib/tupalo_api_client/errors.rb
55
+ - lib/tupalo_api_client/import.rb
56
+ - lib/tupalo_api_client/match.rb
57
+ - lib/tupalo_api_client/review.rb
58
+ - lib/tupalo_api_client/review_widget.rb
59
+ - lib/tupalo_api_client/spot.rb
60
+ - tupalo_api_client.gemspec
61
+ has_rdoc: false
62
+ homepage: https://github.com/tupalo/tupalo_api_client
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options: []
67
+
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ requirements: []
89
+
90
+ rubyforge_project:
91
+ rubygems_version: 1.3.7
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: A convenient wrapper for the Tupalo.com API
95
+ test_files: []
96
+