elibri_onix 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elibri_onix (0.2.1)
4
+ elibri_onix (0.2.2)
5
5
  activesupport (>= 2.3.5)
6
6
  elibri_onix_dict (>= 0.0.5)
7
7
  i18n
@@ -23,7 +23,6 @@ GEM
23
23
  metaclass (~> 0.0.1)
24
24
  multi_json (1.5.0)
25
25
  nokogiri (1.5.6)
26
- nokogiri (1.5.6-java)
27
26
  pry (0.9.9.6)
28
27
  coderay (~> 1.0.5)
29
28
  method_source (~> 0.7.1)
@@ -18,7 +18,7 @@ module Elibri
18
18
  :deletion_text, :cover_type, :cover_price, :vat, :pkwiu, :product_composition, :product_form, :imprint,
19
19
  :publisher, :product_form, :no_contributor, :edition_statement, :number_of_illustrations, :publishing_status,
20
20
  :publishing_date, :premiere, :front_cover, :series_names, :city_of_publication,
21
- :elibri_product_category1_id, :elibri_product_category2_id, :preview_exists, :short_description
21
+ :elibri_product_category1_id, :elibri_product_category2_id, :preview_exists, :short_description, :sale_restricted_to_poland
22
22
  ]
23
23
 
24
24
 
@@ -38,8 +38,8 @@ module Elibri
38
38
  :file_size, :publisher_name, :publisher_id, :imprint_name, :current_state, :reading_age_from, :reading_age_to,
39
39
  :table_of_contents, :description, :reviews, :excerpts, :series, :title, :subtitle, :collection_title,
40
40
  :collection_part, :full_title, :original_title, :trade_title, :short_description,
41
- :elibri_product_category1_id, :elibri_product_category2_id, :preview_exists
42
-
41
+ :elibri_product_category1_id, :elibri_product_category2_id, :preview_exists, :unlimited_licence,
42
+ :licence_limited_to_before_type_cast, :licence_limited_to, :digital_formats, :technical_protection
43
43
 
44
44
  #from xml_accessor
45
45
  attr_accessor :record_reference, :notification_type, :deletion_text
@@ -49,7 +49,7 @@ module Elibri
49
49
  :product_composition, :product_form, :measures, :title_details, :collections, :contributors, :no_contributor,
50
50
  :languages, :extents, :subjects, :audience_ranges, :edition_statement, :number_of_illustrations, :text_contents,
51
51
  :supporting_resources, :imprint, :publisher, :publishing_status, :publishing_date, :sales_restrictions,
52
- :identifiers, :related_products, :supply_details, :to_xml, :city_of_publication
52
+ :identifiers, :related_products, :supply_details, :to_xml, :city_of_publication, :sale_restricted_to_poland
53
53
 
54
54
 
55
55
  def initialize(data)
@@ -95,8 +95,19 @@ module Elibri
95
95
  descriptive_details_setup(data.at_xpath('xmlns:DescriptiveDetail')) if data.at_xpath('xmlns:DescriptiveDetail')
96
96
  collateral_details_setup(data.at_xpath('xmlns:CollateralDetail')) if data.at_xpath('xmlns:CollateralDetail')
97
97
  publishing_details_setup(data.at_xpath('xmlns:PublishingDetail')) if data.at_xpath('xmlns:PublishingDetail')
98
+ licence_information_setup(data)
98
99
  after_parse
99
100
  end
101
+
102
+ def licence_information_setup(data)
103
+ if data.at_xpath("elibri:SaleNotRestricted")
104
+ @unlimited_licence = true
105
+ elsif date = data.at_xpath("elibri:SaleRestrictedTo").try(:text)
106
+ @unlimited_licence = false
107
+ @licence_limited_to_before_type_cast = date
108
+ @licence_limited_to = Date.new(date[0...4].to_i, date[4...6].to_i, date[6...8].to_i)
109
+ end
110
+ end
100
111
 
101
112
  def descriptive_details_setup(data)
102
113
  @product_composition = data.at_xpath('xmlns:ProductComposition').try(:text)
@@ -110,6 +121,19 @@ module Elibri
110
121
  @extents = data.xpath('xmlns:Extent').map { |extent_data| Extent.new(extent_data) }
111
122
  @subjects = data.xpath('xmlns:Subject').map { |subject_data| Subject.new(subject_data) }
112
123
  @audience_ranges = data.xpath('xmlns:AudienceRange').map { |audience_data| AudienceRange.new(audience_data) }
124
+
125
+ if data.xpath("xmlns:ProductFormDetail").size > 0
126
+ @digital_formats = []
127
+ data.xpath("xmlns:ProductFormDetail").each do |format|
128
+ @digital_formats << Elibri::ONIX::Dict::Release_3_0::ProductFormDetail::find_by_onix_code(format.text).name.upcase.gsub("MOBIPOCKET", "MOBI")
129
+ end
130
+ end
131
+
132
+ #zabezpiecznie pliku
133
+ if protection = data.at_xpath("xmlns:EpubTechnicalProtection").try(:text)
134
+ @technical_protection = Elibri::ONIX::Dict::Release_3_0::EpubTechnicalProtection::find_by_onix_code(protection).name
135
+ end
136
+
113
137
  @edition_statement = data.at_xpath('xmlns:EditionStatement').try(:text)
114
138
  @number_of_illustrations = data.at_xpath('xmlns:NumberOfIllustrations').try(:text).try(:to_i)
115
139
  end
@@ -126,6 +150,13 @@ module Elibri
126
150
  @city_of_publication = data.at_xpath("xmlns:CityOfPublication").try(:text)
127
151
  @publishing_date = PublishingDate.new(data.at_xpath('xmlns:PublishingDate')) if data.at_xpath('xmlns:PublishingDate')
128
152
  @sales_restrictions = data.xpath('xmlns:SalesRestriction').map { |restriction_data| SalesRestriction.new(restriction_data) }
153
+ #ograniczenia terytorialne
154
+ if data.at_xpath(".//xmlns:CountriesIncluded").try(:text) == "PL"
155
+ @sale_restricted_to_poland = true
156
+ else
157
+ @sale_restricted_to_poland = false
158
+ end
159
+
129
160
  end
130
161
 
131
162
  # Attributes in namespace elibri:* are specific for dialect >= 3.0.1.
@@ -274,6 +305,8 @@ private
274
305
  compute_state!
275
306
  end
276
307
 
308
+
309
+
277
310
  def compute_state!
278
311
  if @notification_type == "01"
279
312
  @current_state = :announced
@@ -2,7 +2,7 @@ module Elibri
2
2
  module ONIX
3
3
  z = $VERBOSE
4
4
  $VERBOSE = nil
5
- VERSION = "0.2.2"
5
+ VERSION = "0.2.3"
6
6
  Version = VERSION
7
7
  $VERBOSE = z
8
8
  end
@@ -0,0 +1,12 @@
1
+ #encoding: UTF-8
2
+ require 'helper'
3
+
4
+ describe Elibri::ONIX::Release_3_0::ONIXMessage do
5
+
6
+ it "should be able to parse formats and technical protection" do
7
+
8
+ product = load_fixture("onix_epub_details_example.xml")
9
+ assert_equal ["EPUB", "MOBI"], product.digital_formats
10
+ assert_equal "DRM", product.technical_protection
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ #encoding: UTF-8
2
+ require 'helper'
3
+
4
+ describe Elibri::ONIX::Release_3_0::ONIXMessage do
5
+
6
+ it "should be able to parse licence end info" do
7
+
8
+ product = load_fixture("onix_unlimited_book_sample_example.xml")
9
+ assert product.unlimited_licence
10
+
11
+ product = load_fixture("onix_epub_details_example.xml")
12
+ assert !product.unlimited_licence
13
+ assert_equal "20140307", product.licence_limited_to_before_type_cast
14
+ assert_equal Date.new(2014, 3, 7), product.licence_limited_to
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ #encoding: UTF-8
2
+ require 'helper'
3
+
4
+ describe Elibri::ONIX::Release_3_0::ONIXMessage do
5
+
6
+ it "should be able to parse territorial rights info" do
7
+
8
+ product1 = load_fixture("onix_territorial_rights_example.xml", 0)
9
+ assert product1.sale_restricted_to_poland
10
+
11
+ product2 = load_fixture("onix_territorial_rights_example.xml", 1)
12
+ assert !product2.sale_restricted_to_poland
13
+ end
14
+ end
@@ -0,0 +1,54 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ONIXMessage release="3.0" xmlns="http://ns.editeur.org/onix/3.0/reference" xmlns:elibri="http://elibri.com.pl/ns/extensions">
3
+ <elibri:Dialect>3.0.1</elibri:Dialect>
4
+ <Header>
5
+ <Sender>
6
+ <SenderName>Elibri.com.pl</SenderName>
7
+ <ContactName>Tomasz Meka</ContactName>
8
+ <EmailAddress>kontakt@elibri.com.pl</EmailAddress>
9
+ </Sender>
10
+ <SentDateTime>20111111</SentDateTime>
11
+ </Header>
12
+ <Product>
13
+ <RecordReference>fdb8fa072be774d97a97</RecordReference>
14
+ <NotificationType>03</NotificationType>
15
+ <ProductIdentifier>
16
+ <ProductIDType>15</ProductIDType>
17
+ <IDValue>9788324799992</IDValue>
18
+ </ProductIdentifier>
19
+ <DescriptiveDetail>
20
+ <ProductComposition>00</ProductComposition>
21
+ <ProductForm>EA</ProductForm>
22
+ <ProductFormDetail>E101</ProductFormDetail>
23
+ <ProductFormDetail>E127</ProductFormDetail>
24
+ <EpubTechnicalProtection>01</EpubTechnicalProtection>
25
+ <TitleDetail>
26
+ <TitleType>01</TitleType>
27
+ <TitleElement>
28
+ <TitleElementLevel>01</TitleElementLevel>
29
+ <TitleText>Nielegalni</TitleText>
30
+ </TitleElement>
31
+ </TitleDetail>
32
+ </DescriptiveDetail>
33
+ <PublishingDetail>
34
+ <Publisher>
35
+ <PublishingRole>01</PublishingRole>
36
+ <PublisherIdentifier>
37
+ <PublisherIDType>01</PublisherIDType>
38
+ <IDTypeName>ElibriPublisherCode</IDTypeName>
39
+ <IDValue>11</IDValue>
40
+ </PublisherIdentifier>
41
+ <PublisherName>GREG</PublisherName>
42
+ </Publisher>
43
+ <PublishingStatus>04</PublishingStatus>
44
+ <SalesRights>
45
+ <SalesRightsType>01</SalesRightsType>
46
+ <Territory>
47
+ <RegionsIncluded>WORLD</RegionsIncluded>
48
+ </Territory>
49
+ </SalesRights>
50
+ </PublishingDetail>
51
+ <elibri:preview_exists>false</elibri:preview_exists>
52
+ <elibri:SaleRestrictedTo>20140307</elibri:SaleRestrictedTo>
53
+ </Product>
54
+ </ONIXMessage>
@@ -0,0 +1,88 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ONIXMessage release="3.0" xmlns="http://ns.editeur.org/onix/3.0/reference" xmlns:elibri="http://elibri.com.pl/ns/extensions">
3
+ <elibri:Dialect>3.0.1</elibri:Dialect>
4
+ <Header>
5
+ <Sender>
6
+ <SenderName>Elibri.com.pl</SenderName>
7
+ <ContactName>Tomasz Meka</ContactName>
8
+ <EmailAddress>kontakt@elibri.com.pl</EmailAddress>
9
+ </Sender>
10
+ <SentDateTime>20111111</SentDateTime>
11
+ </Header>
12
+ <Product>
13
+ <RecordReference>fdb8fa072be774d97a97</RecordReference>
14
+ <NotificationType>03</NotificationType>
15
+ <ProductIdentifier>
16
+ <ProductIDType>15</ProductIDType>
17
+ <IDValue>9788324799992</IDValue>
18
+ </ProductIdentifier>
19
+ <DescriptiveDetail>
20
+ <ProductComposition>00</ProductComposition>
21
+ <ProductForm>BA</ProductForm>
22
+ <TitleDetail>
23
+ <TitleType>01</TitleType>
24
+ <TitleElement>
25
+ <TitleElementLevel>01</TitleElementLevel>
26
+ <TitleText>Nielegalni</TitleText>
27
+ </TitleElement>
28
+ </TitleDetail>
29
+ </DescriptiveDetail>
30
+ <PublishingDetail>
31
+ <Publisher>
32
+ <PublishingRole>01</PublishingRole>
33
+ <PublisherIdentifier>
34
+ <PublisherIDType>01</PublisherIDType>
35
+ <IDTypeName>ElibriPublisherCode</IDTypeName>
36
+ <IDValue>11</IDValue>
37
+ </PublisherIdentifier>
38
+ <PublisherName>GREG</PublisherName>
39
+ </Publisher>
40
+ <PublishingStatus>04</PublishingStatus>
41
+ <SalesRights>
42
+ <SalesRightsType>01</SalesRightsType>
43
+ <Territory>
44
+ <CountriesIncluded>PL</CountriesIncluded>
45
+ </Territory>
46
+ </SalesRights>
47
+ </PublishingDetail>
48
+ <elibri:preview_exists>false</elibri:preview_exists>
49
+ </Product>
50
+ <Product>
51
+ <RecordReference>fdb8fa072be774d97a97</RecordReference>
52
+ <NotificationType>03</NotificationType>
53
+ <ProductIdentifier>
54
+ <ProductIDType>15</ProductIDType>
55
+ <IDValue>9788324799992</IDValue>
56
+ </ProductIdentifier>
57
+ <DescriptiveDetail>
58
+ <ProductComposition>00</ProductComposition>
59
+ <ProductForm>BA</ProductForm>
60
+ <TitleDetail>
61
+ <TitleType>01</TitleType>
62
+ <TitleElement>
63
+ <TitleElementLevel>01</TitleElementLevel>
64
+ <TitleText>Nielegalni</TitleText>
65
+ </TitleElement>
66
+ </TitleDetail>
67
+ </DescriptiveDetail>
68
+ <PublishingDetail>
69
+ <Publisher>
70
+ <PublishingRole>01</PublishingRole>
71
+ <PublisherIdentifier>
72
+ <PublisherIDType>01</PublisherIDType>
73
+ <IDTypeName>ElibriPublisherCode</IDTypeName>
74
+ <IDValue>11</IDValue>
75
+ </PublisherIdentifier>
76
+ <PublisherName>GREG</PublisherName>
77
+ </Publisher>
78
+ <PublishingStatus>04</PublishingStatus>
79
+ <SalesRights>
80
+ <SalesRightsType>01</SalesRightsType>
81
+ <Territory>
82
+ <RegionsIncluded>WORLD</RegionsIncluded>
83
+ </Territory>
84
+ </SalesRights>
85
+ </PublishingDetail>
86
+ <elibri:preview_exists>false</elibri:preview_exists>
87
+ </Product>
88
+ </ONIXMessage>
@@ -0,0 +1,55 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ONIXMessage release="3.0" xmlns="http://ns.editeur.org/onix/3.0/reference" xmlns:elibri="http://elibri.com.pl/ns/extensions">
3
+ <elibri:Dialect>3.0.1</elibri:Dialect>
4
+ <Header>
5
+ <Sender>
6
+ <SenderName>Elibri.com.pl</SenderName>
7
+ <ContactName>Tomasz Meka</ContactName>
8
+ <EmailAddress>kontakt@elibri.com.pl</EmailAddress>
9
+ </Sender>
10
+ <SentDateTime>20111111</SentDateTime>
11
+ </Header>
12
+ <Product>
13
+ <RecordReference>fdb8fa072be774d97a97</RecordReference>
14
+ <NotificationType>03</NotificationType>
15
+ <ProductIdentifier>
16
+ <ProductIDType>15</ProductIDType>
17
+ <IDValue>9788324799992</IDValue>
18
+ </ProductIdentifier>
19
+ <DescriptiveDetail>
20
+ <ProductComposition>00</ProductComposition>
21
+ <ProductForm>EA</ProductForm>
22
+ <EpubUsageConstraint>
23
+ <EpubUsageType>01</EpubUsageType>
24
+ <EpubUsageStatus>01</EpubUsageStatus>
25
+ </EpubUsageConstraint>
26
+ <TitleDetail>
27
+ <TitleType>01</TitleType>
28
+ <TitleElement>
29
+ <TitleElementLevel>01</TitleElementLevel>
30
+ <TitleText>Nielegalni</TitleText>
31
+ </TitleElement>
32
+ </TitleDetail>
33
+ </DescriptiveDetail>
34
+ <PublishingDetail>
35
+ <Publisher>
36
+ <PublishingRole>01</PublishingRole>
37
+ <PublisherIdentifier>
38
+ <PublisherIDType>01</PublisherIDType>
39
+ <IDTypeName>ElibriPublisherCode</IDTypeName>
40
+ <IDValue>11</IDValue>
41
+ </PublisherIdentifier>
42
+ <PublisherName>GREG</PublisherName>
43
+ </Publisher>
44
+ <PublishingStatus>04</PublishingStatus>
45
+ <SalesRights>
46
+ <SalesRightsType>01</SalesRightsType>
47
+ <Territory>
48
+ <RegionsIncluded>WORLD</RegionsIncluded>
49
+ </Territory>
50
+ </SalesRights>
51
+ </PublishingDetail>
52
+ <elibri:preview_exists>false</elibri:preview_exists>
53
+ <elibri:SaleNotRestricted/>
54
+ </Product>
55
+ </ONIXMessage>
data/test/helper.rb CHANGED
@@ -22,8 +22,8 @@ require 'elibri_onix'
22
22
  class Test::Unit::TestCase
