simpletax 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3d20b5583d0667d6db5379323b4576c33d6183e
4
+ data.tar.gz: a483a20220469e8fee49248725dfd39aa91ad080
5
+ SHA512:
6
+ metadata.gz: 8ed09d3356b30257dab94392fe0fed0c1420cfc086a9d0db0479340c8bd2962a0cf2448ba4340e5cd913c5ba894239952086852a68a06d4cc3b65c769b62972f
7
+ data.tar.gz: 95223e578d503a2e1503dea4f33bcaef04439d98b87c612a6c0c6e46a2710ee8af567c372ad723969a69bd3a309cae14c6f1523555ee3ae78f9420b8bcb9d4d1
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simpletax.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ismael Abreu
2
+
3
+ MIT License
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.
@@ -0,0 +1,47 @@
1
+ # Ruby gem for SimpleTax API
2
+
3
+ SimpleTax (http://gosimpletax.com) is the free, web-based tax software that helps you easily find the most savings and ensures you file an accurate tax return, no matter how complicated your affairs are.
4
+
5
+ This Ruby library allows you to integrate your application with SimpleTax via it's REST API. It relies on OAuth2 for authorising access to a user's account.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'simpletax'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install simpletax
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'simpletax'
26
+
27
+ simpletax = SimpleTax::Client.new redirect_url: 'YOUR_CALLBACK_URL', client_id: 'CLIENT_ID', client_secret: 'CLIENT_SECRET'
28
+ simpletax.authorize_url
29
+ # => "https://secure.gosimpletax.com/o/authorize/?client_id=CLIENT_ID&redirect_uri=YOUR_CALLBACK_URL&response_type=code"
30
+
31
+ # Authorize it in the browser with the given url
32
+
33
+ simpletax.fetch_token 'CODE_GOTTEN_FROM_THE_CALLBACK_URL'
34
+
35
+ simpletax.add_income(2500, description: 'Customer invoice')
36
+ simpletax.add_expense(200, description: 'Photoshop license')
37
+
38
+ # Now check the result on your SimpleTax account'
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( http://github.com/ismaelga/simpletax/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ require 'irb'
5
+ require 'irb/completion'
6
+ require 'simpletax'
7
+ ARGV.clear
8
+ IRB.start
9
+ end
@@ -0,0 +1,102 @@
1
+ require "simpletax/version"
2
+ require 'oauth2'
3
+
4
+ module SimpleTax
5
+ BASE_API = 'https://secure.gosimpletax.com/api/v2/uk'.freeze
6
+ OAUTH_AUTHZ_URL = 'https://secure.gosimpletax.com/o/authorize/'.freeze
7
+ OAUTH_TOKEN_URL = 'https://secure.gosimpletax.com/o/token/'.freeze
8
+
9
+ class Error < Exception
10
+ def initialize status
11
+ super "ServerError #{status}"
12
+ end
13
+ end
14
+
15
+ class ServerError < Exception; end
16
+ class NoAccessError < Exception; end
17
+
18
+ class Client
19
+ attr_reader :redirect_url, :token, :api_endpoint
20
+
21
+ def initialize(options={})
22
+ @api_endpoint = options[:site] || BASE_API
23
+ @redirect_url = options[:redirect_url] || raise("Redirect URL needed")
24
+ client_id = options[:client_id] || raise("client_id needed")
25
+ client_secret = options[:client_secret] || raise("client_secret needed")
26
+ @client = OAuth2::Client.new(
27
+ client_id,
28
+ client_secret,
29
+ site: api_endpoint,
30
+ authorize_url: OAUTH_AUTHZ_URL,
31
+ token_url: OAUTH_TOKEN_URL
32
+ )
33
+ end
34
+
35
+ def authorize_url
36
+ @client.auth_code.authorize_url(redirect_uri: redirect_url)
37
+ end
38
+
39
+ def fetch_token(code)
40
+ @token = @client.auth_code.get_token(code, redirect_uri: redirect_url)
41
+ end
42
+
43
+ def add_income(amount, optionals={})
44
+ requires_token!
45
+ description = optionals[:description] || ''
46
+ date = optionals[:date] || today
47
+ date = format_date(date)
48
+
49
+ data = json_body value: amount, date: date, reference: description
50
+ parse_response token.post(url('/incomes'), body: data)
51
+ end
52
+
53
+ def add_expense(amount, optionals={})
54
+ requires_token!
55
+ description = optionals[:description] || ''
56
+ date = optionals[:date] || today
57
+ date = format_date(date)
58
+
59
+ data = json_body value: amount, date: date, reference: description
60
+ parse_response token.post(url('/expenses'), body: data)
61
+ end
62
+
63
+ private
64
+
65
+ def json_body params
66
+ MultiJson.dump fields: params
67
+ end
68
+
69
+ def url(path)
70
+ "#{api_endpoint}#{path}"
71
+ end
72
+
73
+ def requires_token!
74
+ raise 'Token needed' unless @token
75
+ end
76
+
77
+ def format_date(date)
78
+ date.to_date.strftime('%d/%m/%Y')
79
+ end
80
+
81
+ def today
82
+ Date.today
83
+ end
84
+
85
+ def parse_response resp
86
+ if resp.status >= 400
87
+ parse_error resp
88
+ else
89
+ resp.parsed
90
+ end
91
+ end
92
+
93
+ def parse_error resp
94
+ status = resp.status
95
+ if status >= 500
96
+ raise ServerError.new status
97
+ else
98
+ raise NoAccessError.new status
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,3 @@
1
+ module Simpletax
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simpletax/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simpletax"
8
+ spec.version = Simpletax::VERSION
9
+ spec.authors = ["Ismael Abreu"]
10
+ spec.email = ["ismaelga@gmail.com"]
11
+ spec.summary = %q{Ruby API client to gosimpletax.com}
12
+ spec.description = %q{Ruby API client to gosimpletax.com}
13
+ spec.homepage = "http://github.com/ismaelga/simpletax"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "multi_json"
22
+ spec.add_dependency "oauth2"
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simpletax
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ismael Abreu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Ruby API client to gosimpletax.com
70
+ email:
71
+ - ismaelga@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/simpletax.rb
82
+ - lib/simpletax/version.rb
83
+ - simpletax.gemspec
84
+ homepage: http://github.com/ismaelga/simpletax
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.2.2
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Ruby API client to gosimpletax.com
108
+ test_files: []