tickspot_api 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ module Tickspot
2
+ class Data
3
+
4
+ def initialize(parsed)
5
+ # @data = parsed
6
+ # raise unless parsed.class == Hash
7
+ @data = parsed#[parsed.keys.first]
8
+ end
9
+
10
+ def id
11
+ self.method_missing(:id)
12
+ end
13
+
14
+ # def empty?
15
+ # if @hash["type"] == "array" && @hash["content"] == "\n"
16
+ # true
17
+ # else
18
+ # false
19
+ # end
20
+ # end
21
+
22
+ def method_missing(method, *args)
23
+ puts "->#{method}, #{args}"
24
+ return Data.new(@data[args.first]) if @data.class == Array
25
+ if @data.has_key?(method.to_s)
26
+ entry = @data[method.to_s]
27
+ # return entry[0] unless entry[0].class == Hash && entry[0].has_key?("content")
28
+ # return entry[0]["content"]
29
+ # entry = Data.new(entry) if entry.class == Hash
30
+ entry
31
+ else
32
+ super
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,140 @@
1
+ require 'httparty'
2
+
3
+ module Tickspot
4
+ class Api
5
+ include HTTParty
6
+ format :xml
7
+
8
+ def initialize(site, u, p) #config = nil
9
+ @auth = {email: u, password: p}
10
+ self.class.base_uri "https://#{site}.tickspot.com"
11
+ # default_params :output => 'json'
12
+
13
+ # @cache = {}
14
+ # set_config(config) if config.nil?
15
+ # load_config(find_config) unless config.nil?
16
+ # @domain = config.company + "tickspot.com"
17
+ end
18
+
19
+ # def load_config filename
20
+ # raise "ERROR: Cannot find file #{filename}" unless File.exists? filename
21
+ # config = YAML.load_file(filename)
22
+
23
+ # @ts = Tickspot.new "#{config['company']}.tickspot.com", config['email'], config['password']
24
+ # conf.save_file @config_file
25
+ # YAML::dump(conf, @config_file)
26
+ # end
27
+
28
+ # def find_config
29
+ # search current dir and up
30
+ # '~/.tickconfig'
31
+ # end
32
+
33
+ # def set_config config
34
+ # raise 'Incorrect params' unless config.company and config.email and config.password
35
+ # @company = config['company'] if config.has_key? 'company'
36
+ # @email = config['email'] if config.has_key? 'email'
37
+ # @password = config['password'] if config.has_key? 'password'
38
+ # end
39
+
40
+ # http://tickspot.com/api/
41
+ # The API response is wrapped within a top level XML node which normally matches the method name
42
+ # but on some methods it differs
43
+
44
+ # Optional : :open [true|false]
45
+ def clients optional_params = {}
46
+ request('clients', optional_params)['clients']
47
+ end
48
+
49
+ # Optional : :project_id, :open [true|false], :project_billable [true|false]
50
+ def projects optional_params = {}
51
+ request('projects', optional_params)['projects']
52
+ end
53
+
54
+ # Required : :project_id
55
+ # Optional : :task_id, :open [true|false], :task_billable [true|false]
56
+ def tasks required_params, optional_params = {}
57
+ check required_params, [:project_id]
58
+ # check optional_params, [:task_id, :open, :task_billable], false
59
+ request('tasks', required_params.merge(optional_params))['tasks']
60
+ end
61
+
62
+ def clients_projects_tasks optional_params = {}
63
+ request('clients_projects_tasks', optional_params)['clients']
64
+ end
65
+
66
+ # Required : :start_date, :end_date OR :updated_at
67
+ # Optional : :project_id, :task_id, :user_id, :user_email, :client_id, :entry_billable [true|false], :billed [true|false]
68
+ def entries required_params, optional_params = {}
69
+ check required_params, [:start_date, :end_date]
70
+ # updated_at
71
+ request('entries', required_params.merge(optional_params))['entries']
72
+ end
73
+
74
+ def recent_tasks optional_params = {}
75
+ request('recent_tasks', optional_params)['tasks']
76
+ end
77
+
78
+ # Optional : :project_id
79
+ def users optional_params = {}
80
+ request('users', optional_params)['users']
81
+ end
82
+
83
+ # Required : :task_id, :hours, :date
84
+ # Optional : :notes
85
+ def create_entry required_params, optional_params = {}
86
+ check required_params, [:task_id, :hours, :date]
87
+ request('entry', required_params.merge(optional_params))['entry']
88
+ end
89
+
90
+ # Required : :id
91
+ # Optional : :hours, :date, :billed, :task_id, :user_id, :notes
92
+ def update_entry required_params, optional_params = {}
93
+ check required_params, [:id]
94
+ request('create_entry', required_params.merge(optional_params))['entry']
95
+ end
96
+
97
+ # private
98
+
99
+ def request method, params
100
+ # optional_params.delete 'reload'
101
+ # if !@cache.has_key?(method) || (params.has_key?('reload') && params['reload'] == true) # refresh/force/
102
+ # save cache on every access, load before reading
103
+ ret = self.class.post("/api/#{method}", :query => @auth.merge(params))
104
+ # raise Unauthorized if response.is_a? Net::HTTPUnauthorized
105
+ # ret = @cache[method]
106
+ # ret = Data.new @cache[method]['users']
107
+ # ret = Data.new @cache[method]
108
+ # @cache[method] = request_result
109
+ # end
110
+ ret
111
+ end
112
+
113
+ def check hash, keys
114
+ #, optional = false
115
+ expecting = "expecting one of '#{keys}'"
116
+ raise "Must be a hash, #{expecting}" unless hash.is_a? Hash
117
+ keys.each do |key|
118
+ msg = "Required parameter missing : #{key}, #{expecting}"
119
+ raise msg unless hash.has_key?(key)
120
+ #and optional
121
+ return unless hash.has_key?(key)
122
+ #and optional
123
+ end
124
+ true
125
+ end
126
+
127
+ class Unauthorized < RuntimeError
128
+ def message
129
+ "You are not authorized to perform this action. If your login information is correct, you may be calling at admin-only action. See http://tickspot.com/api/ for more information."
130
+ end
131
+ end
132
+
133
+ class IncorrectParam < RuntimeError
134
+ def message(p)
135
+ "#{p}"
136
+ end
137
+ end
138
+
139
+ end
140
+ end
@@ -0,0 +1,5 @@
1
+ require 'tickspot/tickspot'
2
+
3
+ module Tickspot
4
+ VERSION = '0.0.5'
5
+ end
@@ -0,0 +1,19 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sat, 19 May 2012 14:46:43 GMT
3
+ Server: Apache/2.2.9 (Ubuntu) Phusion_Passenger/3.0.11 mod_ssl/2.2.9 OpenSSL/0.9.8g
4
+ X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
5
+ ETag: "cf7f9ff83de2674ddf4a9eb8389e5cb8"
6
+ X-Runtime: 5
7
+ Cache-Control: private, max-age=0, must-revalidate
8
+ Content-Length: 160
9
+ Status: 200
10
+ Connection: close
11
+ Content-Type: application/xml; charset=utf-8
12
+
13
+ <?xml version="1.0" encoding="UTF-8"?>
14
+ <clients type="array">
15
+ <client>
16
+ <id type="integer">128542</id>
17
+ <name>TestClient2</name>
18
+ </client>
19
+ </clients>
@@ -0,0 +1,63 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sat, 19 May 2012 14:46:46 GMT
3
+ Server: Apache/2.2.9 (Ubuntu) Phusion_Passenger/3.0.11 mod_ssl/2.2.9 OpenSSL/0.9.8g
4
+ X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
5
+ ETag: "11fd1b0d8276fd96cc2a4332ca7cdb5c"
6
+ X-Runtime: 11
7
+ Cache-Control: private, max-age=0, must-revalidate
8
+ Content-Length: 2082
9
+ Status: 200
10
+ Connection: close
11
+ Content-Type: application/xml; charset=utf-8
12
+
13
+ <?xml version="1.0" encoding="UTF-8"?>
14
+ <clients type="array">
15
+ <client>
16
+ <id type="integer">128542</id>
17
+ <name>TestClient2</name>
18
+ <projects type="array">
19
+ <project>
20
+ <id type="integer">408314</id>
21
+ <name type="text">TestClient-TestProject</name>
22
+ <budget type="float">100.00</budget>
23
+ <client_id type="integer">128542</client_id>
24
+ <opened_on type="date">2012-05-14</opened_on>
25
+ <closed_on type="date"></closed_on>
26
+ <created_at type="datetime">Mon, 14 May 2012 02:44:46 -0400</created_at>
27
+ <updated_at type="datetime">Mon, 14 May 2012 02:49:57 -0400</updated_at>
28
+ <tasks type="array">
29
+ <task>
30
+ <id type="integer">2162941</id>
31
+ <name>TestClient-TestProject-TestTask1</name>
32
+ <position type="integer">1</position>
33
+ <project_id type="integer">408314</project_id>
34
+ <opened_on type="date">2012-05-14</opened_on>
35
+ <closed_on type="date"></closed_on>
36
+ <budget type="float">10.00</budget>
37
+ <billable type="boolean"></billable>
38
+ </task>
39
+ <task>
40
+ <id type="integer">2162942</id>
41
+ <name>TestClient-TestProject-TestTask2</name>
42
+ <position type="integer">2</position>
43
+ <project_id type="integer">408314</project_id>
44
+ <opened_on type="date">2012-05-14</opened_on>
45
+ <closed_on type="date"></closed_on>
46
+ <budget type="float">90.00</budget>
47
+ <billable type="boolean"></billable>
48
+ </task>
49
+ <task>
50
+ <id type="integer">2162943</id>
51
+ <name>TestClient-TestProject-TestTask3</name>
52
+ <position type="integer">3</position>
53
+ <project_id type="integer">408314</project_id>
54
+ <opened_on type="date">2012-05-14</opened_on>
55
+ <closed_on type="date"></closed_on>
56
+ <budget type="float">0.00</budget>
57
+ <billable type="boolean"></billable>
58
+ </task>
59
+ </tasks>
60
+ </project>
61
+ </projects>
62
+ </client>
63
+ </clients>
@@ -0,0 +1,37 @@
1
+ ---
2
+ - id: 128542
3
+ name: TestClient2
4
+ projects:
5
+ - id: 408314
6
+ name: TestClient-TestProject
7
+ budget: 100.0
8
+ client_id: 128542
9
+ opened_on: 2012-05-14
10
+ closed_on:
11
+ created_at: 2012-05-14 06:44:46.000000000 Z
12
+ updated_at: 2012-05-14 06:49:57.000000000 Z
13
+ tasks:
14
+ - id: 2162941
15
+ name: TestClient-TestProject-TestTask1
16
+ position: 1
17
+ project_id: 408314
18
+ opened_on: 2012-05-14
19
+ closed_on:
20
+ budget: 10.0
21
+ billable:
22
+ - id: 2162942
23
+ name: TestClient-TestProject-TestTask2
24
+ position: 2
25
+ project_id: 408314
26
+ opened_on: 2012-05-14
27
+ closed_on:
28
+ budget: 90.0
29
+ billable:
30
+ - id: 2162943
31
+ name: TestClient-TestProject-TestTask3
32
+ position: 3
33
+ project_id: 408314
34
+ opened_on: 2012-05-14
35
+ closed_on:
36
+ budget: 0.0
37
+ billable:
@@ -0,0 +1,48 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sat, 19 May 2012 14:53:59 GMT
3
+ Server: Apache/2.2.9 (Ubuntu) Phusion_Passenger/3.0.11 mod_ssl/2.2.9 OpenSSL/0.9.8g
4
+ X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
5
+ ETag: "53e653461f8eae95665a3b4ef8f4f31d"
6
+ X-Runtime: 16
7
+ Cache-Control: private, max-age=0, must-revalidate
8
+ Content-Length: 1449
9
+ Status: 200
10
+ Connection: close
11
+ Content-Type: application/xml; charset=utf-8
12
+
13
+ <?xml version="1.0" encoding="UTF-8"?>
14
+ <entry>
15
+ <id type="integer">13372505</id>
16
+ <task_id type="integer">2162941</task_id>
17
+ <user_id type="integer">86580</user_id>
18
+ <date type="date">2012-05-19</date>
19
+ <hours type="float">1.00</hours>
20
+ <notes></notes>
21
+ <created_at type="datetime">Sat, 19 May 2012 10:53:59 -0400</created_at>
22
+ <updated_at type="datetime">Sat, 19 May 2012 10:53:59 -0400</updated_at>
23
+ <user_email type="text">tickspot@ianvaughan.co.uk</user_email>
24
+ <task>
25
+ <id type="integer">2162941</id>
26
+ <name>TestClient-TestProject-TestTask1</name>
27
+ <position type="integer">1</position>
28
+ <project_id type="integer">408314</project_id>
29
+ <opened_on type="date">2012-05-14</opened_on>
30
+ <closed_on type="date"></closed_on>
31
+ <budget type="float">10.00</budget>
32
+ <billable type="boolean">true</billable>
33
+ <total_hours>1.00</total_hours>
34
+ <user_count>1</user_count>
35
+ </task>
36
+ <project>
37
+ <id type="integer">408314</id>
38
+ <name>TestClient-TestProject</name>
39
+ <budget type="float">100.00</budget>
40
+ <client_id type="integer">128542</client_id>
41
+ <opened_on type="date">2012-05-14</opened_on>
42
+ <closed_on type="date"></closed_on>
43
+ <created_at type="datetime">Mon, 14 May 2012 02:44:46 -0400</created_at>
44
+ <updated_at type="datetime">Mon, 14 May 2012 02:49:57 -0400</updated_at>
45
+ <total_hours type="float">1.00</total_hours>
46
+ <client_name>TestClient2</client_name>
47
+ </project>
48
+ </entry>
@@ -0,0 +1,13 @@
1
+ HTTP/1.1 401 Authorization Required
2
+ Date: Sat, 19 May 2012 14:44:16 GMT
3
+ Server: Apache/2.2.9 (Ubuntu) Phusion_Passenger/3.0.11 mod_ssl/2.2.9 OpenSSL/0.9.8g
4
+ X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
5
+ X-Runtime: 1
6
+ Cache-Control: no-cache
7
+ Content-Length: 43
8
+ Status: 401
9
+ Vary: Accept-Encoding
10
+ Connection: close
11
+ Content-Type: text/html; charset=utf-8
12
+
13
+ The user information provided is not valid.
@@ -0,0 +1,67 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sat, 19 May 2012 14:46:45 GMT
3
+ Server: Apache/2.2.9 (Ubuntu) Phusion_Passenger/3.0.11 mod_ssl/2.2.9 OpenSSL/0.9.8g
4
+ X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
5
+ ETag: "4983022a23b3e64874dcac888b5a6e25"
6
+ X-Runtime: 13
7
+ Cache-Control: private, max-age=0, must-revalidate
8
+ Content-Length: 2262
9
+ Status: 200
10
+ Connection: close
11
+ Content-Type: application/xml; charset=utf-8
12
+
13
+ <?xml version="1.0" encoding="UTF-8"?>
14
+ <projects type="array">
15
+ <project>
16
+ <id type="integer">408314</id>
17
+ <name>TestClient-TestProject</name>
18
+ <budget type="float">100.00</budget>
19
+ <client_id type="integer">128542</client_id>
20
+ <owner_id type="integer">86580</owner_id>
21
+ <opened_on type="date">2012-05-14</opened_on>
22
+ <closed_on type="date"></closed_on>
23
+ <created_at type="datetime">Mon, 14 May 2012 02:44:46 -0400</created_at>
24
+ <updated_at type="datetime">Mon, 14 May 2012 02:49:57 -0400</updated_at>
25
+ <client_name>TestClient2</client_name>
26
+ <sum_hours type="float">0.00</sum_hours>
27
+ <user_count type="integer">0</user_count>
28
+ <tasks type="array">
29
+ <task>
30
+ <id type="integer">2162941</id>
31
+ <name>TestClient-TestProject-TestTask1</name>
32
+ <position type="integer">1</position>
33
+ <project_id type="integer">408314</project_id>
34
+ <opened_on type="date">2012-05-14</opened_on>
35
+ <closed_on type="date"></closed_on>
36
+ <budget type="float">10.00</budget>
37
+ <billable type="boolean">true</billable>
38
+ <sum_hours type="float">0.00</sum_hours>
39
+ <user_count type="integer">0</user_count>
40
+ </task>
41
+ <task>
42
+ <id type="integer">2162942</id>
43
+ <name>TestClient-TestProject-TestTask2</name>
44
+ <position type="integer">2</position>
45
+ <project_id type="integer">408314</project_id>
46
+ <opened_on type="date">2012-05-14</opened_on>
47
+ <closed_on type="date"></closed_on>
48
+ <budget type="float">90.00</budget>
49
+ <billable type="boolean">true</billable>
50
+ <sum_hours type="float">0.00</sum_hours>
51
+ <user_count type="integer">0</user_count>
52
+ </task>
53
+ <task>
54
+ <id type="integer">2162943</id>
55
+ <name>TestClient-TestProject-TestTask3</name>
56
+ <position type="integer">3</position>
57
+ <project_id type="integer">408314</project_id>
58
+ <opened_on type="date">2012-05-14</opened_on>
59
+ <closed_on type="date"></closed_on>
60
+ <budget type="float">0.00</budget>
61
+ <billable type="boolean">true</billable>
62
+ <sum_hours type="float">0.00</sum_hours>
63
+ <user_count type="integer">0</user_count>
64
+ </task>
65
+ </tasks>
66
+ </project>
67
+ </projects>
@@ -0,0 +1,44 @@
1
+ ---
2
+ - id: 408314
3
+ name: TestClient-TestProject
4
+ budget: 100.0
5
+ client_id: 128542
6
+ owner_id: 86580
7
+ opened_on: 2012-05-14
8
+ closed_on:
9
+ created_at: 2012-05-14 06:44:46.000000000 Z
10
+ updated_at: 2012-05-14 06:49:57.000000000 Z
11
+ client_name: TestClient2
12
+ sum_hours: 1.0
13
+ user_count: 1
14
+ tasks:
15
+ - id: 2162941
16
+ name: TestClient-TestProject-TestTask1
17
+ position: 1
18
+ project_id: 408314
19
+ opened_on: 2012-05-14
20
+ closed_on:
21
+ budget: 10.0
22
+ billable: true
23
+ sum_hours: 1.0
24
+ user_count: 1
25
+ - id: 2162942
26
+ name: TestClient-TestProject-TestTask2
27
+ position: 2
28
+ project_id: 408314
29
+ opened_on: 2012-05-14
30
+ closed_on:
31
+ budget: 90.0
32
+ billable: true
33
+ sum_hours: 0.0
34
+ user_count: 0
35
+ - id: 2162943
36
+ name: TestClient-TestProject-TestTask3
37
+ position: 3
38
+ project_id: 408314
39
+ opened_on: 2012-05-14
40
+ closed_on:
41
+ budget: 0.0
42
+ billable: true
43
+ sum_hours: 0.0
44
+ user_count: 0
@@ -0,0 +1,15 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sat, 19 May 2012 14:50:27 GMT
3
+ Server: Apache/2.2.9 (Ubuntu) Phusion_Passenger/3.0.11 mod_ssl/2.2.9 OpenSSL/0.9.8g
4
+ X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
5
+ ETag: "07c22d37714abcccbac7ce5bc330498f"
6
+ X-Runtime: 4
7
+ Cache-Control: private, max-age=0, must-revalidate
8
+ Content-Length: 69
9
+ Status: 200
10
+ Connection: close
11
+ Content-Type: application/xml; charset=utf-8
12
+
13
+ <?xml version="1.0" encoding="UTF-8"?>
14
+ <tasks type="array">
15
+ </tasks>
@@ -0,0 +1,9 @@
1
+ ---
2
+ - id: 2162941
3
+ name: TestClient-TestProject-TestTask1
4
+ position: 1
5
+ project_id: 408314
6
+ opened_on: 2012-05-14
7
+ closed_on:
8
+ budget: 10.0
9
+ billable: true
@@ -0,0 +1,45 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sat, 19 May 2012 14:48:31 GMT
3
+ Server: Apache/2.2.9 (Ubuntu) Phusion_Passenger/3.0.11 mod_ssl/2.2.9 OpenSSL/0.9.8g
4
+ X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
5
+ ETag: "7f4bc0c9b4c4c30f4b6997f7f115ad20"
6
+ X-Runtime: 9
7
+ Cache-Control: private, max-age=0, must-revalidate
8
+ Content-Length: 1187
9
+ Status: 200
10
+ Connection: close
11
+ Content-Type: application/xml; charset=utf-8
12
+
13
+ <?xml version="1.0" encoding="UTF-8"?>
14
+ <tasks type="array">
15
+ <task>
16
+ <id type="integer">2162941</id>
17
+ <name>TestClient-TestProject-TestTask1</name>
18
+ <position type="integer">1</position>
19
+ <project_id type="integer">408314</project_id>
20
+ <opened_on type="date">2012-05-14</opened_on>
21
+ <closed_on type="date"></closed_on>
22
+ <budget type="float">10.00</budget>
23
+ <billable type="boolean">true</billable>
24
+ </task>
25
+ <task>
26
+ <id type="integer">2162942</id>
27
+ <name>TestClient-TestProject-TestTask2</name>
28
+ <position type="integer">2</position>
29
+ <project_id type="integer">408314</project_id>
30
+ <opened_on type="date">2012-05-14</opened_on>
31
+ <closed_on type="date"></closed_on>
32
+ <budget type="float">90.00</budget>
33
+ <billable type="boolean">true</billable>
34
+ </task>
35
+ <task>
36
+ <id type="integer">2162943</id>
37
+ <name>TestClient-TestProject-TestTask3</name>
38
+ <position type="integer">3</position>
39
+ <project_id type="integer">408314</project_id>
40
+ <opened_on type="date">2012-05-14</opened_on>
41
+ <closed_on type="date"></closed_on>
42
+ <budget type="float">0.00</budget>
43
+ <billable type="boolean">true</billable>
44
+ </task>
45
+ </tasks>
@@ -0,0 +1,13 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sat, 19 May 2012 14:56:21 GMT
3
+ Server: Apache/2.2.9 (Ubuntu) Phusion_Passenger/3.0.11 mod_ssl/2.2.9 OpenSSL/0.9.8g
4
+ X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
5
+ X-Runtime: 12
6
+ Cache-Control: no-cache
7
+ Content-Length: 1
8
+ Status: 200
9
+ Vary: Accept-Encoding
10
+ Connection: close
11
+ Content-Type: text/html; charset=utf-8
12
+
13
+
@@ -0,0 +1,31 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Sat, 19 May 2012 14:46:44 GMT
3
+ Server: Apache/2.2.9 (Ubuntu) Phusion_Passenger/3.0.11 mod_ssl/2.2.9 OpenSSL/0.9.8g
4
+ X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11
5
+ ETag: "8f56151c33771f6b04d474fb81cc5e58"
6
+ X-Runtime: 6
7
+ Cache-Control: private, max-age=0, must-revalidate
8
+ Content-Length: 755
9
+ Status: 200
10
+ Connection: close
11
+ Content-Type: application/xml; charset=utf-8
12
+
13
+ <?xml version="1.0" encoding="UTF-8"?>
14
+ <users type="array">
15
+ <user>
16
+ <id type="integer">86580</id>
17
+ <first_name>Ian</first_name>
18
+ <last_name>Vaughan</last_name>
19
+ <email>tickspot@ianvaughan.co.uk</email>
20
+ <created_at type="datetime">Mon, 14 May 2012 02:41:23 -0400</created_at>
21
+ <updated_at type="datetime">Mon, 14 May 2012 02:43:06 -0400</updated_at>
22
+ </user>
23
+ <user>
24
+ <id type="integer">86583</id>
25
+ <first_name>TickSpotTestUser-FirstName</first_name>
26
+ <last_name>TickSpotTestUser-LastName</last_name>
27
+ <email>tickspot-test@ianvaughan.co.uk</email>
28
+ <created_at type="datetime">Mon, 14 May 2012 02:51:24 -0400</created_at>
29
+ <updated_at type="datetime">Mon, 14 May 2012 02:57:57 -0400</updated_at>
30
+ </user>
31
+ </users>
@@ -0,0 +1,13 @@
1
+ ---
2
+ - id: 86580
3
+ first_name: Ian
4
+ last_name: Vaughan
5
+ email: tickspot@ianvaughan.co.uk
6
+ created_at: 2012-05-14 06:41:23.000000000 Z
7
+ updated_at: 2012-05-14 06:43:06.000000000 Z
8
+ - id: 86583
9
+ first_name: TickSpotTestUser-FirstName
10
+ last_name: TickSpotTestUser-LastName
11
+ email: tickspot-test@ianvaughan.co.uk
12
+ created_at: 2012-05-14 06:51:24.000000000 Z
13
+ updated_at: 2012-05-14 06:57:57.000000000 Z
@@ -0,0 +1,21 @@
1
+ require './lib/tickspot'
2
+ TS = Tickspot::Api.new 'company', 'email', 'password'
3
+
4
+ def save name
5
+ File.open("spec/fixtures/#{name}.yml", 'w') do |f|
6
+ yield f
7
+ end
8
+ end
9
+
10
+ def access method
11
+ save method do |f|
12
+ YAML.dump TS.send(method), f
13
+ end
14
+ end
15
+
16
+ %w{users projects clients_projects_tasks recent_tasks}.each do |m|
17
+ access m
18
+ end
19
+
20
+ # ts.tasks
21
+ # ts.entries
@@ -0,0 +1,15 @@
1
+ require 'rspec'
2
+ require 'rspec/autorun'
3
+
4
+ require 'fakeweb'
5
+
6
+ FakeWeb.allow_net_connect = false
7
+
8
+ RSpec.configure do |c|
9
+ # c.mock_with :rspec
10
+
11
+ # def fixture(filename)
12
+ # File.dirname(__FILE__) + '/fixtures/' + filename
13
+ # end
14
+
15
+ end
@@ -0,0 +1,37 @@
1
+ ---
2
+ - id: 128542
3
+ name: TestClient2
4
+ projects:
5
+ - id: 408314
6
+ name: TestClient-TestProject
7
+ budget: 100.0
8
+ client_id: 128542
9
+ opened_on: 2012-05-14
10
+ closed_on:
11
+ created_at: 2012-05-14 06:44:46.000000000 Z
12
+ updated_at: 2012-05-14 06:49:57.000000000 Z
13
+ tasks:
14
+ - id: 2162941
15
+ name: TestClient-TestProject-TestTask1
16
+ position: 1
17
+ project_id: 408314
18
+ opened_on: 2012-05-14
19
+ closed_on:
20
+ budget: 10.0
21
+ billable:
22
+ - id: 2162942
23
+ name: TestClient-TestProject-TestTask2
24
+ position: 2
25
+ project_id: 408314
26
+ opened_on: 2012-05-14
27
+ closed_on:
28
+ budget: 90.0
29
+ billable:
30
+ - id: 2162943
31
+ name: TestClient-TestProject-TestTask3
32
+ position: 3
33
+ project_id: 408314
34
+ opened_on: 2012-05-14
35
+ closed_on:
36
+ budget: 0.0
37
+ billable:
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+ require './lib/tickspot'
3
+
4
+ module Tickspot
5
+ describe Api do
6
+
7
+ context 'init' do
8
+ # it 'should init the object data' do
9
+ # # Api.expects.base_uri = "https://company.tickspot.com"
10
+ # # Api.expects.auth = {email: u, password: p}
11
+ end
12
+
13
+ context 'helpers' do
14
+
15
+ before do
16
+ @ts = Api.new '', '', ''
17
+ end
18
+
19
+ it 'should check params' do
20
+ @ts.check({:id => 1, :name => 'foo'}, [:id]).should be_true
21
+ @ts.check({:id => 1, :name => 'foo'}, [:id, :name]).should be_true
22
+ @ts.check({:id => 1, :name => 'foo', :foo => 'bar'}, [:id, :name]).should be_true
23
+ lambda {
24
+ @ts.check({:id => 1, :name => 'foo'}, [:id, :name, :foo])
25
+ }.should raise_error
26
+ end
27
+ end
28
+
29
+ context 'requests' do
30
+ before do
31
+ @c = 'company'
32
+ @u = 'user@email.com'
33
+ @p = 'password'
34
+ @ts = Api.new @c, @u, @p
35
+ end
36
+
37
+ it 'should request tickspot' do
38
+ # request = "https://#{@c}.tickspot.com/api/clients?email=#{@u}&password=#{@p}"
39
+ request = %r{https://company.tickspot.com/api/clients}
40
+ FakeWeb.register_uri(:post, request, :response => File.join(File.dirname(__FILE__), 'fixtures', 'clients.xml')) # body: 'hi')
41
+
42
+ result = {"clients"=>[{"id"=>128542, "name"=>"TestClient2"}]}
43
+ @ts.request('clients', {}).should eq result
44
+ end
45
+
46
+ it 'should do a post request with the parameters' do
47
+ # HTTParty.any_instance.
48
+ Api.should_receive(:post).with(
49
+ # https://#{@c}.tickspot.com
50
+ "/api/test",
51
+ :query => {
52
+ :email => @u,
53
+ :password => @p
54
+ }
55
+ ).and_return()#@result)
56
+
57
+ @ts.request('test', {})
58
+ end
59
+
60
+ it 'should pass every argument in the query hash' do
61
+ Api.should_receive(:post).with(
62
+ '/api/test',
63
+ :query => {
64
+ :email => @u,
65
+ :password => @p,
66
+ :woo => 'bleh'
67
+ }
68
+ ).and_return(@result)
69
+
70
+ @ts.request('test', :woo => 'bleh')
71
+ end
72
+
73
+ it 'should strip the top level node' do
74
+ pending
75
+ # HTTParty
76
+ Api.stub!(:post).and_return(@result)
77
+
78
+ @ts.request('test', {}).should == []
79
+ end
80
+ end
81
+
82
+ context 'methods' do
83
+
84
+ before do
85
+ c = 'company'
86
+ u = 'user@email.com'
87
+ p = 'password'
88
+ @ts = Api.new c, u, p
89
+ end
90
+
91
+ it 'should get clients' do
92
+ h = {'clients' => [{ 'id' => 128542, 'name' => 'TestClient2' }] }
93
+ @ts.stub(:request).and_return(h)
94
+
95
+ @ts.clients.should eq h['clients']
96
+ end
97
+
98
+ it 'should get clients with options' do
99
+ h = {'clients' => [{ 'id' => 128542, 'name' => 'TestClient2' }] }
100
+ # should_recive {:open => true}
101
+ @ts.stub(:request).and_return(h)
102
+
103
+ @ts.clients('open').should eq h['clients']
104
+ end
105
+
106
+ it 'should get clients_projects_tasks' do
107
+ # h = {"clients"=>[{"id"=>128542, "name"=>"TestClient2", "projects"=>[{"id"=>408314, "name"=>"TestClient-TestProject", "budget"=>100.0, "client_id"=>128542, "opened_on"=>#<Date: 2012-05-14 ((2456062j,0s,0n),+0s,2299161j)>, "closed_on"=>nil, "created_at"=>2012-05-14 06:44:46 UTC, "updated_at"=>2012-05-14 06:49:57 UTC, "tasks"=>[{"id"=>2162941, "name"=>"TestClient-TestProject-TestTask1", "position"=>1, "project_id"=>408314, "opened_on"=>#<Date: 2012-05-14 ((2456062j,0s,0n),+0s,2299161j)>, "closed_on"=>nil, "budget"=>10.0, "billable"=>nil}, {"id"=>2162942, "name"=>"TestClient-TestProject-TestTask2", "position"=>2, "project_id"=>408314, "opened_on"=>#<Date: 2012-05-14 ((2456062j,0s,0n),+0s,2299161j)>, "closed_on"=>nil, "budget"=>90.0, "billable"=>nil}, {"id"=>2162943, "name"=>"TestClient-TestProject-TestTask3", "position"=>3, "project_id"=>408314, "opened_on"=>#<Date: 2012-05-14 ((2456062j,0s,0n),+0s,2299161j)>, "closed_on"=>nil, "budget"=>0.0, "billable"=>nil}]}]}]}
108
+ h = {"clients"=>[{"id"=>128542, "name"=>"TestClient2", "projects"=>[{"id"=>408314, "name"=>"TestClient-TestProject", "budget"=>100.0, "client_id"=>128542, "opened_on"=>0, "closed_on"=>nil, "created_at"=>0, "updated_at"=>0, "tasks"=>[{"id"=>2162941, "name"=>"TestClient-TestProject-TestTask1", "position"=>1, "project_id"=>408314, "opened_on"=>0, "closed_on"=>nil, "budget"=>10.0, "billable"=>nil}, {"id"=>2162942, "name"=>"TestClient-TestProject-TestTask2", "position"=>2, "project_id"=>408314, "opened_on"=>0, "closed_on"=>nil, "budget"=>90.0, "billable"=>nil}, {"id"=>2162943, "name"=>"TestClient-TestProject-TestTask3", "position"=>3, "project_id"=>408314, "opened_on"=>0, "closed_on"=>nil, "budget"=>0.0, "billable"=>nil}]}]}]}
109
+ @ts.stub(:request).and_return(h)
110
+
111
+ @ts.clients_projects_tasks.should eq h['clients']
112
+ end
113
+
114
+ it 'should get projects' do
115
+ # h = {"projects"=>[{"id"=>408314, "name"=>"TestClient-TestProject", "budget"=>100.0, "client_id"=>128542, "owner_id"=>86580, "opened_on"=>#<Date: 2012-05-14 ((2456062j,0s,0n),+0s,2299161j)>, "closed_on"=>nil, "created_at"=>2012-05-14 06:44:46 UTC, "updated_at"=>2012-05-14 06:49:57 UTC, "client_name"=>"TestClient2", "sum_hours"=>0.0, "user_count"=>0, "tasks"=>[{"id"=>2162941, "name"=>"TestClient-TestProject-TestTask1", "position"=>1, "project_id"=>408314, "opened_on"=>#<Date: 2012-05-14 ((2456062j,0s,0n),+0s,2299161j)>, "closed_on"=>nil, "budget"=>10.0, "billable"=>true, "sum_hours"=>0.0, "user_count"=>0}, {"id"=>2162942, "name"=>"TestClient-TestProject-TestTask2", "position"=>2, "project_id"=>408314, "opened_on"=>#<Date: 2012-05-14 ((2456062j,0s,0n),+0s,2299161j)>, "closed_on"=>nil, "budget"=>90.0, "billable"=>true, "sum_hours"=>0.0, "user_count"=>0}, {"id"=>2162943, "name"=>"TestClient-TestProject-TestTask3", "position"=>3, "project_id"=>408314, "opened_on"=>#<Date: 2012-05-14 ((2456062j,0s,0n),+0s,2299161j)>, "closed_on"=>nil, "budget"=>0.0, "billable"=>true, "sum_hours"=>0.0, "user_count"=>0}]}]}
116
+ h = {"projects"=>[{"id"=>408314, "name"=>"TestClient-TestProject", "budget"=>100.0, "client_id"=>128542, "owner_id"=>86580, "opened_on"=>0, "closed_on"=>nil, "created_at"=>1, "updated_at"=>1, "client_name"=>"TestClient2", "sum_hours"=>0.0, "user_count"=>0, "tasks"=>[{"id"=>2162941, "name"=>"TestClient-TestProject-TestTask1", "position"=>1, "project_id"=>408314, "opened_on"=>1, "closed_on"=>nil, "budget"=>10.0, "billable"=>true, "sum_hours"=>0.0, "user_count"=>0}, {"id"=>2162942, "name"=>"TestClient-TestProject-TestTask2", "position"=>2, "project_id"=>408314, "opened_on"=>2, "closed_on"=>nil, "budget"=>90.0, "billable"=>true, "sum_hours"=>0.0, "user_count"=>0}, {"id"=>2162943, "name"=>"TestClient-TestProject-TestTask3", "position"=>3, "project_id"=>408314, "opened_on"=>1, "closed_on"=>nil, "budget"=>0.0, "billable"=>true, "sum_hours"=>0.0, "user_count"=>0}]}]}
117
+ @ts.stub(:request).and_return(h)
118
+
119
+ @ts.projects.should eq h['projects']
120
+ end
121
+
122
+ it 'should get tasks' do
123
+ # h = {"tasks"=>[{"id"=>2162941, "name"=>"TestClient-TestProject-TestTask1", "position"=>1, "project_id"=>408314, "opened_on"=>#<Date: 2012-05-14 ((2456062j,0s,0n),+0s,2299161j)>, "closed_on"=>nil, "budget"=>10.0, "billable"=>true}, {"id"=>2162942, "name"=>"TestClient-TestProject-TestTask2", "position"=>2, "project_id"=>408314, "opened_on"=>#<Date: 2012-05-14 ((2456062j,0s,0n),+0s,2299161j)>, "closed_on"=>nil, "budget"=>90.0, "billable"=>true}, {"id"=>2162943, "name"=>"TestClient-TestProject-TestTask3", "position"=>3, "project_id"=>408314, "opened_on"=>#<Date: 2012-05-14 ((2456062j,0s,0n),+0s,2299161j)>, "closed_on"=>nil, "budget"=>0.0, "billable"=>true}]}
124
+ h = {"tasks"=>[{"id"=>2162941, "name"=>"TestClient-TestProject-TestTask1", "position"=>1, "project_id"=>408314, "opened_on"=>0, "closed_on"=>nil, "budget"=>10.0, "billable"=>true}, {"id"=>2162942, "name"=>"TestClient-TestProject-TestTask2", "position"=>2, "project_id"=>408314, "opened_on"=>1, "closed_on"=>nil, "budget"=>90.0, "billable"=>true}, {"id"=>2162943, "name"=>"TestClient-TestProject-TestTask3", "position"=>3, "project_id"=>408314, "opened_on"=>3, "closed_on"=>nil, "budget"=>0.0, "billable"=>true}]}
125
+ @ts.stub(:request).and_return(h)
126
+
127
+ @ts.tasks(project_id: 2162941).should eq h['tasks']
128
+ end
129
+
130
+ end
131
+ end
132
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tickspot_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ian Vaughan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: This allows your application easy access to the Tickspot API
31
+ email: github@ianvaughan.co.uk
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/tickspot/data.rb
37
+ - lib/tickspot/tickspot.rb
38
+ - lib/tickspot_api.rb
39
+ - spec/fixtures/clients.xml
40
+ - spec/fixtures/clients_projects_tasks.xml
41
+ - spec/fixtures/clients_projects_tasks.yml
42
+ - spec/fixtures/create_entry.xml
43
+ - spec/fixtures/not_auth.xml
44
+ - spec/fixtures/projects.xml
45
+ - spec/fixtures/projects.yml
46
+ - spec/fixtures/recent_tasks.xml
47
+ - spec/fixtures/recent_tasks.yml
48
+ - spec/fixtures/tasks.xml
49
+ - spec/fixtures/update_entry.xml
50
+ - spec/fixtures/users.xml
51
+ - spec/fixtures/users.yml
52
+ - spec/gen_fixtures.rb
53
+ - spec/spec_helper.rb
54
+ - spec/test.yml
55
+ - spec/tickspot_spec.rb
56
+ homepage: http://github.com/ianvaughan/tickspot-api
57
+ licenses: []
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.24
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Ruby wrapper for the Tickspot API
80
+ test_files:
81
+ - spec/fixtures/clients.xml
82
+ - spec/fixtures/clients_projects_tasks.xml
83
+ - spec/fixtures/clients_projects_tasks.yml
84
+ - spec/fixtures/create_entry.xml
85
+ - spec/fixtures/not_auth.xml
86
+ - spec/fixtures/projects.xml
87
+ - spec/fixtures/projects.yml
88
+ - spec/fixtures/recent_tasks.xml
89
+ - spec/fixtures/recent_tasks.yml
90
+ - spec/fixtures/tasks.xml
91
+ - spec/fixtures/update_entry.xml
92
+ - spec/fixtures/users.xml
93
+ - spec/fixtures/users.yml
94
+ - spec/gen_fixtures.rb
95
+ - spec/spec_helper.rb
96
+ - spec/test.yml
97
+ - spec/tickspot_spec.rb