elibri_api_client 1.1.0 → 1.1.1
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/Gemfile +3 -2
- data/Gemfile.lock +16 -6
- data/README.rdoc +11 -10
- data/elibri_api_client.gemspec +11 -8
- data/lib/elibri_api_client.rb +6 -2
- data/lib/elibri_api_client/api_adapters/v1.rb +23 -12
- data/lib/elibri_api_client/api_adapters/v1_helpers.rb +14 -26
- data/lib/elibri_api_client/version.rb +1 -1
- data/test/elibri_api_client_test.rb +12 -5
- data/test/elibri_api_v1_adapter_queue_pop_test.rb +18 -38
- data/test/elibri_api_v1_adapter_queue_test.rb +7 -8
- data/test/elibri_api_v1_adapter_test.rb +99 -51
- metadata +37 -23
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (3.1.
|
4
|
+
activesupport (3.1.1)
|
5
5
|
multi_json (~> 1.0)
|
6
6
|
coderay (0.9.8)
|
7
|
-
|
7
|
+
elibri_onix (0.1.3)
|
8
|
+
activesupport (>= 3.1.0)
|
9
|
+
i18n
|
10
|
+
roxml (= 3.1.6)
|
8
11
|
git (1.2.5)
|
9
|
-
httparty (0.
|
10
|
-
|
12
|
+
httparty (0.8.1)
|
13
|
+
multi_json
|
14
|
+
multi_xml
|
15
|
+
i18n (0.6.0)
|
11
16
|
jeweler (1.6.2)
|
12
17
|
bundler (~> 1.0)
|
13
18
|
git (>= 1.2.5)
|
@@ -17,6 +22,7 @@ GEM
|
|
17
22
|
minitest (2.2.2)
|
18
23
|
mocha (0.9.12)
|
19
24
|
multi_json (1.0.3)
|
25
|
+
multi_xml (0.4.1)
|
20
26
|
nokogiri (1.5.0)
|
21
27
|
pry (0.9.6)
|
22
28
|
coderay (>= 0.9.8)
|
@@ -25,6 +31,9 @@ GEM
|
|
25
31
|
slop (~> 2.1.0)
|
26
32
|
rake (0.9.0)
|
27
33
|
rcov (0.9.9)
|
34
|
+
roxml (3.1.6)
|
35
|
+
activesupport (>= 2.3.0)
|
36
|
+
nokogiri (>= 1.3.3)
|
28
37
|
ruby_parser (2.3.0)
|
29
38
|
sexp_processor (~> 3.0)
|
30
39
|
sexp_processor (3.0.6)
|
@@ -34,9 +43,10 @@ PLATFORMS
|
|
34
43
|
ruby
|
35
44
|
|
36
45
|
DEPENDENCIES
|
37
|
-
activesupport (>= 3.1.0
|
46
|
+
activesupport (>= 3.1.0)
|
38
47
|
bundler (~> 1.0.0)
|
39
|
-
|
48
|
+
elibri_onix (>= 0.1.3)
|
49
|
+
httparty (= 0.8.1)
|
40
50
|
jeweler (~> 1.6.2)
|
41
51
|
minitest
|
42
52
|
mocha
|
data/README.rdoc
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
gem 'elibri_api_client'
|
5
5
|
|
6
6
|
=== 1. Tworzymy instancje klienta
|
7
|
-
elibri = Elibri::ApiClient.new(:login => '1b20fa9d72234423979c', :password => '2847cbf4f15a4057e2ab')
|
7
|
+
elibri = Elibri::ApiClient.new(:login => '1b20fa9d72234423979c', :password => '2847cbf4f15a4057e2ab', :api_version => 'v1', :onix_dialect => '3.0.1')
|
8
8
|
|
9
9
|
=== 2. Przegladanie dostepnych danych
|
10
10
|
|
@@ -24,16 +24,15 @@
|
|
24
24
|
|
25
25
|
# Wypelnij wszystkie kolejki oczekujace, wszystkimi dostepnymi danymi.
|
26
26
|
# Przydatne przy wykonywaniu pelnej synchronizacji pomiedzy nasza aplikacja a Elibri.
|
27
|
-
|
28
|
-
# produktow (moze byc wolniejsze od kolejek zmian).
|
29
|
-
# elibri.refill_all_queues!
|
27
|
+
elibri.refill_all_queues!
|
30
28
|
|
31
29
|
elibri.pending_queues.each do |pending_queue|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
# Wykonuj blok, dopoki sa dane w kolejce
|
31
|
+
pending_queue.each_pop(:count => 10) do |pop|
|
32
|
+
puts pop.onix.release
|
33
|
+
pop.onix.products.each do |product|
|
34
|
+
puts "#{product.record_reference} #{product.isbn13} #{product.publisher.name} #{product.full_title}"
|
35
|
+
end
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
@@ -42,12 +41,14 @@
|
|
42
41
|
meta = elibri.pending_queues.find {|queue| queue.name == 'meta'}
|
43
42
|
|
44
43
|
pop = meta.pop(:count => 5, :testing => true)
|
45
|
-
pop.
|
44
|
+
pop.onix.products.each {|product| puts product.full_title }
|
45
|
+
puts pop.xml
|
46
46
|
|
47
47
|
last_pop = meta.last_pop
|
48
48
|
|
49
49
|
|
50
50
|
==== 3c. Znadz ostatnio pobrane kolejki
|
51
|
+
|
51
52
|
last_pop = elibri.last_pop_from_queue('meta')
|
52
53
|
|
53
54
|
|
data/elibri_api_client.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{elibri_api_client}
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Marcin Urba\305\204ski"]
|
12
|
-
s.date = %q{2011-09
|
12
|
+
s.date = %q{2011-10-09}
|
13
13
|
s.description = %q{API client for elibri.com.pl publishing system}
|
14
14
|
s.email = %q{marcin@urbanski.vdl.pl}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -48,9 +48,10 @@ Gem::Specification.new do |s|
|
|
48
48
|
s.specification_version = 3
|
49
49
|
|
50
50
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
51
|
-
s.add_runtime_dependency(%q<httparty>, ["
|
51
|
+
s.add_runtime_dependency(%q<httparty>, ["= 0.8.1"])
|
52
52
|
s.add_runtime_dependency(%q<nokogiri>, ["~> 1.5.0"])
|
53
|
-
s.add_runtime_dependency(%q<activesupport>, [">= 3.1.0
|
53
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 3.1.0"])
|
54
|
+
s.add_runtime_dependency(%q<elibri_onix>, [">= 0.1.3"])
|
54
55
|
s.add_development_dependency(%q<pry>, [">= 0"])
|
55
56
|
s.add_development_dependency(%q<mocha>, [">= 0"])
|
56
57
|
s.add_development_dependency(%q<minitest>, [">= 0"])
|
@@ -58,9 +59,10 @@ Gem::Specification.new do |s|
|
|
58
59
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
|
59
60
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
60
61
|
else
|
61
|
-
s.add_dependency(%q<httparty>, ["
|
62
|
+
s.add_dependency(%q<httparty>, ["= 0.8.1"])
|
62
63
|
s.add_dependency(%q<nokogiri>, ["~> 1.5.0"])
|
63
|
-
s.add_dependency(%q<activesupport>, [">= 3.1.0
|
64
|
+
s.add_dependency(%q<activesupport>, [">= 3.1.0"])
|
65
|
+
s.add_dependency(%q<elibri_onix>, [">= 0.1.3"])
|
64
66
|
s.add_dependency(%q<pry>, [">= 0"])
|
65
67
|
s.add_dependency(%q<mocha>, [">= 0"])
|
66
68
|
s.add_dependency(%q<minitest>, [">= 0"])
|
@@ -69,9 +71,10 @@ Gem::Specification.new do |s|
|
|
69
71
|
s.add_dependency(%q<rcov>, [">= 0"])
|
70
72
|
end
|
71
73
|
else
|
72
|
-
s.add_dependency(%q<httparty>, ["
|
74
|
+
s.add_dependency(%q<httparty>, ["= 0.8.1"])
|
73
75
|
s.add_dependency(%q<nokogiri>, ["~> 1.5.0"])
|
74
|
-
s.add_dependency(%q<activesupport>, [">= 3.1.0
|
76
|
+
s.add_dependency(%q<activesupport>, [">= 3.1.0"])
|
77
|
+
s.add_dependency(%q<elibri_onix>, [">= 0.1.3"])
|
75
78
|
s.add_dependency(%q<pry>, [">= 0"])
|
76
79
|
s.add_dependency(%q<mocha>, [">= 0"])
|
77
80
|
s.add_dependency(%q<minitest>, [">= 0"])
|
data/lib/elibri_api_client.rb
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
require 'time'
|
3
3
|
require 'httparty'
|
4
4
|
require 'nokogiri'
|
5
|
+
require 'elibri_onix'
|
5
6
|
require 'forwardable'
|
6
7
|
require 'active_support/core_ext/object/blank'
|
7
8
|
require 'active_support/core_ext/hash/keys'
|
9
|
+
require 'active_support/core_ext/string/strip'
|
8
10
|
require 'elibri_api_client/core_extensions'
|
9
11
|
require 'elibri_api_client/version'
|
10
12
|
require 'elibri_api_client/api_adapters'
|
@@ -27,15 +29,17 @@ module Elibri
|
|
27
29
|
# Opcjonalnie mozna podac adres servera API:
|
28
30
|
# cli = Elibri::ApiClient.new(:host_uri => 'http://localhost:3010', :login => '1b20fa9d72234423979c', :password => '2847cbf4f15a4057e2ab')
|
29
31
|
def initialize(options = {})
|
30
|
-
options.assert_valid_keys(:login, :password, :host_uri, :api_version)
|
32
|
+
options.assert_valid_keys(:login, :password, :host_uri, :api_version, :onix_dialect)
|
31
33
|
@login = options[:login]
|
32
34
|
@password = options[:password]
|
33
35
|
@host_uri = options[:host_uri] || DEFAULT_API_HOST_URI
|
36
|
+
@onix_dialect = options[:onix_dialect]
|
37
|
+
raise 'Please specify :onix_dialect' unless @onix_dialect.present?
|
34
38
|
|
35
39
|
# W przyszlosci moga byc nowe wersje API, wiec zostawiamy sobie furtke w postaci adapterow:
|
36
40
|
api_version_str = options[:api_version] || 'v1'
|
37
41
|
adapter_class = Elibri::ApiClient::ApiAdapters.const_get(api_version_str.upcase) # Elibri::ApiClient::ApiAdapters::V1
|
38
|
-
@api_adapter = adapter_class.new(@host_uri, @login, @password)
|
42
|
+
@api_adapter = adapter_class.new(@host_uri, @login, @password, @onix_dialect)
|
39
43
|
end
|
40
44
|
|
41
45
|
|
@@ -14,8 +14,9 @@ module Elibri
|
|
14
14
|
# debug_output $stderr
|
15
15
|
#++
|
16
16
|
|
17
|
-
def initialize(host_uri, login, password) #:nodoc:
|
17
|
+
def initialize(host_uri, login, password, onix_dialect) #:nodoc:
|
18
18
|
@host_uri = host_uri
|
19
|
+
@onix_dialect = onix_dialect
|
19
20
|
@auth = {:username => login, :password => password}
|
20
21
|
end
|
21
22
|
|
@@ -73,20 +74,30 @@ module Elibri
|
|
73
74
|
end
|
74
75
|
|
75
76
|
|
76
|
-
#
|
77
|
-
def pop_from_queue(queue_name,
|
78
|
-
|
79
|
-
|
80
|
-
response = post "/queues/#{queue_name}/pop", :body =>
|
81
|
-
|
82
|
-
|
77
|
+
# params moze przyjac {:testing => 1, :count => 100}
|
78
|
+
def pop_from_queue(queue_name, params = {})
|
79
|
+
params[:testing] = 1 if params[:testing]
|
80
|
+
params = ' ' if params.empty?
|
81
|
+
response = post "/queues/#{queue_name}/pop", :body => params, :headers => {"X-eLibri-API-ONIX-dialect" => @onix_dialect}
|
82
|
+
|
83
|
+
return nil unless response.headers["x-elibri-api-pop-products-count"].to_i > 0
|
84
|
+
Elibri::ApiClient::ApiAdapters::V1::QueuePop.new(
|
85
|
+
:queue_name => response.headers["x-elibri-api-pop-queue-name"],
|
86
|
+
:popped_products_count => response.headers["x-elibri-api-pop-products-count"],
|
87
|
+
:created_at => response.headers["x-elibri-api-pop-created-at"],
|
88
|
+
:xml => response.body
|
89
|
+
)
|
83
90
|
end
|
84
91
|
|
85
92
|
|
86
93
|
def last_pop_from_queue(queue_name)
|
87
|
-
response = get "/queues/#{queue_name}/last_pop"
|
88
|
-
|
89
|
-
|
94
|
+
response = get "/queues/#{queue_name}/last_pop", :headers => {"X-eLibri-API-ONIX-dialect" => @onix_dialect}
|
95
|
+
Elibri::ApiClient::ApiAdapters::V1::QueuePop.new(
|
96
|
+
:queue_name => response.headers["x-elibri-api-pop-queue-name"],
|
97
|
+
:popped_products_count => response.headers["x-elibri-api-pop-products-count"],
|
98
|
+
:created_at => response.headers["x-elibri-api-pop-created-at"],
|
99
|
+
:xml => response.body
|
100
|
+
)
|
90
101
|
rescue Exceptions::NoRecentlyPoppedData # Ignoruj bledy o braku ostatnich POPow.
|
91
102
|
return nil
|
92
103
|
end
|
@@ -109,7 +120,7 @@ module Elibri
|
|
109
120
|
# Zwroc ONIX dla konkretnego produktu.
|
110
121
|
def onix_xml_for_product(product) #:nodoc:
|
111
122
|
raise 'Need a Elibri::ApiClient::ApiAdapters::V1::Product instance' unless product.kind_of? Elibri::ApiClient::ApiAdapters::V1::Product
|
112
|
-
resp = get "/products/#{product.record_reference}"
|
123
|
+
resp = get "/products/#{product.record_reference}", :headers => {"X-eLibri-API-ONIX-dialect" => @onix_dialect}
|
113
124
|
resp.parsed_response.css('Product').first
|
114
125
|
end
|
115
126
|
|
@@ -15,6 +15,7 @@ module Elibri #:nodoc:
|
|
15
15
|
class ServerError < RuntimeError; end
|
16
16
|
class QueueDoesNotExists < RuntimeError; end
|
17
17
|
class NoRecentlyPoppedData < RuntimeError; end
|
18
|
+
class InvalidOnixDialect < RuntimeError; end
|
18
19
|
end
|
19
20
|
|
20
21
|
# Klasy wyjatkow rzucanych, gdy elibri zwroci okreslony blad. Np. gdy dostaniemy:
|
@@ -28,6 +29,7 @@ module Elibri #:nodoc:
|
|
28
29
|
'500' => Exceptions::ServerError,
|
29
30
|
'1001' => Exceptions::QueueDoesNotExists,
|
30
31
|
'1002' => Exceptions::NoRecentlyPoppedData,
|
32
|
+
'1003' => Exceptions::InvalidOnixDialect,
|
31
33
|
}.freeze
|
32
34
|
|
33
35
|
|
@@ -62,10 +64,10 @@ module Elibri #:nodoc:
|
|
62
64
|
end
|
63
65
|
|
64
66
|
|
65
|
-
# Iteruj po kolejnych
|
66
|
-
def
|
67
|
-
while
|
68
|
-
_pop
|
67
|
+
# Iteruj po kolejnych POP`ach w nazwanej kolejce.
|
68
|
+
def each_pop(options = {}, &block) #:yields: QueuePop
|
69
|
+
while _pop = pop(options)
|
70
|
+
yield _pop
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
@@ -90,33 +92,19 @@ module Elibri #:nodoc:
|
|
90
92
|
attr_reader :popped_products_count
|
91
93
|
# Kiedy POP zostal wykonany?
|
92
94
|
attr_reader :created_at
|
93
|
-
# ONIX
|
94
|
-
attr_reader :
|
95
|
+
# Pelna tresc ONIX - lacznie z naglowkiem
|
96
|
+
attr_reader :xml
|
97
|
+
# ONIX przeparsowany za pomoca gemu elibri_onix
|
98
|
+
attr_reader :onix
|
95
99
|
|
96
100
|
|
97
101
|
def initialize(attributes = {}) #:nodoc:
|
98
|
-
attributes.assert_valid_keys(:queue_name, :popped_products_count, :created_at, :
|
102
|
+
attributes.assert_valid_keys(:queue_name, :popped_products_count, :created_at, :xml)
|
99
103
|
@queue_name = attributes[:queue_name]
|
100
104
|
@popped_products_count = attributes[:popped_products_count].to_i
|
101
|
-
@
|
102
|
-
@created_at = Time.parse(attributes[:created_at])
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
def each_product(&block)
|
107
|
-
@products_xmls.each(&block)
|
108
|
-
end
|
109
|
-
|
110
|
-
|
111
|
-
# Zbuduj instancje na podstawie XML`a.
|
112
|
-
def self.build_from_xml(pop_xml) #:nodoc:
|
113
|
-
pop_xml = Nokogiri::XML(pop_xml).css('pop').first if pop_xml.is_a? String
|
114
|
-
QueuePop.new(
|
115
|
-
:queue_name => pop_xml['queue_name'],
|
116
|
-
:popped_products_count => pop_xml['popped_products_count'].to_i,
|
117
|
-
:created_at => pop_xml['created_at'],
|
118
|
-
:products_xmls => pop_xml.css('Product')
|
119
|
-
)
|
105
|
+
@xml = attributes[:xml]
|
106
|
+
@created_at = Time.parse(attributes[:created_at]) rescue nil
|
107
|
+
@onix = Elibri::ONIX::Release_3_0::ONIXMessage.from_xml(@xml) if @xml.present?
|
120
108
|
end
|
121
109
|
|
122
110
|
end
|
@@ -7,7 +7,7 @@ module Elibri
|
|
7
7
|
module ApiAdapters
|
8
8
|
# Testowy adapter.
|
9
9
|
class V999
|
10
|
-
def initialize(host_uri, login, password)
|
10
|
+
def initialize(host_uri, login, password, onix_dialect)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -23,22 +23,29 @@ describe Elibri::ApiClient do
|
|
23
23
|
|
24
24
|
|
25
25
|
it "should take some defaults in constructor" do
|
26
|
-
client = Elibri::ApiClient.new(:login => 'elibri_login', :password => 'pass')
|
26
|
+
client = Elibri::ApiClient.new(:login => 'elibri_login', :password => 'pass', :onix_dialect => '3.0.1')
|
27
27
|
assert_equal Elibri::ApiClient::DEFAULT_API_HOST_URI, client.host_uri
|
28
28
|
|
29
|
-
client = Elibri::ApiClient.new(:login => 'elibri_login', :password => 'pass', :host_uri => 'http://localhost:3000')
|
29
|
+
client = Elibri::ApiClient.new(:login => 'elibri_login', :password => 'pass', :host_uri => 'http://localhost:3000', :onix_dialect => '3.0.1')
|
30
30
|
assert_equal 'http://localhost:3000', client.host_uri
|
31
31
|
end
|
32
32
|
|
33
33
|
|
34
|
+
it "should force user to specify ONIX dialect" do
|
35
|
+
assert_raises RuntimeError do
|
36
|
+
Elibri::ApiClient.new(:login => 'elibri_login', :password => 'pass')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
34
41
|
it "should enable user to pick a version of API" do
|
35
|
-
client = Elibri::ApiClient.new(:login => 'elibri_login', :password => 'pass', :api_version => 'v999')
|
42
|
+
client = Elibri::ApiClient.new(:login => 'elibri_login', :password => 'pass', :api_version => 'v999', :onix_dialect => '3.0.1')
|
36
43
|
assert_kind_of Elibri::ApiClient::ApiAdapters::V999, client.instance_variable_get('@api_adapter')
|
37
44
|
end
|
38
45
|
|
39
46
|
|
40
47
|
it "should delegate several methods to apropriate API adapter" do
|
41
|
-
client = Elibri::ApiClient.new(:login => 'elibri_login', :password => 'pass')
|
48
|
+
client = Elibri::ApiClient.new(:login => 'elibri_login', :password => 'pass', :onix_dialect => '3.0.1')
|
42
49
|
|
43
50
|
delegated_methods = %w{refill_all_queues! pending_data? pending_queues publishers}
|
44
51
|
delegated_methods.each {|method_name| client.instance_variable_get('@api_adapter').expects(method_name) }
|
@@ -5,15 +5,22 @@ require 'helper'
|
|
5
5
|
describe Elibri::ApiClient::ApiAdapters::V1::QueuePop do
|
6
6
|
|
7
7
|
before do
|
8
|
-
@
|
9
|
-
|
8
|
+
@xml = <<-XML.strip_heredoc
|
9
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
10
|
+
<ONIXMessage release="3.0" xmlns:elibri="http://elibri.com.pl/ns/extensions" xmlns="http://www.editeur.org/onix/3.0/reference">
|
11
|
+
<elibri:Dialect>3.0.1</elibri:Dialect>
|
12
|
+
<Header>
|
13
|
+
<Sender>
|
14
|
+
<SenderName>Elibri.com.pl</SenderName>
|
15
|
+
<ContactName>Tomasz Meka</ContactName>
|
16
|
+
<EmailAddress>kontakt@elibri.com.pl</EmailAddress>
|
17
|
+
</Sender>
|
18
|
+
<SentDateTime>20111009</SentDateTime>
|
19
|
+
</Header>
|
10
20
|
<Product>
|
11
|
-
<RecordReference>
|
21
|
+
<RecordReference>fdb8fa072be774d97a97</RecordReference>
|
12
22
|
</Product>
|
13
|
-
|
14
|
-
<RecordReference>456</RecordReference>
|
15
|
-
</Product>
|
16
|
-
</root>
|
23
|
+
</ONIXMessage>
|
17
24
|
XML
|
18
25
|
end
|
19
26
|
|
@@ -24,42 +31,15 @@ describe Elibri::ApiClient::ApiAdapters::V1::QueuePop do
|
|
24
31
|
:queue_name => 'meta',
|
25
32
|
:popped_products_count => 120,
|
26
33
|
:created_at => time.to_s,
|
27
|
-
:
|
34
|
+
:xml => @xml
|
28
35
|
)
|
29
36
|
|
30
37
|
assert_equal 'meta', queue_pop.queue_name
|
31
38
|
assert_equal 120, queue_pop.popped_products_count
|
32
39
|
assert_equal time.to_i, queue_pop.created_at.to_i
|
33
|
-
assert_equal @
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
it "should be able to build itself from provided XML" do
|
38
|
-
xml = <<-XML
|
39
|
-
<pop queue_name="meta" popped_products_count="1500" created_at="2011-02-05 21:02:22 UTC">
|
40
|
-
#{@products_xmls.to_s}
|
41
|
-
</pop>
|
42
|
-
XML
|
43
|
-
|
44
|
-
queue_pop = Elibri::ApiClient::ApiAdapters::V1::QueuePop.build_from_xml(xml)
|
45
|
-
assert_equal 'meta', queue_pop.queue_name
|
46
|
-
assert_equal 1500, queue_pop.popped_products_count
|
47
|
-
assert_equal Time.parse("2011-02-05 21:02:22 UTC"), queue_pop.created_at
|
48
|
-
assert_equal 2, queue_pop.products_xmls.size
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
it "should provide iterator for traversing products list" do
|
53
|
-
xml = <<-XML
|
54
|
-
<pop queue_name="meta" popped_products_count="1500" created_at="2011-02-05 21:02:22 UTC">
|
55
|
-
#{@products_xmls.to_s}
|
56
|
-
</pop>
|
57
|
-
XML
|
58
|
-
|
59
|
-
queue_pop = Elibri::ApiClient::ApiAdapters::V1::QueuePop.build_from_xml(xml)
|
60
|
-
record_references = []
|
61
|
-
queue_pop.each_product {|product_xml| record_references << product_xml.css('RecordReference').text }
|
62
|
-
assert_equal ['123', '456'], record_references
|
40
|
+
assert_equal @xml, queue_pop.xml
|
41
|
+
assert_kind_of Elibri::ONIX::Release_3_0::ONIXMessage, queue_pop.onix
|
42
|
+
assert_equal 'fdb8fa072be774d97a97', queue_pop.onix.products.first.record_reference
|
63
43
|
end
|
64
44
|
|
65
45
|
|
@@ -46,16 +46,15 @@ describe Elibri::ApiClient::ApiAdapters::V1::Queue do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
|
49
|
-
it "should provide iterator for traversing
|
49
|
+
it "should provide iterator for traversing through each pop" do
|
50
50
|
queue = Elibri::ApiClient::ApiAdapters::V1::Queue.new(@api_adapter, :name => 'meta')
|
51
|
-
pop_with_products =
|
52
|
-
|
51
|
+
pop_with_products = stub('QueuePop', :popped_products_count => 5)
|
52
|
+
pop_with_products2 = stub('QueuePop', :popped_products_count => 3)
|
53
|
+
queue.expects(:pop).with(:count => 5).returns(pop_with_products).then.returns(pop_with_products2).then.returns(nil).times(3)
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
queue.each_product {|product_xml| product_xml.css('RecordReference') }
|
55
|
+
pops = []
|
56
|
+
queue.each_pop(:count => 5) {|pop| pops << pop }
|
57
|
+
assert_equal [pop_with_products, pop_with_products2], pops
|
59
58
|
end
|
60
59
|
|
61
60
|
|
@@ -5,30 +5,31 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
|
|
5
5
|
|
6
6
|
FAKE_API_HOST = 'http://localhost:5000'
|
7
7
|
|
8
|
-
def get_request_expected(request_uri)
|
8
|
+
def get_request_expected(request_uri, options = {})
|
9
9
|
Elibri::ApiClient::ApiAdapters::V1.expects(:get).with(
|
10
10
|
request_uri,
|
11
|
-
{:digest_auth => {:username => 'login', :password => 'password'}}
|
11
|
+
{:digest_auth => {:username => 'login', :password => 'password'}}.merge(options)
|
12
12
|
)
|
13
13
|
end
|
14
14
|
|
15
15
|
|
16
16
|
def post_request_expected(request_uri, options = {})
|
17
|
-
options = ' '
|
17
|
+
options[:body] = ' ' unless options[:body]
|
18
|
+
|
18
19
|
Elibri::ApiClient::ApiAdapters::V1.expects(:post).with(
|
19
20
|
request_uri,
|
20
|
-
{:
|
21
|
+
{:digest_auth => {:username => 'login', :password => 'password'}}.merge(options)
|
21
22
|
)
|
22
23
|
end
|
23
24
|
|
24
25
|
|
25
26
|
before do
|
26
|
-
@adapter = Elibri::ApiClient::ApiAdapters::V1.new(FAKE_API_HOST, 'login', 'password')
|
27
|
+
@adapter = Elibri::ApiClient::ApiAdapters::V1.new(FAKE_API_HOST, 'login', 'password', '3.0.1')
|
27
28
|
end
|
28
29
|
|
29
30
|
|
30
31
|
it "should define several exception classes" do
|
31
|
-
exception_classes = %w{Unauthorized NotFound Forbidden ServerError QueueDoesNotExists NoRecentlyPoppedData}
|
32
|
+
exception_classes = %w{Unauthorized NotFound Forbidden ServerError QueueDoesNotExists NoRecentlyPoppedData InvalidOnixDialect}
|
32
33
|
exception_classes.each do |exception_class|
|
33
34
|
assert(Elibri::ApiClient::ApiAdapters::V1::Exceptions.const_get(exception_class) < RuntimeError)
|
34
35
|
end
|
@@ -121,6 +122,7 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
|
|
121
122
|
'500' => Elibri::ApiClient::ApiAdapters::V1::Exceptions::ServerError,
|
122
123
|
'1001' => Elibri::ApiClient::ApiAdapters::V1::Exceptions::QueueDoesNotExists,
|
123
124
|
'1002' => Elibri::ApiClient::ApiAdapters::V1::Exceptions::NoRecentlyPoppedData,
|
125
|
+
'1003' => Elibri::ApiClient::ApiAdapters::V1::Exceptions::InvalidOnixDialect,
|
124
126
|
}
|
125
127
|
end
|
126
128
|
|
@@ -220,7 +222,7 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
|
|
220
222
|
@product = Elibri::ApiClient::ApiAdapters::V1::Product.new(@adapter, stub('publisher'), :record_reference => '076eb83a5f01cb03a217')
|
221
223
|
xml = %Q{<Product><RecordReference>076eb83a5f01cb03a217</RecordReference></Product>}
|
222
224
|
response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML(xml))
|
223
|
-
get_request_expected("#{FAKE_API_HOST}/api/v1/products/076eb83a5f01cb03a217").at_least_once.returns(response_stub)
|
225
|
+
get_request_expected("#{FAKE_API_HOST}/api/v1/products/076eb83a5f01cb03a217", :headers => {'X-eLibri-API-ONIX-dialect' => '3.0.1'}).at_least_once.returns(response_stub)
|
224
226
|
end
|
225
227
|
|
226
228
|
|
@@ -237,47 +239,87 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
|
|
237
239
|
describe "when asked to pop data from specified queue name" do
|
238
240
|
|
239
241
|
before do
|
240
|
-
xml = <<-XML
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
</
|
249
|
-
|
250
|
-
</
|
251
|
-
|
252
|
-
|
253
|
-
</
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
242
|
+
@xml = <<-XML
|
243
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
244
|
+
<ONIXMessage release="3.0" xmlns:elibri="http://elibri.com.pl/ns/extensions" xmlns="http://www.editeur.org/onix/3.0/reference">
|
245
|
+
<elibri:Dialect>3.0.1</elibri:Dialect>
|
246
|
+
<Header>
|
247
|
+
<Sender>
|
248
|
+
<SenderName>Elibri.com.pl</SenderName>
|
249
|
+
<ContactName>Tomasz Meka</ContactName>
|
250
|
+
<EmailAddress>kontakt@elibri.com.pl</EmailAddress>
|
251
|
+
</Sender>
|
252
|
+
<SentDateTime>20111009</SentDateTime>
|
253
|
+
</Header>
|
254
|
+
<Product>
|
255
|
+
<RecordReference>fdb8fa072be774d97a97</RecordReference>
|
256
|
+
</Product>
|
257
|
+
<Product>
|
258
|
+
<RecordReference>6de1bed2f70a8cdae200</RecordReference>
|
259
|
+
</Product>
|
260
|
+
</ONIXMessage>
|
258
261
|
XML
|
259
|
-
|
260
|
-
@response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML(xml))
|
261
262
|
end
|
262
263
|
|
263
264
|
|
264
265
|
it "should send params when they are specified and return QueuePop instance" do
|
265
|
-
|
266
|
+
@response_stub = stub('response_stub',
|
267
|
+
:code => 200,
|
268
|
+
:body => @xml,
|
269
|
+
:parsed_response => Nokogiri::XML(@xml),
|
270
|
+
:headers => {"x-elibri-api-pop-products-count" => 2, "x-elibri-api-pop-queue-name" => "meta", "x-elibri-api-pop-created-at" => "2011-09-06 13:58:21 UTC"}
|
271
|
+
)
|
272
|
+
|
273
|
+
post_request_expected(
|
274
|
+
"#{FAKE_API_HOST}/api/v1/queues/meta/pop",
|
275
|
+
:body => {:testing => 1, :count => 5},
|
276
|
+
:headers => {'X-eLibri-API-ONIX-dialect' => '3.0.1'}
|
277
|
+
).at_least_once.returns(@response_stub)
|
266
278
|
|
267
279
|
pop = @adapter.pop_from_queue('meta', :testing => true, :count => 5)
|
268
280
|
assert_kind_of Elibri::ApiClient::ApiAdapters::V1::QueuePop, pop
|
269
281
|
assert_equal 2, pop.popped_products_count
|
282
|
+
assert_equal 'fdb8fa072be774d97a97', pop.onix.products.first.record_reference
|
270
283
|
end
|
271
284
|
|
272
285
|
|
273
286
|
it "should send empty request body when no params are specified" do
|
274
|
-
|
287
|
+
@response_stub = stub('response_stub',
|
288
|
+
:code => 200,
|
289
|
+
:body => @xml,
|
290
|
+
:parsed_response => Nokogiri::XML(@xml),
|
291
|
+
:headers => {"x-elibri-api-pop-products-count" => 2, "x-elibri-api-pop-queue-name" => "meta", "x-elibri-api-pop-created-at" => "2011-09-06 13:58:21 UTC"}
|
292
|
+
)
|
293
|
+
|
294
|
+
post_request_expected(
|
295
|
+
"#{FAKE_API_HOST}/api/v1/queues/meta/pop",
|
296
|
+
:body => ' ',
|
297
|
+
:headers => {'X-eLibri-API-ONIX-dialect' => '3.0.1'}
|
298
|
+
).at_least_once.returns(@response_stub)
|
275
299
|
|
276
300
|
pop = @adapter.pop_from_queue('meta')
|
277
301
|
assert_kind_of Elibri::ApiClient::ApiAdapters::V1::QueuePop, pop
|
278
302
|
assert_equal 2, pop.popped_products_count
|
279
303
|
end
|
280
304
|
|
305
|
+
|
306
|
+
it "should return nil when there is no data to pop" do
|
307
|
+
@response_stub = stub('response_stub',
|
308
|
+
:code => 200,
|
309
|
+
:body => nil,
|
310
|
+
:parsed_response => nil,
|
311
|
+
:headers => {"x-elibri-api-pop-products-count" => 0}
|
312
|
+
)
|
313
|
+
|
314
|
+
post_request_expected(
|
315
|
+
"#{FAKE_API_HOST}/api/v1/queues/meta/pop",
|
316
|
+
:body => ' ',
|
317
|
+
:headers => {'X-eLibri-API-ONIX-dialect' => '3.0.1'}
|
318
|
+
).at_least_once.returns(@response_stub)
|
319
|
+
|
320
|
+
assert_nil @adapter.pop_from_queue('meta')
|
321
|
+
end
|
322
|
+
|
281
323
|
end
|
282
324
|
|
283
325
|
|
@@ -287,7 +329,7 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
|
|
287
329
|
before do
|
288
330
|
xml = %q{<error id='1002'> <message>There is no recently popped data</message> </error>}
|
289
331
|
response_stub = stub('response_stub', :code => 412, :parsed_response => Nokogiri::XML(xml))
|
290
|
-
get_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/last_pop").once.returns(response_stub)
|
332
|
+
get_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/last_pop", :headers => {'X-eLibri-API-ONIX-dialect' => '3.0.1'}).once.returns(response_stub)
|
291
333
|
end
|
292
334
|
|
293
335
|
it "should return nil, ignoring NoRecentlyPoppedData exception" do
|
@@ -299,36 +341,42 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
|
|
299
341
|
describe "and there was a pop" do
|
300
342
|
|
301
343
|
before do
|
302
|
-
xml = <<-XML
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
</
|
311
|
-
|
312
|
-
</
|
313
|
-
|
314
|
-
|
315
|
-
</
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
344
|
+
@xml = <<-XML
|
345
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
346
|
+
<ONIXMessage release="3.0" xmlns:elibri="http://elibri.com.pl/ns/extensions" xmlns="http://www.editeur.org/onix/3.0/reference">
|
347
|
+
<elibri:Dialect>3.0.1</elibri:Dialect>
|
348
|
+
<Header>
|
349
|
+
<Sender>
|
350
|
+
<SenderName>Elibri.com.pl</SenderName>
|
351
|
+
<ContactName>Tomasz Meka</ContactName>
|
352
|
+
<EmailAddress>kontakt@elibri.com.pl</EmailAddress>
|
353
|
+
</Sender>
|
354
|
+
<SentDateTime>20111009</SentDateTime>
|
355
|
+
</Header>
|
356
|
+
<Product>
|
357
|
+
<RecordReference>fdb8fa072be774d97a97</RecordReference>
|
358
|
+
</Product>
|
359
|
+
<Product>
|
360
|
+
<RecordReference>6de1bed2f70a8cdae200</RecordReference>
|
361
|
+
</Product>
|
362
|
+
</ONIXMessage>
|
320
363
|
XML
|
321
|
-
|
322
|
-
@response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML(xml))
|
323
364
|
end
|
324
365
|
|
325
366
|
|
326
367
|
it "should return QueuePop instance" do
|
327
|
-
|
368
|
+
response_stub = stub('response_stub',
|
369
|
+
:code => 200,
|
370
|
+
:body => @xml,
|
371
|
+
:parsed_response => Nokogiri::XML(@xml),
|
372
|
+
:headers => {"x-elibri-api-pop-products-count" => 2, "x-elibri-api-pop-queue-name" => "meta", "x-elibri-api-pop-created-at" => "2011-09-06 13:58:21 UTC"}
|
373
|
+
)
|
374
|
+
get_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/last_pop", :headers => {'X-eLibri-API-ONIX-dialect' => '3.0.1'}).at_least_once.returns(response_stub)
|
328
375
|
|
329
376
|
pop = @adapter.last_pop_from_queue('meta')
|
330
377
|
assert_kind_of Elibri::ApiClient::ApiAdapters::V1::QueuePop, pop
|
331
378
|
assert_equal 2, pop.popped_products_count
|
379
|
+
assert_equal 'fdb8fa072be774d97a97', pop.onix.products.first.record_reference
|
332
380
|
end
|
333
381
|
end
|
334
382
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elibri_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 1
|
10
|
+
version: 1.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- "Marcin Urba\xC5\x84ski"
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09
|
18
|
+
date: 2011-10-09 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -23,14 +23,14 @@ dependencies:
|
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
24
|
none: false
|
25
25
|
requirements:
|
26
|
-
- -
|
26
|
+
- - "="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
hash:
|
28
|
+
hash: 61
|
29
29
|
segments:
|
30
30
|
- 0
|
31
|
-
- 7
|
32
31
|
- 8
|
33
|
-
|
32
|
+
- 1
|
33
|
+
version: 0.8.1
|
34
34
|
name: httparty
|
35
35
|
version_requirements: *id001
|
36
36
|
prerelease: false
|
@@ -57,29 +57,29 @@ dependencies:
|
|
57
57
|
requirements:
|
58
58
|
- - ">="
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
hash:
|
60
|
+
hash: 3
|
61
61
|
segments:
|
62
62
|
- 3
|
63
63
|
- 1
|
64
64
|
- 0
|
65
|
-
|
66
|
-
- 1
|
67
|
-
version: 3.1.0.rc1
|
65
|
+
version: 3.1.0
|
68
66
|
name: activesupport
|
69
67
|
version_requirements: *id003
|
70
68
|
prerelease: false
|
71
69
|
- !ruby/object:Gem::Dependency
|
72
|
-
type: :
|
70
|
+
type: :runtime
|
73
71
|
requirement: &id004 !ruby/object:Gem::Requirement
|
74
72
|
none: false
|
75
73
|
requirements:
|
76
74
|
- - ">="
|
77
75
|
- !ruby/object:Gem::Version
|
78
|
-
hash:
|
76
|
+
hash: 29
|
79
77
|
segments:
|
80
78
|
- 0
|
81
|
-
|
82
|
-
|
79
|
+
- 1
|
80
|
+
- 3
|
81
|
+
version: 0.1.3
|
82
|
+
name: elibri_onix
|
83
83
|
version_requirements: *id004
|
84
84
|
prerelease: false
|
85
85
|
- !ruby/object:Gem::Dependency
|
@@ -93,7 +93,7 @@ dependencies:
|
|
93
93
|
segments:
|
94
94
|
- 0
|
95
95
|
version: "0"
|
96
|
-
name:
|
96
|
+
name: pry
|
97
97
|
version_requirements: *id005
|
98
98
|
prerelease: false
|
99
99
|
- !ruby/object:Gem::Dependency
|
@@ -107,12 +107,26 @@ dependencies:
|
|
107
107
|
segments:
|
108
108
|
- 0
|
109
109
|
version: "0"
|
110
|
-
name:
|
110
|
+
name: mocha
|
111
111
|
version_requirements: *id006
|
112
112
|
prerelease: false
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
type: :development
|
115
115
|
requirement: &id007 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
hash: 3
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
name: minitest
|
125
|
+
version_requirements: *id007
|
126
|
+
prerelease: false
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
type: :development
|
129
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
116
130
|
none: false
|
117
131
|
requirements:
|
118
132
|
- - ~>
|
@@ -124,11 +138,11 @@ dependencies:
|
|
124
138
|
- 0
|
125
139
|
version: 1.0.0
|
126
140
|
name: bundler
|
127
|
-
version_requirements: *
|
141
|
+
version_requirements: *id008
|
128
142
|
prerelease: false
|
129
143
|
- !ruby/object:Gem::Dependency
|
130
144
|
type: :development
|
131
|
-
requirement: &
|
145
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
132
146
|
none: false
|
133
147
|
requirements:
|
134
148
|
- - ~>
|
@@ -140,11 +154,11 @@ dependencies:
|
|
140
154
|
- 2
|
141
155
|
version: 1.6.2
|
142
156
|
name: jeweler
|
143
|
-
version_requirements: *
|
157
|
+
version_requirements: *id009
|
144
158
|
prerelease: false
|
145
159
|
- !ruby/object:Gem::Dependency
|
146
160
|
type: :development
|
147
|
-
requirement: &
|
161
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
148
162
|
none: false
|
149
163
|
requirements:
|
150
164
|
- - ">="
|
@@ -154,7 +168,7 @@ dependencies:
|
|
154
168
|
- 0
|
155
169
|
version: "0"
|
156
170
|
name: rcov
|
157
|
-
version_requirements: *
|
171
|
+
version_requirements: *id010
|
158
172
|
prerelease: false
|
159
173
|
description: API client for elibri.com.pl publishing system
|
160
174
|
email: marcin@urbanski.vdl.pl
|