elibri_api_client 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gem "nokogiri", "~> 1.5.0"
5
5
  gem 'activesupport', '>= 3.1.0.rc1'
6
6
 
7
7
  group :development do
8
- gem "ruby-debug"
8
+ gem "pry"
9
9
  gem "mocha"
10
10
  gem "minitest", ">= 0"
11
11
  gem "bundler", "~> 1.0.0"
data/Gemfile.lock CHANGED
@@ -3,7 +3,7 @@ GEM
3
3
  specs:
4
4
  activesupport (3.1.0.rc1)
5
5
  multi_json (~> 1.0)
6
- columnize (0.3.3)
6
+ coderay (0.9.8)
7
7
  crack (0.1.8)
8
8
  git (1.2.5)
9
9
  httparty (0.7.8)
@@ -12,20 +12,23 @@ GEM
12
12
  bundler (~> 1.0)
13
13
  git (>= 1.2.5)
14
14
  rake
15
- linecache (0.46)
16
- rbx-require-relative (> 0.0.4)
15
+ method_source (0.6.5)
16
+ ruby_parser (>= 2.0.5)
17
17
  minitest (2.2.2)
18
18
  mocha (0.9.12)
19
19
  multi_json (1.0.3)
20
20
  nokogiri (1.5.0)
21
+ pry (0.9.6)
22
+ coderay (>= 0.9.8)
23
+ method_source (>= 0.6.5)
24
+ ruby_parser (>= 2.0.5)
25
+ slop (~> 2.1.0)
21
26
  rake (0.9.0)
22
- rbx-require-relative (0.0.5)
23
27
  rcov (0.9.9)
24
- ruby-debug (0.10.4)
25
- columnize (>= 0.1)
26
- ruby-debug-base (~> 0.10.4.0)
27
- ruby-debug-base (0.10.4)
28
- linecache (>= 0.3)
28
+ ruby_parser (2.3.0)
29
+ sexp_processor (~> 3.0)
30
+ sexp_processor (3.0.6)
31
+ slop (2.1.0)
29
32
 
30
33
  PLATFORMS
31
34
  ruby
@@ -38,5 +41,5 @@ DEPENDENCIES
38
41
  minitest
39
42
  mocha
40
43
  nokogiri (~> 1.5.0)
44
+ pry
41
45
  rcov
42
- ruby-debug
data/README.rdoc CHANGED
@@ -29,21 +29,26 @@
29
29
  # elibri.refill_all_queues!
30
30
 
31
31
  elibri.pending_queues.each do |pending_queue|
32
- # Aby moc pobierac dane, musimy kolejke oczekujaca przekonwertowac na kolejke nazwana.
33
- # Taka kolejke identyfikujemy po ID i jej tresc pozniej nie ulega zmianie.
34
- named_queue = pending_queue.pick_up!
35
-
36
- # Majac kolejke nazwana, mozemy iterowac po jej produktach (ONIX):
37
- named_queue.each_product_onix do |product_xml, product_no|
32
+ pending_queue.each_product do |product_xml|
38
33
  # Otrzymujemy przeparsowany XML za pomoca Nokogiri
39
34
  # product_xml.class => Nokogiri::XML::Element
40
35
 
41
- puts product.xml.css('RecordReference')
36
+ puts product_xml.css('RecordReference').text
42
37
  end
43
38
  end
44
39
 
45
- ==== 3b. Znadz ostatnio pobrane kolejki
46
- named_queue = elibri.last_pickups.first
40
+ ==== 3b. Pobieranie danych z konkretnej kolejki
41
+
42
+ meta = elibri.pending_queues.find {|queue| queue.name == 'meta'}
43
+
44
+ pop = meta.pop(:count => 5, :testing => true)
45
+ pop.each_product {|product_xml| puts product_xml.css('RecordReference').text }
46
+
47
+ last_pop = meta.last_pop
48
+
49
+
50
+ ==== 3c. Znadz ostatnio pobrane kolejki
51
+ last_pop = elibri.last_pop_from_queue('meta')
47
52
 
48
53
 
49
54
  == Copyright
@@ -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.0.5"
8
+ s.version = "1.1.0"
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-07-17}
12
+ s.date = %q{2011-09-30}
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 = [
@@ -33,6 +33,7 @@ Gem::Specification.new do |s|
33
33
  "test/elibri_api_client_test.rb",
34
34
  "test/elibri_api_v1_adapter_product_test.rb",
35
35
  "test/elibri_api_v1_adapter_publisher_test.rb",
36
+ "test/elibri_api_v1_adapter_queue_pop_test.rb",
36
37
  "test/elibri_api_v1_adapter_queue_test.rb",
37
38
  "test/elibri_api_v1_adapter_test.rb",
38
39
  "test/helper.rb"
@@ -50,7 +51,7 @@ Gem::Specification.new do |s|
50
51
  s.add_runtime_dependency(%q<httparty>, ["~> 0.7.8"])
51
52
  s.add_runtime_dependency(%q<nokogiri>, ["~> 1.5.0"])
52
53
  s.add_runtime_dependency(%q<activesupport>, [">= 3.1.0.rc1"])
53
- s.add_development_dependency(%q<ruby-debug>, [">= 0"])
54
+ s.add_development_dependency(%q<pry>, [">= 0"])
54
55
  s.add_development_dependency(%q<mocha>, [">= 0"])
55
56
  s.add_development_dependency(%q<minitest>, [">= 0"])
56
57
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -60,7 +61,7 @@ Gem::Specification.new do |s|
60
61
  s.add_dependency(%q<httparty>, ["~> 0.7.8"])
61
62
  s.add_dependency(%q<nokogiri>, ["~> 1.5.0"])
62
63
  s.add_dependency(%q<activesupport>, [">= 3.1.0.rc1"])
63
- s.add_dependency(%q<ruby-debug>, [">= 0"])
64
+ s.add_dependency(%q<pry>, [">= 0"])
64
65
  s.add_dependency(%q<mocha>, [">= 0"])
65
66
  s.add_dependency(%q<minitest>, [">= 0"])
66
67
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -71,7 +72,7 @@ Gem::Specification.new do |s|
71
72
  s.add_dependency(%q<httparty>, ["~> 0.7.8"])
72
73
  s.add_dependency(%q<nokogiri>, ["~> 1.5.0"])
73
74
  s.add_dependency(%q<activesupport>, [">= 3.1.0.rc1"])
74
- s.add_dependency(%q<ruby-debug>, [">= 0"])
75
+ s.add_dependency(%q<pry>, [">= 0"])
75
76
  s.add_dependency(%q<mocha>, [">= 0"])
76
77
  s.add_dependency(%q<minitest>, [">= 0"])
77
78
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -11,7 +11,7 @@ module Elibri
11
11
 
12
12
  include HTTParty
13
13
  #--
14
- #debug_output $stderr
14
+ # debug_output $stderr
15
15
  #++
16
16
 
17
17
  def initialize(host_uri, login, password) #:nodoc:
@@ -37,7 +37,7 @@ module Elibri
37
37
  # pending_queues -> array
38
38
  #
39
39
  def pending_queues
40
- resp = get '/queues/pending_data'
40
+ resp = get '/queues'
41
41
 
42
42
  Array.new.tap do |pending_queues|
43
43
  resp.parsed_response.css('queue').each do |queue_xml|
@@ -57,25 +57,6 @@ module Elibri
57
57
  end
58
58
 
59
59
 
60
- # Ostatnio utworzone nazwane kolejki. Gdy wysypie nam sie aplikacja, mozna przegladac ostatnie pickupy
61
- # i ponownie pobierac z nich dane. Zwraca instance Elibri::ApiClient::ApiAdapters::V1::Queue
62
- # call-seq:
63
- # last_pickups -> array
64
- #
65
- def last_pickups
66
- Array.new.tap do |last_pickups|
67
- %w{meta stocks}.each do |queue_name|
68
- begin
69
- response = get "/queues/#{queue_name}/last_pick_up"
70
- queue_xml = response.parsed_response.css('queue').first
71
- last_pickups << Elibri::ApiClient::ApiAdapters::V1::Queue.build_from_xml(self, queue_xml)
72
- rescue Exceptions::NoRecentlyPickedUpQueues # Ignoruj bledy o braku ostatnich pickupow.
73
- end
74
- end
75
- end
76
- end
77
-
78
-
79
60
  # Zwroc liste dostepnych wydawnictw - instancje Elibri::ApiClient::ApiAdapters::V1::Publisher
80
61
  # call-seq:
81
62
  # publishers -> array
@@ -92,51 +73,22 @@ module Elibri
92
73
  end
93
74
 
94
75
 
95
- # Utworz z danych oczekujacych w kolejce np. 'pending_meta', kolejke nazwana.
96
- # Tylko z kolejek nazwanych mozna pobierac dane. Jako argument przyjmuje nazwe kolejki (np. 'pending_meta')
97
- # lub odpowiednia instancje Elibri::ApiClient::ApiAdapters::V1::Queue.
98
- def pick_up_queue!(queue) #:nodoc:
99
- case queue
100
- when Elibri::ApiClient::ApiAdapters::V1::Queue
101
- queue_name = queue.name
102
- when String
103
- queue_name = queue
104
- else
105
- raise 'Specify queue as name or Elibri::ApiClient::ApiAdapters::V1::Queue instance'
106
- end
107
-
108
- response = post "/queues/#{queue_name}/pick_up", :body => ' '
109
- picked_up_queue_xml = response.parsed_response.css('pick_up queue').first
110
- Elibri::ApiClient::ApiAdapters::V1::Queue.build_from_xml(self, picked_up_queue_xml)
111
- end
112
-
113
-
114
- def each_page_in_queue(queue, &block) #:nodoc:
115
- raise 'Need a Elibri::ApiClient::ApiAdapters::V1::Queue instance' unless queue.kind_of? Elibri::ApiClient::ApiAdapters::V1::Queue
116
-
117
- page_no = 1
118
- response = get "/queues/#{queue.name}/#{queue.queue_id}"
119
- yield response.parsed_response.css('current_page content'), page_no
120
- while next_page = response.parsed_response.css('next_page').first
121
- response = get next_page['url']
122
- page_no += 1
123
- yield response.parsed_response.css('current_page content').first, page_no
124
- end
76
+ # Options moze przyjac {:testing => 1, :count => 100}
77
+ def pop_from_queue(queue_name, options = {})
78
+ options[:testing] = 1 if options[:testing]
79
+ options = ' ' if options.empty?
80
+ response = post "/queues/#{queue_name}/pop", :body => options
81
+ pop_xml = response.parsed_response.css('pop').first
82
+ Elibri::ApiClient::ApiAdapters::V1::QueuePop.build_from_xml(pop_xml)
125
83
  end
126
84
 
127
85
 
128
- # Trawersuj kolekcje produktow w nazwanej kolejce. Instancje nazwanej kolejki nalezy przekazac
129
- # jako argument metody.
130
- def each_product_onix_in_queue(queue, &block) #:nodoc:
131
- raise 'Need a Elibri::ApiClient::ApiAdapters::V1::Queue instance' unless queue.kind_of? Elibri::ApiClient::ApiAdapters::V1::Queue
132
-
133
- product_no = 1
134
- each_page_in_queue(queue) do |products_page_xml, page_no|
135
- products_page_xml.css('Product').each do |product_xml|
136
- block.call(product_xml, product_no)
137
- product_no += 1
138
- end
139
- end
86
+ def last_pop_from_queue(queue_name)
87
+ response = get "/queues/#{queue_name}/last_pop"
88
+ pop_xml = response.parsed_response.css('pop').first
89
+ Elibri::ApiClient::ApiAdapters::V1::QueuePop.build_from_xml(pop_xml)
90
+ rescue Exceptions::NoRecentlyPoppedData # Ignoruj bledy o braku ostatnich POPow.
91
+ return nil
140
92
  end
141
93
 
142
94
 
@@ -164,7 +116,7 @@ module Elibri
164
116
 
165
117
  private
166
118
 
167
- # http://api.elibri.com.pl:80/api/v1
119
+ # http://www.elibri.com.pl:80/api/v1
168
120
  def full_api_uri
169
121
  @host_uri + URI_PREFIX
170
122
  end
@@ -13,10 +13,8 @@ module Elibri #:nodoc:
13
13
  class NotFound < RuntimeError; end
14
14
  class Forbidden < RuntimeError; end
15
15
  class ServerError < RuntimeError; end
16
- class NoPendingData < RuntimeError; end
17
- class NoRecentlyPickedUpQueues < RuntimeError; end
18
16
  class QueueDoesNotExists < RuntimeError; end
19
- class InvalidPageNumber < RuntimeError; end
17
+ class NoRecentlyPoppedData < RuntimeError; end
20
18
  end
21
19
 
22
20
  # Klasy wyjatkow rzucanych, gdy elibri zwroci okreslony blad. Np. gdy dostaniemy:
@@ -29,9 +27,7 @@ module Elibri #:nodoc:
29
27
  '403' => Exceptions::Forbidden,
30
28
  '500' => Exceptions::ServerError,
31
29
  '1001' => Exceptions::QueueDoesNotExists,
32
- '1002' => Exceptions::NoPendingData,
33
- '1003' => Exceptions::NoRecentlyPickedUpQueues,
34
- '1004' => Exceptions::InvalidPageNumber
30
+ '1002' => Exceptions::NoRecentlyPoppedData,
35
31
  }.freeze
36
32
 
37
33
 
@@ -41,52 +37,36 @@ module Elibri #:nodoc:
41
37
  attr_reader :name
42
38
  # Ilosc produktow znajdujacych sie w kolejce
43
39
  attr_reader :products_count
44
- # Kiedy kolejka zostala przekonwertowana na nazwana? (otrzymala ID w bazie)
45
- attr_reader :picked_up_at
46
40
  # Kiedy ostatnio umieszczono jakis produkt w kolejce?
47
41
  attr_reader :last_insert_at
48
- # Unikalny identyfikator kolejki w bazie
49
- attr_reader :queue_id
50
- # Entrypoint API, pod ktorym mozna zobaczyc zawartosc kolejki
51
- attr_reader :url
52
42
 
53
43
 
54
44
  def initialize(api_adapter, attributes = {}) #:nodoc:
55
- attributes.assert_valid_keys(:name, :products_count, :queue_id, :url, :last_insert_at, :picked_up_at)
45
+ attributes.assert_valid_keys(:name, :products_count, :last_insert_at)
56
46
  @api_adapter = api_adapter
57
47
  @name = attributes[:name]
58
48
  @products_count = attributes[:products_count].to_i
59
- @queue_id = attributes[:queue_id]
60
- @url = attributes[:url]
61
-
62
49
  @last_insert_at = Time.parse(attributes[:last_insert_at]) if attributes[:last_insert_at].present?
63
- @picked_up_at = Time.parse(attributes[:picked_up_at]) if attributes[:picked_up_at].present?
64
50
  end
65
51
 
66
52
 
67
- # Przekonwertuj kolejke z danymi oczekujacymi (np. 'pending_meta') na kolejke nazwana.
68
- # call-seq:
69
- # pick_up! -> named_queue_instance
70
- #
71
- def pick_up!
72
- @api_adapter.pick_up_queue!(self) unless picked_up?
53
+ # Pobierz dane z kolejki
54
+ def pop(options = {})
55
+ @api_adapter.pop_from_queue(self.name, options)
73
56
  end
74
57
 
75
58
 
76
- # Iteruj po kolejnych rekordach ONIX w nazwanej kolejce.
77
- def each_product_onix(&block) #:yields: product_xml
78
- raise 'Cannot iterate unpicked queue products! Try named = queue.pick_up! and then named.each_product_onix' unless self.picked_up?
79
- @api_adapter.each_product_onix_in_queue(self, &block)
59
+ # Zwroc ostatnio pobrane dane z tej kolejki
60
+ def last_pop
61
+ @api_adapter.last_pop_from_queue(self.name)
80
62
  end
81
63
 
82
64
 
83
- # Czy to jest kolejka nazwana, czy oczekujaca? Wszystkie kolejki z danymi oczekujacymi maja w nazwie
84
- # przedrostek 'pending_'. Np. 'pending_meta', 'pending_stocks'.
85
- # call-seq:
86
- # picked_up? -> true or false
87
- #
88
- def picked_up?
89
- !self.name.start_with?('pending_')
65
+ # Iteruj po kolejnych rekordach ONIX w nazwanej kolejce.
66
+ def each_product(&block) #:yields: product_xml
67
+ while (_pop = pop).popped_products_count > 0
68
+ _pop.each_product(&block)
69
+ end
90
70
  end
91
71
 
92
72
 
@@ -96,16 +76,53 @@ module Elibri #:nodoc:
96
76
  Queue.new(api_adapter,
97
77
  :name => queue_xml['name'],
98
78
  :products_count => queue_xml['products_count'].to_i,
99
- :last_insert_at => queue_xml['last_insert_at'],
100
- :url => queue_xml['url'],
101
- :queue_id => queue_xml['id'],
102
- :picked_up_at => queue_xml['picked_up_at']
79
+ :last_insert_at => queue_xml['last_insert_at']
103
80
  )
104
81
  end
105
82
  end
106
83
 
107
84
 
108
85
 
86
+ class QueuePop
87
+ # Nazwa kolejki ktorej dotyczyl POP
88
+ attr_reader :queue_name
89
+ # Ilosc produktow pobranych w tym POPie
90
+ attr_reader :popped_products_count
91
+ # Kiedy POP zostal wykonany?
92
+ attr_reader :created_at
93
+ # ONIX pobranych produktow
94
+ attr_reader :products_xmls
95
+
96
+
97
+ def initialize(attributes = {}) #:nodoc:
98
+ attributes.assert_valid_keys(:queue_name, :popped_products_count, :created_at, :products_xmls)
99
+ @queue_name = attributes[:queue_name]
100
+ @popped_products_count = attributes[:popped_products_count].to_i
101
+ @products_xmls = attributes[:products_xmls]
102
+ @created_at = Time.parse(attributes[:created_at])
103
+ end
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
+ )
120
+ end
121
+
122
+ end
123
+
124
+
125
+
109
126
  class Publisher
110
127
  # Identyfikator wydawnictwa w bazie
111
128
  attr_reader :publisher_id
@@ -188,6 +205,7 @@ module Elibri #:nodoc:
188
205
  end
189
206
 
190
207
 
208
+
191
209
  class Product
192
210
  # Wydawnictwo, ktore opublikowalo produkt - instancja Elibri::ApiClient::ApiAdapters::V1::Publisher
193
211
  attr_reader :publisher
@@ -3,8 +3,8 @@ module Elibri
3
3
  class ApiClient
4
4
  module Version
5
5
  MAJOR = 1
6
- MINOR = 0
7
- PATCH = 5
6
+ MINOR = 1
7
+ PATCH = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
10
10
  end
@@ -17,7 +17,7 @@ module Elibri
17
17
  extend Forwardable
18
18
 
19
19
  # Domyslny adres serwera API
20
- DEFAULT_API_HOST_URI = 'http://api.elibri.com.pl:80'
20
+ DEFAULT_API_HOST_URI = 'http://www.elibri.com.pl:80'
21
21
  # Adres hosta, pod ktorym figuruje serwer API - domyslnie to DEFAULT_API_HOST_URI
22
22
  attr_reader :host_uri
23
23
 
@@ -40,7 +40,7 @@ module Elibri
40
40
 
41
41
 
42
42
  # Metody API delegujemy do odpowiedniego adaptera:
43
- def_delegators :@api_adapter, :refill_all_queues!, :pending_data?, :pending_queues, :last_pickups, :publishers
43
+ def_delegators :@api_adapter, :refill_all_queues!, :pending_data?, :pending_queues, :publishers, :last_pop_from_queue
44
44
 
