iesde 1.1.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README-OLD-API.md +258 -0
  4. data/README.md +137 -177
  5. data/examples/aulas/buscar.rb +45 -0
  6. data/examples/aulas/link_video.rb +36 -0
  7. data/examples/disciplinas/aulas.rb +30 -0
  8. data/examples/disciplinas/buscar.rb +27 -0
  9. data/examples/disciplinas/link_pdf.rb +14 -0
  10. data/examples/matriculas/ativar.rb +33 -0
  11. data/examples/matriculas/buscar.rb +15 -0
  12. data/examples/matriculas/criar.rb +38 -0
  13. data/examples/matriculas/criar_com_campos_obrigatorios.rb +20 -0
  14. data/iesde.gemspec +12 -3
  15. data/lib/concerns/linkable.rb +6 -0
  16. data/lib/concerns/stringable.rb +7 -0
  17. data/lib/concerns/underscorable.rb +13 -0
  18. data/lib/iesde.rb +28 -16
  19. data/lib/iesde/api.rb +109 -0
  20. data/lib/iesde/api/alterar_status_matricula.rb +9 -0
  21. data/lib/iesde/api/criar_matricula.rb +13 -0
  22. data/lib/iesde/api/obter_aula.rb +12 -0
  23. data/lib/iesde/api/obter_dados_pdf.rb +9 -0
  24. data/lib/iesde/api/obter_disciplina.rb +11 -0
  25. data/lib/iesde/api/obter_link_pdf.rb +10 -0
  26. data/lib/iesde/api/obter_matricula.rb +11 -0
  27. data/lib/iesde/api/obter_video.rb +11 -0
  28. data/lib/iesde/config.rb +2 -2
  29. data/lib/iesde/model/aula.rb +12 -21
  30. data/lib/iesde/model/disciplina.rb +45 -0
  31. data/lib/iesde/model/matricula.rb +43 -23
  32. data/lib/iesde/request.rb +70 -0
  33. data/lib/iesde/version.rb +1 -1
  34. metadata +171 -30
  35. data/lib/iesde/clients/buscararquivo.rb +0 -28
  36. data/lib/iesde/clients/cadastro.rb +0 -32
  37. data/lib/iesde/clients/inativa_acesso.rb +0 -21
  38. data/lib/iesde/clients/lista_curso.rb +0 -22
  39. data/lib/iesde/clients/logout.rb +0 -34
  40. data/lib/iesde/clients/obtem_aulas.rb +0 -21
  41. data/lib/iesde/clients/obtem_matriculas.rb +0 -23
  42. data/lib/iesde/error/validation_error.rb +0 -6
  43. data/lib/iesde/model/aluno.rb +0 -21
  44. data/lib/iesde/model/curso.rb +0 -113
  45. data/lib/iesde/wsdl_client.rb +0 -79
