active_forms 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +7 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/active_forms.gemspec +86 -0
- data/lib/active_forms.rb +36 -0
- data/lib/active_forms/application.rb +27 -0
- data/lib/active_forms/application_print.rb +20 -0
- data/lib/active_forms/configuration.rb +10 -0
- data/lib/active_forms/form.rb +31 -0
- data/lib/active_forms/mapper.rb +57 -0
- data/lib/active_forms/request.rb +86 -0
- data/test/active_forms/application_print_test.rb +58 -0
- data/test/active_forms/application_test.rb +86 -0
- data/test/active_forms/form_test.rb +96 -0
- data/test/active_forms/mapper_test.rb +55 -0
- data/test/active_forms/request_test.rb +113 -0
- data/test/active_forms_test.rb +17 -0
- data/test/fixtures/error.xml +2 -0
- data/test/fixtures/get_applicationdata.xml +38 -0
- data/test/fixtures/get_applicationprint.xml +15 -0
- data/test/fixtures/get_applications.xml +22 -0
- data/test/fixtures/get_applications_single.xml +14 -0
- data/test/fixtures/get_forms.xml +22 -0
- data/test/fixtures/get_forms_single.xml +12 -0
- data/test/fixtures/success.xml +4 -0
- data/test/test_helper.rb +87 -0
- metadata +129 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Michał Szajbe
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "active_forms"
|
8
|
+
gem.summary = %Q{Active Forms API wrapper}
|
9
|
+
gem.email = "michal.szajbe@gmail.com"
|
10
|
+
gem.authors = ["Michał Szajbe"]
|
11
|
+
gem.homepage = "http://github.com/monterail/active_forms"
|
12
|
+
gem.add_dependency "activesupport", ">= 0"
|
13
|
+
gem.add_dependency "httparty", ">= 0.5.2"
|
14
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 2.10.2"
|
15
|
+
gem.add_development_dependency "fakeweb", ">= 1.2.8"
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/*_test.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/*_test.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "active_forms #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.1
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{active_forms}
|
8
|
+
s.version = "0.2.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Micha\305\202 Szajbe"]
|
12
|
+
s.date = %q{2010-04-01}
|
13
|
+
s.email = %q{michal.szajbe@gmail.com}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".document",
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"active_forms.gemspec",
|
26
|
+
"lib/active_forms.rb",
|
27
|
+
"lib/active_forms/application.rb",
|
28
|
+
"lib/active_forms/application_print.rb",
|
29
|
+
"lib/active_forms/configuration.rb",
|
30
|
+
"lib/active_forms/form.rb",
|
31
|
+
"lib/active_forms/mapper.rb",
|
32
|
+
"lib/active_forms/request.rb",
|
33
|
+
"test/active_forms/application_print_test.rb",
|
34
|
+
"test/active_forms/application_test.rb",
|
35
|
+
"test/active_forms/form_test.rb",
|
36
|
+
"test/active_forms/mapper_test.rb",
|
37
|
+
"test/active_forms/request_test.rb",
|
38
|
+
"test/active_forms_test.rb",
|
39
|
+
"test/fixtures/error.xml",
|
40
|
+
"test/fixtures/get_applicationdata.xml",
|
41
|
+
"test/fixtures/get_applicationprint.xml",
|
42
|
+
"test/fixtures/get_applications.xml",
|
43
|
+
"test/fixtures/get_applications_single.xml",
|
44
|
+
"test/fixtures/get_forms.xml",
|
45
|
+
"test/fixtures/get_forms_single.xml",
|
46
|
+
"test/fixtures/success.xml",
|
47
|
+
"test/test_helper.rb"
|
48
|
+
]
|
49
|
+
s.homepage = %q{http://github.com/monterail/active_forms}
|
50
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
51
|
+
s.require_paths = ["lib"]
|
52
|
+
s.rubygems_version = %q{1.3.5}
|
53
|
+
s.summary = %q{Active Forms API wrapper}
|
54
|
+
s.test_files = [
|
55
|
+
"test/active_forms/application_print_test.rb",
|
56
|
+
"test/active_forms/application_test.rb",
|
57
|
+
"test/active_forms/form_test.rb",
|
58
|
+
"test/active_forms/mapper_test.rb",
|
59
|
+
"test/active_forms/request_test.rb",
|
60
|
+
"test/active_forms_test.rb",
|
61
|
+
"test/test_helper.rb"
|
62
|
+
]
|
63
|
+
|
64
|
+
if s.respond_to? :specification_version then
|
65
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
66
|
+
s.specification_version = 3
|
67
|
+
|
68
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
69
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
70
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
|
71
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 2.10.2"])
|
72
|
+
s.add_development_dependency(%q<fakeweb>, [">= 1.2.8"])
|
73
|
+
else
|
74
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
75
|
+
s.add_dependency(%q<httparty>, [">= 0.5.2"])
|
76
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 2.10.2"])
|
77
|
+
s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
|
78
|
+
end
|
79
|
+
else
|
80
|
+
s.add_dependency(%q<activesupport>, [">= 0"])
|
81
|
+
s.add_dependency(%q<httparty>, [">= 0.5.2"])
|
82
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 2.10.2"])
|
83
|
+
s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
data/lib/active_forms.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
require 'active_forms/configuration'
|
4
|
+
require 'active_forms/mapper'
|
5
|
+
require 'active_forms/request'
|
6
|
+
|
7
|
+
require 'active_forms/application'
|
8
|
+
require 'active_forms/application_print'
|
9
|
+
require 'active_forms/form'
|
10
|
+
|
11
|
+
module ActiveForms
|
12
|
+
class << self
|
13
|
+
attr_accessor :configuration
|
14
|
+
|
15
|
+
def configure
|
16
|
+
self.configuration ||= Configuration.new
|
17
|
+
yield(configuration)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Error < StandardError; end
|
22
|
+
|
23
|
+
class MissingParameter < Error; end
|
24
|
+
class ApiVersionNotSupported < Error; end
|
25
|
+
class MissingVendor < Error; end
|
26
|
+
class MissingResource < Error; end
|
27
|
+
class ResourceNotSupported < Error; end
|
28
|
+
class BadParameterFormat < Error; end
|
29
|
+
class ApiKeyInvalid < Error; end
|
30
|
+
class ApiTimestampInvalid < Error; end
|
31
|
+
class ApiSigInvalid < Error; end
|
32
|
+
class MethodNotAllowed < Error; end
|
33
|
+
class FormNotFound < Error; end
|
34
|
+
class FormVersionNotFound < Error; end
|
35
|
+
class ApplicationNotFound < Error; end
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class ActiveForms::Application < ActiveForms::Mapper
|
2
|
+
columns :number, :formCode, :formVersion, :date, :status, :isPrintable, :fieldData
|
3
|
+
|
4
|
+
class << self
|
5
|
+
# required params:
|
6
|
+
# apiStatus = sent | saved | sent_to_be
|
7
|
+
def all(params = {})
|
8
|
+
response = ActiveForms::Request.get("applications", params)
|
9
|
+
|
10
|
+
hashes = response["applications"]["application"]
|
11
|
+
hashes = [hashes] if hashes.is_a?(Hash)
|
12
|
+
|
13
|
+
objects = hashes.map { |attributes| new(attributes) }
|
14
|
+
end
|
15
|
+
|
16
|
+
# required params:
|
17
|
+
# apiFormCode - Form's code
|
18
|
+
# apiNumber - Application's number
|
19
|
+
def find(params = {})
|
20
|
+
response = ActiveForms::Request.get("applicationdata", params)
|
21
|
+
|
22
|
+
attributes = response["applicationData"]
|
23
|
+
|
24
|
+
new(attributes)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class ActiveForms::ApplicationPrint < ActiveForms::Mapper
|
2
|
+
columns :formCode, :formVersionCode, :number, :date, :status, :contentType, :printContent
|
3
|
+
|
4
|
+
class << self
|
5
|
+
# required params:
|
6
|
+
# apiFormCode - Form's code
|
7
|
+
# apiNumber - Application's number
|
8
|
+
def find(params = {})
|
9
|
+
response = ActiveForms::Request.get("applicationprint", params)
|
10
|
+
|
11
|
+
attributes = response["applicationPrint"]
|
12
|
+
|
13
|
+
new(attributes)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def printContent=(value)
|
18
|
+
@attributes["printContent"] = value.is_a?(String) ? value.strip : super
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ActiveForms
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :api_url, :url, :base_url, :api_key, :secret_key
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@api_url = { :protocol => "https", :host => 'api.activeforms.com' }
|
7
|
+
@url = { :protocol => "https", :host => 'www.activeforms.com' }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class ActiveForms::Form < ActiveForms::Mapper
|
2
|
+
columns :name, :code, :url, :status, :activeReleaseCode, :activeReleaseName, :title, :isPrintable
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def all(params = {})
|
6
|
+
response = ActiveForms::Request.get("forms", params)
|
7
|
+
|
8
|
+
hashes = response["forms"]["form"]
|
9
|
+
hashes = [hashes] if hashes.is_a?(Hash)
|
10
|
+
|
11
|
+
objects = hashes.map { |attributes| new(attributes) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def full_url
|
16
|
+
if url.starts_with?("http")
|
17
|
+
url
|
18
|
+
else
|
19
|
+
host = ActiveForms.configuration.url[:protocol] + "://" + ActiveForms.configuration.url[:host]
|
20
|
+
host << "/" << ActiveForms.configuration.base_url << "/" << url
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def active?
|
25
|
+
status == "active"
|
26
|
+
end
|
27
|
+
|
28
|
+
def inactive?
|
29
|
+
status == "inactive"
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module ActiveForms
|
2
|
+
class Mapper
|
3
|
+
|
4
|
+
class << self
|
5
|
+
attr_reader :column_names
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
def columns(*columns)
|
10
|
+
@column_names ||= []
|
11
|
+
@column_names += columns.map(&:to_s)
|
12
|
+
|
13
|
+
columns.each do |column|
|
14
|
+
define_method("#{column}") do
|
15
|
+
@attributes["#{column}"]
|
16
|
+
end
|
17
|
+
|
18
|
+
define_method("#{column}=") do |value|
|
19
|
+
@attributes["#{column}"] = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
attr_reader :attributes
|
26
|
+
|
27
|
+
def initialize(attributes = {})
|
28
|
+
self.attributes = attributes
|
29
|
+
end
|
30
|
+
|
31
|
+
def attributes=(new_attributes = {})
|
32
|
+
@attributes = HashWithIndifferentAccess.new
|
33
|
+
|
34
|
+
# use attribute writers
|
35
|
+
new_attributes.each { |k, v| respond_to?("#{k}=") ? send("#{k}=", v) : (@attributes[k] = v) }
|
36
|
+
|
37
|
+
@attributes.stringify_keys!
|
38
|
+
end
|
39
|
+
|
40
|
+
# ignore
|
41
|
+
def xmlns=(value)
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
|
45
|
+
# ignore
|
46
|
+
def apiVersion=(value)
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def ==(comparison_object)
|
51
|
+
attributes == comparison_object.attributes
|
52
|
+
end
|
53
|
+
|
54
|
+
alias_method :equal?, :==
|
55
|
+
alias_method :eql?, :==
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
require 'cgi'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module ActiveForms
|
6
|
+
class Request
|
7
|
+
attr_reader :http_method, :path, :params, :api_params, :uri
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def get(path, all_params = {})
|
11
|
+
new(:get, path, all_params).perform
|
12
|
+
end
|
13
|
+
|
14
|
+
def post(path, all_params = {})
|
15
|
+
new(:post, path, all_params).perform
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete(path, all_params = {})
|
19
|
+
new(:delete, path, all_params).perform
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(http_method, path, all_params = {})
|
24
|
+
all_params.stringify_keys!
|
25
|
+
|
26
|
+
@http_method = http_method.to_s.upcase
|
27
|
+
@path = path.to_s
|
28
|
+
@api_params = {}
|
29
|
+
@params = {}
|
30
|
+
|
31
|
+
all_params.each do |k, v|
|
32
|
+
if k.starts_with?("api")
|
33
|
+
@api_params[k] = v
|
34
|
+
else
|
35
|
+
@params[k] = v
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
@api_params["apiKey"] = ActiveForms.configuration.api_key
|
40
|
+
@api_params["apiVersion"] = "1.0"
|
41
|
+
@api_params["apiTimestamp"] ||= Time.now.utc.iso8601(3)
|
42
|
+
@api_params["apiSig"] = api_sig
|
43
|
+
|
44
|
+
@uri = build_uri
|
45
|
+
end
|
46
|
+
|
47
|
+
def perform
|
48
|
+
response = HTTParty.send(http_method.downcase, uri)
|
49
|
+
raise_error(response)
|
50
|
+
response
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def build_uri
|
56
|
+
params = http_method == "GET" ? @params.map { |k, v| "#{k}=#{CGI::escape(v)}" } : []
|
57
|
+
api_params = @api_params.map { |k, v| "#{k}=#{v}" }
|
58
|
+
|
59
|
+
url_with_path + "?" + [params, api_params].flatten.join("&")
|
60
|
+
end
|
61
|
+
|
62
|
+
def url_with_path
|
63
|
+
url = ActiveForms.configuration.api_url[:protocol] + "://" + ActiveForms.configuration.api_url[:host]
|
64
|
+
[url, ActiveForms.configuration.base_url, path].join('/')
|
65
|
+
end
|
66
|
+
|
67
|
+
def api_sig
|
68
|
+
string = [
|
69
|
+
http_method,
|
70
|
+
url_with_path,
|
71
|
+
api_params["apiKey"],
|
72
|
+
api_params["apiTimestamp"],
|
73
|
+
ActiveForms.configuration.secret_key
|
74
|
+
].join.downcase
|
75
|
+
|
76
|
+
Digest::SHA1.hexdigest(string)
|
77
|
+
end
|
78
|
+
|
79
|
+
def raise_error(response)
|
80
|
+
if response["error"]
|
81
|
+
klass = ("ActiveForms::" << response["error"]["code"].downcase.camelize).constantize
|
82
|
+
raise klass.new(response["error"]["message"])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActiveForms::ApplicationPrintTest < Test::Unit::TestCase
|
4
|
+
context "" do
|
5
|
+
setup do
|
6
|
+
configure
|
7
|
+
end
|
8
|
+
|
9
|
+
context "instance" do
|
10
|
+
setup do
|
11
|
+
@application = ActiveForms::ApplicationPrint.new(
|
12
|
+
:number => "1234",
|
13
|
+
:form_code => "credit_card_application",
|
14
|
+
:form_version_code => "version_1",
|
15
|
+
:date => "2007-08-23T12:43:03",
|
16
|
+
:status => "sent",
|
17
|
+
:content_type => "application/pdf",
|
18
|
+
:print_content => "wAARCAMABAADASIA"
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
should "have correctly built attributes" do
|
23
|
+
attributes = {
|
24
|
+
"number" => "1234",
|
25
|
+
"form_code" => "credit_card_application",
|
26
|
+
"form_version_code" => "version_1",
|
27
|
+
"date" => "2007-08-23T12:43:03",
|
28
|
+
"status" => "sent",
|
29
|
+
"content_type" => "application/pdf",
|
30
|
+
"print_content" => "wAARCAMABAADASIA"
|
31
|
+
}
|
32
|
+
|
33
|
+
assert_equal attributes, @application.attributes
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when sent ActiveForms::ApplicationPrint.find with form code and application number" do
|
38
|
+
setup do
|
39
|
+
stub_get(/applicationprint/, success_response("get_applicationprint"))
|
40
|
+
@application_print = ActiveForms::ApplicationPrint.find(:apiFormCode => "credit_card_application", :apiNumber => "23456")
|
41
|
+
end
|
42
|
+
|
43
|
+
should "respond with ApplicationPrint instance" do
|
44
|
+
application_print = ActiveForms::ApplicationPrint.new(
|
45
|
+
:number => "23456",
|
46
|
+
:formCode => "credit_card_application",
|
47
|
+
:formVersionCode => "version_1",
|
48
|
+
:date => "2007-08-23T12:43:03",
|
49
|
+
:status => "sent",
|
50
|
+
:contentType => "application/pdf",
|
51
|
+
:printContent => "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAMABAADASIA"
|
52
|
+
)
|
53
|
+
|
54
|
+
assert_equal application_print, @application_print
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActiveForms::ApplicationTest < Test::Unit::TestCase
|
4
|
+
context "" do
|
5
|
+
setup do
|
6
|
+
configure
|
7
|
+
end
|
8
|
+
|
9
|
+
context "instance" do
|
10
|
+
setup do
|
11
|
+
@application = ActiveForms::Application.new(
|
12
|
+
:number => "1234",
|
13
|
+
:form_code => "credit_card_application",
|
14
|
+
:field_data => {
|
15
|
+
:last_name => "Kowalski",
|
16
|
+
:ubezpieczenie => ["ubezpieczenie_karty", "na_zycie"]
|
17
|
+
}
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "have correctly built attributes" do
|
22
|
+
attributes = {
|
23
|
+
"number" => "1234",
|
24
|
+
"form_code" => "credit_card_application",
|
25
|
+
"field_data" => {
|
26
|
+
"last_name" => "Kowalski",
|
27
|
+
"ubezpieczenie" => ["ubezpieczenie_karty", "na_zycie"]
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
assert_equal attributes, @application.attributes
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context "when sent ActiveForms::Application.all with multi-response" do
|
36
|
+
setup do
|
37
|
+
stub_get(/applications/, success_response("get_applications"))
|
38
|
+
@applications = ActiveForms::Application.all
|
39
|
+
end
|
40
|
+
|
41
|
+
should "respond with array of Application instances" do
|
42
|
+
application1 = ActiveForms::Application.new(
|
43
|
+
:number => "12234",
|
44
|
+
:formCode => "credit_card_application",
|
45
|
+
:formVersionCode => "version_1",
|
46
|
+
:date => "2007-08-23T12:43:03",
|
47
|
+
:status => "sent",
|
48
|
+
:isPrintable => "true"
|
49
|
+
)
|
50
|
+
|
51
|
+
application2 = ActiveForms::Application.new(
|
52
|
+
:number => "12235",
|
53
|
+
:formCode => "credit_card_application",
|
54
|
+
:formVersionCode => "version_1",
|
55
|
+
:date => "2007-08-23T12:44:03",
|
56
|
+
:status => "sent",
|
57
|
+
:isPrintable => "true"
|
58
|
+
)
|
59
|
+
|
60
|
+
assert @applications.include?(application1)
|
61
|
+
assert @applications.include?(application2)
|
62
|
+
assert_equal 2, @applications.size
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when sent ActiveForms::Application.all with single-response" do
|
67
|
+
setup do
|
68
|
+
stub_get(/applications/, success_response("get_applications_single"))
|
69
|
+
@applications = ActiveForms::Application.all
|
70
|
+
end
|
71
|
+
|
72
|
+
should "respond with array of Application instances" do
|
73
|
+
application = ActiveForms::Application.new(
|
74
|
+
:number => "12234",
|
75
|
+
:formCode => "credit_card_application",
|
76
|
+
:formVersionCode => "version_1",
|
77
|
+
:date => "2007-08-23T12:43:03",
|
78
|
+
:status => "sent",
|
79
|
+
:isPrintable => "true"
|
80
|
+
)
|
81
|
+
|
82
|
+
assert_equal [application], @applications
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActiveForms::FormTest < Test::Unit::TestCase
|
4
|
+
context "" do
|
5
|
+
setup do
|
6
|
+
configure
|
7
|
+
end
|
8
|
+
|
9
|
+
context "when sent ActiveForms::Form.all with multi-response" do
|
10
|
+
setup do
|
11
|
+
stub_get(/forms/, success_response("get_forms"))
|
12
|
+
@forms = ActiveForms::Form.all
|
13
|
+
end
|
14
|
+
|
15
|
+
should "respond with array of Form instances" do
|
16
|
+
@form1 = ActiveForms::Form.new(
|
17
|
+
:name => "Wniosek o~karte kredytowa",
|
18
|
+
:code => "credit_card_application",
|
19
|
+
:url => "https://www.activeforms.com/mybank/wniosek_o_karte_kredytowa",
|
20
|
+
:status => "active",
|
21
|
+
:activeReleaseCode => "version_1",
|
22
|
+
:activeReleaseName => "Wersja pierwsza",
|
23
|
+
:title => "Wniosek o~karte kredytowa",
|
24
|
+
:isPrintAgreement => "isPrintable"
|
25
|
+
)
|
26
|
+
|
27
|
+
@form2 = ActiveForms::Form.new(
|
28
|
+
:name => "Wniosek o~kredyt hipoteczny",
|
29
|
+
:code => "mortgage_credit",
|
30
|
+
:url => "https://www.activeforms.com/mybank/wniosek_o_kredyt_hipoteczny",
|
31
|
+
:status => "inactive"
|
32
|
+
)
|
33
|
+
|
34
|
+
assert @forms.include?(@form1)
|
35
|
+
assert @forms.include?(@form2)
|
36
|
+
assert_equal 2, @forms.size
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when sent ActiveForms::Form.all with single-response" do
|
41
|
+
setup do
|
42
|
+
stub_get(/forms/, success_response("get_forms_single"))
|
43
|
+
@forms = ActiveForms::Form.all
|
44
|
+
end
|
45
|
+
|
46
|
+
should "respond with array of Form instances" do
|
47
|
+
@form = ActiveForms::Form.new(
|
48
|
+
:name => "Wniosek o~kredyt hipoteczny",
|
49
|
+
:code => "mortgage_credit",
|
50
|
+
:url => "https://www.activeforms.com/mybank/wniosek_o_kredyt_hipoteczny",
|
51
|
+
:status => "inactive"
|
52
|
+
)
|
53
|
+
|
54
|
+
assert_equal [@form], @forms
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "given a form with full url" do
|
59
|
+
setup { @form = ActiveForms::Form.new(:url => "https://www.example2.com/client/pit") }
|
60
|
+
|
61
|
+
should "return url as full_url" do
|
62
|
+
assert_equal "https://www.example2.com/client/pit", @form.full_url
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "given a form with no full url" do
|
67
|
+
setup { @form = ActiveForms::Form.new(:url => "pit") }
|
68
|
+
|
69
|
+
should "construct full_url" do
|
70
|
+
assert_equal "https://www.example.com/client/pit", @form.full_url
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "given a form with active status" do
|
75
|
+
setup { @form = ActiveForms::Form.new(:status => "active") }
|
76
|
+
|
77
|
+
should "respond with true when sent #active?" do
|
78
|
+
assert @form.active?
|
79
|
+
end
|
80
|
+
should "respond with false when sent #inactive?" do
|
81
|
+
assert !@form.inactive?
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "given a form with inactive status" do
|
86
|
+
setup { @form = ActiveForms::Form.new(:status => "inactive") }
|
87
|
+
|
88
|
+
should "respond with true when sent #inactive?" do
|
89
|
+
assert @form.inactive?
|
90
|
+
end
|
91
|
+
should "respond with false when sent #active?" do
|
92
|
+
assert !@form.active?
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActiveForms::MapperTest < Test::Unit::TestCase
|
4
|
+
context "mapper class" do
|
5
|
+
setup do
|
6
|
+
configure
|
7
|
+
end
|
8
|
+
|
9
|
+
teardown do
|
10
|
+
reset_mapper("Dummy")
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when sent #columns" do
|
14
|
+
setup do
|
15
|
+
Dummy.send(:columns, :one, :two)
|
16
|
+
@dummy = Dummy.new
|
17
|
+
end
|
18
|
+
|
19
|
+
should "define column accessors that read/write attributes" do
|
20
|
+
assert @dummy.respond_to?(:one)
|
21
|
+
assert @dummy.respond_to?(:two)
|
22
|
+
|
23
|
+
@dummy.one = "fake"
|
24
|
+
|
25
|
+
assert_equal "fake", @dummy.attributes["one"]
|
26
|
+
assert_equal "fake", @dummy.one
|
27
|
+
|
28
|
+
assert_same_elements ["one", "two", "name", "formCode"], Dummy.column_names
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "instance" do
|
33
|
+
setup do
|
34
|
+
@dummy = Dummy.new(:name => "fake", :formCode => "code")
|
35
|
+
end
|
36
|
+
|
37
|
+
should "have attributes set" do
|
38
|
+
assert_equal "fake", @dummy.name
|
39
|
+
assert_equal "code", @dummy.formCode
|
40
|
+
end
|
41
|
+
|
42
|
+
should "use writer methotd when mass assigning attributes" do
|
43
|
+
@dummy.instance_eval do
|
44
|
+
def name=(value)
|
45
|
+
@attributes["name"] = "#{value} modified"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@dummy.attributes = { :name => "name" }
|
50
|
+
|
51
|
+
assert_equal "name modified", @dummy.name
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActiveForms::RequestTest < Test::Unit::TestCase
|
4
|
+
context "" do
|
5
|
+
setup { configure }
|
6
|
+
|
7
|
+
context "GET request" do
|
8
|
+
setup do
|
9
|
+
@request = ActiveForms::Request.new(:get, "forms", :param => "a&b value", :apiTimestamp => Time.parse("2010-02-18T01:18:19.218Z").utc.iso8601(3), :apiParam => "apiValue", :apiKey => "fake", :apiVersion => "fake", :apiSig => "fake")
|
10
|
+
end
|
11
|
+
|
12
|
+
should "recognize params and apiParams" do
|
13
|
+
assert_equal "a&b value", @request.params["param"]
|
14
|
+
assert_equal "2010-02-18T01:18:19.218Z", @request.api_params["apiTimestamp"]
|
15
|
+
end
|
16
|
+
|
17
|
+
should "set apiKey, apiVersion and apiSig params by itself" do
|
18
|
+
assert_not_equal "fake", @request.api_params["apiKey"]
|
19
|
+
assert_not_equal "fake", @request.api_params["apiVersion"]
|
20
|
+
assert_not_equal "fake", @request.api_params["apiSig"]
|
21
|
+
end
|
22
|
+
|
23
|
+
should "have apiSig counted" do
|
24
|
+
assert_equal "8069430fe9aabbc2c2fcc895cd423f2a83085185", @request.api_params["apiSig"]
|
25
|
+
end
|
26
|
+
|
27
|
+
should "have correct uri" do
|
28
|
+
assert_same_uri "https://api.example.com/client/forms?apiSig=8069430fe9aabbc2c2fcc895cd423f2a83085185&apiKey=123456&apiTimestamp=2010-02-18T01:18:19.218Z&apiVersion=1.0¶m=a%26b+value&apiParam=apiValue", @request.uri
|
29
|
+
end
|
30
|
+
|
31
|
+
should "have params escaped in uri" do
|
32
|
+
assert @request.uri.include?("a%26b+value")
|
33
|
+
assert !@request.uri.include?("a&b value")
|
34
|
+
end
|
35
|
+
|
36
|
+
context "when performed with success" do
|
37
|
+
setup do
|
38
|
+
stub_get(@request.uri, success_response)
|
39
|
+
@response = @request.perform
|
40
|
+
end
|
41
|
+
|
42
|
+
should "return response as no-error hash" do
|
43
|
+
assert @response.is_a?(Hash)
|
44
|
+
assert !@response.has_key?("error")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when performed with failure" do
|
49
|
+
setup do
|
50
|
+
stub_get(@request.uri, error_response)
|
51
|
+
end
|
52
|
+
|
53
|
+
should "raise error" do
|
54
|
+
assert_raise ActiveForms::ApiTimestampInvalid, "Api timestamp parameter value out of 15 minutes slot" do
|
55
|
+
@request.perform
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "POST request" do
|
62
|
+
setup do
|
63
|
+
@request = ActiveForms::Request.new(:post, "forms", :param => "a&b value", :apiTimestamp => Time.parse("2010-02-18T01:18:19.218Z").utc.iso8601(3), :apiParam => "apiValue")
|
64
|
+
end
|
65
|
+
|
66
|
+
should "have api_sig counted" do
|
67
|
+
assert_equal "fa9c81c5fcdf078528730ff765044f7d4dbcaa8e", @request.api_params["apiSig"]
|
68
|
+
end
|
69
|
+
|
70
|
+
should "have correct uri" do
|
71
|
+
assert_same_uri "https://api.example.com/client/forms?apiSig=fa9c81c5fcdf078528730ff765044f7d4dbcaa8e&apiKey=123456&apiTimestamp=2010-02-18T01:18:19.218Z&apiVersion=1.0&apiParam=apiValue", @request.uri
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "Request.post(path)" do
|
76
|
+
setup do
|
77
|
+
stub_post(/.+/, success_response)
|
78
|
+
@response = ActiveForms::Request.post("forms", :param => "value")
|
79
|
+
end
|
80
|
+
|
81
|
+
should "be equivalent to Request.new(:post, path).perform" do
|
82
|
+
request = ActiveForms::Request.new(:post, "forms", :param => "value")
|
83
|
+
assert_equal @response, request.perform
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "DELETE request" do
|
88
|
+
setup do
|
89
|
+
@request = ActiveForms::Request.new(:delete, "forms", :param => "a&b value", :apiTimestamp => Time.parse("2010-02-18T01:18:19.218Z").utc.iso8601(3), :apiParam => "apiValue")
|
90
|
+
end
|
91
|
+
|
92
|
+
should "have api_sig counted" do
|
93
|
+
assert_equal "ac5efc63ff1382765fdc29940cf6fb7119f9c763", @request.api_params["apiSig"]
|
94
|
+
end
|
95
|
+
|
96
|
+
should "have correct uri" do
|
97
|
+
assert_same_uri "https://api.example.com/client/forms?apiSig=ac5efc63ff1382765fdc29940cf6fb7119f9c763&apiKey=123456&apiTimestamp=2010-02-18T01:18:19.218Z&apiVersion=1.0&apiParam=apiValue", @request.uri
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "Request.delete(path)" do
|
102
|
+
setup do
|
103
|
+
stub_delete(/.+/, success_response)
|
104
|
+
@response = ActiveForms::Request.delete("forms", :param => "value")
|
105
|
+
end
|
106
|
+
|
107
|
+
should "be equivalent to Request.new(:delete, path).perform" do
|
108
|
+
request = ActiveForms::Request.new(:delete, "forms", :param => "value")
|
109
|
+
assert_equal @response, request.perform
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ActiveFormsTest < Test::Unit::TestCase
|
4
|
+
should "configure with block" do
|
5
|
+
ActiveForms.configure do |c|
|
6
|
+
c.url = "AnUrl"
|
7
|
+
c.base_url = "MyBaseUrl"
|
8
|
+
c.api_key = "MyApiKey"
|
9
|
+
c.secret_key = "SuperSecret"
|
10
|
+
end
|
11
|
+
|
12
|
+
assert_equal "AnUrl", ActiveForms.configuration.url
|
13
|
+
assert_equal "MyBaseUrl", ActiveForms.configuration.base_url
|
14
|
+
assert_equal "MyApiKey", ActiveForms.configuration.api_key
|
15
|
+
assert_equal "SuperSecret", ActiveForms.configuration.secret_key
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<error apiVersion="1.0" code="API_TIMESTAMP_INVALID" message="Api timestamp parameter value out of 15 minutes slot" requestMethod="GET" requestTimestamp="2010-02-18T16:31:53.060+01:00" requestURL="/client/dummies" xmlns="http://api.example.com"/>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<applicationData
|
3
|
+
xmlns="http://api.activeforms.com"
|
4
|
+
apiVersion="1.0"
|
5
|
+
formCode="credit_card_application"
|
6
|
+
formVersionCode="version_1"
|
7
|
+
number="23456"
|
8
|
+
date="2007-08-23T12:43:03"
|
9
|
+
status="sent"
|
10
|
+
isPrintable="true"
|
11
|
+
>
|
12
|
+
<fieldData identifier="last_name">
|
13
|
+
<value>Kowalski</value>
|
14
|
+
</fieldData>
|
15
|
+
<fieldData identifier="typ_karty">
|
16
|
+
<value>kredytowa</value>
|
17
|
+
</fieldData>
|
18
|
+
<fieldData identifier="ubezpieczenie">
|
19
|
+
<value>ubezpieczenie_karty</value>
|
20
|
+
<value>na_zycie</value>
|
21
|
+
</fieldData>
|
22
|
+
<fieldData identifier="przetwarzanie_danych">
|
23
|
+
<value>YES</value>
|
24
|
+
</fieldData>
|
25
|
+
<fieldData identifier="data_urodzenia">
|
26
|
+
<value>1978-01-12</value>
|
27
|
+
</fieldData>
|
28
|
+
<fieldData identifier="zdjecie">
|
29
|
+
<value>moj_misio.jpg</value>
|
30
|
+
<fileContent>/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
|
31
|
+
HBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIy
|
32
|
+
MjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAMABAADASIA</fileContent>
|
33
|
+
</fieldData>
|
34
|
+
<fieldData identifier="nr_telefonu">
|
35
|
+
<value>+48 22 1234567</value>
|
36
|
+
</fieldData>
|
37
|
+
<fieldData identifier="uwagi"/>
|
38
|
+
</applicationData>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<applicationPrint
|
3
|
+
xmlns="http://api.activeforms.com"
|
4
|
+
apiVersion="1.0"
|
5
|
+
formCode="credit_card_application"
|
6
|
+
formVersionCode="version_1"
|
7
|
+
number="23456"
|
8
|
+
date="2007-08-23T12:43:03"
|
9
|
+
status="sent"
|
10
|
+
contentType="application/pdf"
|
11
|
+
>
|
12
|
+
<printContent>
|
13
|
+
/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAMABAADASIA
|
14
|
+
</printContent>
|
15
|
+
</applicationPrint>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<applications
|
3
|
+
xmlns="http://api.activeforms.com"
|
4
|
+
apiVersion="1.0"
|
5
|
+
>
|
6
|
+
<application
|
7
|
+
number="12234"
|
8
|
+
formCode="credit_card_application"
|
9
|
+
formVersionCode="version_1"
|
10
|
+
date="2007-08-23T12:43:03"
|
11
|
+
status="sent"
|
12
|
+
isPrintable="true"
|
13
|
+
/>
|
14
|
+
<application
|
15
|
+
number="12235"
|
16
|
+
formCode="credit_card_application"
|
17
|
+
formVersionCode="version_1"
|
18
|
+
date="2007-08-23T12:44:03"
|
19
|
+
status="sent"
|
20
|
+
isPrintable="true"
|
21
|
+
/>
|
22
|
+
</applications>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<applications
|
3
|
+
xmlns="http://api.activeforms.com"
|
4
|
+
apiVersion="1.0"
|
5
|
+
>
|
6
|
+
<application
|
7
|
+
number="12234"
|
8
|
+
formCode="credit_card_application"
|
9
|
+
formVersionCode="version_1"
|
10
|
+
date="2007-08-23T12:43:03"
|
11
|
+
status="sent"
|
12
|
+
isPrintable="true"
|
13
|
+
/>
|
14
|
+
</applications>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<forms
|
3
|
+
xmlns="http://api.activeforms.com"
|
4
|
+
apiVersion="1.0"
|
5
|
+
>
|
6
|
+
<form
|
7
|
+
name="Wniosek o~karte kredytowa"
|
8
|
+
code="credit_card_application"
|
9
|
+
url="https://www.activeforms.com/mybank/wniosek_o_karte_kredytowa"
|
10
|
+
status="active"
|
11
|
+
activeReleaseCode="version_1"
|
12
|
+
activeReleaseName="Wersja pierwsza"
|
13
|
+
title="Wniosek o~karte kredytowa"
|
14
|
+
isPrintAgreement="isPrintable"
|
15
|
+
/>
|
16
|
+
<form
|
17
|
+
name="Wniosek o~kredyt hipoteczny"
|
18
|
+
code="mortgage_credit"
|
19
|
+
url="https://www.activeforms.com/mybank/wniosek_o_kredyt_hipoteczny"
|
20
|
+
status="inactive"
|
21
|
+
/>
|
22
|
+
</forms>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<forms
|
3
|
+
xmlns="http://api.activeforms.com"
|
4
|
+
apiVersion="1.0"
|
5
|
+
>
|
6
|
+
<form
|
7
|
+
name="Wniosek o~kredyt hipoteczny"
|
8
|
+
code="mortgage_credit"
|
9
|
+
url="https://www.activeforms.com/mybank/wniosek_o_kredyt_hipoteczny"
|
10
|
+
status="inactive"
|
11
|
+
/>
|
12
|
+
</forms>
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
require 'shoulda'
|
4
|
+
require 'fakeweb'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
require 'active_forms'
|
9
|
+
|
10
|
+
FakeWeb.allow_net_connect = false
|
11
|
+
|
12
|
+
class Test::Unit::TestCase
|
13
|
+
def teardown
|
14
|
+
FakeWeb.clean_registry
|
15
|
+
end
|
16
|
+
|
17
|
+
def configure
|
18
|
+
ActiveForms.configure do |c|
|
19
|
+
c.api_url = { :protocol => "https", :host => "api.example.com" }
|
20
|
+
c.url = { :protocol => "https", :host => "www.example.com" }
|
21
|
+
c.base_url = "client"
|
22
|
+
c.api_key = "123456"
|
23
|
+
c.secret_key = "abcdef"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def assert_same_uri(expected, actual)
|
28
|
+
expected ||= ""
|
29
|
+
actual ||= ""
|
30
|
+
expected_url, expected_params = expected.split('?', 2)
|
31
|
+
actual_url, actual_params = actual.split('?', 2)
|
32
|
+
expected_params = expected_params.to_s.split('&')
|
33
|
+
actual_params = actual_params.to_s.split('&')
|
34
|
+
|
35
|
+
assert_equal expected_url, actual_url, "urls are not equal"
|
36
|
+
assert_same_elements expected_params, actual_params, "params are not equal"
|
37
|
+
end
|
38
|
+
|
39
|
+
def stub_get(uri, response = {})
|
40
|
+
FakeWeb.register_uri(:get, uri, response)
|
41
|
+
end
|
42
|
+
|
43
|
+
def stub_post(uri, response = {})
|
44
|
+
FakeWeb.register_uri(:post, uri, response)
|
45
|
+
end
|
46
|
+
|
47
|
+
def stub_delete(uri, response = {})
|
48
|
+
FakeWeb.register_uri(:delete, uri, response)
|
49
|
+
end
|
50
|
+
|
51
|
+
def success_response(file = nil)
|
52
|
+
response = {
|
53
|
+
:status => ["200", "OK"],
|
54
|
+
:content_type => "text/xml",
|
55
|
+
:body => fixture(file || "success")
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def error_response(file = nil)
|
60
|
+
response = {
|
61
|
+
:status => ["401", "Unauthorized"],
|
62
|
+
:content_type => "text/xml",
|
63
|
+
:body => fixture(file || "error")
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def fixture(file)
|
68
|
+
File.read(File.join(File.dirname(__FILE__), "fixtures", "#{file}.xml"))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def define_mapper(klass)
|
73
|
+
Object.const_set(klass, Class.new(ActiveForms::Mapper))
|
74
|
+
case klass
|
75
|
+
when "Dummy"
|
76
|
+
Dummy.class_eval do
|
77
|
+
columns :name, :formCode
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def reset_mapper(klass)
|
83
|
+
Object.send(:remove_const, klass) rescue nil
|
84
|
+
define_mapper(klass)
|
85
|
+
end
|
86
|
+
|
87
|
+
define_mapper("Dummy")
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_forms
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "Micha\xC5\x82 Szajbe"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-04-01 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activesupport
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: httparty
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.2
|
34
|
+
version:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: thoughtbot-shoulda
|
37
|
+
type: :development
|
38
|
+
version_requirement:
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.10.2
|
44
|
+
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: fakeweb
|
47
|
+
type: :development
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.8
|
54
|
+
version:
|
55
|
+
description:
|
56
|
+
email: michal.szajbe@gmail.com
|
57
|
+
executables: []
|
58
|
+
|
59
|
+
extensions: []
|
60
|
+
|
61
|
+
extra_rdoc_files:
|
62
|
+
- LICENSE
|
63
|
+
- README.rdoc
|
64
|
+
files:
|
65
|
+
- .document
|
66
|
+
- .gitignore
|
67
|
+
- LICENSE
|
68
|
+
- README.rdoc
|
69
|
+
- Rakefile
|
70
|
+
- VERSION
|
71
|
+
- active_forms.gemspec
|
72
|
+
- lib/active_forms.rb
|
73
|
+
- lib/active_forms/application.rb
|
74
|
+
- lib/active_forms/application_print.rb
|
75
|
+
- lib/active_forms/configuration.rb
|
76
|
+
- lib/active_forms/form.rb
|
77
|
+
- lib/active_forms/mapper.rb
|
78
|
+
- lib/active_forms/request.rb
|
79
|
+
- test/active_forms/application_print_test.rb
|
80
|
+
- test/active_forms/application_test.rb
|
81
|
+
- test/active_forms/form_test.rb
|
82
|
+
- test/active_forms/mapper_test.rb
|
83
|
+
- test/active_forms/request_test.rb
|
84
|
+
- test/active_forms_test.rb
|
85
|
+
- test/fixtures/error.xml
|
86
|
+
- test/fixtures/get_applicationdata.xml
|
87
|
+
- test/fixtures/get_applicationprint.xml
|
88
|
+
- test/fixtures/get_applications.xml
|
89
|
+
- test/fixtures/get_applications_single.xml
|
90
|
+
- test/fixtures/get_forms.xml
|
91
|
+
- test/fixtures/get_forms_single.xml
|
92
|
+
- test/fixtures/success.xml
|
93
|
+
- test/test_helper.rb
|
94
|
+
has_rdoc: true
|
95
|
+
homepage: http://github.com/monterail/active_forms
|
96
|
+
licenses: []
|
97
|
+
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options:
|
100
|
+
- --charset=UTF-8
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: "0"
|
108
|
+
version:
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: "0"
|
114
|
+
version:
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.3.5
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Active Forms API wrapper
|
122
|
+
test_files:
|
123
|
+
- test/active_forms/application_print_test.rb
|
124
|
+
- test/active_forms/application_test.rb
|
125
|
+
- test/active_forms/form_test.rb
|
126
|
+
- test/active_forms/mapper_test.rb
|
127
|
+
- test/active_forms/request_test.rb
|
128
|
+
- test/active_forms_test.rb
|
129
|
+
- test/test_helper.rb
|