Permalink
Browse files

Started working on getting Avalara library for ruby

  • Loading branch information...
1 parent 35c4349 commit facb5d5c8441af7dc9dd99347e22ab0d2a067c16 @adamfortuna adamfortuna committed Feb 1, 2012
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm use 1.9.2-p290@avalara
View
@@ -0,0 +1 @@
+0.0.1 - January 31, 2011 - Rough draft of working
View
@@ -0,0 +1,6 @@
+source 'http://rubygems.org'
+gemspec
+
+group :development, :test do
+ gem 'rake'
+end
View
@@ -0,0 +1,49 @@
+PATH
+ remote: .
+ specs:
+ Avalara (0.0.1)
+ hashie
+ httparty
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activesupport (3.2.1)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ addressable (2.2.6)
+ crack (0.3.1)
+ diff-lcs (1.1.3)
+ factory_girl (2.5.0)
+ activesupport
+ hashie (1.2.0)
+ httparty (0.8.1)
+ multi_json
+ multi_xml
+ i18n (0.6.0)
+ multi_json (1.0.4)
+ multi_xml (0.4.1)
+ rake (0.9.2.2)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ vcr (1.11.3)
+ webmock (1.7.10)
+ addressable (~> 2.2, > 2.2.5)
+ crack (>= 0.1.7)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ Avalara!
+ factory_girl
+ rake
+ rspec
+ vcr
+ webmock
View
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Adam Fortuna
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
5 README
@@ -0,0 +1,5 @@
+Avalara
+=====
+
+This API provides access to the [Avalara](http://www.avalara.com/) AvaTax API.
+
View
@@ -0,0 +1,31 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path('../lib', __FILE__)
+require 'avalara/version'
+
+Gem::Specification.new do |s|
+ s.name = 'Avalara'
+ s.version = Avalara::VERSION
+ s.authors = ['Adam Fortuna']
+ s.email = ['adam@envylabs.com']
+ s.homepage = 'https://github.com/adamfortuna/avalara'
+ s.summary = %q{A Ruby interface to the Avalara Tax API}
+ s.description = %q{This library provides Ruby calls to interact with the Avalara Tax API}
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ['lib']
+
+ s.add_dependency 'hashie'
+ s.add_dependency 'httparty'
+ # s.add_dependency 'multi_json', '~> 1.0'
+
+ s.add_development_dependency 'vcr'
+ s.add_development_dependency 'webmock'
+ s.add_development_dependency 'rspec'
+ s.add_development_dependency 'factory_girl'
+ # s.add_development_dependency 'infinity_test'
+ # s.add_development_dependency 'factory_girl', '~> 2.0'
+ # s.add_development_dependency 'rack', '~> 1.2'
+ # s.add_development_dependency 'watchr'
+end
View
@@ -0,0 +1,95 @@
+# encoding: UTF-8
+
+require 'avalara/version'
+require 'avalara/errors'
+require 'avalara/configuration'
+
+require 'avalara/address'
+require 'avalara/line'
+require 'avalara/detail_level'
+require 'avalara/get_tax_request'
+
+require 'httparty'
+
+module Avalara
+
+ def self.configuration
+ @@_configuration ||= Avalara::Configuration.new
+ yield @@_configuration if block_given?
+ @@_configuration
+ end
+
+ def self.configuration=(configuration)
+ raise ArgumentError, 'Expected a Avalara::Configuration instance' unless configuration.kind_of?(Configuration)
+ @@_configuration = configuration
+ end
+
+ def self.configure(&block)
+ configuration(&block)
+ end
+
+ def self.endpoint
+ configuration.endpoint
+ end
+ def self.endpoint=(endpoint)
+ configuration.endpoint = endpoint
+ end
+
+ def self.username
+ configuration.username
+ end
+ def self.username=(username)
+ configuration.username = username
+ end
+
+ def self.password
+ configuration.password
+ end
+ def self.password=(password)
+ configuration.password = password
+ end
+
+ def self.version
+ configuration.version
+ end
+ def self.version=(version)
+ configuration.version = version
+ end
+
+ # https://rest.avalara.net/1.0/tax/get
+ # Request Body
+ # {
+ # "DocDate": "2011-05-11",
+ # "CustomerCode": "CUST1",
+ # "Addresses":
+ # [
+ # {
+ # "AddressCode": "1",
+ # }
+ def self.get_tax(get_tax_request)
+ uri = "#{configuration.endpoint}/#{configuration.version}/tax/get"
+ response = ::HTTParty.post(uri, {
+ :query => get_tax_request,
+ :headers => request_headers(get_tax_request.to_s.length.to_s),
+ :basic_auth => authentication
+ })
+ rescue Timeout::Error
+ puts "Timed out"
+ raise TimeoutError
+ end
+
+ private
+
+ def self.request_headers(length)
+ { 'Accept' => 'application/json', 'User-Agent' => user_agent_string, "Content-Type" => 'text/json', "Content-Length" => length }
+ end
+
+ def self.authentication
+ { :username => configuration.username, :password => configuration.password }
+ end
+
+ def self.user_agent_string
+ "avalara/#{Avalara::VERSION} (Rubygems; Ruby #{RUBY_VERSION} #{RUBY_PLATFORM})"
+ end
+
+end
View
@@ -0,0 +1,19 @@
+# encoding: UTF-8
+require 'hashie/trash'
+
+module Avalara
+ class Address < ::Hashie::Trash
+
+ property :AddressCode, :from => :address_code, :required => true
+ property :Line1, :from => :line_1
+ property :Line2, :from => :line_2
+ property :Line3, :from => :line_3
+ property :City, :from => :city
+ property :Region, :from => :region
+ property :Country, :from => :country
+ property :PostalCode, :from => :postal_code
+ property :Latitude, :from => :latitude
+ property :Longitude, :from => :longitude
+ property :TaxRegionId, :from => :tax_region_id
+ end
+end
@@ -0,0 +1,29 @@
+# encoding: UTF-8
+
+class Avalara::Configuration
+
+ attr_writer :endpoint
+ attr_accessor :password
+ attr_accessor :username
+ attr_writer :version
+
+ ##
+ # Public: Get the API endpoint used by the configuration. Unless explicitly
+ # set, the endpoint will default to the official production endpoint at
+ # 'https://avatax.avalara.net'.
+ #
+ # Returns the String for the API endpoint.
+ #
+ def endpoint
+ @endpoint ||= 'https://rest.avalara.net'
+ end
+
+ ##
+ # Public: Get the API version. Defaults to 1.0.
+ #
+ # Returns the String for the API version.
+ #
+ def version
+ @version ||= '1.0'
+ end
+end
@@ -0,0 +1,13 @@
+# encoding: UTF-8
+require 'hashie/trash'
+
+module Avalara
+ class DetailLevel < ::Hashie::Trash
+
+ property :Line, :from => :line
+ property :Summary, :from => :summary
+ property :Document, :from => :document
+ property :Tax, :from => :tax
+ property :Diagnostic, :from => :diagnostic
+ end
+end
View
@@ -0,0 +1,7 @@
+# encoding: UTF-8
+
+module Avalara
+ Error = Class.new(StandardError)
+ InvalidObjectError = Class.new(Error)
+ TimeoutError = Class.new(Error)
+end
@@ -0,0 +1,23 @@
+# encoding: UTF-8
+require 'hashie/trash'
+
+module Avalara
+ class GetTaxRequest < ::Hashie::Trash
+
+ property :CustomerCode, :from => :customer_code
+ property :DocDate, :from => :doc_date
+ property :CompanyCode, :from => :company_code
+ property :Commit, :from => :commit
+ property :CustomerUsageType, :from => :customer_usage_type
+ property :Discount, :from => :discount
+ property :DocCode, :from => :doc_code
+ property :PurchaseOrderNo, :from => :purchase_order_no
+ property :ExemptionNo, :from => :exemption_no
+ property :DetailLevel, :from => :detail_level
+ property :DocType, :from => :doc_type
+ property :PaymentDate, :from => :payment_date
+ property :Lines, :from => :lines
+ property :Addresses, :from => :addresses
+ property :ReferenceCode, :from => :reference_code
+ end
+end
View
@@ -0,0 +1,21 @@
+# encoding: UTF-8
+require 'hashie/trash'
+
+module Avalara
+ class Line < ::Hashie::Trash
+
+ property :LineNo, :from => :line_no, :required => true
+ property :DestinationCode, :from => :destination_code, :required => true
+ property :OriginCode, :from => :origin_code, :required => true
+ property :ItemCode, :from => :item_code
+ property :TaxCode, :from => :tax_code
+ property :CustomerUsageType, :from => :customer_usage_type
+ property :Description, :from => :description
+ property :Qty, :from => :qty, :required => true
+ property :Amount, :from => :amount, :required => true
+ property :Discounted, :from => :discounted
+ property :TaxIncluded, :from => :tax_included
+ property :Ref1, :from => :ref_1
+ property :Ref2, :from => :ref_2
+ end
+end
View
@@ -0,0 +1,7 @@
+# encoding: UTF-8
+
+module Avalara
+ class Request
+
+ end
+end
View
@@ -0,0 +1,5 @@
+# encoding: UTF-8
+
+module Avalara
+ VERSION = '0.0.1'
+end
View
@@ -0,0 +1,2 @@
+username: 'testaccount'
+password: 'testkey'
@@ -0,0 +1,13 @@
+Factory.define :address, :class => Avalara::Address do |c|
+ c.address_code "address_code"
+ c.line_1 "line_1"
+ c.line_2 "line_2"
+ c.line_3 "line_3"
+ c.city "city"
+ c.region "region"
+ c.country "country"
+ c.postal_code "postal_code"
+ c.latitude "latitude"
+ c.longitude "longitude"
+ c.tax_region_id "tax_region_id"
+end
@@ -0,0 +1,7 @@
+Factory.define :detail_level, :class => Avalara::DetailLevel do |c|
+ c.line "line"
+ c.summary "summary"
+ c.document "document"
+ c.tax "tax"
+ c.diagnostic "diagnostic"
+end
Oops, something went wrong.

0 comments on commit facb5d5

Please sign in to comment.