45
45
  end
46
46
  end
@@ -40,7 +40,7 @@ describe Elibri::ApiClient do
40
40
  it "should delegate several methods to apropriate API adapter" do
41
41
  client = Elibri::ApiClient.new(:login => 'elibri_login', :password => 'pass')
42
42
 
43
- delegated_methods = %w{refill_all_queues! pending_data? pending_queues last_pickups publishers}
43
+ delegated_methods = %w{refill_all_queues! pending_data? pending_queues publishers}
44
44
  delegated_methods.each {|method_name| client.instance_variable_get('@api_adapter').expects(method_name) }
45
45
  delegated_methods.each {|method_name| client.send(method_name) }
46
46
  end
@@ -13,7 +13,7 @@ describe Elibri::ApiClient::ApiAdapters::V1::Product do
13
13
  product = Elibri::ApiClient::ApiAdapters::V1::Product.new(@api_adapter, @publisher,
14
14
  :record_reference => 'AAAAAAAAAAAAAAA',
15
15
  :title => 'Erlang Programming',
16
- :url => 'http://api.elibri.com.pl/api/v1/products/AAAAAAAAAAAAAAA'
16
+ :url => 'http://www.elibri.com.pl/api/v1/products/AAAAAAAAAAAAAAA'
17
17
  )
18
18
 
19
19
  assert_equal 'Erlang Programming', product.title
@@ -25,13 +25,13 @@ describe Elibri::ApiClient::ApiAdapters::V1::Product do
25
25
 
26
26
  it "should be able to build itself from provided XML" do
27
27
  xml = %Q{
28
- <product record_reference="04325b31fdece145d22e" title="Erlang Programming" url="http://api.elibri.com.pl/api/v1/products/04325b31fdece145d22e"/>
28
+ <product record_reference="04325b31fdece145d22e" title="Erlang Programming" url="http://www.elibri.com.pl/api/v1/products/04325b31fdece145d22e"/>
29
29
  }
30
30
 
31
31
  product = Elibri::ApiClient::ApiAdapters::V1::Product.build_from_xml(@api_adapter, @publisher, xml)
32
32
  assert_equal 'Erlang Programming', product.title
33
33
  assert_equal '04325b31fdece145d22e', product.record_reference
34
- assert_equal "http://api.elibri.com.pl/api/v1/products/04325b31fdece145d22e", product.url
34
+ assert_equal "http://www.elibri.com.pl/api/v1/products/04325b31fdece145d22e", product.url
35
35
  end
36
36
 
37
37
 
@@ -13,13 +13,13 @@ describe Elibri::ApiClient::ApiAdapters::V1::Publisher do
13
13
  :name => 'Wydawnicta Naukowo-Techniczne',
14
14
  :publisher_id => '1020',
15
15
  :products_count => 1503,
16
- :products_url => 'http://api.elibri.com.pl/api/v1/publishers/1020/products'
16
+ :products_url => 'http://www.elibri.com.pl/api/v1/publishers/1020/products'
17
17
  )
18
18
 
19
19
  assert_equal 'Wydawnicta Naukowo-Techniczne', publisher.name
20
20
  assert_equal 1020, publisher.publisher_id
21
21
  assert_equal 1503, publisher.products_count
22
- assert_equal 'http://api.elibri.com.pl/api/v1/publishers/1020/products', publisher.products_url
22
+ assert_equal 'http://www.elibri.com.pl/api/v1/publishers/1020/products', publisher.products_url
23
23
  end
24
24
 
25
25
 
@@ -28,7 +28,7 @@ describe Elibri::ApiClient::ApiAdapters::V1::Publisher do
28
28
  xml = %Q{
29
29
  <publishers>
30
30
  <publisher name="Wydawnicta Naukowo-Techniczne" city="Kraków" company_name="WNT Polska Sp. z o.o." zip_code="30-417" id="1" street="Łagiewnicka 33a" phone1="(12) 252-85-92" phone2="(12) 252-85-80" nip="679-284-08-64" www="http://www.wnt.com" email="sprzedaz@wnt.com">
31
- <products url="http://api.elibri.com.pl/api/v1/publishers/1/products" count="350"/>
31
+ <products url="http://www.elibri.com.pl/api/v1/publishers/1/products" count="350"/>
32
32
  </publisher>
33
33
  </publishers>
34
34
  }
@@ -47,7 +47,7 @@ describe Elibri::ApiClient::ApiAdapters::V1::Publisher do
47
47
  assert_equal "679-284-08-64", publisher.nip
48
48
  assert_equal "http://www.wnt.com", publisher.www
49
49
  assert_equal "sprzedaz@wnt.com", publisher.email
50
- assert_equal 'http://api.elibri.com.pl/api/v1/publishers/1/products', publisher.products_url
50
+ assert_equal 'http://www.elibri.com.pl/api/v1/publishers/1/products', publisher.products_url
51
51
  end
52
52
 
53
53
 
@@ -0,0 +1,66 @@
1
+
2
+ require 'helper'
3
+
4
+
5
+ describe Elibri::ApiClient::ApiAdapters::V1::QueuePop do
6
+
7
+ before do
8
+ @products_xmls = Nokogiri::XML(<<-XML).css('Product')
9
+ <root>
10
+ <Product>
11
+ <RecordReference>123</RecordReference>
12
+ </Product>
13
+ <Product>
14
+ <RecordReference>456</RecordReference>
15
+ </Product>
16
+ </root>
17
+ XML
18
+ end
19
+
20
+
21
+ it "should have several attributes" do
22
+ time = Time.now
23
+ queue_pop = Elibri::ApiClient::ApiAdapters::V1::QueuePop.new(
24
+ :queue_name => 'meta',
25
+ :popped_products_count => 120,
26
+ :created_at => time.to_s,
27
+ :products_xmls => @products_xmls
28
+ )
29
+
30
+ assert_equal 'meta', queue_pop.queue_name
31
+ assert_equal 120, queue_pop.popped_products_count
32
+ assert_equal time.to_i, queue_pop.created_at.to_i
33
+ assert_equal @products_xmls, queue_pop.products_xmls
34
+ end
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
63
+ end
64
+
65
+
66
+ end
@@ -13,74 +13,50 @@ describe Elibri::ApiClient::ApiAdapters::V1::Queue do
13
13
  queue = Elibri::ApiClient::ApiAdapters::V1::Queue.new(@api_adapter,
14
14
  :name => 'meta',
15
15
  :products_count => 120,
16
- :queue_id => '192f134e666df34464bcc14d0413',
17
- :url => 'http://api.elibri.com.pl/api/v1/queues/meta/192f134e666df34464bcc14d0413',
18
- :last_insert_at => time.to_s,
19
- :picked_up_at => time.to_s
16
+ :last_insert_at => time.to_s
20
17
  )
21
18
 
22
19
  assert_equal 'meta', queue.name
23
20
  assert_equal 120, queue.products_count
24
- assert_equal '192f134e666df34464bcc14d0413', queue.queue_id
25
- assert_equal 'http://api.elibri.com.pl/api/v1/queues/meta/192f134e666df34464bcc14d0413', queue.url
26
21
  assert_equal time.to_i, queue.last_insert_at.to_i
27
- assert_equal time.to_i, queue.picked_up_at.to_i
28
22
  end
29
23
 
30
24
 
31
-
32
25
  it "should be able to build itself from provided XML" do
33
- xml = %Q{<queue name="stocks" id="192f134e666df34464bcc14d04135cda2bd13a0c" url="http://api.elibri.com.pl/api/v1/queues/stocks/192f134e666df34464bcc14d04135cda2bd13a0c" products_count="1500" last_insert_at="2011-02-05 21:02:22 UTC" picked_up_at="2011-02-05 22:02:22 UTC"/>}
26
+ xml = %Q{<queue name="stocks" products_count="1500" last_insert_at="2011-02-05 21:02:22 UTC" />}
34
27
 
35
28
  queue = Elibri::ApiClient::ApiAdapters::V1::Queue.build_from_xml(@api_adapter, xml)
36
29
  assert_equal 'stocks', queue.name
37
30
  assert_equal 1500, queue.products_count
38
- assert_equal '192f134e666df34464bcc14d04135cda2bd13a0c', queue.queue_id
39
- assert_equal 'http://api.elibri.com.pl/api/v1/queues/stocks/192f134e666df34464bcc14d04135cda2bd13a0c', queue.url
40
31
  assert_equal Time.parse("2011-02-05 21:02:22 UTC"), queue.last_insert_at
41
- assert_equal Time.parse("2011-02-05 22:02:22 UTC"), queue.picked_up_at
42
-
43
- xml = %Q{<queue name="pending_stocks" products_count="1500" last_insert_at="2011-02-05 21:02:22 UTC"/>}
44
- queue = Elibri::ApiClient::ApiAdapters::V1::Queue.build_from_xml(@api_adapter, xml)
45
- assert_nil queue.queue_id
46
- assert_nil queue.picked_up_at
47
- assert_nil queue.url
48
32
  end
49
33
 
50
34
 
51
- it "should be able to establish if its a picked up queue" do
52
- queue = Elibri::ApiClient::ApiAdapters::V1::Queue.new(@api_adapter, :name => 'pending_meta')
53
- assert !queue.picked_up?
54
-
35
+ it "should be able to pop data from itself" do
55
36
  queue = Elibri::ApiClient::ApiAdapters::V1::Queue.new(@api_adapter, :name => 'meta')
56
- assert queue.picked_up?
37
+ @api_adapter.expects(:pop_from_queue).with(queue.name, {:testing => 1, :count => 20})
38
+ queue.pop(:testing => 1, :count => 20)
57
39
  end
58
40
 
59
-
60
-
61
-
62
- it "should be able to pick up itself when its a pending queue" do
63
- queue = Elibri::ApiClient::ApiAdapters::V1::Queue.new(@api_adapter, :name => 'pending_meta')
64
- @api_adapter.expects(:pick_up_queue!).with(queue)
65
- queue.pick_up!
66
-
41
+
42
+ it "should be able to establish last pop from itself" do
67
43
  queue = Elibri::ApiClient::ApiAdapters::V1::Queue.new(@api_adapter, :name => 'meta')
68
- @api_adapter.expects(:pick_up_queue!).with(queue).never
69
- queue.pick_up!
44
+ @api_adapter.expects(:last_pop_from_queue).with('meta')
45
+ queue.last_pop
70
46
  end
71
47
 
72
-
73
48
 
74
49
  it "should provide iterator for traversing products list" do
75
- block = lambda {|product_xml| product_xml.css('RecordReference') }
76
-
77
50
  queue = Elibri::ApiClient::ApiAdapters::V1::Queue.new(@api_adapter, :name => 'meta')
78
- @api_adapter.expects(:each_product_onix_in_queue).with(queue)
79
- queue.each_product_onix(&block)
80
- end
81
-
82
-
51
+ pop_with_products = mock('QueuePop', :popped_products_count => 10)
52
+ pop_with_products.expects(:each_product)
83
53
 
54
+ pop_without_products = mock('QueuePop', :popped_products_count => 0)
55
+ pop_without_products.expects(:each_product).never
56
+ queue.expects(:pop).returns(pop_with_products).then.returns(pop_without_products).twice
84
57
 
58
+ queue.each_product {|product_xml| product_xml.css('RecordReference') }
59
+ end
60
+
85
61
 
86
62
  end
@@ -13,10 +13,11 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
13
13
  end
14
14
 
15
15
 
16
- def post_request_expected(request_uri)
16
+ def post_request_expected(request_uri, options = {})
17
+ options = ' ' if options.empty?
17
18
  Elibri::ApiClient::ApiAdapters::V1.expects(:post).with(
18
19
  request_uri,
19
- {:body => ' ', :digest_auth => {:username => 'login', :password => 'password'}}
20
+ {:body => options, :digest_auth => {:username => 'login', :password => 'password'}}
20
21
  )
21
22
  end
22
23
 
@@ -27,7 +28,7 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
27
28
 
28
29
 
29
30
  it "should define several exception classes" do
30
- exception_classes = %w{Unauthorized NotFound Forbidden ServerError NoPendingData NoRecentlyPickedUpQueues QueueDoesNotExists InvalidPageNumber}
31
+ exception_classes = %w{Unauthorized NotFound Forbidden ServerError QueueDoesNotExists NoRecentlyPoppedData}
31
32
  exception_classes.each do |exception_class|
32
33
  assert(Elibri::ApiClient::ApiAdapters::V1::Exceptions.const_get(exception_class) < RuntimeError)
33
34
  end
@@ -44,11 +45,11 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
44
45
  it "should normalise request URI before performing real request" do
45
46
  response_stub = stub('response_stub', :code => 200, :parsed_response => nil)
46
47
 
47
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/192f134e666df34464bcc14d0413").once.returns(response_stub)
48
- @adapter.send(:get, "#{FAKE_API_HOST}/api/v1/queues/meta/192f134e666df34464bcc14d0413")
49
-
50
48
  get_request_expected("#{FAKE_API_HOST}/api/v1/api_entrypoint").once.returns(response_stub)
