witei_web_api 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ff86af65124a22f14b2a6c047eba2dfd8a326fd61e44cc46b7e2b68173dc1886
4
- data.tar.gz: d0090260665754d8d95ae9c51b2e11dd8be4d09ff8f06e1db33bf3d97a90fc26
3
+ metadata.gz: ef7ae971b1b5c8710e2d84df99059690b8d5793c0357be1eec2a330f19dc8898
4
+ data.tar.gz: 34c882511b11b6e9bb56e9bc30480d4e08023f44aa4f5afb26f03e817e1216bf
5
5
  SHA512:
6
- metadata.gz: 1e70f5a774f33a57a3326f1c73d4048bc0f9d1d3e5fab51c72c2f652031f007d735e87070d8b9100d65fd6373748a1fde5d0b9d18c7402b809707a75bf6a59d6
7
- data.tar.gz: ce07c85a6c082e61f181db5d0a4b61573ac25e060ffd52fb4b45ffac10332943dde6deda7dbdd947be4a8d3217664b520284394955dca0655bbee48722aa8ffe
6
+ metadata.gz: 0aac2f6a738ecb3f8526a4c03eac43b29282060f51cba3b04cf57455c5b0bd451f23ff5164674079b32cd2b1dc3e92275e3cc3440b848e077fd9330d45803b6c
7
+ data.tar.gz: 1ad0754a9ff942f9f9996eaea74ee714a693a43be13647f2e20f91a0ad3da967a5c9662d272aef0840e0dce516cb513f1f6560fc3384cdd4ddffe7b6fee1eae1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- witei_web_api (0.1.2)
4
+ witei_web_api (0.2.0)
5
5
  activemodel (~> 5.0)
6
6
  mechanize (~> 2.7)
7
7
 
@@ -92,4 +92,4 @@ DEPENDENCIES
92
92
  yard (~> 0.9, >= 0.9.11)
93
93
 
94
94
  BUNDLED WITH
95
- 1.16.4
95
+ 1.17.1
@@ -9,25 +9,23 @@ module WiteiWebApi
9
9
  def self.agent
10
10
  Thread.current[:witei_web_api_agent] ||= begin
11
11
  agent = WiteiWebApi::Agent.new
12
- login!(agent)
12
+ login(agent)
13
13
  agent
14
14
  end
15
15
  end
16
16
 
17
- def self.login(agent, login, password)
18
- page = agent.get 'https://witei.com/pro/accounts/login/?next=/pro/agencies/dashboard/'
17
+ def self.login(agent, login: WiteiWebApi.login, password: WiteiWebApi.password, uri: nil)
18
+ uri ||= '/pro/agencies/dashboard/'
19
+ page = agent.get("https://witei.com/pro/accounts/login/?next=#{CGI.escape(uri)}")
19
20
 
20
- form = page.form_with class: 'form-horizontal'
21
+ form = page.form_with(class: 'form-horizontal')
21
22
  form.login = login
22
23
  form.password = password
23
- x = form.submit
24
- x.uri.path == '/pro/agencies/dashboard/'
25
- end
26
-
27
- def self.login!(agent)
28
- unless login(agent, WiteiWebApi.login, WiteiWebApi.password)
24
+ new_page = form.submit
25
+ if new_page.uri.path != URI.parse(uri).path
29
26
  raise(LoginFailedException.new)
30
27
  end
28
+ new_page
31
29
  end
32
30
 
33
31
  def self.has_one(name, &block)
@@ -39,7 +37,22 @@ module WiteiWebApi
39
37
  end
40
38
  end
41
39
 
40
+ def self.get(uri)
41
+ page = agent.get("https://witei.com#{uri}")
42
+ uri_path = URI.parse(uri).path
43
+ if page.uri.path != uri_path
44
+ page = login(agent, uri: uri)
45
+ if page.uri.path != uri_path
46
+ raise LoggedOutException.new("Cannot get #{uri}")
47
+ end
48
+ end
49
+ page
50
+ end
51
+
42
52
  class LoginFailedException < Exception
43
53
  end
54
+
55
+ class LoggedOutException < Exception
56
+ end
44
57
  end
45
58
  end
@@ -4,7 +4,7 @@ class WiteiWebApi::Contact < WiteiWebApi::Base
4
4
  has_one(:commercial) { WiteiWebApi::OfficeUser }
5
5
 
6
6
  def self.find(id)
7
- page = agent.get "https://witei.com/pro/agencies/contact/#{id}/update/"
7
+ page = get("/pro/agencies/contact/#{id}/update/")
8
8
  form = page.forms_with(css: '.form-horizontal').first
9
9
 
10
10
  contact = new
@@ -8,11 +8,8 @@ class WiteiWebApi::House < WiteiWebApi::Base
8
8
  has_one(:creator) { WiteiWebApi::OfficeUser }
9
9
 
10
10
  def self.find(identifier)
11
- page = agent.get "https://witei.com/pro/agencies/houses/list/?_hidden__action_identifier_bcd32c=unacc_eq&_hidden_identifier_bcd32c=#{identifier}&listView=block"
12
- id = page.css('#id_houses_0').first['value']
13
- p id
14
-
15
- page = agent.get "https://witei.com/pro/house/update/#{id}/"
11
+ id = id_by_identifier(identifier)
12
+ page = get("/pro/house/update/#{id}/")
16
13
 
17
14
  form = page.forms_with(css: '.form-horizontal').first
18
15
 
@@ -26,4 +23,9 @@ p id
26
23
  )
27
24
  house
28
25
  end
26
+
27
+ def self.id_by_identifier(identifier)
28
+ page = get("/pro/agencies/houses/list/?_hidden__action_identifier_bcd32c=unacc_eq&_hidden_identifier_bcd32c=#{identifier}&listView=block")
29
+ page.css('#id_houses_0').first['value']
30
+ end
29
31
  end
@@ -1,12 +1,8 @@
1
1
  class WiteiWebApi::OfficeUser < WiteiWebApi::Base
2
2
  attr_accessor :id, :name, :email, :phone
3
3
 
4
- # def self.all
5
- # agent.get 'https://witei.com/pro/agencies/account_management/agency_users/'
6
- # end
7
-
8
4
  def self.find(id)
9
- page = agent.get "https://witei.com/pro/agencies/account_management/agency/user_update/#{id}/"
5
+ page = get("/pro/agencies/account_management/agency/user_update/#{id}/")
10
6
 
11
7
  form = page.forms_with(css: '.form-horizontal').first
12
8
 
@@ -1,3 +1,3 @@
1
1
  module WiteiWebApi
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: witei_web_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Polushkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-31 00:00:00.000000000 Z
11
+ date: 2019-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler