Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 64bde8d98c564ce01753b401af6c72043551f412 1 parent 2010bc7
@joost joost authored
View
4 Gemfile
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in refreshingmenus_api.gemspec
+gemspec
View
22 LICENSE
@@ -0,0 +1,22 @@
+Copyright (c) 2012 Joopp BV / RefreshingMenus
+
+MIT License
+
+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:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+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.
View
35 README.md
@@ -1,4 +1,33 @@
-refreshingmenus_api
-===================
+# RefreshingmenusApi
-Ruby API to use the Refreshing Menus REST API.
+Ruby API to use the Refreshing Menus REST API.
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'refreshingmenus_api'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install refreshingmenus_api
+
+## Usage
+
+ api = RefreshingmenusApi::Client.new(:auth_token => 'your_auth_token_here')
+ result = api.places(:q => "o'pazzo") # Returns Array or results
+ result.first[:name] # => "O'Pazzo Pizzeria"
+ result.first[:id] # => "194ebdcc-fcd9-11e1-b4ac-5254006b3bb5"
+ result.first[:menus].first[:title] # => "Pizzeria Kaart"
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
View
2  Rakefile
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
View
67 lib/refreshingmenus_api.rb
@@ -0,0 +1,67 @@
+# require 'refreshingmenus_api/version'
+
+require 'httparty'
+require 'active_support/core_ext'
+require 'active_support/core_ext/hash'
+
+module RefreshingmenusApi
+
+ class ApiError < StandardError;
+ end
+ class NotFoundError < ApiError;
+ end
+ class UnprocessableEntityError < ApiError;
+ end
+
+ # Usage:
+ # api = RefreshingmenusApi::Client.new(:auth_token => 'your_auth_token_here')
+ # api.places(:q => 'some query')
+ class Client
+
+ ERRORS = {
+ 404 => NotFoundError,
+ 422 => UnprocessableEntityError,
+ }
+ ERRORS.default = ApiError
+
+ include HTTParty
+
+ attr_reader :auth_token, :version, :format
+
+ def initialize(options = {})
+ @auth_token = options[:auth_token]
+ @version = options[:version] || '1'
+ self.class.base_uri(options[:base_uri] || 'www.refreshingmenus.com')
+ end
+
+ def places(options)
+ get('places.json', :query => options)
+ end
+
+ def get(*args)
+ request :get, *args
+ end
+
+ private
+
+ def request(method, path, options = {})
+ options[:query] ||= {}
+ options[:query][:auth_token] ||= auth_token
+ path = File.join("/api/v#{version}", path)
+ response = self.class.send(method, path, options)
+
+ # In 2XX range is success otherwise it's probably error (3XX redirects range is handled by HTTParty).
+ # In case of error we lookup error class or default to ApiError.
+ case response.code
+ when 200..299
+ result = response.parsed_response
+ result = result.collect {|r| r.is_a?(Hash) ? r.with_indifferent_access : r} if result.is_a?(Array)
+ return result
+ else
+ raise ERRORS[response.code], "Got HTTP code #{response.code} (#{response.message}) from API.\nPath: #{path} #{options.inspect}\nAuthToken: #{auth_token}"
+ end
+ end
+
+ end
+
+end
View
3  lib/refreshingmenus_api/version.rb
@@ -0,0 +1,3 @@
+module RefreshingmenusApi
+ VERSION = "0.0.1"
+end
View
20 refreshingmenus_api.gemspec
@@ -0,0 +1,20 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/refreshingmenus_api/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Joost Hietbrink"]
+ gem.email = ["joost@joopp.com"]
+ gem.description = %q{Ruby API to use the Refreshing Menus REST API.}
+ gem.summary = %q{Ruby API to use the Refreshing Menus REST API.}
+ gem.homepage = "http://www.refreshingmenus.com"
+
+ gem.files = `git ls-files`.split($\)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "refreshingmenus_api"
+ gem.require_paths = ["lib"]
+ gem.version = RefreshingmenusApi::VERSION
+
+ gem.add_dependency('httparty')
+ gem.add_dependency('activesupport')
+end
Please sign in to comment.
Something went wrong with that request. Please try again.