51
- @adapter.send(:get, '/api_entrypoint')
49
+ @adapter.send(:get, "#{FAKE_API_HOST}/api/v1/api_entrypoint")
50
+
51
+ get_request_expected("#{FAKE_API_HOST}/api/v1/api_entrypoint?param1=value1").once.returns(response_stub)
52
+ @adapter.send(:get, '/api_entrypoint?param1=value1')
52
53
 
53
54
  get_request_expected("#{FAKE_API_HOST}/api/v1/api_entrypoint_without_leading_slash").once.returns(response_stub)
54
55
  @adapter.send(:get, 'api_entrypoint_without_leading_slash')
@@ -58,17 +59,17 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
58
59
 
59
60
  describe "when asked to establish pending queues list" do
60
61
 
61
- describe "and there is pending data awaiting for pull" do
62
+ describe "and there is pending data awaiting for pop" do
62
63
  before do
63
64
  xml = <<-XML
64
- <pending_data>
65
- <queue name="pending_meta" products_count="24" last_insert_at="2011-02-05 21:02:22 UTC"/>
66
- <queue name="pending_stocks" products_count="1500" last_insert_at="2011-02-05 21:02:22 UTC"/>
67
- </pending_data>
65
+ <queues>
66
+ <queue name="meta" products_count="24" last_insert_at="2011-02-05 21:02:22 UTC"/>
67
+ <queue name="stocks" products_count="1500" last_insert_at="2011-02-05 21:02:22 UTC"/>
68
+ </queues>
68
69
  XML
69
70
 
70
71
  response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML(xml))
71
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/pending_data").at_least_once.returns(response_stub)
72
+ get_request_expected("#{FAKE_API_HOST}/api/v1/queues").at_least_once.returns(response_stub)
72
73
  end
73
74
 
74
75
 
@@ -77,14 +78,14 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
77
78
  pending_queues = @adapter.pending_queues
78
79
  assert_equal 2, pending_queues.size
79
80
 
80
- pending_meta = pending_queues.find {|queue| queue.name == 'pending_meta' }
81
- pending_stocks = pending_queues.find {|queue| queue.name == 'pending_stocks' }
81
+ meta = pending_queues.find {|queue| queue.name == 'meta' }
82
+ stocks = pending_queues.find {|queue| queue.name == 'stocks' }
82
83
 
83
- assert_equal 24, pending_meta.products_count
84
- assert_kind_of Time, pending_meta.last_insert_at
84
+ assert_equal 24, meta.products_count
85
+ assert_kind_of Time, meta.last_insert_at
85
86
 
86
- assert_equal 1500, pending_stocks.products_count
87
- assert_kind_of Time, pending_stocks.last_insert_at
87
+ assert_equal 1500, stocks.products_count
88
+ assert_kind_of Time, stocks.last_insert_at
88
89
  end
89
90
  end
90
91
 
@@ -92,14 +93,14 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
92
93
  describe "and there is no pending data awaiting for pull" do
93
94
  before do
94
95
  xml = <<-XML
95
- <pending_data>
96
- <queue name="pending_meta" products_count="0" />
97
- <queue name="pending_stocks" products_count="0" />
98
- </pending_data>
96
+ <queues>
97
+ <queue name="meta" products_count="0" />
98
+ <queue name="stocks" products_count="0" />
99
+ </queues>
99
100
  XML
100
101
 
101
102
  response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML(xml))
102
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/pending_data").at_least_once.returns(response_stub)
103
+ get_request_expected("#{FAKE_API_HOST}/api/v1/queues").at_least_once.returns(response_stub)
103
104
  end
104
105
 
105
106
 
@@ -110,47 +111,6 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
110
111
  end
111
112
  end
112
113
 
113
-
114
-
115
- describe "when asked to pick up queue" do
116
- before do
117
- xml = <<-XML
118
- <pick_up>
119
- <queue name="meta" id="192f134e666df34464bcc14d04135cda2bd13a0c" url="#{FAKE_API_HOST}/api/v1/queues/meta/192f134e666df34464bcc14d04135cda2bd13a0c" products_count="24" last_insert_at="2011-02-05 21:02:22 UTC" picked_up_at="2011-02-05 21:02:22 UTC"/>
120
- </pick_up>
121
- XML
122
-
123
- @response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML(xml))
124
- end
125
-
126
-
127
- it "should be able to pick it up by name" do
128
- post_request_expected("#{FAKE_API_HOST}/api/v1/queues/pending_meta/pick_up").at_least_once.returns(@response_stub)
129
- picked_up_queue = @adapter.pick_up_queue!('pending_meta')
130
- assert_equal 24, picked_up_queue.products_count
131
- assert_kind_of Time, picked_up_queue.picked_up_at
132
- end
133
-
134
-
135
- it "should be able to pick it up by Queue instance" do
136
- post_request_expected("#{FAKE_API_HOST}/api/v1/queues/pending_meta/pick_up").at_least_once.returns(@response_stub)
137
- queue_to_pick_up = Elibri::ApiClient::ApiAdapters::V1::Queue.new(@api_adapter, :name => 'pending_meta')
138
- picked_up_queue = @adapter.pick_up_queue!(queue_to_pick_up)
139
- assert_equal 24, picked_up_queue.products_count
140
- assert_kind_of Time, picked_up_queue.picked_up_at
141
- end
142
-
143
-
144
- it "should raise error when cannot infer queue name from argument" do
145
- post_request_expected("#{FAKE_API_HOST}/api/v1/queues/pending_meta/pick_up").never
146
- post_request_expected("#{FAKE_API_HOST}/api/v1/queues/pending_stocks/pick_up").never
147
-
148
- assert_raises(RuntimeError) { @adapter.pick_up_queue!(12345) }
149
- assert_raises(RuntimeError) { @adapter.pick_up_queue!(Array.new) }
150
- end
151
- end
152
-
153
-
154
114
 
155
115
  describe "when there was error reported" do
156
116
  before do
@@ -160,9 +120,7 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
160
120
  '403' => Elibri::ApiClient::ApiAdapters::V1::Exceptions::Forbidden,
161
121
  '500' => Elibri::ApiClient::ApiAdapters::V1::Exceptions::ServerError,
162
122
  '1001' => Elibri::ApiClient::ApiAdapters::V1::Exceptions::QueueDoesNotExists,
163
- '1002' => Elibri::ApiClient::ApiAdapters::V1::Exceptions::NoPendingData,
164
- '1003' => Elibri::ApiClient::ApiAdapters::V1::Exceptions::NoRecentlyPickedUpQueues,
165
- '1004' => Elibri::ApiClient::ApiAdapters::V1::Exceptions::InvalidPageNumber
123
+ '1002' => Elibri::ApiClient::ApiAdapters::V1::Exceptions::NoRecentlyPoppedData,
166
124
  }
