Skip to content

Instantly share code, notes, and snippets.

@IanVaughan
Created May 15, 2012 20:44
Show Gist options
  • Select an option

  • Save IanVaughan/2704999 to your computer and use it in GitHub Desktop.

Select an option

Save IanVaughan/2704999 to your computer and use it in GitHub Desktop.
Api Idea
require 'httparty'
require 'yaml'
require 'app_conf'
module Tickspot
class ApiAccess
include HTTParty
def initialize(site, u, p)
@auth = {email: u, password: p}
self.class.base_uri "https://#{site}.tickspot.com"
end
# http://tickspot.com/api/
# The API response is wrapped within a top level XML node which normally matches the method name
# but on some methods it differs
[
# clients
# -------
# Optional
# :open [true|false]
{ m: :clients, d: 'clients' },
# projects
# --------
# Optional
# :project_id
# :open [true|false]
# :project_billable [true|false]
{ m: :projects, d: 'projects' },
# tasks
# -----
# Required
# :project_id
# Optional
# :task_id
# :open [true|false]
# :task_billable [true|false]
{ m: :tasks, d: 'tasks' },
# clients_projects_tasks
# ----------------------
{ m: :clients_projects_tasks, d: 'clients' },
# entries
# --------
# Required
# :start_date
# :end_date
# OR
# :updated_at
# Optional
# :project_id
# :task_id
# :user_id
# :user_email
# :client_id
# :entry_billable [true|false]
# :billed [true|false]
{ m: :entries, d: 'entries' },
# recent_tasks
# ------------
{ m: :recent_tasks, d: 'tasks' },
# users
# -----
# Optional
# :project_id
{ m: :users, d: 'users' },
# create_entry
# ------------
# Required
# :task_id
# :hours
# :date
# Optional
# :notes
{ m: :create_entry, d: 'entry' },
# update_entry
# ------------
# Required
# :id
# Optional
# :hours
# :date
# :billed
# :task_id
# :user_id
# :notes
{ m: :update_entry, d: 'entry' }
].each do | m |
define_method m[:m], ->(params = {}) do
# conf = AppConf.new
request_result = self.class.post("/api/#{m[:m].to_s}", :query => @auth.merge(params))
# conf.from_hash request_result #["#{m.to_s}"]
request_result["#{m[:d]}"]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment