brand2csv 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ require 'stringio'
4
+ require 'ostruct'
5
+
6
+ module Kernel
7
+ # for stdout/stderr
8
+ def capture(stream)
9
+ begin
10
+ stream = stream.to_s
11
+ eval "$#{stream} = StringIO.new"
12
+ yield
13
+ result = eval("$#{stream}").string
14
+ ensure
15
+ eval "$#{stream} = #{stream.upcase}"
16
+ end
17
+ result
18
+ end
19
+
20
+ alias :original_exit :exit
21
+ # for load executable file
22
+ def exit(status=false)
23
+ (status == 1) ? raise(LoadError) : original_exit
24
+ end
25
+ end
26
+
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ module ServerMockHelper
5
+
6
+ def setup_swissreg_ch_server(trademark, timespan, result_folder, trademark_ids)
7
+ # main
8
+ stub_html_url = "https://www.swissreg.ch/srclient/faces/jsp/start.jsp"
9
+ stub_response = File.read(File.expand_path("../../data/main.html", __FILE__))
10
+ stub_request(:get, stub_html_url).
11
+ with(
12
+ :headers => {
13
+ "Accept" => "*/*",
14
+ "Host" => "www.swissreg.ch",
15
+ }).
16
+ to_return(
17
+ :status => 200,
18
+ :headers => {"Content-Type" => 'text/html; charset=utf-8'},
19
+ :body => stub_response)
20
+ # erweiterte
21
+ stub_html_url = "https://www.swissreg.ch/srclient/faces/jsp/start.jsp"
22
+ stub_response = File.read(File.expand_path("../../data/erweiterte_suche.html", __FILE__))
23
+ stub_request(:post, stub_html_url).
24
+ with(
25
+ :headers => {
26
+ "Accept" => "*/*",
27
+ "Host" => "www.swissreg.ch",
28
+ },
29
+ :body => {
30
+ "autoScroll" => "",
31
+ "id_swissreg:_idcl" => "id_swissreg_sub_nav_ipiNavigation_item0",
32
+ "id_swissreg:_link_hidden_" => "",
33
+ "id_swissreg_SUBMIT" => "1",
34
+ "javax.faces.ViewState" =>"rO0ABXVyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAAN0AAExcHQADi9qc3Avc3RhcnQuanNw"
35
+ }).
36
+ to_return(
37
+ :status => 200,
38
+ :headers => {"Content-Type" => 'text/html; charset=utf-8'},
39
+ :body => stub_response)
40
+ # result page 1
41
+ stub_html_url = "https://www.swissreg.ch/srclient/faces/jsp/trademark/sr3.jsp"
42
+ stub_response = File.read(File.expand_path("../../data/#{result_folder}/first_results.html", __FILE__))
43
+ stub_request(:post, stub_html_url).
44
+ with(
45
+ :headers => {
46
+ "Accept" => "*/*",
47
+ "Host" => "www.swissreg.ch",
48
+ },
49
+ :body => {
50
+ "autoScroll" => "0,829",
51
+ "id_swissreg:_idcl" => "",
52
+ "id_swissreg:_link_hidden_" => "",
53
+ "id_swissreg:mainContent:id_cbxCountry" => "_ALL",
54
+ "id_swissreg:mainContent:id_cbxFormatChoice" => "1",
55
+ "id_swissreg:mainContent:id_cbxHitsPerPage" => "250",
56
+ "id_swissreg:mainContent:id_cbxTMColorClaim" => "_ALL",
57
+ "id_swissreg:mainContent:id_cbxTMForm" => "_ALL",
58
+ "id_swissreg:mainContent:id_cbxTMTypeGrp" => "_ALL",
59
+ "id_swissreg:mainContent:id_ckbTMChoice" => "tm_lbl_app_date",
60
+ "id_swissreg:mainContent:id_ckbTMPubReason" => "8",
61
+ "id_swissreg:mainContent:id_ckbTMState" => "3",
62
+ "id_swissreg:mainContent:id_txf_agent" => "",
63
+ "id_swissreg:mainContent:id_txf_appDate" => "#{timespan}",
64
+ "id_swissreg:mainContent:id_txf_app_no" => "",
65
+ "id_swissreg:mainContent:id_txf_applicant" => "",
66
+ "id_swissreg:mainContent:id_txf_expiryDate" => "",
67
+ "id_swissreg:mainContent:id_txf_licensee" => "",
68
+ "id_swissreg:mainContent:id_txf_nizza_class" => "",
69
+ "id_swissreg:mainContent:id_txf_pub_date" => "",
70
+ "id_swissreg:mainContent:id_txf_tm_no" => "",
71
+ "id_swissreg:mainContent:id_txf_tm_text" => "#{trademark}",
72
+ "id_swissreg:mainContent:sub_fieldset:id_submit" => "suchen",
73
+ "id_swissreg_SUBMIT" => "1",
74
+ "javax.faces.ViewState" => "rO0ABXVyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAAN0AAExcHQADi9qc3Avc3RhcnQuanNw"
75
+ }).
76
+ to_return(
77
+ :status => 200,
78
+ :headers => {"Content-Type" => 'text/html; charset=utf-8'},
79
+ :body => stub_response)
80
+ # result page 2
81
+ stub_html_url = "https://www.swissreg.ch/srclient/faces/jsp/trademark/sr3.jsp"
82
+ stub_response = File.read(File.expand_path("../../data/#{result_folder}/first_results.html", __FILE__))
83
+ stub_request(:post, stub_html_url).
84
+ with(
85
+ :headers => {
86
+ "Accept" => "*/*",
87
+ "Host" => "www.swissreg.ch",
88
+ },
89
+ :body => {
90
+ "autoScroll" => "",
91
+ "id_swissreg:_idcl" => "id_swissreg_sub_nav_ipiNavigation_item0_item3",
92
+ "id_swissreg:_link_hidden_" => "",
93
+ "id_swissreg:mainContent:id_cbxCountry" => "_ALL",
94
+ "id_swissreg:mainContent:id_cbxFormatChoice" => "1",
95
+ "id_swissreg:mainContent:id_cbxHitsPerPage" => "25",
96
+ "id_swissreg:mainContent:id_cbxTMColorClaim" => "_ALL",
97
+ "id_swissreg:mainContent:id_cbxTMForm" => "_ALL",
98
+ "id_swissreg:mainContent:id_cbxTMTypeGrp" => "_ALL",
99
+ "id_swissreg:mainContent:id_ckbTMChoice" => "tm_lbl_applicant",
100
+ "id_swissreg:mainContent:id_ckbTMPubReason" => "8",
101
+ "id_swissreg:mainContent:id_ckbTMState" => "3",
102
+ "id_swissreg:mainContent:id_txf_agent" => "",
103
+ "id_swissreg:mainContent:id_txf_appDate" => "",
104
+ "id_swissreg:mainContent:id_txf_app_no" => "",
105
+ "id_swissreg:mainContent:id_txf_applicant" => "",
106
+ "id_swissreg:mainContent:id_txf_expiryDate" => "",
107
+ "id_swissreg:mainContent:id_txf_licensee" => "",
108
+ "id_swissreg:mainContent:id_txf_nizza_class" => "",
109
+ "id_swissreg:mainContent:id_txf_pub_date" => "",
110
+ "id_swissreg:mainContent:id_txf_tm_no" => "",
111
+ "id_swissreg:mainContent:id_txf_tm_text" => "",
112
+ "id_swissreg_SUBMIT" => "1",
113
+ "javax.faces.ViewState" => "rO0ABXVyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAAN0AAEzcHQAFi9qc3AvdHJhZGVtYXJrL3NyMy5qc3A="
114
+ }).
115
+ to_return(
116
+ :status => 200,
117
+ :headers => {"Content-Type" => 'text/html; charset=utf-8'},
118
+ :body => stub_response)
119
+
120
+ counter = 0
121
+ trademark_ids.each{
122
+ |trademark_id|
123
+ counter += 1
124
+ # https://www.swissreg.ch/srclient/faces/jsp/trademark/sr300.jsp?language=de&section=tm&id=57862/2013
125
+ stub_html_url = "https://www.swissreg.ch/srclient/faces/jsp/trademark/sr300.jsp?language=de&section=tm&id=#{trademark_id}"
126
+ filename = File.expand_path("../../data/#{result_folder}/detail_#{sprintf('%05i',counter)}_#{trademark_id.sub('/','.')}.html", __FILE__)
127
+ stub_response = File.read(filename)
128
+ stub_request(:get, stub_html_url).
129
+ with(
130
+ :headers => {
131
+ "Accept" => "*/*",
132
+ "Host" => "www.swissreg.ch",
133
+ }).
134
+ to_return(
135
+ :status => 200,
136
+ :headers => {"Content-Type" => 'text/html; charset=utf-8'},
137
+ :body => stub_response)
138
+
139
+ }
140
+ end
141
+
142
+ end
@@ -0,0 +1,44 @@
1
+ #encoding : utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'Get some simple example from swissreg' do
5
+
6
+ HasVertreterPos = 4
7
+
8
+ it "should get correct results from swissreg" do
9
+ marke = 'aspectra*'
10
+ timespan = '01.01.2012-31.12.2012'
11
+ setup_swissreg_ch_server(marke, timespan, 'aspectra', ["P-480296", "P-482236", "641074"])
12
+ results = nil
13
+ capture(:stdout) { results = Brand2csv::run(timespan, marke) }
14
+ results.should_not be_nil
15
+ results.size.should == 3
16
+ results[0].zeile_1.should == 'Aspectra AG'
17
+ results[0].plz.should == '8004'
18
+ results[0].ort.should == 'Zürich'
19
+ csv = "#{timespan}.csv"
20
+ csv_lines = IO.readlines(csv)
21
+ csv_lines[1].split(';')[HasVertreterPos].should == "true"
22
+ csv_lines[2].split(';')[HasVertreterPos].should == "true"
23
+ csv_lines[3].split(';')[HasVertreterPos].should == "false"
24
+ end
25
+
26
+ it "should get correct results from swissreg when owner has two postal addresses" do
27
+ marke = 'Urner Wildheu'
28
+ timespan = '01.05.2013-30.06.2013'
29
+ setup_swissreg_ch_server(marke, timespan, 'urner_wildheu', ["57862/2013"])
30
+ results = nil
31
+ capture(:stdout) { results = Brand2csv::run(timespan, marke) }
32
+ results.should_not be_nil
33
+ results.size.should == 1
34
+ results[0].zeile_1.should == 'Philipp Arnold'
35
+ results[0].zeile_2.should == 'Seestrasse 37a'
36
+ results[0].plz.should == '6454'
37
+ results[0].ort.should == 'Flüelen'
38
+ csv = "#{timespan}.csv"
39
+ csv_lines = IO.readlines(csv)
40
+ csv_lines[1].split(';')[2].should == 'Philipp Arnold, Seestrasse 37a, 6454 Flüelen'
41
+ csv_lines[1].split(';')[HasVertreterPos].should == "true"
42
+ end
43
+
44
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ include Brand2csv
4
+
5
+ describe 'trademark number search' do
6
+
7
+ before :each do
8
+ dataDir = File.expand_path(File.join(File.dirname(__FILE__), 'data'))
9
+ filename = "#{dataDir}/result_short.html"
10
+ File.exists?(filename).should be_true
11
+ @doc = Nokogiri::Slop(File.open(filename))
12
+ end
13
+
14
+ it "trademark number search must contain 9 numbers" do
15
+ numbers = Swissreg::getTrademarkNumbers(@doc)
16
+ numbers.should_not be_nil
17
+ numbers.size.should == 9
18
+ numbers.index('00127/2011').should_not be_nil
19
+ end
20
+
21
+ end
@@ -67,4 +67,17 @@ describe 'Tests parsing adress line' do
67
67
  plz.should == '3018'