167
125
  end
168
126
 
@@ -170,7 +128,7 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
170
128
  it "should raise proper exception class" do
171
129
  @exception_classes.each do |error_code, exception_class|
172
130
  response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML( @xml.gsub('ERROR_CODE', error_code) ))
173
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/pending_data").once.returns(response_stub)
131
+ get_request_expected("#{FAKE_API_HOST}/api/v1/queues").once.returns(response_stub)
174
132
  assert_raises(exception_class) { @adapter.pending_queues }
175
133
  end
176
134
  end
@@ -178,137 +136,20 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
178
136
 
179
137
  it "should raise Unauthorized, when there is 401 response code" do
180
138
  response_stub = stub('response_stub', :code => 401, :parsed_response => nil)
181
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/pending_data").once.returns(response_stub)
139
+ get_request_expected("#{FAKE_API_HOST}/api/v1/queues").once.returns(response_stub)
182
140
  assert_raises(Elibri::ApiClient::ApiAdapters::V1::Exceptions::Unauthorized) { @adapter.pending_queues }
183
141
  end
184
142
 
185
143
 
186
144
  it "should raise RuntimeError on unknown error code" do
187
145
  response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML( @xml.gsub('ERROR_CODE', 'UNKNOWN_ERROR_CODE') ))
188
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/pending_data").once.returns(response_stub)
146
+ get_request_expected("#{FAKE_API_HOST}/api/v1/queues").once.returns(response_stub)
189
147
  assert_raises(Elibri::ApiClient::ApiAdapters::V1::Exceptions::UnknownError) { @adapter.pending_queues }
190
148
  end
191
149
 
192
150
  end
193
151
 
194
152
 
195
-
196
- describe "when asked to get latest pickups" do
197
- describe "and there is no recently picked up queues" do
198
- before do
199
- xml = %q{<error id='1003'> <message>There is no recently picked up queue</message> </error>}
200
- response_stub = stub('response_stub', :code => 412, :parsed_response => Nokogiri::XML(xml))
201
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/last_pick_up").once.returns(response_stub)
202
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/stocks/last_pick_up").once.returns(response_stub)
203
- end
204
-
205
- it "should return empty latest pickups list" do
206
- assert @adapter.last_pickups.empty?
207
- end
208
- end
209
-
210
-
211
- describe "and there were recently picked up queues" do
212
- before do
213
- meta_xml = <<-XML
214
- <pick_up>
215
- <queue name="meta" id="192f134e666df34464bcc14d04135cda2bd13a0c" url="#{FAKE_API_HOST}/api/v1/queues/meta/192f134e666df34464bcc14d04135cda2bd13a0c" products_count="24" last_insert_at="2011-02-05 21:02:22 UTC" picked_up_at="2011-02-05 21:02:22 UTC"/>
216
- </pick_up>
217
- XML
218
-
219
- stocks_xml = <<-XML
220
- <pick_up>
221
- <queue name="stocks" id="192f134e666df34464bcc14d04135cda2bd13a0d" url="#{FAKE_API_HOST}/api/v1/queues/stocks/192f134e666df34464bcc14d04135cda2bd13a0d" products_count="50" last_insert_at="2011-02-05 21:02:22 UTC" picked_up_at="2011-02-05 21:02:22 UTC"/>
222
- </pick_up>
223
- XML
224
-
225
- meta_response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML(meta_xml))
226
- stocks_response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML(stocks_xml))
227
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/last_pick_up").once.returns(meta_response_stub)
228
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/stocks/last_pick_up").once.returns(stocks_response_stub)
229
- end
230
-
231
-
232
- it "should return latest pickups as Queue instances" do
233
- last_pickups = @adapter.last_pickups
234
- assert_equal 2, last_pickups.size
235
- assert(last_pickups.all? { |pickup| pickup.is_a? Elibri::ApiClient::ApiAdapters::V1::Queue })
236
- end
237
- end
238
- end
239
-
240
-
241
-
242
- describe "when asked to iterate by products in a queue" do
243
- before do
244
- @queue = Elibri::ApiClient::ApiAdapters::V1::Queue.new(@adapter, :name => 'meta', :queue_id => 'QUEUE_ID')
245
- first_page_xml = <<-XML
246
- <queue name="meta" id="QUEUE_ID" products_count="54" picked_up_at="2011-02-05 21:02:22 UTC">
247
- <items paginated="true">
248
- <pages total="3" items_per_page="20" >
249
- <next_page page_no="2" url="#{FAKE_API_HOST}/api/v1/queues/meta/QUEUE_ID/2" />
250
- <current_page page_no="1" url="#{FAKE_API_HOST}/api/v1/queues/meta/QUEUE_ID" >
251
- <content><Product>PRODUCT_FROM_PAGE_1</Product></content>
252
- </current_page>
253
- </pages>
254
- </items>
255
- </queue>
256
- XML
257
- second_page_xml = <<-XML
258
- <queue name="meta" id="QUEUE_ID" products_count="54" picked_up_at="2011-02-05 21:02:22 UTC">
259
- <items paginated="true">
260
- <pages total="3" items_per_page="20" >
261
- <previous_page page_no="1" url="#{FAKE_API_HOST}/api/v1/queues/meta/QUEUE_ID" />
262
- <next_page page_no="3" url="#{FAKE_API_HOST}/api/v1/queues/meta/QUEUE_ID/3" />
263
- <current_page page_no="2" url="#{FAKE_API_HOST}/api/v1/queues/meta/QUEUE_ID/2" >
264
- <content><Product>PRODUCT_FROM_PAGE_2</Product></content>
265
- </current_page>
266
- </pages>
267
- </items>
268
- </queue>
269
- XML
270
- third_page_xml = <<-XML
271
- <queue name="meta" id="QUEUE_ID" products_count="54" picked_up_at="2011-02-05 21:02:22 UTC">
272
- <items paginated="true">
273
- <pages total="3" items_per_page="20" >
274
- <previous_page page_no="2" url="#{FAKE_API_HOST}/api/v1/queues/meta/QUEUE_ID/2" />
275
- <current_page page_no="3" url="#{FAKE_API_HOST}/api/v1/queues/meta/QUEUE_ID/3" >
276
- <content><Product>PRODUCT_FROM_PAGE_3</Product></content>
277
- </current_page>
278
- </pages>
279
- </items>
280
- </queue>
281
- XML
282
-
283
- first_page_response_stub = stub('response1_stub', :code => 200, :parsed_response => Nokogiri::XML(first_page_xml))
284
- second_page_response_stub = stub('response2_stub', :code => 200, :parsed_response => Nokogiri::XML(second_page_xml))
285
- third_page_response_stub = stub('response3_stub', :code => 200, :parsed_response => Nokogiri::XML(third_page_xml))
286
-
287
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/QUEUE_ID").once.returns(first_page_response_stub)
288
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/QUEUE_ID/2").once.returns(second_page_response_stub)
289
- get_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/QUEUE_ID/3").once.returns(third_page_response_stub)
290
- end
291
-
292
-
293
- it "should be able to iterate through products pages" do
294
- expected_content = %w{<Product>PRODUCT_FROM_PAGE_1</Product> <Product>PRODUCT_FROM_PAGE_2</Product> <Product>PRODUCT_FROM_PAGE_3</Product>}
295
- @adapter.each_page_in_queue(@queue) do |page_content, page_no|
296
- assert_equal expected_content[page_no-1], page_content.children.to_s
297
- end
298
- end
299
-
300
-
301
- it "should be able to iterate through all product records" do
302
- expected_records = %w{PRODUCT_FROM_PAGE_1 PRODUCT_FROM_PAGE_2 PRODUCT_FROM_PAGE_3}
303
- @adapter.each_product_onix_in_queue(@queue) do |product_xml, product_no|
304
- assert_kind_of Nokogiri::XML::Element, product_xml
305
- assert_equal expected_records[product_no-1], product_xml.text
306
- end
307
- end
308
- end
309
-
310
-
311
-
312
153
  describe "when asked to establish available publishers list" do
