Class: Tickspot::Api
- Inherits:
-
Object
- Object
- Tickspot::Api
- Includes:
- HTTParty
- Defined in:
- lib/tickspot/tickspot.rb
Defined Under Namespace
Classes: IncorrectParam, Unauthorized
Instance Method Summary collapse
- #check(hash, keys) ⇒ Object
-
#clients(optional_params = {}) ⇒ Object
Optional : :open [true|false].
- #clients_projects_tasks(optional_params = {}) ⇒ Object
-
#create_entry(required_params, optional_params = {}) ⇒ Object
Required : :task_id, :hours, :date Optional : :notes.
-
#entries(required_params, optional_params = {}) ⇒ Object
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].
-
#initialize(site, u, p) ⇒ Api
constructor
config = nil.
-
#projects(optional_params = {}) ⇒ Object
Optional : :project_id, :open [true|false], :project_billable [true|false].
- #recent_tasks(optional_params = {}) ⇒ Object
-
#request(method, params) ⇒ Object
private.
-
#tasks(required_params, optional_params = {}) ⇒ Object
Required : :project_id Optional : :task_id, :open [true|false], :task_billable [true|false].
-
#update_entry(required_params, optional_params = {}) ⇒ Object
Required : :id Optional : :hours, :date, :billed, :task_id, :user_id, :notes.
-
#users(optional_params = {}) ⇒ Object
Optional : :project_id.
Constructor Details
#initialize(site, u, p) ⇒ Api
config = nil
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/tickspot/tickspot.rb', line 8 def initialize(site, u, p) #config = nil @auth = {email: u, password: p} self.class.base_uri "https://#{site}.tickspot.com" # default_params :output => 'json' # @cache = {} # set_config(config) if config.nil? # load_config(find_config) unless config.nil? # @domain = config.company + "tickspot.com" end |
Instance Method Details
#check(hash, keys) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/tickspot/tickspot.rb', line 113 def check hash, keys #, optional = false expecting = "expecting one of '#{keys}'" raise "Must be a hash, #{expecting}" unless hash.is_a? Hash keys.each do |key| msg = "Required parameter missing : #{key}, #{expecting}" raise msg unless hash.has_key?(key) #and optional return unless hash.has_key?(key) #and optional end true end |
#clients(optional_params = {}) ⇒ Object
Optional : :open [true|false]
45 46 47 |
# File 'lib/tickspot/tickspot.rb', line 45 def clients optional_params = {} request('clients', optional_params)['clients'] end |
#clients_projects_tasks(optional_params = {}) ⇒ Object
62 63 64 |
# File 'lib/tickspot/tickspot.rb', line 62 def clients_projects_tasks optional_params = {} request('clients_projects_tasks', optional_params)['clients'] end |
#create_entry(required_params, optional_params = {}) ⇒ Object
Required : :task_id, :hours, :date Optional : :notes
85 86 87 88 |
# File 'lib/tickspot/tickspot.rb', line 85 def create_entry required_params, optional_params = {} check required_params, [:task_id, :hours, :date] request('entry', required_params.merge(optional_params))['entry'] end |
#entries(required_params, optional_params = {}) ⇒ Object
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]
68 69 70 71 72 |
# File 'lib/tickspot/tickspot.rb', line 68 def entries required_params, optional_params = {} check required_params, [:start_date, :end_date] # updated_at request('entries', required_params.merge(optional_params))['entries'] end |
#projects(optional_params = {}) ⇒ Object
Optional : :project_id, :open [true|false], :project_billable [true|false]
50 51 52 |
# File 'lib/tickspot/tickspot.rb', line 50 def projects optional_params = {} request('projects', optional_params)['projects'] end |
#recent_tasks(optional_params = {}) ⇒ Object
74 75 76 |
# File 'lib/tickspot/tickspot.rb', line 74 def recent_tasks optional_params = {} request('recent_tasks', optional_params)['tasks'] end |
#request(method, params) ⇒ Object
private
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/tickspot/tickspot.rb', line 99 def request method, params # optional_params.delete 'reload' # if [email protected]_key?(method) || (params.has_key?('reload') && params['reload'] == true) # refresh/force/ # save cache on every access, load before reading ret = self.class.post("/api/#{method}", :query => @auth.merge(params)) # raise Unauthorized if response.is_a? Net::HTTPUnauthorized # ret = @cache[method] # ret = Data.new @cache[method]['users'] # ret = Data.new @cache[method] # @cache[method] = request_result # end ret end |
#tasks(required_params, optional_params = {}) ⇒ Object
Required : :project_id Optional : :task_id, :open [true|false], :task_billable [true|false]
56 57 58 59 60 |
# File 'lib/tickspot/tickspot.rb', line 56 def tasks required_params, optional_params = {} check required_params, [:project_id] # check optional_params, [:task_id, :open, :task_billable], false request('tasks', required_params.merge(optional_params))['tasks'] end |
#update_entry(required_params, optional_params = {}) ⇒ Object
Required : :id Optional : :hours, :date, :billed, :task_id, :user_id, :notes
92 93 94 95 |
# File 'lib/tickspot/tickspot.rb', line 92 def update_entry required_params, optional_params = {} check required_params, [:id] request('create_entry', required_params.merge(optional_params))['entry'] end |
#users(optional_params = {}) ⇒ Object
Optional : :project_id
79 80 81 |
# File 'lib/tickspot/tickspot.rb', line 79 def users optional_params = {} request('users', optional_params)['users'] end |