tec_doc 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.md +29 -0
- data/bin/tec_doc +51 -0
- data/lib/tec_doc.rb +28 -0
- data/lib/tec_doc/article.rb +317 -0
- data/lib/tec_doc/article_attribute.rb +17 -0
- data/lib/tec_doc/article_document.rb +49 -0
- data/lib/tec_doc/article_oe_number.rb +11 -0
- data/lib/tec_doc/article_thumbnail.rb +18 -0
- data/lib/tec_doc/assembly_group.rb +77 -0
- data/lib/tec_doc/brand.rb +18 -0
- data/lib/tec_doc/client.rb +84 -0
- data/lib/tec_doc/date_parser.rb +14 -0
- data/lib/tec_doc/error.rb +4 -0
- data/lib/tec_doc/fuel_type.rb +0 -0
- data/lib/tec_doc/generic_article.rb +47 -0
- data/lib/tec_doc/language.rb +22 -0
- data/lib/tec_doc/vehicle.rb +121 -0
- data/lib/tec_doc/vehicle_manufacturer.rb +46 -0
- data/lib/tec_doc/vehicle_model.rb +46 -0
- data/lib/tec_doc/version.rb +3 -0
- data/spec/cassettes/article_all.yml +88 -0
- data/spec/cassettes/article_all_with_details.yml +84 -0
- data/spec/cassettes/article_details.yml +68 -0
- data/spec/cassettes/article_details_for_trade_number.yml +56 -0
- data/spec/cassettes/article_document_all.yml +49 -0
- data/spec/cassettes/article_document_content.yml +763 -0
- data/spec/cassettes/article_information.yml +55 -0
- data/spec/cassettes/article_linked_manufacturers.yml +45 -0
- data/spec/cassettes/article_linked_vehicle_ids.yml +45 -0
- data/spec/cassettes/article_linked_vehicles.yml +372 -0
- data/spec/cassettes/article_linked_vehicles_with_details.yml +430 -0
- data/spec/cassettes/article_search.yml +62 -0
- data/spec/cassettes/article_search_for_linked_manufacturers.yml +47 -0
- data/spec/cassettes/article_thumbnail_all.yml +45 -0
- data/spec/cassettes/article_thumbnail_content.yml +399 -0
- data/spec/cassettes/article_trade_number.yml +46 -0
- data/spec/cassettes/article_with_a_lot_linked_vehicles.yml +60 -0
- data/spec/cassettes/assembly_group_all.yml +90 -0
- data/spec/cassettes/assembly_group_children.yml +55 -0
- data/spec/cassettes/brand_all.yml +81 -0
- data/spec/cassettes/generic_article_all.yml +46 -0
- data/spec/cassettes/language_all.yml +48 -0
- data/spec/cassettes/linked_targets_by_manufacturers.yml +2584 -0
- data/spec/cassettes/status_401.yml +38 -0
- data/spec/cassettes/vehicle_all.yml +79 -0
- data/spec/cassettes/vehicle_assembly_groups.yml +83 -0
- data/spec/cassettes/vehicle_child_assembly_groups.yml +49 -0
- data/spec/cassettes/vehicle_find_by_id.yml +50 -0
- data/spec/cassettes/vehicle_manufacturer_all.yml +52 -0
- data/spec/cassettes/vehicle_model_all.yml +119 -0
- data/spec/spec_helper.rb +28 -0
- data/spec/tec_doc/article_document_spec.rb +34 -0
- data/spec/tec_doc/article_spec.rb +185 -0
- data/spec/tec_doc/article_thumbnail_spec.rb +34 -0
- data/spec/tec_doc/assembly_group_spec.rb +48 -0
- data/spec/tec_doc/brand_spec.rb +22 -0
- data/spec/tec_doc/client_spec.rb +11 -0
- data/spec/tec_doc/date_parser_spec.rb +17 -0
- data/spec/tec_doc/generic_article_spec.rb +30 -0
- data/spec/tec_doc/language_spec.rb +22 -0
- data/spec/tec_doc/vehicle_manufacturer_spec.rb +43 -0
- data/spec/tec_doc/vehicle_model_spec.rb +35 -0
- data/spec/tec_doc/vehicle_spec.rb +80 -0
- metadata +426 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.unshift File.dirname(__FILE__) + '/../lib'
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler/setup"
|
5
|
+
require "tec_doc"
|
6
|
+
require "vcr"
|
7
|
+
require "simplecov"
|
8
|
+
|
9
|
+
SimpleCov.start
|
10
|
+
|
11
|
+
VCR.config do |c|
|
12
|
+
c.cassette_library_dir = "spec/cassettes"
|
13
|
+
c.stub_with :fakeweb
|
14
|
+
c.ignore_localhost = true
|
15
|
+
c.default_cassette_options = { :record => :new_episodes }
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.extend VCR::RSpec::Macros
|
20
|
+
config.before(:all) do
|
21
|
+
I18n.locale = "lv"
|
22
|
+
TecDoc.client = TecDoc::Client.new(
|
23
|
+
:provider => 330,
|
24
|
+
:country => "lv",
|
25
|
+
:mode => :test
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe TecDoc::ArticleDocument do
|
4
|
+
context ".all" do
|
5
|
+
before do
|
6
|
+
VCR.use_cassette('article_document_all') do
|
7
|
+
@documents = TecDoc::ArticleDocument.all(:article_id => 201756)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return array of documents" do
|
12
|
+
@documents.should be_an_instance_of(Array)
|
13
|
+
@documents.size.should > 0
|
14
|
+
@documents.each do |document|
|
15
|
+
document.should be_an_instance_of(TecDoc::ArticleDocument)
|
16
|
+
document.id.should be_kind_of(Integer)
|
17
|
+
document.id.should > 0
|
18
|
+
document.file_name.should be_an_instance_of(String)
|
19
|
+
document.file_name.size.should > 0
|
20
|
+
document.type_id.should be_kind_of(Integer)
|
21
|
+
document.type_id.size.should > 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#content" do
|
26
|
+
it "should return picture" do
|
27
|
+
document = @documents[0]
|
28
|
+
VCR.use_cassette('article_document_content') do
|
29
|
+
document.content.should include("JFIF")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe TecDoc::Article do
|
5
|
+
context ".search" do
|
6
|
+
before do
|
7
|
+
VCR.use_cassette('article_search') do
|
8
|
+
@articles = TecDoc::Article.search(
|
9
|
+
:article_number => "31966",
|
10
|
+
:number_type => 10,
|
11
|
+
:search_exact => false
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return array of articles" do
|
17
|
+
@articles.should be_an_instance_of(Array)
|
18
|
+
@articles.each do |article|
|
19
|
+
article.should be_an_instance_of(TecDoc::Article)
|
20
|
+
article.id.should be_kind_of(Integer)
|
21
|
+
article.id.should > 0
|
22
|
+
article.name.should be_an_instance_of(String)
|
23
|
+
article.name.size.should > 0
|
24
|
+
article.search_number.size.should > 0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "#article_details" do
|
29
|
+
before do
|
30
|
+
@article = @articles.detect { |a| a.brand_name == "FEBI BILSTEIN" && a.number == "31966" }
|
31
|
+
VCR.use_cassette('article_details') do
|
32
|
+
@article.send(:article_details)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should have EAN number" do
|
37
|
+
@article.ean_number.should == "4027816319665"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have information" do
|
41
|
+
VCR.use_cassette("article_information") do
|
42
|
+
@article.send(:direct_article_data_en)
|
43
|
+
end
|
44
|
+
@article.information[0][:info_text].should == "for air conditioning"
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with state and trade number" do
|
48
|
+
before do
|
49
|
+
VCR.use_cassette('article_trade_number') do
|
50
|
+
@article = TecDoc::Article.search(
|
51
|
+
:article_number => "4PK1217",
|
52
|
+
:number_type => 0,
|
53
|
+
:search_exact => true
|
54
|
+
)[0]
|
55
|
+
end
|
56
|
+
|
57
|
+
VCR.use_cassette('article_details_for_trade_number') do
|
58
|
+
@article.send(:article_details)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should have state" do
|
63
|
+
@article.state.should == "Normāls"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should have trade number" do
|
67
|
+
@article.trade_numbers.should == "4 PK 1216, 4 PK 1217, 4 PK 1218, 4 PK 1219"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should have OE numbers" do
|
72
|
+
@article.oe_numbers.size.should > 0
|
73
|
+
@article.oe_numbers.each do |oe_number|
|
74
|
+
oe_number.should be_an_instance_of(TecDoc::ArticleOENumber)
|
75
|
+
oe_number.brand_name.should == "BMW"
|
76
|
+
oe_number.oe_number.should be_an_instance_of(String)
|
77
|
+
oe_number.oe_number.size.should > 0
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should have attributes" do
|
82
|
+
@article.attributes.size.should > 0
|
83
|
+
@article.attributes.each do |attribute|
|
84
|
+
attribute.name.should be_an_instance_of(String)
|
85
|
+
attribute.name.size.should > 0
|
86
|
+
attribute.value.should be_an_instance_of(String)
|
87
|
+
attribute.value.size.should > 0
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context ".all" do
|
94
|
+
it "should return all vehicles articles with specified generic article" do
|
95
|
+
VCR.use_cassette('article_all') do
|
96
|
+
@articles = TecDoc::Article.all(
|
97
|
+
:linking_target_type => "C",
|
98
|
+
:linking_target_id => 10502,
|
99
|
+
:generic_article_id => { :array => {:id => [7] } }
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
@articles.count.should == 30
|
104
|
+
@articles.map(&:generic_article_id).uniq.should == [7]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context ".all_with_details" do
|
109
|
+
it "should get all article detail information in and set it to articles" do
|
110
|
+
VCR.use_cassette("article_all_with_details") do
|
111
|
+
@articles = TecDoc::Article.all_with_details(:ids => [208662, 212551])
|
112
|
+
end
|
113
|
+
|
114
|
+
@articles.each do |article|
|
115
|
+
["07642101", "07642077"].include?(article.instance_variable_get(:@trade_number))
|
116
|
+
article.instance_variable_get(:@attributes).to_a.empty?.should be_false
|
117
|
+
article.id.should_not be_nil
|
118
|
+
article.number.should_not be_nil
|
119
|
+
article.brand_number.should_not be_nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "for linked_manufacturers and linked vehicles" do
|
125
|
+
before do
|
126
|
+
VCR.use_cassette('article_search_for_linked_manufacturers') do
|
127
|
+
@articles = TecDoc::Article.search(
|
128
|
+
:article_number => "4PK1025",
|
129
|
+
:number_type => 0,
|
130
|
+
:search_exact => true
|
131
|
+
)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should return array of linked manufacturers" do
|
136
|
+
VCR.use_cassette('article_linked_manufacturers') do
|
137
|
+
@articles[0].linked_manufacturers
|
138
|
+
end
|
139
|
+
@articles[0].linked_manufacturers.map(&:name).should == ["CITRO","HONDA","NISSA","SUZUK"]
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should return array of linked vehicle ids" do
|
143
|
+
VCR.use_cassette('article_linked_vehicle_ids') do
|
144
|
+
@articles[0].linked_vehicle_ids
|
145
|
+
end
|
146
|
+
@articles[0].linked_vehicle_ids.count.should == 16
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should return array of linked vehicles" do
|
150
|
+
VCR.use_cassette('article_linked_vehicles') do
|
151
|
+
@articles[0].linked_vehicles
|
152
|
+
end
|
153
|
+
@articles[0].linked_vehicles.count.should == 30
|
154
|
+
@articles[0].linked_vehicles.map(&:motor_codes).flatten.uniq.include?("A 18 XER").should be_true
|
155
|
+
@articles[0].linked_vehicles.first.class.should == TecDoc::Vehicle
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should return article linked vehicle with details" do
|
159
|
+
VCR.use_cassette('article_linked_vehicles_with_details') do
|
160
|
+
@articles[0].linked_vehicles_with_details
|
161
|
+
end
|
162
|
+
|
163
|
+
vehicle = @articles[0].linked_vehicles_with_details.detect{ |v| v.name =~ /HYUNDAI/i }
|
164
|
+
vehicle.manu_id.should > 0
|
165
|
+
vehicle.mod_id.should > 0
|
166
|
+
vehicle.attributes.length.should == 3
|
167
|
+
|
168
|
+
attribute = vehicle.attributes[0]
|
169
|
+
attribute.name.should == "Sākot ar izlaiduma gadu"
|
170
|
+
attribute.value.should == TecDoc::DateParser.new("199207").to_date
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "super long list for linking targets" do
|
175
|
+
it "should successfully rescue from error and fetch all linked vehicles by manufacturers" do
|
176
|
+
VCR.use_cassette('article_with_a_lot_linked_vehicles') do
|
177
|
+
@article = TecDoc::Article.all_with_details(:ids => [948671])[0]
|
178
|
+
end
|
179
|
+
VCR.use_cassette('linked_targets_by_manufacturers') do
|
180
|
+
@article.linked_targets
|
181
|
+
end
|
182
|
+
@article.linked_targets.size.should > 7000
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe TecDoc::ArticleThumbnail do
|
4
|
+
context ".all" do
|
5
|
+
before do
|
6
|
+
VCR.use_cassette('article_thumbnail_all') do
|
7
|
+
@thumbnails = TecDoc::ArticleThumbnail.all(:article_id => 201756)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return array of thumbnails" do
|
12
|
+
@thumbnails.should be_an_instance_of(Array)
|
13
|
+
@thumbnails.size.should > 0
|
14
|
+
@thumbnails.each do |thumbnail|
|
15
|
+
thumbnail.should be_an_instance_of(TecDoc::ArticleThumbnail)
|
16
|
+
thumbnail.id.should be_kind_of(Integer)
|
17
|
+
thumbnail.id.should > 0
|
18
|
+
thumbnail.file_name.should be_an_instance_of(String)
|
19
|
+
thumbnail.file_name.size.should > 0
|
20
|
+
thumbnail.type_id.should be_kind_of(Integer)
|
21
|
+
thumbnail.type_id.size.should > 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#content" do
|
26
|
+
it "should return picture" do
|
27
|
+
thumbnail = @thumbnails[0]
|
28
|
+
VCR.use_cassette('article_thumbnail_content') do
|
29
|
+
thumbnail.content.should include("JFIF")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe TecDoc::AssemblyGroup do
|
4
|
+
context ".all" do
|
5
|
+
before do
|
6
|
+
VCR.use_cassette('assembly_group_all') do
|
7
|
+
@groups = TecDoc::AssemblyGroup.all(
|
8
|
+
:child_nodes => false,
|
9
|
+
:linking_target_type => "C"
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return array of groups" do
|
15
|
+
@groups.should be_an_instance_of(Array)
|
16
|
+
@groups.each do |group|
|
17
|
+
group.should be_an_instance_of(TecDoc::AssemblyGroup)
|
18
|
+
group.id.should be_kind_of(Integer)
|
19
|
+
group.id.should > 0
|
20
|
+
group.name.should be_an_instance_of(String)
|
21
|
+
group.name.size.should > 0
|
22
|
+
group.parent_id.should be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "#children" do
|
27
|
+
before do
|
28
|
+
@parent = @groups.first
|
29
|
+
VCR.use_cassette('assembly_group_children') do
|
30
|
+
@children = @parent.children
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have children" do
|
35
|
+
@children.should be_an_instance_of(Array)
|
36
|
+
@children.each do |group|
|
37
|
+
group.should be_an_instance_of(TecDoc::AssemblyGroup)
|
38
|
+
group.id.should be_kind_of(Integer)
|
39
|
+
group.id.should > 0
|
40
|
+
group.name.should be_an_instance_of(String)
|
41
|
+
group.name.size.should > 0
|
42
|
+
group.parent_id.should == @parent.id
|
43
|
+
group.parent.should == @parent
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe TecDoc::Brand do
|
4
|
+
context ".all" do
|
5
|
+
before do
|
6
|
+
VCR.use_cassette('brand_all') do
|
7
|
+
@brands = TecDoc::Brand.all
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return array of brands" do
|
12
|
+
@brands.should be_an_instance_of(Array)
|
13
|
+
@brands.each do |brand|
|
14
|
+
brand.should be_an_instance_of(TecDoc::Brand)
|
15
|
+
brand.number.should be_kind_of(Integer)
|
16
|
+
brand.number.should > 0
|
17
|
+
brand.name.should be_an_instance_of(String)
|
18
|
+
brand.name.size.should > 0
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe TecDoc::Client do
|
4
|
+
it "should raise TecDoc::Error with status_text when the returned XML doesn't contains <status>200</status>" do
|
5
|
+
lambda {
|
6
|
+
VCR.use_cassette('status_401') do
|
7
|
+
TecDoc.client.request(:get_pegasus_version_info)
|
8
|
+
end
|
9
|
+
}.should raise_error(TecDoc::Error, "Access not allowed")
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe TecDoc::DateParser do
|
4
|
+
describe "#to_date" do
|
5
|
+
it "should convert 199904 to April 1st, 1999" do
|
6
|
+
TecDoc::DateParser.new("199904").to_date.should == Date.new(1999, 4, 1)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should convert 201012 to December 1st, 2012" do
|
10
|
+
TecDoc::DateParser.new("201012").to_date.should == Date.new(2010, 12, 1)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return nil when nil" do
|
14
|
+
TecDoc::DateParser.new(nil).to_date.should == nil
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe TecDoc::GenericArticle do
|
5
|
+
before do
|
6
|
+
VCR.use_cassette("generic_article_all") do
|
7
|
+
@generic_articles = TecDoc::GenericArticle.all({
|
8
|
+
:linking_target_type => "C",
|
9
|
+
:linking_target_id => 10502,
|
10
|
+
:generic_article_id => { :array => { :id => [7] } },
|
11
|
+
})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context ".all" do
|
16
|
+
it "should return distinct generic articles" do
|
17
|
+
@generic_articles.count.should == 1
|
18
|
+
@generic_articles.first.name.should == "Eļļas filtrs"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return all vehicles articles without any options if scope is present" do
|
23
|
+
generic_article = TecDoc::GenericArticle.new(:id => 7)
|
24
|
+
VCR.use_cassette("article_all") do
|
25
|
+
@articles = generic_article.articles
|
26
|
+
end
|
27
|
+
@articles.count.should == 30
|
28
|
+
@articles.map(&:generic_article_id).uniq.should == [ 7 ]
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe TecDoc::Language do
|
4
|
+
context ".all" do
|
5
|
+
before do
|
6
|
+
VCR.use_cassette('language_all') do
|
7
|
+
@languages = TecDoc::Language.all
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return array of languages" do
|
12
|
+
@languages.should be_an_instance_of(Array)
|
13
|
+
@languages.each do |language|
|
14
|
+
language.should be_an_instance_of(TecDoc::Language)
|
15
|
+
language.code.should be_an_instance_of(String)
|
16
|
+
language.code.size.should > 0
|
17
|
+
language.name.should be_an_instance_of(String)
|
18
|
+
language.name.size.should > 0
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|