freeagent_api 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Aaron Russell
1
+ Copyright (c) 2009-2010 Aaron Russell
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -11,10 +11,10 @@ This supports all GET, POST, PUT and DELETE ActiveResource calls for the followi
11
11
  * Invoices
12
12
  * Invoice Items
13
13
  * Timeslips
14
+ * Users
14
15
 
15
16
  At the moment, the following API resources are NOT supported (although is being worked on):
16
17
 
17
- * Users
18
18
  * Expenses
19
19
  * Attachments
20
20
 
@@ -229,10 +229,43 @@ Please note: version 0.2 is significantly different from 0.1 so if you are upgra
229
229
  # or
230
230
  @timeslip.destroy
231
231
 
232
- == Author
232
+ === Users
233
+
234
+ <b>Find users</b>
235
+
236
+ @users = User.find :all # returns all users
237
+ @user = User.find id # returns specific user
238
+ @user = User.find_by_email email
239
+
240
+ <b>Create user</b>
241
+
242
+ # Required attributes
243
+ # :first_name
244
+ # :last_name
245
+ # :email
246
+ # :role # must be Owner, Director, Partner, Company Secretary, Employee, Shareholder, or Accountant
247
+ # :password
248
+ # :password_confirmation
249
+
250
+ @user = User.new params
251
+ @user.save
252
+
253
+ <b>Update user</b>
254
+
255
+ @user.first_name = 'Joe Bloggs'
256
+ @user.save
257
+
258
+ <b>Delete user</b>
259
+
260
+ User.delete id
261
+ # or
262
+ @user.destroy
263
+
264
+ == Author & Contributors
233
265
 
234
266
  * Aaron Russell - (www.aaronrussell.co.uk)
267
+ * Alex Comans - (www.alexcoomans.com)
235
268
 
236
269
  == Copyright
237
270
 
238
- Copyright (c) 2009 Aaron Russell. See LICENSE for details.
271
+ Copyright (c) 2009-2010 Aaron Russell. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{freeagent_api}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Russell"]
12
- s.date = %q{2009-10-27}
12
+ s.date = %q{2010-05-25}
13
13
  s.description = %q{This is an ActiveResource Ruby wrapper for the Freeagent API. Currently supports the following API resources: Company, Contacts, Projects, Tasks, Invoices, Invoice Items, Timeslips (more will follow).}
14
14
  s.email = %q{aaron@gc4.co.uk}
15
15
  s.extra_rdoc_files = [
@@ -49,14 +49,17 @@ Gem::Specification.new do |s|
49
49
  "test/stubs/tasks/find_single",
50
50
  "test/stubs/timeslips/find_all",
51
51
  "test/stubs/timeslips/find_single",
52
+ "test/stubs/users/find_all",
53
+ "test/stubs/users/find_single",
52
54
  "test/task_test.rb",
53
55
  "test/test_helper.rb",
54
- "test/timeslip_test.rb"
56
+ "test/timeslip_test.rb",
57
+ "test/user_test.rb"
55
58
  ]
