sgn 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,64 @@
1
+ # Sgn
2
+
3
+ ## Instalation
4
+ ```ruby
5
+ gem install sgn
6
+ require 'sgn'
7
+ ```
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ customer_number = "001"
13
+ customer_password = "118576708972562"
14
+
15
+ ws = Sgn::Webservice.new(customer_number, customer_password)
16
+ ws.get('busca_imoveis2', { 'itenspp' => 1 })
17
+
18
+ # {
19
+ # 'total' => 3,
20
+ # 'num_pags' => 3,
21
+ # 'imoveis' => {
22
+ # '0' => {
23
+ # 'ref' => '0092',
24
+ # 'preco' => '1.00',
25
+ # 'tipo' => 'Sobrado',
26
+ # 'cidade' => 'OSASCO'
27
+ # 'bairro' => 'QUITAÚNA'
28
+ # 'dormitorios' => nil,
29
+ # 'suite' => nil,
30
+ # 'garagem' => nil,
31
+ # 'descricao' => 'dgdsggsdsg SOBRADO LINDO',
32
+ # 'area_util' => nil,
33
+ # 'area_construida' => nil,
34
+ # 'area_terreno' => nil,
35
+ # 'finalidade' => 'L',
36
+ # 'cond_fechado' => 'N',
37
+ # 'saldo_devedor' => 'N',
38
+ # 'uso_imovel' => 'R',
39
+ # 'fotos' => [
40
+ # 'http://www.sgn2.com.br/clientes/customer/loc/pic1.jpg',
41
+ # 'http://www.sgn2.com.br/clientes/customer/loc/pic2.jpg'
42
+ # ],
43
+ # 'destaque' => 'N',
44
+ # 'plantao' => 'N',
45
+ # 'video_youtube' => nil,
46
+ # 'placa' => 'N',
47
+ # 'permuta' => 'N',
48
+ # 'iptu' => nil,
49
+ # 'valor_sem_bonificacao' => 1,
50
+ # 'regiao' => nil,
51
+ # 'endereco' => 'RUA JEQUIE, 12',
52
+ # 'banheiros' => nil,
53
+ # 'titulo_anuncio' => nil,
54
+ # 'caracteristicas' => nil,
55
+ # 'opcao' => 0,
56
+ # 'corretores' => { '0' => nil, '1' => nil }
57
+ # }
58
+ # }
59
+ # }
60
+
61
+ ```
62
+
63
+ ## Author
64
+ Marcelo Jacobus
@@ -0,0 +1,4 @@
1
+ module Sgn
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -0,0 +1,38 @@
1
+ require 'addressable/uri'
2
+ require 'net/http'
3
+ require 'json'
4
+
5
+ module Sgn
6
+ class Webservice
7
+ WS_HOST = 'www.sgn.com.br'
8
+ WS_BASE = '/webservice/'
9
+
10
+ def initialize(customer_id, password, version = 'sgn2')
11
+ @customer_id = customer_id
12
+ @password = password
13
+ @version = version
14
+ end
15
+
16
+ def get(service, params = {})
17
+ get_json(service, params)
18
+ end
19
+
20
+ private
21
+ def get_json(service, params = {})
22
+ params.merge!({
23
+ cliente: @customer_id,
24
+ senha: @password,
25
+ sistema: @version
26
+ })
27
+
28
+ klass = self.class
29
+ query_string = ::Addressable::URI.new(query_values: params).query
30
+ uri = [klass::WS_BASE, service, '.php?', query_string].join()
31
+ response = Net::HTTP.get_response(klass::WS_HOST, uri)
32
+ json = JSON.parse(response.body)
33
+ raise Error.new(json['msg']) if json['erro']
34
+ json
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,15 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start do
4
+ add_filter "spec"
5
+ end
6
+
7
+ require 'sgn'
8
+
9
+ Dir["./spec/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.filter_run :focus => true
14
+ config.run_all_when_everything_filtered = true
15
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sgn::Webservice, "#get" do
4
+ subject { described_class.new('customer_id', 'password')}
5
+ let(:params) { { limit: 10 } }
6
+ let(:expected_uri) { '/webservice/service.php?cliente=customer_id&limit=10&senha=password&sistema=sgn2' }
7
+
8
+ it "calls ws with correct params and parse json" do
9
+ response = stub(:response, body: '{"a":"b"}')
10
+
11
+ Net::HTTP.should_receive(:get_response)
12
+ .with('www.sgn.com.br', expected_uri).and_return(response)
13
+
14
+ subject.get('service', params).should eq({'a' => 'b'})
15
+ end
16
+
17
+ it "raises error when response.erro == true" do
18
+ response = stub(:response, body: '{"erro":true,"msg":"An error occurred"}')
19
+
20
+ Net::HTTP.should_receive(:get_response)
21
+ .with('www.sgn.com.br', expected_uri).and_return(response)
22
+
23
+ expect { subject.get('service', params) }.to raise_error(Sgn::Error, "An error occurred")
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sgn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -113,7 +113,12 @@ executables: []
113
113
  extensions: []
114
114
  extra_rdoc_files: []
115
115
  files:
116
+ - README.md
116
117
  - lib/sgn.rb
118
+ - lib/sgn/webservice.rb
119
+ - lib/sgn/error.rb
120
+ - spec/svg/webservice_spec.rb
121
+ - spec/spec_helper.rb
117
122
  homepage: https://github.com/mjacobus/sgn
118
123
  licenses: []
119
124
  post_install_message:
@@ -137,5 +142,7 @@ rubyforge_project:
137
142
  rubygems_version: 1.8.24
138
143
  signing_key:
139
144
  specification_version: 3
140
- summary: Webservice para o sistema imobiliário http://www.sgn.com.br
141
- test_files: []
145
+ summary: Webservice para Imobiliárias
146
+ test_files:
147
+ - spec/svg/webservice_spec.rb
148
+ - spec/spec_helper.rb