Sha256: 32624bf48b284beaacf70d5e6da3a5c1ffbbaddc55f40abf6bc45289d4581500

Contents?: true

Size: 1.48 KB

Versions: 3

Compression:

Stored size: 1.48 KB

Contents

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
google_contacts_api-0.2.5 lib/google_contacts_api/api.rb
google_contacts_api-0.2.4 lib/google_contacts_api/api.rb
google_contacts_api-0.2.3 lib/google_contacts_api/api.rb