@@ -0,0 +1,45 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+ require "awesome_print"
3
+ require 'iesde'
4
+
5
+ IDS = [ Expected_ids]
6
+
7
+ def call_with_config_params
8
+ aulas_com_config = Iesde::Model::Aula.buscar({
9
+ 'MatriculaID' => 12345,
10
+ 'DisciplinaID' => 123,
11
+ config: {
12
+ user: ENV['IESDE_USER'],
13
+ password: ENV['IESDE_PWD'],
14
+ ead_api_key: ENV['EAD_API_KEY']
15
+ }
16
+ })
17
+
18
+ puts aulas_com_config.size == IDS.length
19
+
20
+ puts aulas_com_config.map(&:matricula_id) == IDS
21
+
22
+ puts aulas_com_config.map(&:to_s)
23
+ end
24
+
25
+ def simple_call
26
+ Iesde.configure do |c|
27
+ c.user = ENV['IESDE_USER']
28
+ c.password = ENV['IESDE_PWD']
29
+ c.ead_api_key = ENV['EAD_API_KEY']
30
+ end
31
+
32
+ aulas = Iesde::Model::Aula.buscar({
33
+ 'MatriculaID' => 12345,
34
+ 'DisciplinaID' => 123
35
+ })
36
+
37
+ ap aulas.size == IDS.length
38
+
39
+ ap aulas.map(&:matricula_id) == IDS
40
+ puts aulas.map(&:to_s)
41
+ end
42
+
43
+ call_with_config_params
44
+
45
+ simple_call
@@ -0,0 +1,36 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+ require "awesome_print"
3
+ require 'iesde'
4
+
5
+ # chamada passando parametros de configuracoes
6
+ def call_with_config_params
7
+ aulas = Iesde::Model::Aula.buscar({
8
+ 'MatriculaID' => 12345,
9
+ 'DisciplinaID' => 123,
10
+ config: {
11
+ user: ENV['IESDE_USER'],
12
+ password: ENV['IESDE_PWD'],
13
+ ead_api_key: ENV['EAD_API_KEY']
14
+ }
15
+ })
16
+
17
+ ap aulas.first.link_video
18
+ end
19
+
20
+ def simple_call
21
+ Iesde.configure do |c|
22
+ c.user = ENV['IESDE_USER']
23
+ c.password = ENV['IESDE_PWD']
24
+ c.ead_api_key = ENV['EAD_API_KEY']
25
+ end
26
+
27
+ aulas = Iesde::Model::Aula.buscar({
28
+ 'MatriculaID' => 12345,
29
+ 'DisciplinaID' => 123
30
+ })
31
+
32
+ ap aulas.first.link_video
33
+ end
34
+
35
+ simple_call
36
+ call_with_config_params
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+ require "awesome_print"
3
+ require 'iesde'
4
+
5
+ # chamada passando parametros de configuracoes
6
+ def call_with_config_params
7
+ disciplina = Iesde::Model::Disciplina.buscar(
8
+ config: {
9
+ user: ENV['IESDE_USER'],
10
+ password: ENV['IESDE_PWD'],
11
+ ead_api_key: ENV['EAD_API_KEY']
12
+ }).select {|d| d.disciplina_id.to_i == 123 }.first
13
+
14
+ ap disciplina.aulas(12345)
15
+ end
16
+
17
+ def simple_call
18
+ Iesde.configure do |c|
19
+ c.user = ENV['IESDE_USER']
20
+ c.password = ENV['IESDE_PWD']
21
+ c.ead_api_key = ENV['EAD_API_KEY']
22
+ end
23
+
24
+ disciplina = Iesde::Model::Disciplina.buscar.select {|d| d.disciplina_id.to_i == 123 }.first
25
+
26
+ ap disciplina.aulas(12345)
27
+ end
28
+
29
+ call_with_config_params
30
+ simple_call
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+ require "awesome_print"
3
+ require 'iesde'
4
+
5
+ def simple_call
6
+ Iesde.configure do |c|
7
+ c.user = ENV['IESDE_USER']
8
+ c.password = ENV['IESDE_PWD']
9
+ c.ead_api_key = ENV['EAD_API_KEY']
10
+ end
11
+
12
+ disciplinas = Iesde::Model::Disciplina.buscar()
13
+
14
+ ap disciplinas
15
+ end
16
+
17
+ def call_with_config_params
18
+ disciplinas = Iesde::Model::Disciplina.buscar(config: {
19
+ user: ENV['IESDE_USER'],
20
+ password: ENV['IESDE_PWD'],
21
+ ead_api_key: ENV['EAD_API_KEY']
22
+ })
23
+
24
+ ap disciplinas
25
+ end
26
+
27
+ call_with_config_params
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+ require "awesome_print"
3
+ require 'iesde'
4
+
5
+ Iesde.configure do |c|
6
+ c.user = ENV['IESDE_USER']
7
+ c.password = ENV['IESDE_PWD']
8
+ c.ead_api_key = ENV['EAD_API_KEY']
9
+ end
10
+
11
+ disciplina = Iesde::Model::Disciplina.buscar.select {|d| d.disciplina_id.to_i == 123 }.first
12
+
13
+ link_pdf = disciplina.pdf(12345)
14
+ ap link_pdf
@@ -0,0 +1,33 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+ require "awesome_print"
3
+ require 'iesde'
4
+
5
+ def simple_call
6
+ Iesde.configure do |c|
7
+ c.user = ENV['IESDE_USER']
8
+ c.password = ENV['IESDE_PWD']
9
+ c.ead_api_key = ENV['EAD_API_KEY']
10
+ end
11
+
12
+ matricula = Iesde::Model::Matricula.buscar.first
13
+ ap matricula.ativar!
14
+
15
+ ap matricula
16
+ end
17
+
18
+
19
+ def call_with_config_params
20
+ matricula = Iesde::Model::Matricula.buscar(
21
+ config:{
22
+ user: ENV['IESDE_USER'],
23
+ password: ENV['IESDE_PWD'],
24
+ ead_api_key: ENV['EAD_API_KEY']
25
+ }).first
26
+ ap matricula.ativar!
27
+
28
+ ap matricula
29
+ end
30
+
31
+
32
+ simple_call
33
+ call_with_config_params
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+ require "awesome_print"
3
+ require 'iesde'
4
+
5
+ config = {
6
+ config: {
7
+ user: ENV['IESDE_USER'],
8
+ password: ENV['IESDE_PWD'],
9
+ ead_api_key: ENV['EAD_API_KEY']
10
+ }
11
+ }
12
+
13
+ matricula = Iesde::Model::Matricula.buscar(config)
14
+ require 'pry'; binding.pry
15
+ ap matricula
@@ -0,0 +1,38 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+ require "awesome_print"
3
+ require 'iesde'
4
+
5
+ Iesde.configure do |c|
6
+ c.user = ENV['IESDE_USER']
7
+ c.password = ENV['IESDE_PWD']
8
+ c.ead_api_key = ENV['EAD_API_KEY']
9
+ end
10
+
11
+ # Criar matriculas
12
+ cpf = '82432858816'
13
+ cpf_errado = '04992817564'
14
+
15
+ params = {
16
+ 'CursoID' => 12345 ,
17
+ 'PoloID' => 1,
18
+ 'Nome' => 'Usuario Legal',
19
+ 'CPF' => cpf,
20
+ 'Email' => 'usuario@muitolegal.com',
21
+ 'RG' => '2003000152000',
22
+ 'OrgaoRG' => 'Pulmão',
23
+ 'UFRG' => 'CE',
24
+ 'CEP' => '60120-140',
25
+ 'Endereco' => 'Rua dos Anzois Pereira',
26
+ 'Bairro' => 'BEM LONGE',
27
+ 'Numero' => 123,
28
+ 'Compl' => 'Bloco Z apto 500',
29
+ 'Telefone' => '8588889999',
30
+ 'Celular' => '8599999999',
31
+ 'DtNascto' => '06/01/1966',
32
+ 'EstadoCivil' => 1,
33
+ 'Sexo' => 'M'
34
+ }
35
+
36
+ matricula = Iesde::Model::Matricula.criar(params)
37
+
38
+ ap matricula
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
+ require "awesome_print"
3
+ require 'iesde'
4
+
5
+ Iesde.configure do |c|
6
+ c.user = ENV['IESDE_USER']
7
+ c.password = ENV['IESDE_PWD']
8
+ c.ead_api_key = ENV['EAD_API_KEY']
9
+ end
10
+
11
+ matricula = Iesde::Model::Matricula.criar_com_campos_obrigatorios(
12
+ 123456,
13
+ 'Heron Da Silva',
14
+ '83550113501',
15
+ 'heron@email2.com',
16
+ '60120-140',
17
+ 123
18
+ )
19
+
20
+ ap matricula
data/iesde.gemspec CHANGED
@@ -6,10 +6,10 @@ require 'iesde/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "iesde"
8
8
  spec.version = Iesde::VERSION
