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.
Files changed (41) hide show
  1. data/.gitignore +15 -19
  2. data/.travis.yml +10 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +3 -1
  5. data/README.md +31 -0
  6. data/Rakefile +3 -49
  7. data/active_forms.gemspec +16 -81
  8. data/lib/active_forms.rb +41 -15
  9. data/lib/active_forms/application.rb +3 -1
  10. data/lib/active_forms/application_print.rb +2 -0
  11. data/lib/active_forms/configuration.rb +3 -1
  12. data/lib/active_forms/entry.rb +51 -0
  13. data/lib/active_forms/entry_printout.rb +22 -0
  14. data/lib/active_forms/form.rb +3 -1
  15. data/lib/active_forms/form_version.rb +19 -0
  16. data/lib/active_forms/mapper.rb +2 -0
  17. data/lib/active_forms/request.rb +27 -8
  18. data/lib/active_forms/token.rb +18 -0
  19. data/lib/active_forms/version.rb +3 -0
  20. data/test/active_forms/application_print_test.rb +2 -0
  21. data/test/active_forms/application_test.rb +2 -0
  22. data/test/active_forms/entry_printout_test.rb +60 -0
  23. data/test/active_forms/entry_test.rb +125 -0
  24. data/test/active_forms/form_test.rb +2 -0
  25. data/test/active_forms/form_version_test.rb +37 -0
  26. data/test/active_forms/mapper_test.rb +2 -0
  27. data/test/active_forms/request_test.rb +14 -12
  28. data/test/active_forms/token_test.rb +33 -0
  29. data/test/active_forms_test.rb +2 -0
  30. data/test/fixtures/get_entries.xml +22 -0
  31. data/test/fixtures/get_entries_single.xml +14 -0
  32. data/test/fixtures/get_entrydata.xml +38 -0
  33. data/test/fixtures/get_entryprintout.xml +15 -0
  34. data/test/fixtures/get_formaccesstokens.xml +12 -0
  35. data/test/fixtures/get_forminfo.xml +21 -0
  36. data/test/fixtures/post_entrydata.xml +12 -0
  37. data/test/test_helper.rb +5 -4
  38. metadata +99 -32
  39. data/.document +0 -5
  40. data/README.rdoc +0 -7
  41. data/VERSION +0 -1
data/.gitignore CHANGED
@@ -1,21 +1,17 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
17
9
  coverage
18
- rdoc
10
+ doc/
11
+ lib/bundler/man
19
12
  pkg
20
-
21
- ## PROJECT::SPECIFIC
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ script: "rake test"
3
+ rvm:
4
+ - 1.8.7
5
+ - ree
6
+ - 1.9.2
7
+ - 1.9.3
8
+ branches:
9
+ only:
10
+ - master
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_forms.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2009 Michał Szajbe
1
+ Copyright (c) 2009 Monterail.com
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ [![Build Status](https://secure.travis-ci.org/monterail/active_forms.png?branch=master)](http://travis-ci.org/monterail/active_forms)
2
+
3
+ # ActiveForms
4
+
5
+ ActiveForms API wrapper.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'active_forms'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install active_forms
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create new Pull Request
28
+
29
+ ## Copyright
30
+
31
+ Copyright (c) 2009 Monterail.com. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,55 +1,9 @@
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
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
22
3
 
23
4
  require 'rake/testtask'
24
5
  Rake::TestTask.new(:test) do |test|
25
6
  test.libs << 'lib' << 'test'
26
- test.pattern = 'test/**/*_test.rb'
7
+ test.test_files = Dir.glob("test/**/*_test.rb")
27
8
  test.verbose = true
28
9
  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/active_forms.gemspec CHANGED
@@ -1,86 +1,21 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/active_forms/version', __FILE__)
5
3
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{active_forms}
8
- s.version = "0.2.1"
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Micha\xC5\x82 Szajbe"]
6
+ gem.email = ["michal.szajbe@gmail.com"]
7
+ gem.summary = %q{Active Forms API wrapper}
8
+ gem.homepage = "http://github.com/monterail/active_forms"
9
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
- ]
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
+ gem.name = "active_forms"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = ActiveForms::VERSION
63
16
 
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
17
+ gem.add_runtime_dependency "activesupport", ">= 0"
18
+ gem.add_runtime_dependency "httparty", ">= 0.5.2"
19
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 2.10.2"
20
+ gem.add_development_dependency "fakeweb", ">= 1.2.8"
85
21
  end
86
-
data/lib/active_forms.rb CHANGED
@@ -1,12 +1,22 @@
1
+ # encoding: UTF-8
2
+
1
3
  require 'active_support'
4
+ require 'active_support/core_ext/hash/indifferent_access'
5
+ require 'active_support/core_ext/string/inflections'
6
+ require 'active_support/core_ext/string/starts_ends_with'
2
7
 
3
8
  require 'active_forms/configuration'
4
9
  require 'active_forms/mapper'
5
10
  require 'active_forms/request'
11
+ require 'active_forms/version'
6
12
 
7
13
  require 'active_forms/application'
8
14
  require 'active_forms/application_print'
15
+ require 'active_forms/entry'
16
+ require 'active_forms/entry_printout'
9
17
  require 'active_forms/form'
18
+ require 'active_forms/form_version'
19
+ require 'active_forms/token'
10
20
 
11
21
  module ActiveForms
12
22
  class << self
@@ -16,21 +26,37 @@ module ActiveForms
16
26
  self.configuration ||= Configuration.new
17
27
  yield(configuration)
18
28
  end
29
+
30
+ def log(msg)
31
+ if configuration.logger
32
+ configuration.logger.info(msg)
33
+ end
34
+ end
19
35
  end
20
36
 
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
37
+ class Error < StandardError; end
38
+
39
+ class ApiKeyInvalid < Error; end
40
+ class ApiSigInvalid < Error; end
41
+ class ApiTimestampInvalid < Error; end
42
+ class ApiVersionNotSupported < Error; end
43
+ class ApplicationNotFound < Error; end
44
+ class ApplicationNotSent < Error; end
45
+ class BadParameterFormat < Error; end
46
+ class FieldNotFound < Error; end
47
+ class FieldNotMultiple < Error; end
48
+ class Forbidden < Error; end
49
+ class FormActiveVersionNotFound < Error; end
50
+ class FormNotFound < Error; end
51
+ class FormVersionNotFound < Error; end
52
+ class InternalServerError < Error; end
53
+ class MethodNotAllowed < Error; end
54
+ class MissingParameter < Error; end
55
+ class MissingResource < Error; end
56
+ class MissingVendor < Error; end
57
+ class NullResponse < Error; end
58
+ class OptionNotFound < Error; end
59
+ class ResourceNotSupported < Error; end
60
+ class TemplateNotFound < Error; end
61
+ class Unauthorized < Error; end
36
62
  end
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  class ActiveForms::Application < ActiveForms::Mapper
2
4
  columns :number, :formCode, :formVersion, :date, :status, :isPrintable, :fieldData
3
5
 
@@ -10,7 +12,7 @@ class ActiveForms::Application < ActiveForms::Mapper
10
12
  hashes = response["applications"]["application"]
11
13
  hashes = [hashes] if hashes.is_a?(Hash)
12
14
 
13
- objects = hashes.map { |attributes| new(attributes) }
15
+ objects = hashes.nil? ? [] : hashes.map { |attributes| new(attributes) }
14
16
  end
15
17
 
16
18
  # required params:
@@ -1,3 +1,5 @@
1
+ # encoding: UTF-8
2
+
1
3
  class ActiveForms::ApplicationPrint < ActiveForms::Mapper
2
4
  columns :formCode, :formVersionCode, :number, :date, :status, :contentType, :printContent
3
5
 
@@ -1,6 +1,8 @@
1
+ # encoding: UTF-8
2
+
1
3
  module ActiveForms
2
4
  class Configuration
3
- attr_accessor :api_url, :url, :base_url, :api_key, :secret_key
5
+ attr_accessor :api_url, :url, :base_url, :api_key, :secret_key, :logger
4
6
 
5
7
  def initialize
6
8
  @api_url = { :protocol => "https", :host => 'api.activeforms.com' }
@@ -0,0 +1,51 @@
1
+ # encoding: UTF-8
2
+
3
+ class ActiveForms::Entry < ActiveForms::Mapper
4
+ columns :number, :formCode, :formVersionCode, :date, :status, :isPrintable, :fieldData, :accessToken
5
+
6
+ class << self
7
+
8
+ def all(params = {})
9
+ response = ActiveForms::Request.get("entries", params)
10
+
11
+ hashes = response["entries"]["entry"]
12
+ hashes = [hashes] if hashes.is_a?(Hash)
13
+
14
+ objects = hashes.nil? ? [] : hashes.map { |attributes| new(attributes) }
15
+ end
16
+
17
+ # required params:
18
+ # apiFormCode - form's code
19
+ # apiNumber or apiEntryToken - entry's number or token
20
+ def find(params = {})
21
+ response = ActiveForms::Request.get("entrydata", params)
22
+
23
+ attributes = response["entryData"]
24
+
25
+ new(attributes)
26
+ end
27
+
28
+ # required params:
29
+ # apiFormCode
30
+ # field id
31
+ def create(params = {})
32
+ response = ActiveForms::Request.post("entrydata", params)
33
+
34
+ attributes = response["entryPutConfirmation"]
35
+
36
+ new(attributes)
37
+ end
38
+
39
+ # required params:
40
+ # apiFormCode
41
+ # apiNumber or apiEntryToken
42
+ def delete(params = {})
43
+ response = ActiveForms::Request.delete("entrydata", params)
44
+ response && response.code.to_i == 204
45
+ end
46
+ end
47
+
48
+ def destroy
49
+ ActiveForms::Entry.delete :apiFormCode => self.formCode, :apiNumber => self.number
50
+ end
51
+ end
@@ -0,0 +1,22 @@
1
+ # encoding: UTF-8
2
+
3
+ class ActiveForms::EntryPrintout < ActiveForms::Mapper
4
+ columns :formCode, :formVersionCode, :number, :date, :status, :contentType, :identifier, :printoutContent
5
+
6
+ class << self
7
+ # required params:
8
+ # apiFormCode - Form's code
9
+ # apiNumber - Application's number
10
+ def find(params = {})
11
+ response = ActiveForms::Request.get("entryprintout", params)
12
+
13
+ attributes = response["entryPrintout"]
14
+
15
+ new(attributes)
16
+ end
17
+ end
18
+
19
+ def printoutContent=(value)
20
+ @attributes["printoutContent"] = value.is_a?(String) ? value.strip : super
21
+ end
22
+ end