require 'active_support/core_ext' module GoogleContactsApi class Api # keep separate in case of new auth method BASE_URL = "https://www.google.com/m8/feeds/" attr_reader :oauth def initialize(oauth) # TODO: Later, accept ClientLogin @oauth = oauth end # Get request to specified link, with query params # For get, post, put, delete, always use JSON, it's simpler # and lets us use Hashie::Mash. Note that in the JSON conversion from XML, # ":" is replaced with $, element content is keyed with $t def get(link, params = {}, headers = {}) params["alt"] = "json" @oauth.get("#{BASE_URL}#{link}?#{params.to_query}", headers) end # Post request to specified link, with query params # Not tried yet, might be issues with params def post(link, params = {}, headers = {}) raise NotImplementedError params["alt"] = "json" @oauth.post("#{BASE_URL}#{link}?#{params.to_query}", headers) end # Put request to specified link, with query params # Not tried yet def put(link, params = {}, headers = {}) raise NotImplementedError params["alt"] = "json" @oauth.put("#{BASE_URL}#{link}?#{params.to_query}", headers) end # Delete request to specified link, with query params # Not tried yet def delete(link, params = {}, headers = {}) raise NotImplementedError params["alt"] = "json" @oauth.delete("#{BASE_URL}#{link}?#{params.to_query}", headers) end end end