23
23
  end
24
24
 
25
- def load_fixture(filename)
25
+ def load_fixture(filename, idx = 0)
26
26
  xml_string = File.read File.join(File.dirname(__FILE__), "..", "test", "fixtures", filename)
27
27
  onix = Elibri::ONIX::Release_3_0::ONIXMessage.new(xml_string)
28
- return onix.products.first
28
+ return onix.products[idx]
29
29
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elibri_onix
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marcin Urbanski
@@ -214,7 +214,9 @@ files:
214
214
  - test/elibri_edition_test.rb
215
215
  - test/elibri_extensions_test.rb
216
216
  - test/elibri_extent_test.rb
217
+ - test/elibri_formats_and_protection_test.rb
217
218
  - test/elibri_languages_test.rb
219
+ - test/elibri_licence_information_test.rb
218
220
  - test/elibri_measurement_test.rb
219
221
  - test/elibri_onix_release_3_0_onix_message_test.rb
220
222
  - test/elibri_onix_test.rb
@@ -225,6 +227,7 @@ files:
225
227
  - test/elibri_sale_restrictions_test.rb
226
228
  - test/elibri_series_memberships_test.rb
227
229
  - test/elibri_supporting_resources_test.rb
230
+ - test/elibri_territorial_rights_test.rb
228
231
  - test/elibri_texts_test.rb