68
68
  ort.should == 'Bern'
69
69
  end
70
+
71
+ it "must handle several postal addresses correctly" do
72
+ full_address_line = 'Philipp Arnold, Seestrasse 37a, 6454 Flüelen, , Peter Tresoldi, c/o Xitix GmbH, Rathausplatz 4, 6460 Altdorf'
73
+ number = 'for_debugging'
74
+ zeile_1, zeile_2, zeile_3, zeile_4, zeile_5, plz, ort = Swissreg::parseAddress(number, full_address_line)
75
+ zeile_1.should == 'Philipp Arnold'
76
+ zeile_2.should == 'Seestrasse 37a'
77
+ zeile_3.should be_nil
78
+ zeile_4.should be_nil
79
+ zeile_5.should be_nil
80
+ plz.should == '6454'
81
+ ort.should == 'Flüelen'
82
+ end
70
83
  end
metadata CHANGED
@@ -1,100 +1,89 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brand2csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
5
- prerelease:
4
+ version: 0.2.9
6
5
  platform: ruby
7
6
  authors:
8
- - Niklaus Giger, Zeno R.R. Davatz
7
+ - Niklaus Giger, Yasuhiro Asaka, Zeno R.R. Davatz
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-28 00:00:00.000000000 Z
11
+ date: 2013-09-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: mechanize
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '2.6'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '2.6'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rdoc
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
37
- version: '4.0'
33
+ version: '3.10'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
45
- version: '4.0'
40
+ version: '3.10'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: webmock
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: hoe
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '3.4'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '3.4'
94
- description: ! "brand2csv creates csv files for swiss brand registered in a specific
83
+ description: "brand2csv creates csv files for swiss brand registered in a specific
95
84
  time period. \n The csv contains the brand, link to image (if present), link to