9
- spec.authors = ["Pedro Benevides"]
10
- spec.email = ["pedroaugusto@gmail.com"]
9
+ spec.authors = ["Pedro Benevides", "Heron Medeiros"]
10
+ spec.email = ["pedroaugusto@gmail.com", "heron.medeiros@gmail.com"]
11
11
 
12
- spec.summary = "Client do WebService SOAP do IESDE"
12
+ spec.summary = "Client do WebService REST do IESDE"
13
13
  spec.description = "Esta não é uma versão oficial"
14
14
  spec.homepage = "https://github.com/fortesinformatica/iesde"
15
15
  spec.license = "MIT"
@@ -24,5 +24,14 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency "savon", "~> 2.10"
25
25
  spec.add_dependency "json", "~> 1.7"
26
26
  spec.add_dependency "activesupport", "~> 4.2"
27
+ spec.add_dependency "actionview"
28
+ spec.add_dependency "net-http-digest_auth"
27
29
 
30
+ spec.add_development_dependency "rspec"
31
+ spec.add_development_dependency "awesome_print"
32
+ spec.add_development_dependency "pry"
33
+ spec.add_development_dependency "pry-byebug"
34
+ spec.add_development_dependency "vcr"
35
+ spec.add_development_dependency "webmock"
36
+ spec.add_development_dependency 'simplecov'
28
37
  end
