freeagent 0.1.0

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.
Files changed (47) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +1 -0
  3. data/CHANGELOG.rdoc +6 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +50 -0
  6. data/LICENSE +22 -0
  7. data/README.rdoc +27 -0
  8. data/Rakefile +28 -0
  9. data/freeagent.gemspec +27 -0
  10. data/lib/free_agent.rb +64 -0
  11. data/lib/free_agent/attachment.rb +21 -0
  12. data/lib/free_agent/bank_account.rb +7 -0
  13. data/lib/free_agent/base.rb +6 -0
  14. data/lib/free_agent/bill.rb +15 -0
  15. data/lib/free_agent/contact.rb +7 -0
  16. data/lib/free_agent/invoice.rb +7 -0
  17. data/lib/free_agent/invoice_item.rb +10 -0
  18. data/lib/free_agent/project.rb +7 -0
  19. data/lib/free_agent/version.rb +16 -0
  20. data/lib/freeagent.rb +1 -0
  21. data/spec/fixtures/attachments/all.xml +23 -0
  22. data/spec/fixtures/attachments/single.xml +11 -0
  23. data/spec/fixtures/bank_accounts/all.xml +35 -0
  24. data/spec/fixtures/bank_accounts/single.xml +15 -0
  25. data/spec/fixtures/bills/all.xml +37 -0
  26. data/spec/fixtures/bills/single.xml +18 -0
  27. data/spec/fixtures/contacts/all.xml +47 -0
  28. data/spec/fixtures/contacts/single.xml +23 -0
  29. data/spec/fixtures/invoice_items/all.xml +15 -0
  30. data/spec/fixtures/invoice_items/single.xml +13 -0
  31. data/spec/fixtures/invoices/all.xml +75 -0
  32. data/spec/fixtures/invoices/single.xml +37 -0
  33. data/spec/fixtures/projects/all.xml +25 -0
  34. data/spec/fixtures/projects/single.xml +23 -0
  35. data/spec/spec_helper.rb +33 -0
  36. data/spec/support/helper.rb +18 -0
  37. data/spec/support/mimic.rb +47 -0
  38. data/spec/unit/attachment_spec.rb +56 -0
  39. data/spec/unit/bank_account_spec.rb +56 -0
  40. data/spec/unit/base_spec.rb +9 -0
  41. data/spec/unit/bill_spec.rb +66 -0
  42. data/spec/unit/contact_spec.rb +56 -0
  43. data/spec/unit/freeagent_spec.rb +54 -0
  44. data/spec/unit/invoice_item_spec.rb +77 -0
  45. data/spec/unit/invoice_spec.rb +56 -0
  46. data/spec/unit/project_spec.rb +56 -0
  47. metadata +169 -0
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ # https://github.com/weppos/gitignore/blob/weppos/Ruby.gitignore
2
+
3
+ coverage
4
+ rdoc
5
+ tmp
6
+
7
+ # Bundler
8
+ .bundle
9
+ pkg
10
+
11
+ # Rubinius
12
+ *.rbc
13
+
14
+ # YARD artifacts
15
+ .yardoc
16
+ _yardoc
17
+ doc/
18
+
19
+ utils/whois-utf8.rb
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/CHANGELOG.rdoc ADDED
@@ -0,0 +1,6 @@
1
+ = Changelog
2
+
3
+
4
+ == Release 0.1.0
5
+
6
+ * Initial version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in freeagent.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ freeagent (0.1.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ activemodel (3.0.6)
10
+ activesupport (= 3.0.6)
11
+ builder (~> 2.1.2)
12
+ i18n (~> 0.5.0)
13
+ activeresource (3.0.6)
14
+ activemodel (= 3.0.6)
15
+ activesupport (= 3.0.6)
16
+ activesupport (3.0.6)
17
+ builder (2.1.2)
18
+ diff-lcs (1.1.2)
19
+ i18n (0.5.0)
20
+ json (1.5.1)
21
+ mimic (0.4.1)
22
+ json
23
+ plist
24
+ rack
25
+ sinatra
26
+ plist (3.1.0)
27
+ rack (1.2.2)
28
+ rspec (2.5.0)
29
+ rspec-core (~> 2.5.0)
30
+ rspec-expectations (~> 2.5.0)
31
+ rspec-mocks (~> 2.5.0)
32
+ rspec-core (2.5.1)
33
+ rspec-expectations (2.5.0)
34
+ diff-lcs (~> 1.1.2)
35
+ rspec-mocks (2.5.0)
36
+ sinatra (1.2.1)
37
+ rack (~> 1.1)
38
+ tilt (< 2.0, >= 1.2.2)
39
+ tilt (1.2.2)
40
+ yard (0.6.7)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ activeresource (>= 3.0.0)
47
+ freeagent!
48
+ mimic
49
+ rspec (~> 2.5.0)
50
+ yard
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2011 Simone Carletti <weppos@weppos.net>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,27 @@
1
+ = FreeAgent Client
2
+
3
+ (Unofficial) Ruby client for the {FreeAgent Central API}[http://www.freeagentcentral.com/developers/freeagent-api].
4
+
5
+
6
+ == Requirements
7
+
8
+ * Ruby >= 1.8.7
9
+ * ActiveResource 3.0.x
10
+
11
+
12
+ == Installation
13
+
14
+ $ gem install freeagent
15
+
16
+
17
+ == Author
18
+
19
+ * {Simone Carletti}[http://www.simonecarletti.com] <weppos@weppos.net>
20
+
21
+
22
+ == License
23
+
24
+ FreeAgent (the Client) is Copyright (c) 2011 Simone Carletti.
25
+ This is Free Software distributed under the MIT license.
26
+
27
+ FreeAgent Online Accounting Software is Copyright (c) by FreeAgent Central.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ require 'rspec/core/rake_task'
4
+ require 'yard'
5
+ require 'yard/rake/yardoc_task'
6
+
7
+
8
+ # Run test by default.
9
+ task :default => :rspec
10
+ task :test => :rspec
11
+
12
+
13
+ Bundler::GemHelper.install_tasks
14
+
15
+
16
+ # Run all the specs in the /spec folder
17
+ RSpec::Core::RakeTask.new(:rspec)
18
+
19
+
20
+ YARD::Rake::YardocTask.new(:yardoc) do |y|
21
+ y.options = ["--output-dir", "yardoc"]
22
+ end
23
+
24
+
25
+ desc "Open an irb session preloaded with this library"
26
+ task :console do
27
+ sh "irb -rubygems -I lib -r freeagent.rb"
28
+ end
data/freeagent.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "free_agent/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "freeagent"
7
+ s.version = FreeAgent::VERSION
8
+ s.summary = ""
9
+ s.description = ""
10
+
11
+ s.platform = Gem::Platform::RUBY
12
+ s.required_ruby_version = ">= 1.8.7"
13
+
14
+ s.authors = ["Simone Carletti"]
15
+ s.email = ["weppos@weppos.net"]
16
+ s.homepage = ""
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_development_dependency("rspec", "~> 2.5.0")
24
+ s.add_development_dependency("yard")
25
+ s.add_development_dependency("activeresource", ">= 3.0.0")
26
+ s.add_development_dependency("mimic")
27
+ end
data/lib/free_agent.rb ADDED
@@ -0,0 +1,64 @@
1
+ require 'active_resource'
2
+ require 'free_agent/version'
3
+ require 'free_agent/base'
4
+
5
+ module FreeAgent
6
+
7
+ BASE_URI = "https://%s.freeagentcentral.com"
8
+
9
+ autoload :Attachment, 'free_agent/attachment'
10
+ autoload :BankAccount, 'free_agent/bank_account'
11
+ autoload :Bill, 'free_agent/bill'
12
+ autoload :Contact, 'free_agent/contact'
13
+ autoload :Invoice, 'free_agent/invoice'
14
+ autoload :InvoiceItem, 'free_agent/invoice_item'
15
+ autoload :Project, 'free_agent/project'
16
+
17
+
18
+ class << self
19
+
20
+ # Checks if the client is properly configured.
21
+ #
22
+ # @return [Boolean]
23
+ def configured?
24
+ Base.user && Base.password && Base.site
25
+ end
26
+
27
+ # Sets the client configuration.
28
+ #
29
+ # @return [void]
30
+ #
31
+ # @yield [self]
32
+ #
33
+ # @example
34
+ # FreeAgent.configure do |config|
35
+ # config.username = "email@example.com"
36
+ # config.password = "letmein"
37
+ # config.subdomain = "example"
38
+ # end
39
+ #
40
+ def configure
41
+ if block_given?
42
+ yield self
43
+ else
44
+ raise LocalJumpError, "Required configuration block"
45
+ # TODO: allow users to pass configuration using an environment variable
46
+ end
47
+ end
48
+
49
+
50
+ def username=(value)
51
+ Base.user = value
52
+ end
53
+
54
+ def password=(value)
55
+ Base.password = value
56
+ end
57
+
58
+ def subdomain=(value)
59
+ Base.site = value.blank? ? nil : (BASE_URI % value)
60
+ end
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,21 @@
1
+ module FreeAgent
2
+
3
+ # Represents an Attachment in FreeAgent.
4
+ #
5
+ # == Attachment URL
6
+ #
7
+ # FreeAgent stores attachments on Amazon S3. The real attachment URL
8
+ # is stored in the {Attachment#location} attribute.
9
+ #
10
+ # a = FreeAgent::Attachment.first
11
+ # a.location
12
+ # # => "https://s3.amazonaws.com/freeagent-prod/attachments/165002/original.pdf"
13
+ #
14
+ # Attachments stored on Amazon S3 are private. For this reason,
15
+ # the location returned by FreeAgent contains an amazon AWSAccessKeyId and Signature
16
+ # that allows you to access the content for a limited set of time.
17
+ #
18
+ class Attachment < Base
19
+ end
20
+
21
+ end
@@ -0,0 +1,7 @@
1
+ module FreeAgent
2
+
3
+ # Represents a Bank Account in FreeAgent.
4
+ class BankAccount < Base
5
+ end
6
+
7
+ end
@@ -0,0 +1,6 @@
1
+ module FreeAgent
2
+
3
+ class Base < ActiveResource::Base
4
+ end
5
+
6
+ end
@@ -0,0 +1,15 @@
1
+ module FreeAgent
2
+
3
+ # Represents a Bill in FreeAgent.
4
+ class Bill < Base
5
+
6
+ # TODO
7
+ # This resource requires a period parameter which is used
8
+ # to specify the date range of the bills to retrieve.
9
+ # The format of this parameter is yyyy-mm-dd_yyyy-mm-dd
10
+ # where the first date is the 'from' date
11
+ # and the second date is the 'to' date.
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,7 @@
1
+ module FreeAgent
2
+
3
+ # Represents a Contact in FreeAgent.
4
+ class Contact < Base
5
+ end
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ module FreeAgent
2
+
3
+ # Represents an Invoice in FreeAgent.
4
+ class Invoice < Base
5
+ end
6
+
7
+ end
@@ -0,0 +1,10 @@
1
+ module FreeAgent
2
+
3
+ # Represents an Invoice Item in FreeAgent.
4
+ class InvoiceItem < Base
5
+
6
+ self.prefix = '/invoices/:invoice_id/'
7
+
8
+ end
9
+
10
+ end
@@ -0,0 +1,7 @@
1
+ module FreeAgent
2
+
3
+ # Represents a Project in FreeAgent.
4
+ class Project < Base
5
+ end
6
+
7
+ end
@@ -0,0 +1,16 @@
1
+ module FreeAgent
2
+
3
+ # Holds information about library version.
4
+ module Version
5
+ MAJOR = 0
6
+ MINOR = 1
7
+ PATCH = 0
8
+ BUILD = nil
9
+
10
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join(".")
11
+ end
12
+
13
+ # The current library version.
14
+ VERSION = Version::STRING
15
+
16
+ end
data/lib/freeagent.rb ADDED
@@ -0,0 +1 @@
1
+ require 'free_agent'
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <attachments type="array">
3
+ <attachment location="https://s3.amazonaws.com/freeagent-prod/attachments/165002/original.pdf?AWSAccessKeyId=00000000000000000000&amp;Expires=1302622321&amp;Signature=008SugGf4dWD05ZPaZHSt6R%2BCPA%3D">
4
+ <id type="integer">165002</id>
5
+ <content-type>application/pdf</content-type>
6
+ <file-name>Invoice-USD100_20100104.pdf</file-name>
7
+ <file-size type="integer">9214</file-size>
8
+ <description>Invoice</description>
9
+ <attachable-id type="integer">157514</attachable-id>
10
+ <attachable-type>Bill</attachable-type>
11
+ <processing>false</processing>
12
+ </attachment>
13
+ <attachment location="https://s3.amazonaws.com/freeagent-prod/attachments/165006/original.pdf?AWSAccessKeyId=00000000000000000000&amp;Expires=1302622321&amp;Signature=00CY0P6sRBhHE4G854lK1seR0Lg%3D">
14
+ <id type="integer">165006</id>
15
+ <content-type>application/pdf</content-type>
16
+ <file-name>Invoice-USD122_20110401.pdf</file-name>
17
+ <file-size type="integer">33653</file-size>
18
+ <description>Invoice</description>
19
+ <attachable-id type="integer">157528</attachable-id>
20
+ <attachable-type>Bill</attachable-type>
21
+ <processing>false</processing>
22
+ </attachment>
23
+ </attachments>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <attachment location="https://s3.amazonaws.com/freeagent-prod/attachments/165002/original.pdf?AWSAccessKeyId=00000000000000000000&amp;Expires=1302622321&amp;Signature=008SugGf4dWD05ZPaZHSt6R%2BCPA%3D">
3
+ <id type="integer">165002</id>
4
+ <content-type>application/pdf</content-type>
5
+ <file-name>Invoice-USD100_20100104.pdf</file-name>
6
+ <file-size type="integer">9214</file-size>
7
+ <description>Invoice</description>
8
+ <attachable-id type="integer">157514</attachable-id>
9
+ <attachable-type>Bill</attachable-type>
10
+ <processing>false</processing>
11
+ </attachment>
@@ -0,0 +1,35 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <records type="array">
3
+ <bank-account>
4
+ <id type="integer">85327</id>
5
+ <type>StandardBankAccount</type>
6
+ <name>Business Checking Account</name>
7
+ <account-number>00000000</account-number>
8
+ <sort-code>00000000</sort-code>
9
+ <secondary-sort-code></secondary-sort-code>
10
+ <iban></iban>
11
+ <bic></bic>
12
+ <current-balance type="decimal">5571.18</current-balance>
13
+ <current-balance-date type="datetime">2011-04-04</current-balance-date>
14
+ <opening-balance type="decimal">4733.42</opening-balance>
15
+ <is-personal>false</is-personal>
16
+ </bank-account>
17
+ <bank-account>
18
+ <id type="integer">85563</id>
19
+ <type>CreditCardAccount</type>
20
+ <name>Credit</name>
21
+ <account-number>XXXX-XXXX-0000-0000</account-number>
22
+ <current-balance type="decimal">1000.0</current-balance>
23
+ <current-balance-date type="datetime">2011-04-12</current-balance-date>
24
+ <opening-balance type="decimal">1000.0</opening-balance>
25
+ </bank-account>
26
+ <bank-account>
27
+ <id type="integer">85564</id>
28
+ <type>PaypalAccount</type>
29
+ <name>Example</name>
30
+ <email>email@example.com</email>
31
+ <current-balance type="decimal">1000.0</current-balance>
32
+ <current-balance-date type="datetime">2011-04-12</current-balance-date>
33
+ <opening-balance type="decimal">1000.0</opening-balance>
34
+ </bank-account>
35
+ </records>