96
85
  the detailinfo at swissreg.ch, name and address of owner (Inhaber)"
97
- email: ngiger@ywesee.com, zdavatz@ywesee.com
86
+ email: ngiger@ywesee.com, yasaka@ywesee.com, zdavatz@ywesee.com
98
87
  executables:
99
88
  - brand2csv
100
89
  extensions: []
@@ -102,7 +91,6 @@ extra_rdoc_files:
102
91
  - History.txt
103
92
  - LICENCE.txt
104
93
  - Manifest.txt
105
- - README.md
106
94
  files:
107
95
  - .gitignore
108
96
  - .rspec
@@ -111,7 +99,6 @@ files:
111
99
  - Gemfile.lock
112
100
  - History.txt
113
101
  - LICENCE.txt
114
- - LICENSE
115
102
  - Manifest.txt
116
103
  - README.md
117
104
  - Rakefile
@@ -130,19 +117,30 @@ files:
130
117
  - protocol.2013.05.12.textile
131
118
  - protocol.2013.05.15.textile
132
119
  - protocol.2013.05.21.textile
120
+ - spec/brand2csv_spec.rb
133
121
  - spec/csv_spec.rb
122
+ - spec/data/aspectra/detail_00001_P-480296.html
123
+ - spec/data/aspectra/detail_00002_P-482236.html
124
+ - spec/data/aspectra/detail_00003_641074.html
125
+ - spec/data/aspectra/first_results.html
134
126
  - spec/data/einfache_suche.html
