refreshingmenus_api 0.0.1
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 +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +33 -0
- data/Rakefile +2 -0
- data/lib/refreshingmenus_api/version.rb +3 -0
- data/lib/refreshingmenus_api.rb +67 -0
- data/refreshingmenus_api.gemspec +20 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Joopp BV / RefreshingMenus
|
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,33 @@
|
|
1
|
+
# RefreshingmenusApi
|
2
|
+
|
3
|
+
Ruby API to use the Refreshing Menus REST API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'refreshingmenus_api'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install refreshingmenus_api
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
api = RefreshingmenusApi::Client.new(:auth_token => 'your_auth_token_here')
|
22
|
+
result = api.places(:q => "o'pazzo") # Returns Array or results
|
23
|
+
result.first[:name] # => "O'Pazzo Pizzeria"
|
24
|
+
result.first[:id] # => "194ebdcc-fcd9-11e1-b4ac-5254006b3bb5"
|
25
|
+
result.first[:menus].first[:title] # => "Pizzeria Kaart"
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# require 'refreshingmenus_api/version'
|
2
|
+
|
3
|
+
require 'httparty'
|
4
|
+
require 'active_support/core_ext'
|
5
|
+
require 'active_support/core_ext/hash'
|
6
|
+
|
7
|
+
module RefreshingmenusApi
|
8
|
+
|
9
|
+
class ApiError < StandardError;
|
10
|
+
end
|
11
|
+
class NotFoundError < ApiError;
|
12
|
+
end
|
13
|
+
class UnprocessableEntityError < ApiError;
|
14
|
+
end
|
15
|
+
|
16
|
+
# Usage:
|
17
|
+
# api = RefreshingmenusApi::Client.new(:auth_token => 'your_auth_token_here')
|
18
|
+
# api.places(:q => 'some query')
|
19
|
+
class Client
|
20
|
+
|
21
|
+
ERRORS = {
|
22
|
+
404 => NotFoundError,
|
23
|
+
422 => UnprocessableEntityError,
|
24
|
+
}
|
25
|
+
ERRORS.default = ApiError
|
26
|
+
|
27
|
+
include HTTParty
|
28
|
+
|
29
|
+
attr_reader :auth_token, :version, :format
|
30
|
+
|
31
|
+
def initialize(options = {})
|
32
|
+
@auth_token = options[:auth_token]
|
33
|
+
@version = options[:version] || '1'
|
34
|
+
self.class.base_uri(options[:base_uri] || 'www.refreshingmenus.com')
|
35
|
+
end
|
36
|
+
|
37
|
+
def places(options)
|
38
|
+
get('places.json', :query => options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get(*args)
|
42
|
+
request :get, *args
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def request(method, path, options = {})
|
48
|
+
options[:query] ||= {}
|
49
|
+
options[:query][:auth_token] ||= auth_token
|
50
|
+
path = File.join("/api/v#{version}", path)
|
51
|
+
response = self.class.send(method, path, options)
|
52
|
+
|
53
|
+
# In 2XX range is success otherwise it's probably error (3XX redirects range is handled by HTTParty).
|
54
|
+
# In case of error we lookup error class or default to ApiError.
|
55
|
+
case response.code
|
56
|
+
when 200..299
|
57
|
+
result = response.parsed_response
|
58
|
+
result = result.collect {|r| r.is_a?(Hash) ? r.with_indifferent_access : r} if result.is_a?(Array)
|
59
|
+
return result
|
60
|
+
else
|
61
|
+
raise ERRORS[response.code], "Got HTTP code #{response.code} (#{response.message}) from API.\nPath: #{path} #{options.inspect}\nAuthToken: #{auth_token}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/refreshingmenus_api/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Joost Hietbrink"]
|
6
|
+
gem.email = ["joost@joopp.com"]
|
7
|
+
gem.description = %q{Ruby API to use the Refreshing Menus REST API.}
|
8
|
+
gem.summary = %q{Ruby API to use the Refreshing Menus REST API.}
|
9
|
+
gem.homepage = "http://www.refreshingmenus.com"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "refreshingmenus_api"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = RefreshingmenusApi::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency('httparty')
|
19
|
+
gem.add_dependency('activesupport')
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: refreshingmenus_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joost Hietbrink
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Ruby API to use the Refreshing Menus REST API.
|
47
|
+
email:
|
48
|
+
- joost@joopp.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/refreshingmenus_api.rb
|
59
|
+
- lib/refreshingmenus_api/version.rb
|
60
|
+
- refreshingmenus_api.gemspec
|
61
|
+
homepage: http://www.refreshingmenus.com
|
62
|
+
licenses: []
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.24
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Ruby API to use the Refreshing Menus REST API.
|
85
|
+
test_files: []
|
86
|
+
has_rdoc:
|