313
154
  before do
314
155
  xml = <<-XML
@@ -390,4 +231,109 @@ describe Elibri::ApiClient::ApiAdapters::V1 do
390
231
  end
391
232
 
392
233
  end
234
+
235
+
236
+
237
+ describe "when asked to pop data from specified queue name" do
238
+
239
+ before do
240
+ xml = <<-XML
241
+ <pop created_at="2011-09-06 13:58:21 UTC" queue_name="meta" popped_products_count="2">
242
+ <ONIXMessage release="3.0">
243
+ <Header>
244
+ <Sender>
245
+ <SenderName>Elibri.com.pl</SenderName>
246
+ <ContactName>Tomasz Meka</ContactName>
247
+ <EmailAddress>kontakt@elibri.com.pl</EmailAddress>
248
+ </Sender>
249
+ <SentDateTime>20110906</SentDateTime>
250
+ </Header>
251
+
252
+ <Product>
253
+ </Product>
254
+ <Product>
255
+ </Product>
256
+ </ONIXMessage>
257
+ </pop>
258
+ XML
259
+
260
+ @response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML(xml))
261
+ end
262
+
263
+
264
+ it "should send params when they are specified and return QueuePop instance" do
265
+ post_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/pop", :testing => 1, :count => 5).at_least_once.returns(@response_stub)
266
+
267
+ pop = @adapter.pop_from_queue('meta', :testing => true, :count => 5)
268
+ assert_kind_of Elibri::ApiClient::ApiAdapters::V1::QueuePop, pop
269
+ assert_equal 2, pop.popped_products_count
270
+ end
271
+
272
+
273
+ it "should send empty request body when no params are specified" do
274
+ post_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/pop").at_least_once.returns(@response_stub)
275
+
276
+ pop = @adapter.pop_from_queue('meta')
277
+ assert_kind_of Elibri::ApiClient::ApiAdapters::V1::QueuePop, pop
278
+ assert_equal 2, pop.popped_products_count
279
+ end
280
+
281
+ end
282
+
283
+
284
+ describe "when asked to get last pop for specified queue name" do
285
+
286
+ describe "and there was no recent pop" do
287
+ before do
288
+ xml = %q{<error id='1002'> <message>There is no recently popped data</message> </error>}
289
+ 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)
291
+ end
292
+
293
+ it "should return nil, ignoring NoRecentlyPoppedData exception" do
294
+ assert_nil @adapter.last_pop_from_queue('meta')
295
+ end
296
+ end
297
+
298
+
299
+ describe "and there was a pop" do
300
+
301
+ before do
302
+ xml = <<-XML
303
+ <pop created_at="2011-09-06 13:58:21 UTC" queue_name="meta" popped_products_count="2">
304
+ <ONIXMessage release="3.0">
305
+ <Header>
306
+ <Sender>
307
+ <SenderName>Elibri.com.pl</SenderName>
308
+ <ContactName>Tomasz Meka</ContactName>
309
+ <EmailAddress>kontakt@elibri.com.pl</EmailAddress>
310
+ </Sender>
311
+ <SentDateTime>20110906</SentDateTime>
312
+ </Header>
313
+
314
+ <Product>
315
+ </Product>
316
+ <Product>
317
+ </Product>
318
+ </ONIXMessage>
319
+ </pop>
320
+ XML
321
+
322
+ @response_stub = stub('response_stub', :code => 200, :parsed_response => Nokogiri::XML(xml))
323
+ end
324
+
325
+
326
+ it "should return QueuePop instance" do
327
+ get_request_expected("#{FAKE_API_HOST}/api/v1/queues/meta/last_pop").at_least_once.returns(@response_stub)
328
+
329
+ pop = @adapter.last_pop_from_queue('meta')
330
+ assert_kind_of Elibri::ApiClient::ApiAdapters::V1::QueuePop, pop
331
+ assert_equal 2, pop.popped_products_count
332
+ end
333
+ end
334
+
335
+
336
+ end
337
+
338
+
393
339
  end
data/test/helper.rb CHANGED
@@ -10,8 +10,7 @@ end
10
10
  require 'test/unit'
11
11
  require 'minitest/autorun'
12
12
  require 'mocha'
13
- require 'ruby-debug'
14
- Debugger.settings[:autoeval] = true rescue nil
13
+ require 'pry'
15
14
 
16
15
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
17
16
  $LOAD_PATH.unshift(File.dirname(__FILE__))
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: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 5
10
- version: 1.0.5
10
+ version: 1.1.0
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-07-17 00:00:00 +02:00
18
+ date: 2011-09-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -79,7 +79,7 @@ dependencies:
79
79
  segments:
80
80
  - 0
81
81
  version: "0"
82
- name: ruby-debug
82
+ name: pry
83
83
  version_requirements: *id004
84
84
  prerelease: false
85
85
  - !ruby/object:Gem::Dependency
@@ -182,6 +182,7 @@ files:
182
182
  - test/elibri_api_client_test.rb
183
183
  - test/elibri_api_v1_adapter_product_test.rb
184
184
  - test/elibri_api_v1_adapter_publisher_test.rb
185
+ - test/elibri_api_v1_adapter_queue_pop_test.rb
185
186
  - test/elibri_api_v1_adapter_queue_test.rb
186
187
  - test/elibri_api_v1_adapter_test.rb
187
188
  - test/helper.rb