ratsit 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/ratsit.rb +82 -58
- data/lib/ratsit/errors.rb +3 -0
- data/lib/ratsit/filter/filter.rb +212 -0
- data/lib/ratsit/filter/filter_company.rb +27 -0
- data/lib/ratsit/filter/filter_get_annual_report.rb +21 -0
- data/lib/ratsit/filter/filter_get_companies.rb +27 -0
- data/lib/ratsit/filter/filter_get_company_information_package.rb +23 -0
- data/lib/ratsit/filter/filter_get_person_information_package.rb +23 -0
- data/lib/ratsit/filter/filter_person.rb +30 -0
- data/lib/ratsit/filter/filter_search_one_person.rb +26 -0
- data/lib/ratsit/filter/filter_search_persons.rb +34 -0
- data/lib/ratsit/request/open_request.rb +65 -0
- data/lib/ratsit/request/request.rb +48 -0
- data/lib/ratsit/request/request_get_companies.rb +46 -0
- data/lib/ratsit/request/request_search_one_person.rb +41 -0
- data/lib/ratsit/request/request_search_persons.rb +47 -0
- data/lib/ratsit/request/token_request.rb +35 -0
- data/lib/ratsit/version.rb +2 -1
- data/ratsit.gemspec +3 -2
- metadata +35 -9
- data/lib/ratsit/filters.rb +0 -155
- data/lib/ratsit/package.rb +0 -22
- data/lib/ratsit/person.rb +0 -39
- data/lib/ratsit/request.rb +0 -80
- data/lib/ratsit/search_type.rb +0 -19
data/lib/ratsit/version.rb
CHANGED
data/ratsit.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Stefan Nyman"]
|
10
10
|
spec.email = ["stefan@qoorp.com"]
|
11
11
|
|
12
|
-
spec.summary = "Ratsit searches
|
13
|
-
spec.description = "
|
12
|
+
spec.summary = "Perform Ratsit searches for persons and companies."
|
13
|
+
spec.description = "Can search using either the open api endpoints or by using an api key. Search methods: OpenPersonSearch, OpenCompanySearch, SearchCompanies, SearchPersons, SearchOnePerson."
|
14
14
|
spec.homepage = "http://github.com/qoorp/ratsit"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency "rspec", "~> 3.2"
|
33
33
|
|
34
34
|
spec.add_runtime_dependency "faraday", "~> 0.9.2"
|
35
|
+
spec.add_runtime_dependency "savon", "~> 2.10.0"
|
35
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ratsit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Nyman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,23 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.9.2
|
69
|
-
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: savon
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.10.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.10.0
|
83
|
+
description: 'Can search using either the open api endpoints or by using an api key.
|
84
|
+
Search methods: OpenPersonSearch, OpenCompanySearch, SearchCompanies, SearchPersons,
|
85
|
+
SearchOnePerson.'
|
70
86
|
email:
|
71
87
|
- stefan@qoorp.com
|
72
88
|
executables: []
|
@@ -83,12 +99,22 @@ files:
|
|
83
99
|
- bin/setup
|
84
100
|
- lib/ratsit.rb
|
85
101
|
- lib/ratsit/errors.rb
|
86
|
-
- lib/ratsit/
|
102
|
+
- lib/ratsit/filter/filter.rb
|
103
|
+
- lib/ratsit/filter/filter_company.rb
|
104
|
+
- lib/ratsit/filter/filter_get_annual_report.rb
|
105
|
+
- lib/ratsit/filter/filter_get_companies.rb
|
106
|
+
- lib/ratsit/filter/filter_get_company_information_package.rb
|
107
|
+
- lib/ratsit/filter/filter_get_person_information_package.rb
|
108
|
+
- lib/ratsit/filter/filter_person.rb
|
109
|
+
- lib/ratsit/filter/filter_search_one_person.rb
|
110
|
+
- lib/ratsit/filter/filter_search_persons.rb
|
87
111
|
- lib/ratsit/monkey.rb
|
88
|
-
- lib/ratsit/
|
89
|
-
- lib/ratsit/
|
90
|
-
- lib/ratsit/request.rb
|
91
|
-
- lib/ratsit/
|
112
|
+
- lib/ratsit/request/open_request.rb
|
113
|
+
- lib/ratsit/request/request.rb
|
114
|
+
- lib/ratsit/request/request_get_companies.rb
|
115
|
+
- lib/ratsit/request/request_search_one_person.rb
|
116
|
+
- lib/ratsit/request/request_search_persons.rb
|
117
|
+
- lib/ratsit/request/token_request.rb
|
92
118
|
- lib/ratsit/version.rb
|
93
119
|
- ratsit.gemspec
|
94
120
|
homepage: http://github.com/qoorp/ratsit
|
@@ -115,5 +141,5 @@ rubyforge_project:
|
|
115
141
|
rubygems_version: 2.4.5.1
|
116
142
|
signing_key:
|
117
143
|
specification_version: 4
|
118
|
-
summary: Ratsit searches
|
144
|
+
summary: Perform Ratsit searches for persons and companies.
|
119
145
|
test_files: []
|
data/lib/ratsit/filters.rb
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'ratsit/errors'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
module Ratsit
|
6
|
-
|
7
|
-
# Person filters
|
8
|
-
FILTER_MARRIED = 'Married'
|
9
|
-
FILTER_UNMARRIED = 'Unmarried'
|
10
|
-
FILTER_MALE = 'Male'
|
11
|
-
FILTER_FEMALE = 'Female'
|
12
|
-
FILTER_COMPANY_ENGAGEMENT = 'CompanyEngagement'
|
13
|
-
FILTER_NO_COMPANY_ENGAGEMENT = 'NoCompanyEngagement'
|
14
|
-
FILTER_AGE_FROM = 'AgeFrom'
|
15
|
-
FILTER_AGE_TO = 'AgeTo'
|
16
|
-
|
17
|
-
# Company filters
|
18
|
-
FILTER_AB = 'AB'
|
19
|
-
FILTER_EF = 'EF'
|
20
|
-
FILTER_HB = 'HB'
|
21
|
-
FILTER_OTHER = 'Other'
|
22
|
-
|
23
|
-
|
24
|
-
class RatsitFilter
|
25
|
-
|
26
|
-
def initialize()
|
27
|
-
@active_filters = {}
|
28
|
-
@filter_defaults = {}
|
29
|
-
end
|
30
|
-
|
31
|
-
def active_filters
|
32
|
-
return (@active_filters.nil?)? nil: @active_filters
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_json
|
36
|
-
af = self.active_filters
|
37
|
-
return '{}' if af.nil?
|
38
|
-
af.to_json
|
39
|
-
end
|
40
|
-
|
41
|
-
def update(filter_key='', filter_value)
|
42
|
-
#puts "update #{filter_key}: #{filter_value}"
|
43
|
-
if !filter_key.is_a?(String)
|
44
|
-
raise RatsitFilterError, 'Invalid filter key'
|
45
|
-
end
|
46
|
-
if filter_value.nil?
|
47
|
-
raise RatsitFilterError, 'Invalid filter value'
|
48
|
-
end
|
49
|
-
if !@active_filters.has_key?(filter_key)
|
50
|
-
raise RatsitFilterError, 'Non-existent filter key'
|
51
|
-
end
|
52
|
-
@curr_filters = Marshal.load(Marshal.dump(@active_filters))
|
53
|
-
@curr_filters[filter_key] = filter_value
|
54
|
-
@active_filters = validate_filters(@filter_defaults, @curr_filters)
|
55
|
-
end
|
56
|
-
|
57
|
-
def reset(filter_name='')
|
58
|
-
if !filter_name.is_a?(String)
|
59
|
-
raise RatsitFilterError, 'Invalid filter key'
|
60
|
-
end
|
61
|
-
if !@filter_defaults.has_key?(filter_name)
|
62
|
-
raise RatsitFilterError, 'Non-existent filter key'
|
63
|
-
end
|
64
|
-
@active_filters[filter_name] = @filter_defaults[filter_name][:default]
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
class PersonFilter < RatsitFilter
|
70
|
-
include Ratsit
|
71
|
-
#{"Married":true,"Unmarried":true,"Male":true,"Female":true,"CompanyEngagement":true,"NoCompanyEngagement":true,"AgeFrom":"0","AgeTo":"150"}
|
72
|
-
def initialize(filters={})
|
73
|
-
super()
|
74
|
-
@filter_defaults = {
|
75
|
-
FILTER_MARRIED => {:parse => method(:parse_bool), :default => true},
|
76
|
-
FILTER_UNMARRIED => {:parse => method(:parse_bool), :default => true},
|
77
|
-
FILTER_MALE => {:parse => method(:parse_bool), :default => true},
|
78
|
-
FILTER_FEMALE => {:parse => method(:parse_bool), :default => true},
|
79
|
-
FILTER_COMPANY_ENGAGEMENT => {:parse => method(:parse_bool), :default => true},
|
80
|
-
FILTER_NO_COMPANY_ENGAGEMENT => {:parse => method(:parse_bool), :default => true},
|
81
|
-
FILTER_AGE_FROM => {:parse => method(:parse_age), :default => '0'},
|
82
|
-
FILTER_AGE_TO => {:parse => method(:parse_age), :default => '150'}
|
83
|
-
}
|
84
|
-
@active_filters = validate_filters(@filter_defaults, filters)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
class CompanyFilter < RatsitFilter
|
89
|
-
include Ratsit
|
90
|
-
#{"AB":true,"EF":true,"HB":true,"Other":true}
|
91
|
-
def initialize(filters={})
|
92
|
-
super()
|
93
|
-
@filter_defaults = {
|
94
|
-
FILTER_AB => {:parse => method(:parse_bool), :default => true},
|
95
|
-
FILTER_EF => {:parse => method(:parse_bool), :default => true},
|
96
|
-
FILTER_HB => {:parse => method(:parse_bool), :default => true},
|
97
|
-
FILTER_OTHER => {:parse => method(:parse_bool), :default => true}
|
98
|
-
}
|
99
|
-
@active_filters = validate_filters(@filter_defaults, filters)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
class EstateFilter < RatsitFilter
|
104
|
-
include Ratsit
|
105
|
-
def initialize()
|
106
|
-
raise NotImplementedError, 'Functionality doesn\'t exist'
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
private
|
111
|
-
|
112
|
-
def parse_bool(arg)
|
113
|
-
return arg if arg.is_a?(TrueClass) || arg.is_a?(FalseClass)
|
114
|
-
raise RatsitFilterError, 'Invalid bool representation' if !arg.is_a?(String)
|
115
|
-
return true if arg.downcase == 'true'
|
116
|
-
return false if arg.downcase == 'false'
|
117
|
-
raise RatsitFilterError, 'Invalid textual bool value'
|
118
|
-
end
|
119
|
-
|
120
|
-
def parse_age(arg)
|
121
|
-
if arg.is_a?(String)
|
122
|
-
if !(arg =~ /^[0-9]+$/)
|
123
|
-
raise RatsitFilterError, 'Invalid age in filter'
|
124
|
-
end
|
125
|
-
larg = arg.to_i
|
126
|
-
elsif arg.is_a?(Integer)
|
127
|
-
larg = arg
|
128
|
-
else
|
129
|
-
raise RatsitFilterError, 'Invalid arg type in filter'
|
130
|
-
end
|
131
|
-
# ratsit specifies these ages.
|
132
|
-
if larg < 0 || larg > 150
|
133
|
-
raise RatsitFilterError, 'Invalid age'
|
134
|
-
end
|
135
|
-
return "#{larg}"
|
136
|
-
end
|
137
|
-
|
138
|
-
def validate_filters(filter_defaults={}, filters={})
|
139
|
-
if !filters.is_a?(Hash)
|
140
|
-
filters = {}
|
141
|
-
end
|
142
|
-
filters.reject! { |k,_| !filter_defaults.keys.include? k }
|
143
|
-
filter_defaults.each do |filter_name, defs|
|
144
|
-
if !filters.keys.include? filter_name
|
145
|
-
filters[filter_name] = defs[:default]
|
146
|
-
end
|
147
|
-
filters[filter_name] = defs[:parse].call(filters[filter_name])
|
148
|
-
end
|
149
|
-
if filters[FILTER_AGE_TO].to_i < filters[FILTER_AGE_FROM].to_i
|
150
|
-
raise RatsitFilterError, 'Invalid age span'
|
151
|
-
end
|
152
|
-
return filters
|
153
|
-
end
|
154
|
-
|
155
|
-
end
|
data/lib/ratsit/package.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
|
2
|
-
module Ratsit
|
3
|
-
PACKAGE_SMALL_1 = 'small 1'
|
4
|
-
PACKAGE_SMALL_2 = 'small 2'
|
5
|
-
PACKAGE_SMALL_3 = 'small 3'
|
6
|
-
PACKAGE_REMARK = 'anmarkning'
|
7
|
-
PACKAGE_MEDIUM = 'medium'
|
8
|
-
PACKAGE_LARGE = 'large'
|
9
|
-
|
10
|
-
def Ratsit.validate_package(package)
|
11
|
-
raise RatsitError, 'Invalid package argument type' if !package.is_a?(String)
|
12
|
-
return [
|
13
|
-
PACKAGE_SMALL_1,
|
14
|
-
PACKAGE_SMALL_2,
|
15
|
-
PACKAGE_SMALL_3,
|
16
|
-
PACKAGE_REMARK,
|
17
|
-
PACKAGE_MEDIUM,
|
18
|
-
PACKAGE_LARGE
|
19
|
-
].include?(package)
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
data/lib/ratsit/person.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'ratsit/monkey'
|
3
|
-
require 'ratsit/errors'
|
4
|
-
|
5
|
-
module Ratsit
|
6
|
-
|
7
|
-
class Person
|
8
|
-
|
9
|
-
def initialize(json_obj)
|
10
|
-
if !json_obj.is_a?(Hash)
|
11
|
-
raise RatsitError, 'Invalid Person initializer'
|
12
|
-
end
|
13
|
-
@json_source = json_obj
|
14
|
-
json_obj.each do |k, v|
|
15
|
-
case k
|
16
|
-
when 'FirstName'
|
17
|
-
v.gsub!("<b>", "")
|
18
|
-
v.gsub!("</b>", "")
|
19
|
-
when 'Gender'
|
20
|
-
v = v.gsub("icon_", "")
|
21
|
-
v = v.gsub(".png", "")
|
22
|
-
when 'Married'
|
23
|
-
v = v.gsub("icon_", "")
|
24
|
-
v = v.gsub(".png", "")
|
25
|
-
when 'CompanyEngagement'
|
26
|
-
v = v.gsub("icon_", "")
|
27
|
-
v = v.gsub(".png", "")
|
28
|
-
else
|
29
|
-
v = v
|
30
|
-
end
|
31
|
-
self.class.send(:define_method, k.underscore) {
|
32
|
-
return v
|
33
|
-
}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
data/lib/ratsit/request.rb
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'faraday'
|
3
|
-
require 'uri'
|
4
|
-
require 'json'
|
5
|
-
require 'ratsit/errors'
|
6
|
-
require 'ratsit/filters'
|
7
|
-
require 'ratsit/search_type'
|
8
|
-
|
9
|
-
module Ratsit
|
10
|
-
|
11
|
-
class RatsitRequest
|
12
|
-
|
13
|
-
def initialize()
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def exec()
|
18
|
-
uri = self.build_uri
|
19
|
-
conn = Faraday.new(:url => "http://#{uri.host}")
|
20
|
-
#puts "http://#{uri.host}"
|
21
|
-
#puts self.compose_request_body
|
22
|
-
@response = conn.post do |req|
|
23
|
-
req.url uri.request_uri
|
24
|
-
req.headers['Content-Type'] = 'application/json'
|
25
|
-
req.body = self.compose_request_body
|
26
|
-
end
|
27
|
-
#puts @response.body
|
28
|
-
#puts @response.status
|
29
|
-
end
|
30
|
-
|
31
|
-
def response_ok
|
32
|
-
return false if @response.nil?
|
33
|
-
return @response.status == 200
|
34
|
-
end
|
35
|
-
|
36
|
-
def response_body
|
37
|
-
return nil if @response.nil?
|
38
|
-
return @response.body
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class RatsitOpenRequest < RatsitRequest
|
43
|
-
|
44
|
-
def initialize(search_term, search_area, search_type, filters)
|
45
|
-
super()
|
46
|
-
if search_type == Ratsit::SEARCH_TYPE_ESTATE
|
47
|
-
raise RatsitRequestError, 'Estate search is not available in open api'
|
48
|
-
end
|
49
|
-
@base_url = 'http://www.ratsit.se/BC/SearchSimple.aspx/'
|
50
|
-
@search_term = search_term
|
51
|
-
@search_area = search_area
|
52
|
-
@search_type = search_type
|
53
|
-
@search_filter = filters
|
54
|
-
self
|
55
|
-
end
|
56
|
-
|
57
|
-
def build_uri
|
58
|
-
if !Ratsit.validate_search_type(@search_type)
|
59
|
-
raise RatsitRequestError, 'Invalid search type'
|
60
|
-
end
|
61
|
-
URI.parse("#{@base_url}#{@search_type}")
|
62
|
-
end
|
63
|
-
|
64
|
-
def compose_request_body
|
65
|
-
{
|
66
|
-
'who': @search_term,
|
67
|
-
'where': @search_area,
|
68
|
-
'filter': @search_filter.to_json
|
69
|
-
}.to_json
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
class RatsitTokenRequest < RatsitRequest
|
75
|
-
def initialize()
|
76
|
-
raise NotImplementedError, 'Token requests are not supported yet'
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
data/lib/ratsit/search_type.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'ratsit/errors'
|
3
|
-
|
4
|
-
module Ratsit
|
5
|
-
|
6
|
-
SEARCH_TYPE_PERSON = 'PersonSearch'
|
7
|
-
SEARCH_TYPE_COMPANY = 'CompanySearch'
|
8
|
-
SEARCH_TYPE_ESTATE = 'EstateSearch'
|
9
|
-
|
10
|
-
def Ratsit.validate_search_type(search_type)
|
11
|
-
raise RatsitError, 'Invalid search_type argument' if !search_type.is_a?(String)
|
12
|
-
return [
|
13
|
-
SEARCH_TYPE_PERSON,
|
14
|
-
SEARCH_TYPE_COMPANY,
|
15
|
-
SEARCH_TYPE_ESTATE
|
16
|
-
].include?(search_type)
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|