cresca_brasil_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.project ADDED
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>cresca_brasil_api</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>org.radrails.rails.core.railsnature</nature>
16
+ <nature>com.aptana.ruby.core.rubynature</nature>
17
+ </natures>
18
+ </projectDescription>
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+ #interface to your soap service
3
+ gemspec
4
+
5
+ gem "savon", "~> 2.1.0"
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler"
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ require "cresca_brasil_api/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "cresca_brasil_api"
8
+ s.version = CrescaBrasilApi::VERSION
9
+ s.authors = ["Tarik"]
10
+ s.email = ["tarik@boschi.com.br"]
11
+ s.homepage = "http://www.boschi.com.br"
12
+ s.summary = %q{API Cresça Brasil}
13
+ s.description = %q{GEM para integração com a API da Cresça Brasil}
14
+
15
+ s.rubyforge_project = "cresca_brasil_api"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'savon', '~> 2.1.0'
23
+
24
+ # specify any dependencies here; for example:
25
+ # s.add_development_dependency "rspec"
26
+ # s.add_runtime_dependency "rest-client"
27
+ end
@@ -0,0 +1,29 @@
1
+ require 'savon'
2
+ require 'active_support/core_ext/class/attribute_accessors'
3
+ require 'active_support/core_ext/module/attribute_accessors'
4
+ require 'active_support/core_ext/hash'
5
+ require 'builder'
6
+ [:version,:connection, :course, :passport].each { |lib| require "cresca_brasil_api/#{lib}" }
7
+
8
+ module CrescaBrasilApi
9
+ class Production
10
+ URL = "http://api.crescabrasil.com.br/"
11
+ end
12
+
13
+ class Development
14
+ URL = "http://apibeta.crescabrasil.com.br/"
15
+ end
16
+
17
+ @@environment = :development
18
+ mattr_accessor :environment
19
+ @@login = ""
20
+ mattr_accessor :login
21
+ @@password = ""
22
+ mattr_accessor :password
23
+
24
+ def self.setup
25
+ yield self
26
+ end
27
+
28
+ class MissingArgumentError < StandardError; end
29
+ end
@@ -0,0 +1,40 @@
1
+ #encoding: utf-8
2
+ module CrescaBrasilApi
3
+ class Connection
4
+ attr_reader :environment
5
+ def initialize
6
+ @environment = eval(CrescaBrasilApi.environment.to_s.capitalize)
7
+ end
8
+
9
+ def request(service, method, version, xml)
10
+ client = client_savon(service, true)
11
+ response = client.call(method) do
12
+ message({:versao => version, :xmlParametros => xml})
13
+ end
14
+ get_response(method, response.body.to_hash)
15
+ end
16
+
17
+ def view_operations(service)
18
+ client = client_savon(service, false)
19
+ client.operations
20
+ end
21
+
22
+ private
23
+ def client_savon(service, authenticate)
24
+ soap_header = {"AutenticacaoServico" => {email: CrescaBrasilApi.login, senha: CrescaBrasilApi.password}}
25
+ url = "#{self.environment::URL}#{service}.asmx?WSDL"
26
+ namespace = {"xmlns" => "http://tempuri.org/"}
27
+ if authenticate
28
+ client = Savon.client(wsdl: url, soap_header: soap_header, namespaces: namespace)
29
+ else
30
+ client = Savon.client(wsdl: url)
31
+ end
32
+ end
33
+
34
+ def get_response(method, data)
35
+ response = "#{method}_response".to_sym
36
+ result = "#{method}_result".to_sym
37
+ data[response][result]
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,22 @@
1
+ module CrescaBrasilApi
2
+ class Course
3
+ def initialize
4
+ @connection = CrescaBrasilApi::Connection.new
5
+ end
6
+
7
+ def get_all_course(version, category = 0)
8
+ xml = "<curso><id_categoria>#{category}</id_categoria></curso>"
9
+ @connection.request("curso", :consultar_cursos_online, version, xml)
10
+ end
11
+
12
+ def get_all_course_for_rescue(version, category = 0)
13
+ xml = "<curso><id_categoria>#{category}</id_categoria></curso>"
14
+ @connection.request("curso", :consultar_cursos_resgate, version, xml)
15
+ end
16
+
17
+ def get_all_category(version, language = "pt-BR")
18
+ xml = "<categoria><idioma>#{language}</idioma></categoria>"
19
+ @connection.request("curso", :consultar_categorias, version, xml)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ module CrescaBrasilApi
2
+ class Passport
3
+ def initialize
4
+ @connection = CrescaBrasilApi::Connection.new
5
+ end
6
+
7
+ def generate(version, type_passport)
8
+ xml = "<passaporte><codigo_tipo>#{type_passport}</codigo_tipo><cliente></cliente></passaporte>"
9
+ @connection.request("passaporte", :gerar_passaporte, version, xml)
10
+ end
11
+
12
+ def generate_associated_course(version, type_passport, course_id)
13
+ xml = "<passaporte><codigo_tipo>#{type_passport}</codigo_tipo><codigo_curso>#{course_id}</codigo_curso><cliente></cliente></passaporte>"
14
+ @connection.request("passaporte", :gerar_passaporte_vinculado_ao_curso, version, xml)
15
+ end
16
+
17
+ def confirm_receive(version, passport_serie)
18
+ xml = "<passaporte><serie>#{passport_serie}</serie></passaporte>"
19
+ @connection.request("passaporte", :confirmar_passaporte, version, xml)
20
+ end
21
+
22
+ def cancel
23
+ xml = "<passaporte><serie>#{passport_serie}</serie></passaporte>"
24
+ @connection.request("passaporte", :cancelar_passaporte, version, xml)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module CrescaBrasilApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,13 @@
1
+ module CrescaBrasilApi
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("../../templates",__FILE__)
5
+
6
+ desc "Cria o initializer da CrescaBrasilApi na app rails"
7
+
8
+ def copy_initializer
9
+ template "cresca_brasil_api.rb", "config/initializers/cresca_brasil_api.rb"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ # Use esse arquivo para configurar a integração com a Cresca Brasil.
3
+ CrescaBrasilApi.setup do |config|
4
+ env = Rails.env
5
+ if(env == "production")
6
+ config.environment = :production
7
+ config.login = ""
8
+ config.password = ""
9
+ else
10
+ config.environment = :development
11
+ config.login = ""
12
+ config.password = ""
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cresca_brasil_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tarik
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: savon
16
+ requirement: &19954248 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *19954248
25
+ description: GEM para integração com a API da Cresça Brasil
26
+ email:
27
+ - tarik@boschi.com.br
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - .project
34
+ - Gemfile
35
+ - Rakefile
36
+ - cresca_brasil_api.gemspec
37
+ - lib/cresca_brasil_api.rb
38
+ - lib/cresca_brasil_api/connection.rb
39
+ - lib/cresca_brasil_api/course.rb
40
+ - lib/cresca_brasil_api/passport.rb
41
+ - lib/cresca_brasil_api/version.rb
42
+ - lib/generators/cresca_brasil_api/install_generator.rb
43
+ - lib/generators/templates/cresca_brasil_api.rb
44
+ homepage: http://www.boschi.com.br
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project: cresca_brasil_api
64
+ rubygems_version: 1.8.16
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: API Cresça Brasil
68
+ test_files: []