active_forms 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -19
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE +3 -1
- data/README.md +31 -0
- data/Rakefile +3 -49
- data/active_forms.gemspec +16 -81
- data/lib/active_forms.rb +41 -15
- data/lib/active_forms/application.rb +3 -1
- data/lib/active_forms/application_print.rb +2 -0
- data/lib/active_forms/configuration.rb +3 -1
- data/lib/active_forms/entry.rb +51 -0
- data/lib/active_forms/entry_printout.rb +22 -0
- data/lib/active_forms/form.rb +3 -1
- data/lib/active_forms/form_version.rb +19 -0
- data/lib/active_forms/mapper.rb +2 -0
- data/lib/active_forms/request.rb +27 -8
- data/lib/active_forms/token.rb +18 -0
- data/lib/active_forms/version.rb +3 -0
- data/test/active_forms/application_print_test.rb +2 -0
- data/test/active_forms/application_test.rb +2 -0
- data/test/active_forms/entry_printout_test.rb +60 -0
- data/test/active_forms/entry_test.rb +125 -0
- data/test/active_forms/form_test.rb +2 -0
- data/test/active_forms/form_version_test.rb +37 -0
- data/test/active_forms/mapper_test.rb +2 -0
- data/test/active_forms/request_test.rb +14 -12
- data/test/active_forms/token_test.rb +33 -0
- data/test/active_forms_test.rb +2 -0
- data/test/fixtures/get_entries.xml +22 -0
- data/test/fixtures/get_entries_single.xml +14 -0
- data/test/fixtures/get_entrydata.xml +38 -0
- data/test/fixtures/get_entryprintout.xml +15 -0
- data/test/fixtures/get_formaccesstokens.xml +12 -0
- data/test/fixtures/get_forminfo.xml +21 -0
- data/test/fixtures/post_entrydata.xml +12 -0
- data/test/test_helper.rb +5 -4
- metadata +99 -32
- data/.document +0 -5
- data/README.rdoc +0 -7
- data/VERSION +0 -1
data/lib/active_forms/form.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
class ActiveForms::Form < ActiveForms::Mapper
|
2
4
|
columns :name, :code, :url, :status, :activeReleaseCode, :activeReleaseName, :title, :isPrintable
|
3
5
|
|
@@ -8,7 +10,7 @@ class ActiveForms::Form < ActiveForms::Mapper
|
|
8
10
|
hashes = response["forms"]["form"]
|
9
11
|
hashes = [hashes] if hashes.is_a?(Hash)
|
10
12
|
|
11
|
-
objects = hashes.map { |attributes| new(attributes) }
|
13
|
+
objects = hashes.nil? ? [] : hashes.map { |attributes| new(attributes) }
|
12
14
|
end
|
13
15
|
end
|
14
16
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
class ActiveForms::FormVersion < ActiveForms::Mapper
|
4
|
+
columns :name, :code, :url, :mailIntegration, :accessType, :authKey, :status,
|
5
|
+
:description, :creationDate, :isPrintable
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# required params:
|
9
|
+
# apiFormCode
|
10
|
+
def all(params = {})
|
11
|
+
response = ActiveForms::Request.get("forminfo", params)
|
12
|
+
|
13
|
+
hashes = response["formInfo"]["formVersion"]
|
14
|
+
hashes = [hashes] if hashes.is_a?(Hash)
|
15
|
+
|
16
|
+
objects = hashes.nil? ? [] : hashes.map { |attributes| new(attributes) }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/active_forms/mapper.rb
CHANGED
data/lib/active_forms/request.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'digest/sha1'
|
2
4
|
require 'cgi'
|
3
5
|
require 'httparty'
|
@@ -37,16 +39,22 @@ module ActiveForms
|
|
37
39
|
end
|
38
40
|
|
39
41
|
@api_params["apiKey"] = ActiveForms.configuration.api_key
|
40
|
-
@api_params["apiVersion"] = "
|
41
|
-
@api_params["apiTimestamp"] ||= Time.now.
|
42
|
+
@api_params["apiVersion"] = "3.0"
|
43
|
+
@api_params["apiTimestamp"] ||= Time.now.strftime('%Y-%m-%dT%H:%M:%S.000 %z')
|
42
44
|
@api_params["apiSig"] = api_sig
|
43
45
|
|
44
46
|
@uri = build_uri
|
45
47
|
end
|
46
48
|
|
47
49
|
def perform
|
48
|
-
|
49
|
-
|
50
|
+
ActiveForms.log("[ActiveForms] Request: #{http_method.upcase} #{uri}")
|
51
|
+
begin
|
52
|
+
response = HTTParty.send(http_method.downcase, uri)
|
53
|
+
verify_response(response)
|
54
|
+
rescue
|
55
|
+
response = HTTParty.send(http_method.downcase, uri)
|
56
|
+
verify_response(response)
|
57
|
+
end
|
50
58
|
response
|
51
59
|
end
|
52
60
|
|
@@ -54,7 +62,13 @@ module ActiveForms
|
|
54
62
|
|
55
63
|
def build_uri
|
56
64
|
params = http_method == "GET" ? @params.map { |k, v| "#{k}=#{CGI::escape(v)}" } : []
|
57
|
-
api_params = @api_params.map
|
65
|
+
api_params = @api_params.map do |k, v|
|
66
|
+
if k == 'apiTimestamp'
|
67
|
+
"#{k}=#{CGI::escape(v)}"
|
68
|
+
else
|
69
|
+
"#{k}=#{v}"
|
70
|
+
end
|
71
|
+
end
|
58
72
|
|
59
73
|
url_with_path + "?" + [params, api_params].flatten.join("&")
|
60
74
|
end
|
@@ -76,10 +90,15 @@ module ActiveForms
|
|
76
90
|
Digest::SHA1.hexdigest(string)
|
77
91
|
end
|
78
92
|
|
79
|
-
def
|
93
|
+
def verify_response(response)
|
94
|
+
ActiveForms.log("[ActiveForms] Response: #{response}")
|
80
95
|
if response["error"]
|
81
|
-
|
82
|
-
|
96
|
+
begin
|
97
|
+
klass = ("ActiveForms::" << response["error"]["code"].downcase.camelize).constantize
|
98
|
+
raise klass.new(response["error"]["message"])
|
99
|
+
rescue NameError, NoMethodError
|
100
|
+
raise("Unknown exception: #{response["error"].inspect}")
|
101
|
+
end
|
83
102
|
end
|
84
103
|
end
|
85
104
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
class ActiveForms::Token < ActiveForms::Mapper
|
4
|
+
columns :value
|
5
|
+
|
6
|
+
class << self
|
7
|
+
# required params:
|
8
|
+
# apiFormCode
|
9
|
+
def all(params = {})
|
10
|
+
response = ActiveForms::Request.get('formaccesstokens', params)
|
11
|
+
|
12
|
+
hashes = response['formAccessTokens']['token']
|
13
|
+
hashes = [hashes] if hashes.is_a?(Hash)
|
14
|
+
|
15
|
+
objects = hashes.nil? ? [] : hashes.map { |attributes| new(attributes) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class ActiveForms::EntryPrintoutTest < Test::Unit::TestCase
|
6
|
+
context "" do
|
7
|
+
setup do
|
8
|
+
configure
|
9
|
+
end
|
10
|
+
|
11
|
+
context "instance" do
|
12
|
+
setup do
|
13
|
+
@entry = ActiveForms::EntryPrintout.new(
|
14
|
+
:number => "1234",
|
15
|
+
:form_code => "credit_card_entry",
|
16
|
+
:form_version_code => "version_1",
|
17
|
+
:date => "2007-08-23T12:43:03",
|
18
|
+
:status => "sent",
|
19
|
+
:content_type => "application/pdf",
|
20
|
+
:print_content => "wAARCAMABAADASIA"
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
should "have correctly built attributes" do
|
25
|
+
attributes = {
|
26
|
+
"number" => "1234",
|
27
|
+
"form_code" => "credit_card_entry",
|
28
|
+
"form_version_code" => "version_1",
|
29
|
+
"date" => "2007-08-23T12:43:03",
|
30
|
+
"status" => "sent",
|
31
|
+
"content_type" => "application/pdf",
|
32
|
+
"print_content" => "wAARCAMABAADASIA"
|
33
|
+
}
|
34
|
+
|
35
|
+
assert_equal attributes, @entry.attributes
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when sent ActiveForms::EntryPrintout.find with form code and application number" do
|
40
|
+
setup do
|
41
|
+
stub_get(/entryprintout/, success_response("get_entryprintout"))
|
42
|
+
@entry_printout = ActiveForms::EntryPrintout.find(:formCode => "credit_card_entry", :number => "23456")
|
43
|
+
end
|
44
|
+
|
45
|
+
should "respond with ActiveForms::EntryPrintout instance" do
|
46
|
+
entry_printout = ActiveForms::EntryPrintout.new(
|
47
|
+
:number => "23456",
|
48
|
+
:formCode => "credit_card_entry",
|
49
|
+
:formVersionCode => "version_1",
|
50
|
+
:date => "2007-08-23T12:43:03",
|
51
|
+
:status => "sent",
|
52
|
+
:contentType => "application/pdf",
|
53
|
+
:printoutContent => "/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAMABAADASIA"
|
54
|
+
)
|
55
|
+
|
56
|
+
assert_equal entry_printout, @entry_printout
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class ActiveForms::EntryTest < Test::Unit::TestCase
|
6
|
+
context "" do
|
7
|
+
setup do
|
8
|
+
configure
|
9
|
+
end
|
10
|
+
|
11
|
+
context "instance" do
|
12
|
+
setup do
|
13
|
+
@entry = ActiveForms::Entry.new(
|
14
|
+
:number => "1234",
|
15
|
+
:form_code => "credit_card_entry",
|
16
|
+
:field_data => {
|
17
|
+
:last_name => "Kowalski",
|
18
|
+
:ubezpieczenie => ["ubezpieczenie_karty", "na_zycie"]
|
19
|
+
}
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
should "have correctly built attributes" do
|
24
|
+
attributes = {
|
25
|
+
"number" => "1234",
|
26
|
+
"form_code" => "credit_card_entry",
|
27
|
+
"field_data" => {
|
28
|
+
"last_name" => "Kowalski",
|
29
|
+
"ubezpieczenie" => ["ubezpieczenie_karty", "na_zycie"]
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
assert_equal attributes, @entry.attributes
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "when sent ActiveForms::Entry.all with multi-response" do
|
38
|
+
setup do
|
39
|
+
stub_get(/entries/, success_response("get_entries"))
|
40
|
+
@entries = ActiveForms::Entry.all
|
41
|
+
end
|
42
|
+
|
43
|
+
should "respond with array of entry instances" do
|
44
|
+
entry1 = ActiveForms::Entry.new(
|
45
|
+
:number => "12234",
|
46
|
+
:formCode => "credit_card_entry",
|
47
|
+
:formVersionCode => "version_1",
|
48
|
+
:date => "2007-08-23T12:43:03",
|
49
|
+
:status => "sent",
|
50
|
+
:isPrintable => "true"
|
51
|
+
)
|
52
|
+
|
53
|
+
entry2 = ActiveForms::Entry.new(
|
54
|
+
:number => "12235",
|
55
|
+
:formCode => "credit_card_entry",
|
56
|
+
:formVersionCode => "version_1",
|
57
|
+
:date => "2007-08-23T12:44:03",
|
58
|
+
:status => "sent",
|
59
|
+
:isPrintable => "true"
|
60
|
+
)
|
61
|
+
|
62
|
+
assert @entries.include?(entry1)
|
63
|
+
assert @entries.include?(entry2)
|
64
|
+
assert_equal 2, @entries.size
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when sent ActiveForms::Entry.all with single-response" do
|
69
|
+
setup do
|
70
|
+
stub_get(/entries/, success_response("get_entries_single"))
|
71
|
+
@entries = ActiveForms::Entry.all
|
72
|
+
end
|
73
|
+
|
74
|
+
should "respond with array of entry instances" do
|
75
|
+
entry = ActiveForms::Entry.new(
|
76
|
+
:number => "12234",
|
77
|
+
:formCode => "credit_card_entry",
|
78
|
+
:formVersionCode => "version_1",
|
79
|
+
:date => "2007-08-23T12:43:03",
|
80
|
+
:status => "sent",
|
81
|
+
:isPrintable => "true"
|
82
|
+
)
|
83
|
+
|
84
|
+
assert_equal [entry], @entries
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "when post entry data by ActiveForms::Entry.create" do
|
89
|
+
setup do
|
90
|
+
stub_post(/entrydata/, success_response("post_entrydata"))
|
91
|
+
@entry = ActiveForms::Entry.create :apiFormCode => 'credit_card_entry'
|
92
|
+
end
|
93
|
+
|
94
|
+
should "respond instance of ActiveForms::Entry and accessToken" do
|
95
|
+
entry = ActiveForms::Entry.new(
|
96
|
+
:number => "12234",
|
97
|
+
:formCode => "credit_card_entry",
|
98
|
+
:formVersionCode => "version_1",
|
99
|
+
:date => "2008-01-01T00:00:00.00+0000",
|
100
|
+
:status => "saved",
|
101
|
+
:isPrintable => "true",
|
102
|
+
:accessToken => "43r9j34f9j3"
|
103
|
+
)
|
104
|
+
assert_equal entry, @entry
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when sent ActiveForms::Entry.destroy on got entry" do
|
109
|
+
setup do
|
110
|
+
@response = { :status => ["204", "No content"], :content_type => "text/xml"}
|
111
|
+
stub_delete(/entrydata/, @response)
|
112
|
+
stub_get(/entries/, success_response("get_entries"))
|
113
|
+
@entries = ActiveForms::Entry.all
|
114
|
+
end
|
115
|
+
|
116
|
+
should "respond with 204 status" do
|
117
|
+
@entries.each do |entrydata|
|
118
|
+
assert entrydata.destroy
|
119
|
+
assert ActiveForms::Entry.delete({ :apiFormCode => entrydata.formCode, :apiNumber => entrydata.number })
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class ActiveForms::FormVersionTest < Test::Unit::TestCase
|
6
|
+
context "" do
|
7
|
+
setup do
|
8
|
+
configure
|
9
|
+
end
|
10
|
+
|
11
|
+
context "when send ActiveForms::FormVersion.all with multi-response" do
|
12
|
+
setup do
|
13
|
+
stub_get(/forminfo/, success_response("get_forminfo"))
|
14
|
+
@versions = ActiveForms::FormVersion.all :apiFormCode => 'hipoteka'
|
15
|
+
end
|
16
|
+
|
17
|
+
should "get all versions of form" do
|
18
|
+
formVersion1 = ActiveForms::FormVersion.new(
|
19
|
+
:code => "1.0", :name => "Podstawowa", :status => "active",
|
20
|
+
:description => "Pierwsza wersja wniosku",
|
21
|
+
:creationDate => "2007-01-01 12:00:00+0100", :isPrintable => "false")
|
22
|
+
formVersion2 = ActiveForms::FormVersion.new(
|
23
|
+
:code => "1.1", :name => "Poprawki", :status => "inactive",
|
24
|
+
:description => "Druga wersja wniosku",
|
25
|
+
:creationDate => "2007-01-02 12:00:00+0100", :isPrintable => "true")
|
26
|
+
formVersion3 = ActiveForms::FormVersion.new(
|
27
|
+
:code => "1.2", :name => "Poprawki 2", :status => "inactive",
|
28
|
+
:description => "Trzecia wersja wniosku",
|
29
|
+
:creationDate => "2007-01-03 12:00:00+0100", :isPrintable => "true")
|
30
|
+
|
31
|
+
assert @versions.include?(formVersion1)
|
32
|
+
assert @versions.include?(formVersion2)
|
33
|
+
assert @versions.include?(formVersion3)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class ActiveForms::RequestTest < Test::Unit::TestCase
|
@@ -6,12 +8,12 @@ class ActiveForms::RequestTest < Test::Unit::TestCase
|
|
6
8
|
|
7
9
|
context "GET request" do
|
8
10
|
setup do
|
9
|
-
@request = ActiveForms::Request.new(:get, "forms", :param => "a&b value", :apiTimestamp =>
|
11
|
+
@request = ActiveForms::Request.new(:get, "forms", :param => "a&b value", :apiTimestamp => "2010-02-18T01:18:19.210+0200", :apiParam => "apiValue", :apiKey => "fake", :apiVersion => "fake", :apiSig => "fake")
|
10
12
|
end
|
11
13
|
|
12
14
|
should "recognize params and apiParams" do
|
13
15
|
assert_equal "a&b value", @request.params["param"]
|
14
|
-
assert_equal "2010-02-18T01:18:19.
|
16
|
+
assert_equal "2010-02-18T01:18:19.210+0200", @request.api_params["apiTimestamp"]
|
15
17
|
end
|
16
18
|
|
17
19
|
should "set apiKey, apiVersion and apiSig params by itself" do
|
@@ -21,11 +23,11 @@ class ActiveForms::RequestTest < Test::Unit::TestCase
|
|
21
23
|
end
|
22
24
|
|
23
25
|
should "have apiSig counted" do
|
24
|
-
assert_equal "
|
26
|
+
assert_equal "4d249bdd51f7da5fa4c9bfbdfc44ff5df291862b", @request.api_params["apiSig"]
|
25
27
|
end
|
26
28
|
|
27
29
|
should "have correct uri" do
|
28
|
-
assert_same_uri "https://api.example.com/client/forms?apiSig=
|
30
|
+
assert_same_uri "https://api.example.com/client/forms?apiSig=4d249bdd51f7da5fa4c9bfbdfc44ff5df291862b&apiKey=123456&apiTimestamp=2010-02-18T01%3A18%3A19.210%2B0200&apiVersion=3.0¶m=a%26b+value&apiParam=apiValue", @request.uri
|
29
31
|
end
|
30
32
|
|
31
33
|
should "have params escaped in uri" do
|
@@ -60,15 +62,15 @@ class ActiveForms::RequestTest < Test::Unit::TestCase
|
|
60
62
|
|
61
63
|
context "POST request" do
|
62
64
|
setup do
|
63
|
-
@request = ActiveForms::Request.new(:post, "forms", :param => "a&b value", :apiTimestamp =>
|
65
|
+
@request = ActiveForms::Request.new(:post, "forms", :param => "a&b value", :apiTimestamp => "2010-02-18T01:18:19.218+0200", :apiParam => "apiValue")
|
64
66
|
end
|
65
67
|
|
66
68
|
should "have api_sig counted" do
|
67
|
-
assert_equal "
|
69
|
+
assert_equal "eaeb701de3bb1450859ef16eb9fda5c7db407e38", @request.api_params["apiSig"]
|
68
70
|
end
|
69
71
|
|
70
72
|
should "have correct uri" do
|
71
|
-
assert_same_uri "https://api.example.com/client/forms?apiSig=
|
73
|
+
assert_same_uri "https://api.example.com/client/forms?apiSig=eaeb701de3bb1450859ef16eb9fda5c7db407e38&apiKey=123456&apiTimestamp=2010-02-18T01%3A18%3A19.218%2B0200&apiVersion=3.0&apiParam=apiValue", @request.uri
|
72
74
|
end
|
73
75
|
end
|
74
76
|
|
@@ -80,21 +82,21 @@ class ActiveForms::RequestTest < Test::Unit::TestCase
|
|
80
82
|
|
81
83
|
should "be equivalent to Request.new(:post, path).perform" do
|
82
84
|
request = ActiveForms::Request.new(:post, "forms", :param => "value")
|
83
|
-
assert_equal @response, request.perform
|
85
|
+
assert_equal @response.parsed_response, request.perform.parsed_response
|
84
86
|
end
|
85
87
|
end
|
86
88
|
|
87
89
|
context "DELETE request" do
|
88
90
|
setup do
|
89
|
-
@request = ActiveForms::Request.new(:delete, "forms", :param => "a&b value", :apiTimestamp =>
|
91
|
+
@request = ActiveForms::Request.new(:delete, "forms", :param => "a&b value", :apiTimestamp => "2010-02-18T01:18:19.218+0200", :apiParam => "apiValue")
|
90
92
|
end
|
91
93
|
|
92
94
|
should "have api_sig counted" do
|
93
|
-
assert_equal "
|
95
|
+
assert_equal "3d82ae9adde6db7cf3b4ef0d35e411f0cc6b1e42", @request.api_params["apiSig"]
|
94
96
|
end
|
95
97
|
|
96
98
|
should "have correct uri" do
|
97
|
-
assert_same_uri "https://api.example.com/client/forms?apiSig=
|
99
|
+
assert_same_uri "https://api.example.com/client/forms?apiSig=3d82ae9adde6db7cf3b4ef0d35e411f0cc6b1e42&apiKey=123456&apiTimestamp=2010-02-18T01%3A18%3A19.218%2B0200&apiVersion=3.0&apiParam=apiValue", @request.uri
|
98
100
|
end
|
99
101
|
end
|
100
102
|
|
@@ -106,7 +108,7 @@ class ActiveForms::RequestTest < Test::Unit::TestCase
|
|
106
108
|
|
107
109
|
should "be equivalent to Request.new(:delete, path).perform" do
|
108
110
|
request = ActiveForms::Request.new(:delete, "forms", :param => "value")
|
109
|
-
assert_equal @response, request.perform
|
111
|
+
assert_equal @response.parsed_response, request.perform.parsed_response
|
110
112
|
end
|
111
113
|
end
|
112
114
|
end
|