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 +4 -4
- data/Gemfile.lock +2 -2
- data/lib/witei_web_api/base.rb +23 -10
- data/lib/witei_web_api/contact.rb +1 -1
- data/lib/witei_web_api/house.rb +7 -5
- data/lib/witei_web_api/office_user.rb +1 -5
- data/lib/witei_web_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef7ae971b1b5c8710e2d84df99059690b8d5793c0357be1eec2a330f19dc8898
|
4
|
+
data.tar.gz: 34c882511b11b6e9bb56e9bc30480d4e08023f44aa4f5afb26f03e817e1216bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0aac2f6a738ecb3f8526a4c03eac43b29282060f51cba3b04cf57455c5b0bd451f23ff5164674079b32cd2b1dc3e92275e3cc3440b848e077fd9330d45803b6c
|
7
|
+
data.tar.gz: 1ad0754a9ff942f9f9996eaea74ee714a693a43be13647f2e20f91a0ad3da967a5c9662d272aef0840e0dce516cb513f1f6560fc3384cdd4ddffe7b6fee1eae1
|
data/Gemfile.lock
CHANGED
data/lib/witei_web_api/base.rb
CHANGED
@@ -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
|
12
|
+
login(agent)
|
13
13
|
agent
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.login(agent, login, password)
|
18
|
-
|
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
|
21
|
+
form = page.form_with(class: 'form-horizontal')
|
21
22
|
form.login = login
|
22
23
|
form.password = password
|
23
|
-
|
24
|
-
|
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 =
|
7
|
+
page = get("/pro/agencies/contact/#{id}/update/")
|
8
8
|
form = page.forms_with(css: '.form-horizontal').first
|
9
9
|
|
10
10
|
contact = new
|
data/lib/witei_web_api/house.rb
CHANGED
@@ -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
|
-
|
12
|
-
|
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 =
|
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
|
|
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.
|
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:
|
11
|
+
date: 2019-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|