229
232
  - test/elibri_titles_test.rb
230
233
  - test/fixtures/all_possible_tags.xml
@@ -238,6 +241,7 @@ files:
238
241
  - test/fixtures/onix_ebook_extent_example.xml
239
242
  - test/fixtures/onix_edition_example.xml
240
243
  - test/fixtures/onix_elibri_extensions_example.xml
244
+ - test/fixtures/onix_epub_details_example.xml
241
245
  - test/fixtures/onix_languages_example.xml
242
246
  - test/fixtures/onix_measurement_example.xml
243
247
  - test/fixtures/onix_no_contributors_example.xml
@@ -250,9 +254,11 @@ files:
250
254
  - test/fixtures/onix_sale_restrictions_example.xml
251
255
  - test/fixtures/onix_series_memberships_example.xml
252
256
  - test/fixtures/onix_supporting_resources_example.xml
257
+ - test/fixtures/onix_territorial_rights_example.xml
253
258
  - test/fixtures/onix_texts_example.xml
254
259
  - test/fixtures/onix_title_with_collection_example.xml
255
260
  - test/fixtures/onix_titles_example.xml
261
+ - test/fixtures/onix_unlimited_book_sample_example.xml
256
262
  - test/helper.rb
257
263
  has_rdoc: true
258
264
  homepage: http://github.com/elibri/elibri_onix
@@ -295,7 +301,9 @@ test_files:
295
301
  - test/elibri_edition_test.rb
296
302
  - test/elibri_extensions_test.rb
297
303
  - test/elibri_extent_test.rb
304
+ - test/elibri_formats_and_protection_test.rb
298
305
  - test/elibri_languages_test.rb
306
+ - test/elibri_licence_information_test.rb
299
307
  - test/elibri_measurement_test.rb
300
308
  - test/elibri_onix_release_3_0_onix_message_test.rb
301
309
  - test/elibri_onix_test.rb
@@ -306,6 +314,7 @@ test_files:
306
314
  - test/elibri_sale_restrictions_test.rb
307
315
  - test/elibri_series_memberships_test.rb
308
316
  - test/elibri_supporting_resources_test.rb
317
+ - test/elibri_territorial_rights_test.rb
309
318
  - test/elibri_texts_test.rb
310
319
  - test/elibri_titles_test.rb
311
320
  - test/fixtures/all_possible_tags.xml
@@ -319,6 +328,7 @@ test_files:
319
328
  - test/fixtures/onix_ebook_extent_example.xml
320
329
  - test/fixtures/onix_edition_example.xml
321
330
  - test/fixtures/onix_elibri_extensions_example.xml
331
+ - test/fixtures/onix_epub_details_example.xml
322
332
  - test/fixtures/onix_languages_example.xml
323
333
  - test/fixtures/onix_measurement_example.xml
324
334
  - test/fixtures/onix_no_contributors_example.xml
@@ -331,7 +341,9 @@ test_files:
331
341
  - test/fixtures/onix_sale_restrictions_example.xml
332
342
  - test/fixtures/onix_series_memberships_example.xml
333
343
  - test/fixtures/onix_supporting_resources_example.xml
344
+ - test/fixtures/onix_territorial_rights_example.xml
334
345
  - test/fixtures/onix_texts_example.xml
335
346
  - test/fixtures/onix_title_with_collection_example.xml
336
347
  - test/fixtures/onix_titles_example.xml
348
+ - test/fixtures/onix_unlimited_book_sample_example.xml
337
349
  - test/helper.rb