monetra 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest ADDED
@@ -0,0 +1,11 @@
1
+ Manifest
2
+ Rakefile
3
+ lib/monetra.rb
4
+ lib/monetra/configuration.rb
5
+ lib/monetra/connection.rb
6
+ lib/monetra/parse.rb
7
+ lib/monetra/transaction.rb
8
+ lib/monetra/transaction/admin.rb
9
+ lib/monetra/transaction/engine.rb
10
+ lib/monetra/transaction/token.rb
11
+ lib/monetra/transaction/user.rb
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('monetra', '0.0.2') do |p|
6
+ p.description = "A gem that uses the Monetra API to perform actions"
7
+ p.url = "http://github.com/winelibrary/monetra"
8
+ p.author = "Dan Ahern"
9
+ p.email = "gems@danahern.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
data/lib/monetra.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'net/http'
2
+ require 'open-uri'
3
+ require 'builder'
4
+ require 'active_support/core_ext'
5
+ require 'csv'
6
+
7
+ module Monetra
8
+ require 'monetra/configuration'
9
+ require 'monetra/connection'
10
+ require 'monetra/transaction/admin'
11
+ require 'monetra/transaction/engine'
12
+ require 'monetra/transaction/token'
13
+ require 'monetra/transaction/user'
14
+ require 'monetra/parse'
15
+ end
@@ -0,0 +1,32 @@
1
+ module Monetra
2
+ class Configuration
3
+ class << self
4
+ def options(options_or_path_to=nil)
5
+ @options ||= case options_or_path_to.class.to_s
6
+ when "String"
7
+ YAML::load_file(options_or_path_to)
8
+ when "Hash"
9
+ options_or_path_to
10
+ when "NilClass"
11
+ YAML::load_file(File.join(Rails.root, 'config', 'monetra.yml'))[Rails.env]
12
+ end
13
+ end
14
+
15
+ def user_name
16
+ options[:user_name]
17
+ end
18
+
19
+ def password
20
+ options[:password]
21
+ end
22
+
23
+ def host
24
+ options[:host]
25
+ end
26
+
27
+ def port
28
+ options[:port]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ module Monetra
2
+ class Connection
3
+ class << self
4
+ def base
5
+ @base ||= Net::HTTP.new(Configuration.host, Configuration.port)
6
+ end
7
+
8
+ def post(data)
9
+ request = base.post("/", data)
10
+ request.body
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ module Monetra
2
+ class Parse
3
+ class << self
4
+ def request(request={})
5
+ xml = Builder::XmlMarkup.new({:indent => 2})
6
+ xml.tag!("MonetraTrans") do
7
+ case request.class.to_s
8
+ when "Array"
9
+ request.each_with_index do |transaction, index|
10
+ xml.tag!("Trans", :identifier => index+1) do
11
+ transaction.instance_variables.each do |key|
12
+ xml.tag!(key.to_s.delete("@"), transaction.instance_variable_get(key))
13
+ end
14
+ end
15
+ end
16
+ else #Monetra::Transaction::Token::Request
17
+ xml.tag!("Trans", :identifier => 1) do
18
+ request.instance_variables.each do |key|
19
+ xml.tag!(key.to_s.delete("@"), request.instance_variable_get(key))
20
+ end
21
+ end
22
+ end
23
+ end
24
+ xml.target!
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module Monetra
2
+ module Transaction
3
+
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Monetra
2
+ module Transaction
3
+ class Admin
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,64 @@
1
+ module Monetra
2
+ module Transaction
3
+ module Engine
4
+ class Request
5
+ # attr_accessor :username, :password, :action, :annual_transaction_limit, :begin_date, :card_types, :company_name, :connection_id, :debug, :device_type, :end_date, :email, :encrypt, :error_code, :file
6
+ # attr_accessor :industry_code, :ip_address, :key, :level, :license_id, :localhost_only, :error_marker, :max_version, :merchant_restrictions, :method, :mode, :num_users, :os, :partial, :partner_id
7
+ # attr_accessor :processing_instructions, :profile_id, :pwd, :require_signed_modules, :required_modules, :restriction, :restriction_data, :restriction_type, :sqlite_only, :sub_account
8
+ # attr_accessor :transaction_types, :ttid, :user
9
+ #
10
+ # alias_method :annual_transaction_limit=, :annual_trans_limit=
11
+ # alias_method :begin_date=, :bdate=
12
+ # alias_method :card_types=, :cardtypes=
13
+ # alias_method :company_name=, :compname=
14
+ # alias_method :connection_id=, :connid=
15
+ # alias_method :device_type=, :devicetype=
16
+ # alias_method :end_date=, :edate=
17
+ # alias_method :error_code=, :errorcode=
18
+ # alias_method :industry_code=, :indcode=
19
+ # alias_method :ip_address=, :ipaddr
20
+ # alias_method :error_code=, :errorcode=
21
+ # alias_method :error_marker=, :marker=
22
+ # alias_method :processing_instructions=, :proc=
23
+ # alias_method :require_signed_modules=, :req_signed_mods=
24
+ # alias_method :sub_account=, :sub=
25
+ #
26
+ #
27
+ #
28
+ # def begin_date=(value)
29
+ # end
30
+ #
31
+ # def card_types=(value)
32
+ # end
33
+ #
34
+ # def end_date=(value)
35
+ # end
36
+ #
37
+ # def industry_code=(value)
38
+ # end
39
+ #
40
+ # def restriction_type=(value)
41
+ #
42
+ # end
43
+ end
44
+
45
+ class Response
46
+ # attr_accessor :code, :msoft_code, :verbiage, :card_types, :mode, :connection_priority, :email, :configured_methods, :current_method, :online_methods, :offline_methods
47
+ #
48
+ # alias_method :consecerrors
49
+ # alias_method :card_types=, :cardtypes=
50
+ # alias_method :connection_priority=, :conn_priority=
51
+ # alias_method :configured_methods=, :configuredmethods=
52
+ # alias_method :current_method=, :currentmethod
53
+ # alias_method :online_methods, :onlinemethods
54
+ # alias_method :offline_methods, :offlinemethods
55
+ #
56
+ # def code=(value)
57
+ # end
58
+ #
59
+ # def msoft_code=(value)
60
+ # end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,115 @@
1
+ module Monetra
2
+ module Transaction
3
+ module Token
4
+ class Request
5
+ attr_accessor :username, :password, :action, :account, :admin, :type, :expdate, :street, :zip, :clientref, :desc, :token, :expdate_end
6
+ attr_accessor :active, :hist_id, :amount, :installment_total, :frequency, :bdate, :edate, :cardholdername
7
+ def initialize(attributes={})
8
+ attributes.each do |att, val|
9
+ self.__send__("#{att}=", val) if self.respond_to?("#{att}=")
10
+ end
11
+ end
12
+ end
13
+
14
+ class Response
15
+ attr_accessor :code, :verbiage, :token
16
+ attr_accessor :token, :type, :active, :cardtype, :account, :expdate, :cardholdername, :street, :zip, :descr, :clientref, :amount, :frequency, :bdate, :edate, :installment_num, :installment_total
17
+ attr_accessor :last_run_id, :last_success_date, :last_run_date, :next_run_date, :next_run_amount, :abaroute, :datablock
18
+
19
+ def initialize(attributes={})
20
+ attributes.each do |att, val|
21
+ self.__send__("#{att}=", val) if self.respond_to?("#{att}=")
22
+ end
23
+ end
24
+
25
+ def datablock=(data)
26
+ csv_data = CSV.parse(data)
27
+ headers = csv_data.shift.map {|i| i.to_s }
28
+ string_data = csv_data.map {|row| row.map {|cell| cell.to_s } }
29
+ array_of_hashes = string_data.map {|row| Hash[*headers.zip(row).flatten] }
30
+ array_of_hashes.first.each_pair do |k,v|
31
+ self.__send__("#{k}=", v)
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ class << self
38
+ def new(attributes={})
39
+ request = Request.new(attributes.merge(:action => "Admin", :type => "store", :admin => "recurringadd"))
40
+ body = Connection.post(Monetra::Parse.request(request))
41
+ body = Hash.from_xml(body)
42
+ transfer_status = body["MonetraResp"]["DataTransferStatus"]
43
+ responses = case body["MonetraResp"]["Resp"].class.to_s
44
+ when "Hash"
45
+ hash_response(body["MonetraResp"]["Resp"])
46
+ when "Array"
47
+ array_response(body["MonetraResp"]["Resp"])
48
+ end
49
+ responses
50
+ end
51
+
52
+ def find(attributes={})
53
+ request = Request.new(attributes.merge(:action => "Admin", :type => "store", :admin => "recurringlist"))
54
+ body = Connection.post(Monetra::Parse.request(request))
55
+ body = Hash.from_xml(body)
56
+ transfer_status = body["MonetraResp"]["DataTransferStatus"]
57
+ responses = case body["MonetraResp"]["Resp"].class.to_s
58
+ when "Hash"
59
+ hash_response(body["MonetraResp"]["Resp"])
60
+ when "Array"
61
+ array_response(body["MonetraResp"]["Resp"])
62
+ end
63
+ responses
64
+ end
65
+
66
+ def edit(attributes={})
67
+ request = Request.new(attributes.merge(:action => "Admin", :type => "store", :admin => "recurringedit"))
68
+ body = Connection.post(Monetra::Parse.request(request))
69
+ body = Hash.from_xml(body)
70
+ transfer_status = body["MonetraResp"]["DataTransferStatus"]
71
+ responses = case body["MonetraResp"]["Resp"].class.to_s
72
+ when "Hash"
73
+ hash_response(body["MonetraResp"]["Resp"])
74
+ when "Array"
75
+ array_response(body["MonetraResp"]["Resp"])
76
+ end
77
+ responses
78
+ end
79
+
80
+ def destroy(attributes={})
81
+ request = Request.new(attributes.merge(:action => "Admin", :type => "store", :admin => "recurringdel"))
82
+ body = Connection.post(Monetra::Parse.request(request))
83
+ body = Hash.from_xml(body)
84
+ transfer_status = body["MonetraResp"]["DataTransferStatus"]
85
+ responses = case body["MonetraResp"]["Resp"].class.to_s
86
+ when "Hash"
87
+ hash_response(body["MonetraResp"]["Resp"])
88
+ when "Array"
89
+ array_response(body["MonetraResp"]["Resp"])
90
+ end
91
+ responses
92
+ end
93
+
94
+ private
95
+ def hash_response(response)
96
+ response_hash = {}
97
+ response.each_pair do |k,v|
98
+ response_hash[k.downcase] = v
99
+ end
100
+ Response.new(response_hash)
101
+ end
102
+
103
+ def array_response(responses)
104
+ responses.map do |resp|
105
+ response_hash = {}
106
+ resp.each_pair do |k,v|
107
+ response_hash[k.downcase] = v
108
+ end
109
+ Response.new(resp)
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,13 @@
1
+ module Monetra
2
+ module Transaction
3
+ module User
4
+ class Request
5
+ attr_accessor :username, :password, :action, :account
6
+ end
7
+
8
+ class Response
9
+
10
+ end
11
+ end
12
+ end
13
+ end
data/monetra.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{monetra}
5
+ s.version = "0.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Dan Ahern"]
9
+ s.date = %q{2010-11-15}
10
+ s.description = %q{A gem that uses the Monetra API to perform actions}
11
+ s.email = %q{gems@danahern.com}
12
+ s.extra_rdoc_files = ["lib/monetra.rb", "lib/monetra/configuration.rb", "lib/monetra/connection.rb", "lib/monetra/parse.rb", "lib/monetra/transaction.rb", "lib/monetra/transaction/admin.rb", "lib/monetra/transaction/engine.rb", "lib/monetra/transaction/token.rb", "lib/monetra/transaction/user.rb"]
13
+ s.files = ["Manifest", "Rakefile", "lib/monetra.rb", "lib/monetra/configuration.rb", "lib/monetra/connection.rb", "lib/monetra/parse.rb", "lib/monetra/transaction.rb", "lib/monetra/transaction/admin.rb", "lib/monetra/transaction/engine.rb", "lib/monetra/transaction/token.rb", "lib/monetra/transaction/user.rb", "monetra.gemspec"]
14
+ s.homepage = %q{http://github.com/winelibrary/monetra}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Monetra"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{monetra}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{A gem that uses the Monetra API to perform actions}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monetra
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Dan Ahern
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-15 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A gem that uses the Monetra API to perform actions
22
+ email: gems@danahern.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - lib/monetra.rb
29
+ - lib/monetra/configuration.rb
30
+ - lib/monetra/connection.rb
31
+ - lib/monetra/parse.rb
32
+ - lib/monetra/transaction.rb
33
+ - lib/monetra/transaction/admin.rb
34
+ - lib/monetra/transaction/engine.rb
35
+ - lib/monetra/transaction/token.rb
36
+ - lib/monetra/transaction/user.rb
37
+ files:
38
+ - Manifest
39
+ - Rakefile
40
+ - lib/monetra.rb
41
+ - lib/monetra/configuration.rb
42
+ - lib/monetra/connection.rb
43
+ - lib/monetra/parse.rb
44
+ - lib/monetra/transaction.rb
45
+ - lib/monetra/transaction/admin.rb
46
+ - lib/monetra/transaction/engine.rb
47
+ - lib/monetra/transaction/token.rb
48
+ - lib/monetra/transaction/user.rb
49
+ - monetra.gemspec
50
+ has_rdoc: true
51
+ homepage: http://github.com/winelibrary/monetra
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --line-numbers
57
+ - --inline-source
58
+ - --title
59
+ - Monetra
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 1
77
+ - 2
78
+ version: "1.2"
79
+ requirements: []
80
+
81
+ rubyforge_project: monetra
82
+ rubygems_version: 1.3.7
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A gem that uses the Monetra API to perform actions
86
+ test_files: []
87
+