56
59
  s.homepage = %q{http://github.com/aaronrussell/freeagent_api}
57
60
  s.rdoc_options = ["--charset=UTF-8"]
58
61
  s.require_paths = ["lib"]
59
- s.rubygems_version = %q{1.3.5}
62
+ s.rubygems_version = %q{1.3.6}
60
63
  s.summary = %q{ActiveResource Ruby wrapper for the Freeagent Central API.}
61
64
  s.test_files = [
62
65
  "test/authentication_test.rb",
@@ -67,7 +70,8 @@ Gem::Specification.new do |s|
67
70
  "test/project_test.rb",
68
71
  "test/task_test.rb",
69
72
  "test/test_helper.rb",
70
- "test/timeslip_test.rb"
73
+ "test/timeslip_test.rb",
74
+ "test/user_test.rb"
71
75
  ]
72
76
 
73
77
  if s.respond_to? :specification_version then
@@ -89,3 +93,4 @@ Gem::Specification.new do |s|
89
93
  s.add_dependency(%q<activeresource>, [">= 0"])
90
94
  end
91
95
  end
96
+
data/lib/freeagent_api.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'activeresource'
2
+ require 'active_resource'
3
3
 
4
4
  module Freeagent
5
5
 
@@ -111,5 +111,18 @@ module Freeagent
111
111
  end
112
112
  end
113
113
  end
114
-
114
+
115
+ # Users
116
+
117
+ class User < Base
118
+ self.prefix = '/company/'
119
+ def self.find_by_email(email)
120
+ users = User.find :all
121
+ users.each do |u|
122
+ u.email == email ? (return u) : next
123
+ end
124
+ raise Error, "No user matches that email!"
125
+ end
126
+ end
127
+
115
128
  end
@@ -0,0 +1,33 @@
1
+ HTTP/1.1 200 OK
2
+ Status: 200
3
+ Content-Type: application/xml; charset=utf-8
4
+
5
+ <?xml version="1.0" encoding="UTF-8"?>
6
+ <users type="array">
7
+ <user>
8
+ <company-id type="integer">10</company-id>
9
+ <email>olly@lylo.co.uk</email>
10
+ <first-name>Olly</first-name>
11
+ <id type="integer">11</id>
12
+ <last-logged-in-at type="datetime">2008-03-03T21:16:09Z</last-logged-in-at>
13
+ <last-name>Headey</last-name>
14
+ <opening-director-loan-account-balance type="decimal">0.0</opening-director-loan-account-balance>
15
+ <opening-expense-balance type="decimal">0.0</opening-expense-balance>
16
+ <opening-salary-balance type="decimal">0.0</opening-salary-balance>
17
+ <opening-share-or-capital-balance type="decimal">0.0</opening-share-or-capital-balance>
18
+ <role>Director</role>
19
+ </user>
20
+ <user>
21
+ <company-id type="integer">11</company-id>
22
+ <email>olly@gmail.com</email>
23
+ <first-name>Olly</first-name>
24
+ <id type="integer">11</id>
25
+ <last-logged-in-at type="datetime">2008-03-03T21:16:09Z</last-logged-in-at>
26
+ <last-name>Headey</last-name>
27
+ <opening-director-loan-account-balance type="decimal">0.0</opening-director-loan-account-balance>
28
+ <opening-expense-balance type="decimal">0.0</opening-expense-balance>
29
+ <opening-salary-balance type="decimal">0.0</opening-salary-balance>
30
+ <opening-share-or-capital-balance type="decimal">0.0</opening-share-or-capital-balance>
31
+ <role>Director</role>
32
+ </user>
33
+ </users>
@@ -0,0 +1,18 @@
1
+ HTTP/1.1 200 OK
2
+ Status: 200
3
+ Content-Type: application/xml; charset=utf-8
4
+
5
+ <?xml version="1.0" encoding="UTF-8"?>
6
+ <user>
7
+ <company-id type="integer">11</company-id>
8
+ <email>olly@gmail.com</email>
9
+ <first-name>Olly</first-name>
10
+ <id type="integer">11</id>
11
+ <last-logged-in-at type="datetime">2008-03-03T21:16:09Z</last-logged-in-at>
12
+ <last-name>Headey</last-name>
13
+ <opening-director-loan-account-balance type="decimal">0.0</opening-director-loan-account-balance>
14
+ <opening-expense-balance type="decimal">0.0</opening-expense-balance>
15
+ <opening-salary-balance type="decimal">0.0</opening-salary-balance>
16
+ <opening-share-or-capital-balance type="decimal">0.0</opening-share-or-capital-balance>
17
+ <role>Director</role>
18
+ </user>
data/test/test_helper.rb CHANGED
@@ -43,6 +43,8 @@ def fake_it_all
43
43
  '/timeslips.xml?view=2009-10-01_2009-10-10' => File.join('timeslips', 'find_all'),
44
44
  '/timeslips/84445.xml' => File.join('timeslips', 'find_single'),
45
45
  '/projects/17820/timeslips.xml' => File.join('projects', 'timeslips'),
46
+ '/company/users.xml' => File.join('users', 'find_all'),
47
+ '/company/users/11.xml' => File.join('users', 'find_single')
46
48
  }.each do |path, stub|
47
49
  FakeWeb.register_uri(:get, site_url+path, :response => stub_file(stub))
48
50
  end
@@ -54,6 +56,7 @@ def fake_it_all
54
56
  '/invoices.xml' => File.join('http', '201'),
55
57
  '/invoices/73867/invoice_items.xml' => File.join('http', '201'),
56
58
  '/timeslips.xml' => File.join('http', '201'),
59
+ '/company/users.xml' => File.join('http', '201')
57
60
  }.each do |path, stub|
58
61
  FakeWeb.register_uri(:post, site_url+path, :response => stub_file(stub))
59
62
  end
@@ -70,6 +73,7 @@ def fake_it_all
70
73
  '/invoices/73867/invoice_items/169399.xml' => File.join('http', '200'),
71
74
  '/timeslips/84445.xml' => File.join('http', '200'),
72
75
  '/timeslips/74814.xml' => File.join('http', '200'),
76
+ '/company/users/11.xml' => File.join('http', '200')
73
77
  }.each do |path, stub|
74
78
  FakeWeb.register_uri(:put, site_url+path, :response => stub_file(stub))
75
79
  end
@@ -83,6 +87,7 @@ def fake_it_all
83
87
  '/invoices/73867/invoice_items/169399.xml' => File.join('http', '200'),
84
88
  '/timeslips/84445.xml' => File.join('http', '200'),
85
89
  '/timeslips/74814.xml' => File.join('http', '200'),
90
+ '/company/users/11.xml' => File.join('http', '200')
86
91
  }.each do |path, stub|
87
92
  FakeWeb.register_uri(:delete, site_url+path, :response => stub_file(stub))
