tallyable 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License
2
+ ===============
3
+
4
+ Copyright (c) 2014 Supreeth Burji
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ ## Tallyable
2
+
3
+ * Basic Tally ERP.9 integration using xml api
4
+ * The motivation is to provide a "Get Started" framework for Tally integration. This has to be essentially extended as per custom requirements.
5
+ * This requires Tally ERP.9 to be running with the Company selected from the Tally interface
6
+ * To be used as a guide to develope integration capabilities for your rails application with Tally ERP.9
7
+ * Authentication is interestingly kept open with default configuration, for the xml interface
8
+ * This is because Authentication is not yet configurable in Tally ERP.9 remote user using xml api interface
9
+ * Allows only Tally .NET user's Application login for now
10
+ * TDL (Tally Domain Language) was found to be the most relevant and easy to use for integration purposes
11
+ * Refer test cases for usage
12
+ * To run test cases use `rake test`
13
+ * Disclaimer
14
+ * Author does not endorse TALLY, nor has any links with TALLY trademark or brand
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'tallyable'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install tallyable
29
+
30
+ ## Usage
31
+
32
+ require 'tallyable'
33
+
34
+ class Employee
35
+ acts_as_tallyable "http://example.com", 9002 # Tally host and port options
36
+
37
+ self.class.employee_request
38
+ end
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Tallyable'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
25
+ require 'rake/testtask'
26
+
27
+ Rake::TestTask.new(:test) do |t|
28
+ t.libs << 'lib'
29
+ t.libs << 'test'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = false
32
+ end
33
+
34
+ task :default => :test
data/lib/tallyable.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'tallyable/acts_as_tallyable'
2
+
3
+ module Tallyable
4
+ end
@@ -0,0 +1,82 @@
1
+ require 'net/http'
2
+ require 'nokogiri'
3
+
4
+ module Tallyable
5
+ module ActsAsTallyable
6
+ def self.included(base)
7
+ base.extend ClassMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def acts_as_tallyable(host, port = 9002, options = {})
12
+ @@host = host
13
+ @@port = port
14
+ end
15
+
16
+ def employee_request
17
+ result = tally_request("#{ File.dirname(__FILE__) }/employee_request.xml")
18
+ employees = []
19
+
20
+ unless result.is_a? String
21
+ xml = Nokogiri.XML(result.body)
22
+ xml.xpath("ENVELOPE").each do |nodes|
23
+ params = {}
24
+ nodes.children.each do |node|
25
+ params[:name] = node.text if node.name == "EMPPROFILENAME"
26
+ %w[EMPPROFILEEMAILID
27
+ EMPPROFILEGENDER
28
+ EMPPROFILEDATEOFBIRTH
29
+ EMPPROFILECONTACTNUMBER
30
+ EMPPROFILEEMPLOYEEADDRESS].each do |tag|
31
+ if node.at(tag)
32
+ case node.at(tag).name
33
+ when "EMPPROFILEEMAILID"
34
+ params[:email] = node.at(tag).text
35
+ when "EMPPROFILEGENDER"
36
+ params[:gender] = node.at(tag).text
37
+ when "EMPPROFILEDATEOFBIRTH"
38
+ params[:date_of_birth] = node.at(tag).text
39
+ when "EMPPROFILECONTACTNUMBER"
40
+ params[:phone] = node.at(tag).text
41
+ when "EMPPROFILEEMPLOYEEADDRESS"
42
+ params[:address] = node.at(tag).text
43
+ end
44
+ end
45
+ end
46
+
47
+ # hack to find a record delimiter, hierarchical tags are better
48
+ if node.name == "EMPPROFILESNO" and !params.empty?
49
+ employees << params
50
+ params = {}
51
+ end
52
+ end
53
+ employees << params
54
+ end
55
+ end
56
+
57
+ employees
58
+ end
59
+
60
+ private
61
+ # helper method for "POST" ing XML request to Tally
62
+ def tally_request(tdl_file)
63
+ uri = URI.parse("#{ @@host }:#{ @@port }")
64
+ http_handler = Net::HTTP.new(uri.host, uri.port)
65
+
66
+ request_handler = Net::HTTP::Post.new(uri.to_s)
67
+ begin
68
+ request_handler.body = File.read(tdl_file)
69
+ http_handler.request(request_handler)
70
+ rescue Exception => e
71
+ "#{e.message}"
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ if defined?(ActiveRecord::Base)
79
+ ActiveRecord::Base.send(:include, Tallyable::ActsAsTallyable)
80
+ else
81
+ include Tallyable::ActsAsTallyable
82
+ end
@@ -0,0 +1,16 @@
1
+ <ENVELOPE>
2
+ <HEADER>
3
+ <VERSION>1</VERSION>
4
+ <TALLYREQUEST>Export</TALLYREQUEST>
5
+ <TYPE>Data</TYPE>
6
+ <ID>All Employee Profile</ID>
7
+ </HEADER>
8
+ <BODY>
9
+ <DESC>
10
+ <STATICVARIABLES>
11
+ <EXPLODEFLAG>Yes</EXPLODEFLAG>
12
+ <SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT>
13
+ </STATICVARIABLES>
14
+ </DESC>
15
+ </BODY>
16
+ </ENVELOPE>
@@ -0,0 +1,3 @@
1
+ module Tallyable
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+ require 'employee'
3
+
4
+ class ActsAsTallyableTest < Minitest::Test
5
+ def employee_stub(stub_response)
6
+ stub_request(:post, "http://example.com:9002").
7
+ with( body: File.read("lib/tallyable/employee_request.xml") ).
8
+ to_return(stub_response)
9
+ end
10
+
11
+ def test_an_employee_tallyable_for_invalid_request
12
+ employee_stub(status: 500, body: "Internal Server Error", headers: {})
13
+
14
+ result = Employee.employee_request
15
+ assert_equal result, []
16
+ end
17
+
18
+ def test_an_employee_tallyable_on_a_valid_request
19
+ employee_stub(status: 200,
20
+ body: File.read("test/fixtures/employee_response.xml"), headers: {})
21
+
22
+ result = Employee.employee_request
23
+ assert_equal result.count, 3
24
+ end
25
+
26
+ def test_an_employee_tallyable_response_on_a_valid_request
27
+ employee_stub(status: 200,
28
+ body: File.read("test/fixtures/employee_response.xml"), headers: {})
29
+
30
+ result = Employee.employee_request
31
+ assert_equal result.first[:name], "test_employee_1"
32
+ assert_equal result.first[:email], "test_employee_1@example.com"
33
+ assert_equal result.first[:date_of_birth], '20-July-1970'
34
+ assert_equal result.first[:gender], "Male"
35
+ assert_equal result.first[:address], "Bangalore"
36
+ assert_equal result.first[:phone], "1234567890"
37
+ end
38
+ end
data/test/employee.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'tallyable/acts_as_tallyable'
2
+
3
+ class Employee
4
+ acts_as_tallyable "http://example.com"
5
+ end
@@ -0,0 +1,31 @@
1
+ <ENVELOPE>
2
+ <EMPPROFILESNO>1</EMPPROFILESNO>
3
+ <EMPPROFILENAME>test_employee_1</EMPPROFILENAME>
4
+ <SVCURRENTEMPLOYEE>
5
+ <EMPPROFILEEMAILID>test_employee_1@example.com</EMPPROFILEEMAILID>
6
+ <EMPPROFILEGENDER>Male</EMPPROFILEGENDER>
7
+ <EMPPROFILEEMPLOYEEADDRESS>Bangalore</EMPPROFILEEMPLOYEEADDRESS>
8
+ <EMPPROFILECONTACTNUMBER>1234567890</EMPPROFILECONTACTNUMBER>
9
+ <EMPPROFILEDATEOFBIRTH>20-July-1970</EMPPROFILEDATEOFBIRTH>
10
+ </SVCURRENTEMPLOYEE>
11
+
12
+ <EMPPROFILESNO>2</EMPPROFILESNO>
13
+ <EMPPROFILENAME>test_employee_2</EMPPROFILENAME>
14
+ <SVCURRENTEMPLOYEE>
15
+ <EMPPROFILEEMAILID>test_employee_2@example.com</EMPPROFILEEMAILID>
16
+ <EMPPROFILEGENDER>Female</EMPPROFILEGENDER>
17
+ <EMPPROFILEEMPLOYEEADDRESS>Mysore</EMPPROFILEEMPLOYEEADDRESS>
18
+ <EMPPROFILECONTACTNUMBER>1234567891</EMPPROFILECONTACTNUMBER>
19
+ <EMPPROFILEDATEOFBIRTH>20-July-1980</EMPPROFILEDATEOFBIRTH>
20
+ </SVCURRENTEMPLOYEE>
21
+
22
+ <EMPPROFILESNO>3</EMPPROFILESNO>
23
+ <EMPPROFILENAME>test_employee_3</EMPPROFILENAME>
24
+ <SVCURRENTEMPLOYEE>
25
+ <EMPPROFILEEMAILID>test_employee_3@example.com</EMPPROFILEEMAILID>
26
+ <EMPPROFILEGENDER>Male</EMPPROFILEGENDER>
27
+ <EMPPROFILEEMPLOYEEADDRESS>Belgaum</EMPPROFILEEMPLOYEEADDRESS>
28
+ <EMPPROFILECONTACTNUMBER>1234567892</EMPPROFILECONTACTNUMBER>
29
+ <EMPPROFILEDATEOFBIRTH>20-July-1990</EMPPROFILEDATEOFBIRTH>
30
+ </SVCURRENTEMPLOYEE>
31
+ </ENVELOPE>
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class TallyableTest < Minitest::Test
4
+ def test_truth
5
+ assert_kind_of Module, Tallyable
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ require 'minitest/autorun'
2
+ require 'webmock/minitest'
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tallyable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Supreeth Burji
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
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
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A Proof of concept.
47
+ email:
48
+ - supreethjburji@yahoo.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/tallyable/employee_request.xml
54
+ - lib/tallyable/acts_as_tallyable.rb
55
+ - lib/tallyable/version.rb
56
+ - lib/tallyable.rb
57
+ - LICENSE.md
58
+ - Rakefile
59
+ - README.md
60
+ - test/tallyable_test.rb
61
+ - test/fixtures/employee_response.xml
62
+ - test/test_helper.rb
63
+ - test/employee.rb
64
+ - test/acts_as_tallyable_test.rb
65
+ homepage: https://github.com/sjburji/tallyable
66
+ licenses:
67
+ - MIT
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.23
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Tally ERP 0.9 integration using xml api
90
+ test_files:
91
+ - test/tallyable_test.rb
92
+ - test/fixtures/employee_response.xml
93
+ - test/test_helper.rb
94
+ - test/employee.rb
95
+ - test/acts_as_tallyable_test.rb