@@ -0,0 +1,6 @@
1
+ module Linkable
2
+ def link
3
+ return unless @response
4
+ @response.gsub(/"/, '').gsub(/\\/, '')
5
+ end
6
+ end
@@ -0,0 +1,7 @@
1
+ module Stringable
2
+ def to_s
3
+ instance_variables.map do |v|
4
+ "#{v[1..-1]}: #{instance_variable_get(v)}"
5
+ end.join(', ' )
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module Underscorable
2
+ def underscorize_fields model
3
+ as_json.map do |reco|
4
+ params = {}
5
+
6
+ reco.map do |key, value|
7
+ params[key.underscore.to_sym] = value
8
+ end
9
+
10
+ model.new(*params.values)
11
+ end
12
+ end
13
+ end
data/lib/iesde.rb CHANGED
@@ -1,34 +1,47 @@
1
1
  require 'active_support/core_ext/module/attribute_accessors'
2
2
  require 'active_support/inflector'
3
+ require 'action_view'
3
4
  require 'json'
4
- require 'savon'
5
+ require 'net/http'
6
+ require 'net/http/digest_auth'
7
+ require 'uri'
8
+ require "awesome_print"
9
+ require "pry"
5
10
 
6
11
  module Iesde
12
+ autoload :Request, 'iesde/request'
13
+ autoload :API, 'iesde/api'
14
+
15
+ module Api
16
+ autoload :ObterMatricula, "iesde/api/obter_matricula"
17
+ autoload :CriarMatricula, "iesde/api/criar_matricula"
18
+ autoload :AlterarStatusMatricula, "iesde/api/alterar_status_matricula"
19
+ autoload :ObterDisciplina, "iesde/api/obter_disciplina"
20
+ autoload :ObterAula, "iesde/api/obter_aula"
21
+ autoload :ObterDadosPdf, "iesde/api/obter_dados_pdf"
22
+ autoload :ObterLinkPdf, "iesde/api/obter_link_pdf"
23
+ autoload :ObterVideo, "iesde/api/obter_video"
24
+ end
25
+
7
26
  module Clients
8
27
  autoload :ListaCurso,"iesde/clients/lista_curso"
9
- autoload :ObtemAula,"iesde/clients/obtem_aulas"
10
- autoload :ObtemMatricula,"iesde/clients/obtem_matriculas"
11
- autoload :Cadastro,"iesde/clients/cadastro"
12
- autoload :InativaAcesso,"iesde/clients/inativa_acesso"
13
- autoload :Logout,"iesde/clients/logout"
14
- autoload :Buscararquivo,"iesde/clients/buscararquivo"
15
28
  end
16
29
 
17
30
  module Error
18
- autoload :ValidationError,'iesde/error/validation_error'
19
31
  autoload :WSError,'iesde/error/ws_error'
20
32
  end
21
33
 
22
34
  module Model
23
- autoload :Curso,"iesde/model/curso"
24
- autoload :Aula,"iesde/model/aula"
25
- autoload :Matricula,"iesde/model/matricula"
26
- autoload :Aluno,"iesde/model/aluno"
35
+ autoload :Matricula, "iesde/model/matricula"
36
+ autoload :Disciplina, "iesde/model/disciplina"
37
+ autoload :Aula, "iesde/model/aula"
27
38
  end
28
39
 
29
- autoload :VERSION, "iesde/version"
30
- autoload :Config,"iesde/config"
31
- autoload :WSDLClient,"iesde/wsdl_client"
40
+ autoload :VERSION, "iesde/version"
41
+ autoload :Config, "iesde/config"
42
+ autoload :Linkable, "concerns/linkable"
43
+ autoload :Underscorable, "concerns/underscorable"
44
+ autoload :Stringable, "concerns/stringable"
32
45
 
33
46
  mattr_accessor :config
34
47
 
@@ -36,5 +49,4 @@ module Iesde
36
49
  self.config ||= Iesde::Config.new
37
50
  yield(config) if block_given?
38
51
  end
39
-
40
52
  end
data/lib/iesde/api.rb ADDED
@@ -0,0 +1,109 @@
1
+ module Iesde
2
+ class API
3
+ include ActionView::Helpers::SanitizeHelper
4
+
5
+ def initialize(o_que, format, opts = {})
6
+ tipo = tipo_requisicao(o_que)
7
+ config_api(opts)
8
+
9
+ params = config_params(opts)
10
+ request = Request.new(tipo, format, api_hash)
11
+ @response = request.execute(params)
12
+ end
13
+
14
+ def as_json
15
+ return JSON.parse(@response)
16
+ rescue JSON::ParserError
17
+ return @response
18
+ end
19
+
20
+ def status
21
+ as_json["status"]
22
+ end
23
+
24
+ def tem_chave?(chave)
25
+ as_json.has_key?(chave)
26
+ end
27
+
28
+ def tem_matricula?
29
+ tem_chave?("MatriculaID")
30
+ end
31
+
32
+ def salvo_com_sucesso?
33
+ status == 1 && tem_matricula?
34
+ end
35
+
36
+ def msg
37
+ msg = (status() == false) ? as_json['mensagem'] : as_json['msg']
38
+ sanitize(msg)
39
+ end
40
+
41
+ def self.build_url(ask_for, format)
42
+ [ BASE, WEB_SERVICE, ask_for, 'format', FORMATS[format]].join('/')
43
+ end
44
+
45
+ def tipo_requisicao(o_que)
46
+ strings = {
47
+ cursos: 'getCursos',
48
+ matriculas: 'getMatriculas',
49
+ grades: 'getGrades',
50
+ questoes: 'getBancoQuestoes',
51
+ alternativas: 'getAlternativas',
52
+ disciplinas: 'getDisciplinas',
53
+ processos: 'getProcSeletivos',
54
+ notas: 'notas',
55
+ acessos: 'getAcessos',
56
+ professores: 'getProfessor',
57
+ cadastro_matricula: 'cadastro',
58
+ info_pessoa: 'getInfoPessoa',
59
+ alterar_matricula: 'situacao',
60
+ aulas: 'getAulas',
61
+ video_aula: 'getVideoAula',
62
+ pdf: 'getPdfsDisciplina',
63
+ get_pdf: 'getPdf'
64
+ }
65
+
66
+ strings.fetch(o_que)
67
+ rescue ArgumentError => e
68
+ raise 'Você precisa passar um tipo de requisição válido'
69
+ end
70
+
71
+ FORMATS = { json: "json", html: 'html', xml: 'xml' }
72
+ BASE = 'http://ead.portalava.com.br'
73
+ WEB_SERVICE = 'web_service'
74
+
75
+ private
76
+
77
+ def config_params(opts)
78
+ opts.reject { |k,_| k == :config }
79
+ end
80
+
81
+ def config_api(opts = {})
82
+ unless opts.has_key?(:config)
83
+ ap '===> usando config original' if ENV['DEBUG']
84
+ opts.merge!(config: {})
85
+ end
86
+
87
+ # opts.merge!(config: {}) unless opts.has_key?(:config)
88
+
89
+ _config = opts[:config]
90
+
91
+ @user = _config[:user] || Iesde.config.user
92
+ @password = _config[:password] || Iesde.config.password
93
+ @ead_api_key = _config[:ead_api_key] || Iesde.config.ead_api_key
94
+
95
+ rescue NoMethodError => e
96
+ raise 'Você precisa configurar usuario e password'
97
+ end
98
+
99
+ def api_hash
100
+ {
101
+ config: {
102
+ user: @user,
103
+ password: @password,
104
+ ead_api_key: @ead_api_key
105
+ }
106
+ }
107
+ end
108
+ end
109
+ end