135
127
  - spec/data/erweiterte_suche.html
136
128
  - spec/data/main.html
137
129
  - spec/data/result_short.html
138
130
  - spec/data/resultate_1.html
139
131
  - spec/data/resultate_2.html
132
+ - spec/data/urner_wildheu/detail_00001_57862.2013.html
133
+ - spec/data/urner_wildheu/first_results.html
140
134
  - spec/data/vereinfachte_1.html
141
135
  - spec/data/vereinfachte_detail_33.html
142
136
  - spec/detail_spec.rb
143
137
  - spec/short_spec.rb
144
138
  - spec/simple_search.rb
145
139
  - spec/spec_helper.rb
140
+ - spec/support/core_ext/kernel.rb
141
+ - spec/support/server_mock_helper.rb
142
+ - spec/swissreg_spec.rb
143
+ - spec/trademark_numbers_spec.rb
146
144
  - spec/utilities_spec.rb
147
145
  - spike.rb
148
146
  - spike_mechanize_swissreg.rb
@@ -150,7 +148,9 @@ files:
150
148
  - swissreg.rb
151
149
  - .gemtest
152
150
  homepage: https://github.com/zdavatz/brand2csv
153
- licenses: []
151
+ licenses:
152
+ - GPLv3.0
153
+ metadata: {}
154
154
  post_install_message:
155
155
  rdoc_options:
156
156
  - --main
@@ -158,21 +158,19 @@ rdoc_options:
158
158
  require_paths:
159
159
  - lib
160
160
  required_ruby_version: !ruby/object:Gem::Requirement
161
- none: false
162
161
  requirements:
163
- - - ! '>='
162
+ - - '>='
164
163
  - !ruby/object:Gem::Version
165
164
  version: '0'
166
165
  required_rubygems_version: !ruby/object:Gem::Requirement
167
- none: false
168
166
  requirements:
169
- - - ! '>='
167
+ - - '>='
170
168
  - !ruby/object:Gem::Version
171
169
  version: '0'
172
170
  requirements: []
173
171
  rubyforge_project: brand2csv
174
- rubygems_version: 1.8.25
172
+ rubygems_version: 2.0.3
175
173
  signing_key:
176
- specification_version: 3
174
+ specification_version: 4
177
175
  summary: brand2csv creates csv files for swiss brands.
178
176
  test_files: []