88
93
  end
data/test/user_test.rb ADDED
@@ -0,0 +1,75 @@
1
+ require 'test_helper'
2
+
3
+ class UserTest < Test::Unit::TestCase
4
+
5
+ fake_it_all
6
+
7
+ context "User class" do
8
+ should "have correct collection path" do
9
+ assert_equal '/company/users.xml', User.collection_path
10
+ end
11
+ should "have correct element path" do
12
+ assert_equal '/company/users/first.xml', User.element_path(:first)
13
+ assert_equal '/company/users/1000.xml', User.element_path(1000)
14
+ end
15
+ end
16
+
17
+ context "Users" do
18
+ setup do
19
+ @users = User.find :all
20
+ end
21
+ should "return an array" do
22
+ assert @users.is_a? Array
23
+ end
24
+ should "return Users" do
25
+ assert_equal 2, @users.size
26
+ assert @users.first.is_a? User
27
+ end
28
+ end
29
+
30
+ context "User" do
31
+ setup do
32
+ @user = User.find 11
33
+ end
34
+ should "return a User" do
35
+ assert @user.is_a? User
36
+ end
37
+ should "update and save" do
38
+ @user.email = 'olly@gmail.com'
39
+ assert @user.save
40
+ end
41
+ should "be destroyed" do
42
+ assert @user.destroy
43
+ end
44
+ end
45
+
46
+ context "Finding User" do
47
+ setup do
48
+ @user = User.find_by_email('olly@gmail.com')
49
+ end
50
+ should "return a User" do
51
+ assert @user.is_a? User
52
+ end
53
+ should "return the correct User" do
54
+ assert_equal User.find(11), @user
55
+ end
56
+ end
57
+
58
+ context "New User" do
59
+ setup do
60
+ params = {
61
+ :first_name => 'John',
62
+ :last_name => 'Doe',
63
+ :email => 'jdoe@example.com',
64
+ :role => 'Owner',
65
+ :password => 'password',
66
+ :password_confirmation => 'password'
67
+ }
68
+ @user = User.new params
69
+ end
70
+ should "validate and save" do
71
+ assert @user.save_with_validation
72
+ end
73
+ end
74
+
75
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freeagent_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Aaron Russell
@@ -9,39 +14,45 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-10-27 00:00:00 +00:00
17
+ date: 2010-05-25 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: thoughtbot-shoulda
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
23
29
  version: "0"
24
- version:
30
+ type: :development
31
+ version_requirements: *id001
25
32
  - !ruby/object:Gem::Dependency
26
33
  name: fakeweb
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - ">="
32
38
  - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
33
41
  version: "0"
34
- version:
42
+ type: :development
43
+ version_requirements: *id002
35
44
  - !ruby/object:Gem::Dependency
36
45
  name: activeresource
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
46
+ prerelease: false
47
+ requirement: &id003 !ruby/object:Gem::Requirement
40
48
  requirements:
41
49
  - - ">="
42
50
  - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
43
53
  version: "0"
44
- version:
54
+ type: :runtime
55
+ version_requirements: *id003
45
56
  description: "This is an ActiveResource Ruby wrapper for the Freeagent API. Currently supports the following API resources: Company, Contacts, Projects, Tasks, Invoices, Invoice Items, Timeslips (more will follow)."
46
57
  email: aaron@gc4.co.uk
47
58
  executables: []
@@ -84,9 +95,12 @@ files:
84
95
  - test/stubs/tasks/find_single
85
96
  - test/stubs/timeslips/find_all
86
97
  - test/stubs/timeslips/find_single
98
+ - test/stubs/users/find_all
99
+ - test/stubs/users/find_single
87
100
  - test/task_test.rb
88
101
  - test/test_helper.rb
89
102
  - test/timeslip_test.rb
103
+ - test/user_test.rb
90
104
  has_rdoc: true
91
105
  homepage: http://github.com/aaronrussell/freeagent_api
92
106
  licenses: []
@@ -100,18 +114,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
102
116
  - !ruby/object:Gem::Version
117
+ segments:
118
+ - 0
103
119
  version: "0"
104
- version:
105
120
  required_rubygems_version: !ruby/object:Gem::Requirement
106
121
  requirements:
107
122
  - - ">="
108
123
  - !ruby/object:Gem::Version
124
+ segments:
125
+ - 0
109
126
  version: "0"
110
- version:
111
127
  requirements: []
112
128
 
113
129
  rubyforge_project:
114
- rubygems_version: 1.3.5
130
+ rubygems_version: 1.3.6
115
131
  signing_key:
116
132
  specification_version: 3
117
133
  summary: ActiveResource Ruby wrapper for the Freeagent Central API.
@@ -125,3 +141,4 @@ test_files:
125
141
  - test/task_test.rb
126
142
  - test/test_helper.rb
127
143
  - test/timeslip_test.rb
144
+ - test/user_test.rb