insales_api 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +39 -17
  3. data/insales_api.gemspec +26 -10
  4. data/lib/active_resource/singleton.rb +4 -6
  5. data/lib/insales/controller/autologin.rb +39 -35
  6. data/lib/insales/controller/base_helpers.rb +19 -18
  7. data/lib/insales/controller/session_actions.rb +6 -4
  8. data/lib/insales_api/active_resource_proxy.rb +7 -4
  9. data/lib/insales_api/app.rb +14 -13
  10. data/lib/insales_api/application_charge.rb +1 -1
  11. data/lib/insales_api/application_widget.rb +1 -1
  12. data/lib/insales_api/base.rb +2 -2
  13. data/lib/insales_api/category.rb +2 -2
  14. data/lib/insales_api/collect.rb +1 -1
  15. data/lib/insales_api/currency.rb +2 -1
  16. data/lib/insales_api/custom_status.rb +3 -0
  17. data/lib/insales_api/helpers/init_api.rb +1 -1
  18. data/lib/insales_api/js_tag.rb +1 -1
  19. data/lib/insales_api/marketplace.rb +3 -0
  20. data/lib/insales_api/option_name.rb +1 -1
  21. data/lib/insales_api/option_value.rb +1 -1
  22. data/lib/insales_api/order.rb +7 -2
  23. data/lib/insales_api/pick_up_source.rb +3 -0
  24. data/lib/insales_api/price_kind.rb +2 -1
  25. data/lib/insales_api/product_field_value.rb +3 -3
  26. data/lib/insales_api/property.rb +1 -1
  27. data/lib/insales_api/resource/countable.rb +1 -1
  28. data/lib/insales_api/resource/paginated.rb +3 -1
  29. data/lib/insales_api/resource/with_updated_since.rb +6 -4
  30. data/lib/insales_api/stock_currency.rb +2 -1
  31. data/lib/insales_api/theme.rb +1 -3
  32. data/lib/insales_api/version.rb +2 -2
  33. data/lib/insales_api.rb +7 -4
  34. metadata +24 -27
  35. data/.gitignore +0 -4
  36. data/.travis.yml +0 -9
  37. data/Gemfile +0 -3
  38. data/Rakefile +0 -8
  39. data/spec/lib/insales_api/active_resource_proxy_spec.rb +0 -49
  40. data/spec/lib/insales_api/app_spec.rb +0 -67
  41. data/spec/lib/insales_api_spec.rb +0 -110
  42. data/spec/spec_helper.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1b1bb7720ee3166a7d3d9a2c3cfc3d518f6a592b
4
- data.tar.gz: 719e683432b89d70155607786a9b659a665c7498
2
+ SHA256:
3
+ metadata.gz: 62b41ec2560cf18731edf0215696e41b99f3060d2c685d1ab1c66cdff3bb1b1b
4
+ data.tar.gz: 50cb0265ef23f2087243865e0a99c64560b6ef9bc5af49838e751c2e42bacb1e
5
5
  SHA512:
6
- metadata.gz: a79a98a7569ff8b71f9fd11a3056482acb8781a609886605c11c55849e5d6f584f6813fba470a5c4ab3a57b484fd03eb34a87ad5390fdb72f22624188db4ae43
7
- data.tar.gz: ef9c698fe3426129b64a55a925e9a402bfc437ef952e5464dc984a37f9fd96a315fe1735dbf3791393cdf03ef6b3af2943dcc948ba7e930efaa9384f41659c37
6
+ metadata.gz: 31027f6d9125e5e43309698dd91ccb2938bbf23c9c633bb9976562cf834c789a5f7ed962dbea15a150d157afca7381568614b292c60fbfd10cdd2549aa6fe70b
7
+ data.tar.gz: d3f508decd731d258cb89adbbac0a0bb09cf6e160e3ef64136542d792e5fe5d142c7d7d2aeeef16950182608bd7be6588fdf95a48245fc8b7bef77f5fcb2fba9
data/CHANGELOG.md CHANGED
@@ -1,24 +1,46 @@
1
- ## 0.1.0
1
+
2
+ ## 0.2.0
3
+ * Added: support 429 response code
4
+ * Removed unnecessary files from the gem
5
+ * Fix `Order#to_xml` `order_lines_attributes`
6
+ * Fix `updated_since` time format
7
+ * Added `CustomStatus`
8
+ * Added `Marketplace`
9
+
10
+ ## 0.1.3 (August 31, 2016)
11
+ * `WithUpdatedSince` raises `ActiveResource::ResourceNotFound` on 404
12
+ * `Category` and `Collection` now support `WithUpdatedSince`
13
+ * Added `Currency`
14
+ * Added `PriceKind`
15
+ * Added `StockCurrency`
16
+
17
+ ## 0.1.1 (September 30, 2015)
18
+ * `App#auth_token` and`Password.create` support optional user_email/user_name/user_id
19
+ * Added `Characteristic`
20
+ * Added `User`
21
+ * Added `Notification`
22
+
23
+ ## 0.1.0 (May 06, 2015)
2
24
 
3
25
  * Helpers
4
- * ProductFieldValue
26
+ * Added `ProductFieldValue`
5
27
  * Controller auth mixins
6
- * Account inherits AR::Singleton (it breaks ::current & #update methods)
7
- * Added wait_retry method
8
- * Added Property resource
9
- * Added ProductField resource
10
- * Added ClientGroup resource
28
+ * `Account` inherits `AR::Singleton` (this breaks `::current` & `#update` methods)
29
+ * Added `wait_retry` method
30
+ * Added `Property` resource
31
+ * Added `ProductField` resource
32
+ * Added `ClientGroup` resource
11
33
 
12
- ## 0.0.14
34
+ ## 0.0.14 (not released to rubygems)
13
35
 
14
- * Added Image resource
15
- * Fixed Variant.group_update
16
- * Added DiscountCode resource
17
- * Added Product.count method
18
- * Added Order.paid? method
19
- * Added ApplicationCharge resource
36
+ * Added `Image` resource
37
+ * Fixed `Variant.group_update`
38
+ * Added `DiscountCode` resource
39
+ * Added `Product.count` method
40
+ * Added `Order.paid?` method
41
+ * Added `ApplicationCharge` resource
20
42
 
21
- ## 0.0.13
43
+ ## 0.0.13 (August 23, 2013)
22
44
 
23
- * ActiveResource::Singleton backport.
24
- * Fix for multiple InsalesApi::Apps child-classes in single app.
45
+ * `ActiveResource::Singleton` backport.
46
+ * Fix for multiple `InsalesApi::App` child-classes in a single app.
data/insales_api.gemspec CHANGED
@@ -1,4 +1,7 @@
1
- $:.push File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ # $LOAD_PATH.push File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
5
  require 'insales_api/version'
3
6
 
4
7
  Gem::Specification.new do |s|
@@ -7,17 +10,30 @@ Gem::Specification.new do |s|
7
10
  s.authors = 'InSales'
8
11
  s.email = 'dg@insales.ru'
9
12
  s.homepage = 'https://github.com/insales/insales_api'
10
- s.summary = %q{Gem for accessing the InSales REST web services}
11
- s.description = %q{Gem for accessing the InSales REST web services}
13
+ s.summary = 'Gem for accessing the InSales REST web services'
14
+ s.description = 'Gem for accessing the InSales REST web services'
12
15
 
13
- s.rubyforge_project = 'insales_api'
16
+ if s.respond_to?(:metadata) # old rubygems do not support metadata
17
+ s.metadata["homepage_uri"] = s.homepage
18
+ s.metadata["source_code_uri"] = "https://github.com/insales/insales_api"
19
+ s.metadata["changelog_uri"] = "https://github.com/insales/insales_api/blob/master/CHANGELOG.md"
20
+ end
14
21
 
15
- s.files = `git ls-files`.split("\n")
16
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.required_ruby_version = '>= 1.9'
23
+
24
+ s.files = `git ls-files`.split("\n").reject do |f|
25
+ f.match(Regexp.union(
26
+ %r{^gemfiles/},
27
+ %r{^spec/},
28
+ /^\./,
29
+ /^Appraisals/,
30
+ /^Gemfile/,
31
+ /^Rakefile/
32
+ ))
33
+ end
18
34
 
19
- s.add_dependency('activesupport', ['>= 3.0.0'])
20
35
  s.add_dependency('activeresource', ['>= 3.0.0'])
21
- s.add_development_dependency 'rspec', '~> 2.13.0'
22
- s.add_development_dependency 'rake', '~> 10.3'
36
+ s.add_dependency('activesupport', ['>= 3.0.0'])
37
+ s.add_development_dependency 'rake', '>= 10.3'
38
+ s.add_development_dependency 'rspec', '~> 3.12'
23
39
  end
@@ -60,11 +60,12 @@ module ActiveResource
60
60
  #
61
61
  # Inventory.find
62
62
  # # => raises ResourceNotFound
63
- def find(options={})
63
+ def find(options = {})
64
64
  find_singleton(options)
65
65
  end
66
66
 
67
67
  private
68
+
68
69
  # Find singleton resource
69
70
  def find_singleton(options)
70
71
  prefix_options, query_options = split_options(options[:params])
@@ -73,8 +74,8 @@ module ActiveResource
73
74
  resp = self.format.decode(self.connection.get(path, self.headers).body)
74
75
  instantiate_record(resp, {})
75
76
  end
76
-
77
77
  end
78
+
78
79
  # Deletes the resource from the remove service.
79
80
  #
80
81
  # ==== Examples
@@ -85,7 +86,6 @@ module ActiveResource
85
86
  connection.delete(singleton_path, self.class.headers)
86
87
  end
87
88
 
88
-
89
89
  protected
90
90
 
91
91
  # Update the resource on the remote service
@@ -108,7 +108,5 @@ module ActiveResource
108
108
  def singleton_path(options = nil)
109
109
  self.class.singleton_path(options || prefix_options)
110
110
  end
111
-
112
111
  end
113
-
114
- end
112
+ end
@@ -1,45 +1,49 @@
1
1
  module Insales::Controller
2
2
  module Autologin
3
3
  protected
4
- def insales_authenticate!
5
- params[:domain] ||= params[:shop]
6
- insales_logout if params[:domain].present? && params[:domain] != session[:domain]
7
- return if insales_authenticate_from_session
8
- store_location
9
- account = find_account_by_request
10
- return insales_autologin_start(account) if account
11
- redirect_to insales_login_path
12
- end
13
4
 
14
- def insales_authenticate_from_session
15
- data = session[:insales_session]
16
- return unless data && data[:account_id] && data[:insales_id]
17
- @account = account_class.where(account_id: data[:account_id]).
18
- find_by_insales_id(data[:insales_id])
19
- end
5
+ def insales_authenticate!
6
+ params[:domain] ||= params[:shop]
7
+ insales_logout if params[:domain].present? && params[:domain] != session[:domain]
8
+ return if insales_authenticate_from_session
20
9
 
21
- def insales_autologin_start(account)
22
- app = insales_app_class.new(account.insales_domain, account.insales_password)
23
- auth_url = app.authorization_url
24
- session[:insales_token] = app.auth_token
25
- session[:insales_token_data] = {
26
- domain: account.insales_domain,
27
- account_id: account.id,
28
- insales_id: account.insales_id,
29
- }
30
- redirect_to auth_url
31
- end
10
+ store_location
11
+ account = find_account_by_request
12
+ return insales_autologin_start(account) if account
32
13
 
33
- def insales_autologin_finish(token = params[:token])
34
- if token && session[:insales_token] == token && session[:insales_token_data].is_a?(Hash)
35
- session[:insales_session] = session[:insales_token_data]
36
- end
37
- session[:insales_token] = session[:insales_token_data] = nil
38
- session[:account_id].present?
39
- end
14
+ redirect_to insales_login_path
15
+ end
40
16
 
41
- def insales_logout
42
- session.delete(:insales_session)
17
+ def insales_authenticate_from_session
18
+ data = session[:insales_session]
19
+ return unless data && data[:account_id] && data[:insales_id]
20
+
21
+ @account = account_class.where(account_id: data[:account_id])
22
+ .find_by_insales_id(data[:insales_id])
23
+ end
24
+
25
+ def insales_autologin_start(account)
26
+ app = insales_app_class.new(account.insales_domain, account.insales_password)
27
+ auth_url = app.authorization_url
28
+ session[:insales_token] = app.auth_token
29
+ session[:insales_token_data] = {
30
+ domain: account.insales_domain,
31
+ account_id: account.id,
32
+ insales_id: account.insales_id,
33
+ }
34
+ redirect_to auth_url
35
+ end
36
+
37
+ def insales_autologin_finish(token = params[:token])
38
+ if token && session[:insales_token] == token && session[:insales_token_data].is_a?(Hash)
39
+ session[:insales_session] = session[:insales_token_data]
43
40
  end
41
+ session[:insales_token] = session[:insales_token_data] = nil
42
+ session[:account_id].present?
43
+ end
44
+
45
+ def insales_logout
46
+ session.delete(:insales_session)
47
+ end
44
48
  end
45
49
  end
@@ -5,9 +5,9 @@ module Insales::Controller
5
5
  included do
6
6
  class_attribute :insales_config
7
7
  self.insales_config = {
8
- account_class: '::Account',
9
- insales_app_class: '::InsalesApi::App',
10
- login_path: 'login_path',
8
+ account_class: '::Account',
9
+ insales_app_class: '::InsalesApi::App',
10
+ login_path: 'login_path',
11
11
  success_login_path: 'account_path',
12
12
  }
13
13
 
@@ -29,24 +29,25 @@ module Insales::Controller
29
29
  end
30
30
 
31
31
  protected
32
- delegate :insales_app_class, :account_class,
33
- :insales_login_path, :insales_success_login_path,
34
- to: :class
35
32
 
36
- def store_location(path = request.url)
37
- session[:return_to] = path
38
- end
33
+ delegate :insales_app_class, :account_class,
34
+ :insales_login_path, :insales_success_login_path,
35
+ to: :class
39
36
 
40
- def stored_location
41
- session.delete(:return_to)
42
- end
37
+ def store_location(path = request.url)
38
+ session[:return_to] = path
39
+ end
43
40
 
44
- def find_account_by_request
45
- if params[:insales_id]
46
- account_class.find_by_insales_id(params[:insales_id])
47
- elsif params[:domain]
48
- account_class.find_by_insales_domain(params[:domain])
49
- end
41
+ def stored_location
42
+ session.delete(:return_to)
43
+ end
44
+
45
+ def find_account_by_request
46
+ if params[:insales_id]
47
+ account_class.find_by_insales_id(params[:insales_id])
48
+ elsif params[:domain]
49
+ account_class.find_by_insales_domain(params[:domain])
50
50
  end
51
+ end
51
52
  end
52
53
  end
@@ -13,6 +13,7 @@ module Insales::Controller
13
13
  def create
14
14
  account = find_account_by_request
15
15
  return render_not_found unless account
16
+
16
17
  store_location(insales_success_login_path)
17
18
  insales_autologin_start(account)
18
19
  end
@@ -31,9 +32,10 @@ module Insales::Controller
31
32
  end
32
33
 
33
34
  protected
34
- def render_not_found
35
- flash.now[:error] = t(:'.account_not_found').html_safe
36
- render action: :new
37
- end
35
+
36
+ def render_not_found
37
+ flash.now[:error] = t(:'.account_not_found').html_safe
38
+ render action: :new
39
+ end
38
40
  end
39
41
  end
@@ -4,6 +4,7 @@ module InsalesApi
4
4
  def need_proxy?(value)
5
5
  klass = value.is_a?(Class) ? value : value.class
6
6
  return true if klass < Base || klass <= ActiveResource::Collection
7
+
7
8
  false
8
9
  end
9
10
  end
@@ -22,9 +23,11 @@ module InsalesApi
22
23
  end
23
24
 
24
25
  private
25
- def proxy_for(value)
26
- return value unless self.class.need_proxy?(value)
27
- self.class.new(@configurer, value)
28
- end
26
+
27
+ def proxy_for(value)
28
+ return value unless self.class.need_proxy?(value)
29
+
30
+ self.class.new(@configurer, value)
31
+ end
29
32
  end
30
33
  end
@@ -1,8 +1,9 @@
1
1
  module InsalesApi
2
2
  class App
3
3
  class_attribute :api_key, :api_secret, :api_autologin_url, :api_host, :api_autologin_path,
4
- :base_resource_class
4
+ :base_resource_class
5
5
  attr_reader :authorized, :domain, :password
6
+
6
7
  self.base_resource_class = Base
7
8
 
8
9
  class << self
@@ -18,15 +19,15 @@ module InsalesApi
18
19
 
19
20
  alias_method :prepare_shop, :prepare_domain
20
21
  deprecate prepare_shop: :prepare_domain,
21
- api_host: :api_autologin_url,
22
- api_autologin_path: :api_autologin_url,
23
- deprecator: Deprecator
22
+ api_host: :api_autologin_url,
23
+ api_autologin_path: :api_autologin_url,
24
+ deprecator: Deprecator
24
25
 
25
- def install(domain, token, insales_id)
26
+ def install(domain, token, insales_id) # rubocop:disable Lint/UnusedMethodArgument
26
27
  true
27
28
  end
28
29
 
29
- def uninstall(domain, password)
30
+ def uninstall(domain, password) # rubocop:disable Lint/UnusedMethodArgument
30
31
  true
31
32
  end
32
33
 
@@ -46,13 +47,13 @@ module InsalesApi
46
47
  match = /(.+):(\d+)/.match host
47
48
  host, port = match[1..2] if match
48
49
  URI::Generic.build(
49
- scheme: 'http',
50
- host: host,
51
- port: port && port.to_i,
52
- path: "/admin/applications/#{api_key}/login",
53
- query: {
54
- token: salt,
55
- login: api_autologin_url || "http://#{api_host}/#{api_autologin_path}",
50
+ scheme: 'http',
51
+ host: host,
52
+ port: port && port.to_i,
53
+ path: "/admin/applications/#{api_key}/login",
54
+ query: {
55
+ token: salt,
56
+ login: api_autologin_url || "http://#{api_host}/#{api_autologin_path}",
56
57
  }.to_query,
57
58
  ).to_s
58
59
  end
@@ -1,3 +1,3 @@
1
1
  module InsalesApi
2
2
  class ApplicationCharge < Base; end
3
- end
3
+ end
@@ -1,3 +1,3 @@
1
1
  module InsalesApi
2
2
  class ApplicationWidget < Base; end
3
- end
3
+ end
@@ -27,8 +27,8 @@ module InsalesApi
27
27
 
28
28
  def dump_config
29
29
  {
30
- user: self.user,
31
- site: self.site,
30
+ user: self.user,
31
+ site: self.site,
32
32
  password: self.password,
33
33
  }
34
34
  end
@@ -4,8 +4,8 @@ module InsalesApi
4
4
  class << self
5
5
  def set_products_category(new_category_id, product_ids)
6
6
  data = {
7
- id: new_category_id,
8
- product_ids: Array(product_ids),
7
+ id: new_category_id,
8
+ product_ids: Array(product_ids),
9
9
  }
10
10
  put(:set_products_category, {}, format.encode(data, root: :new_category))
11
11
  end
@@ -4,7 +4,7 @@ module InsalesApi
4
4
  def group_create(product_ids, collection_ids)
5
5
  data = {
6
6
  collection_ids: Array(collection_ids),
7
- product_ids: Array(product_ids),
7
+ product_ids: Array(product_ids),
8
8
  }
9
9
  post(:group_create, {}, format.encode(data, root: :group_create))
10
10
  end
@@ -1,4 +1,5 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module InsalesApi
3
4
  class Currency < Base
4
5
  include ActiveResource::Singleton
@@ -0,0 +1,3 @@
1
+ module InsalesApi
2
+ class CustomStatus < Base; end
3
+ end
@@ -53,7 +53,7 @@ module InsalesApi::Helpers
53
53
  file, line = caller.first.split(':', 2)
54
54
  methods.each do |method|
55
55
  alias_method_chain method, :init_api do |target, punct|
56
- class_eval <<-RUBY, file, line.to_i - 1
56
+ class_eval <<-RUBY, file, line.to_i - 1
57
57
  def #{target}_with_init_api#{punct}(*args, &block) # def sell_with_init_api(*args, &block)
58
58
  init_api { #{target}_without_init_api#{punct}(*args, &block) } # init_api { sell_without_init_api(*args, &block) }
59
59
  end # end
@@ -1,3 +1,3 @@
1
1
  module InsalesApi
2
2
  class JsTag < Base; end
3
- end
3
+ end
@@ -0,0 +1,3 @@
1
+ module InsalesApi
2
+ class Marketplace < Base; end
3
+ end
@@ -1,3 +1,3 @@
1
- module InsalesApi
1
+ module InsalesApi
2
2
  class OptionName < Base; end
3
3
  end
@@ -1,3 +1,3 @@
1
- module InsalesApi
1
+ module InsalesApi
2
2
  class OptionValue < Base; end
3
3
  end
@@ -1,4 +1,5 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module InsalesApi
3
4
  class Order < Base
4
5
  extend Resource::WithUpdatedSince
@@ -13,7 +14,11 @@ module InsalesApi
13
14
  end
14
15
 
15
16
  def to_xml(options = {})
16
- super(options.merge(methods: :order_lines_attributes))
17
+ serialized_options = options.dup
18
+ if respond_to? :order_lines_attributes
19
+ serialized_options[:methods] = :order_lines_attributes
20
+ end
21
+ super(serialized_options)
17
22
  end
18
23
 
19
24
  def paid?
@@ -0,0 +1,3 @@
1
+ module InsalesApi
2
+ class PickUpSource < Base; end
3
+ end
@@ -1,4 +1,5 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module InsalesApi
3
4
  class PriceKind < Base
4
5
  def variant_price_method_name
@@ -5,12 +5,12 @@ module InsalesApi
5
5
  class << self
6
6
  def find_by_field_id(params)
7
7
  field_id = params[:product_field_id]
8
- all(params: {product_id: params[:product_id]}).
9
- find { |x| x.product_field_id == field_id }
8
+ all(params: { product_id: params[:product_id] })
9
+ .find { |x| x.product_field_id == field_id }
10
10
  end
11
11
 
12
12
  def create_or_update(params)
13
- if value = find_by_field_id(params)
13
+ if (value = find_by_field_id(params))
14
14
  value.update_attribute(:value, params[:value])
15
15
  value
16
16
  else
@@ -1,7 +1,7 @@
1
1
  module InsalesApi
2
2
  class Property < Base
3
3
  def characteristics
4
- InsalesApi::Characteristic.all(params: { property_id: id } )
4
+ InsalesApi::Characteristic.all(params: { property_id: id })
5
5
  end
6
6
  end
7
7
  end
@@ -2,7 +2,7 @@ module InsalesApi
2
2
  module Resource
3
3
  module Countable
4
4
  def count(options = {})
5
- get(:count, options).to_i
5
+ get(:count, options)['count'].to_i
6
6
  end
7
7
  end
8
8
  end
@@ -11,13 +11,15 @@ module InsalesApi
11
11
 
12
12
  def find_in_batches(options = {})
13
13
  per_page = options[:per_page] || PER_PAGE_DEFAULT
14
- params = {per_page: per_page}.merge(options[:params] || {})
14
+ params = { per_page: per_page }.merge(options[:params] || {})
15
15
  page = 1
16
16
  loop do
17
17
  items = all(params: params.merge(page: page))
18
18
  return unless items.any?
19
+
19
20
  yield items
20
21
  return if items.count < per_page
22
+
21
23
  page += 1
22
24
  end
23
25
  end
@@ -2,18 +2,19 @@ module InsalesApi
2
2
  module Resource
3
3
  module WithUpdatedSince
4
4
  def find_in_batches(options = {}, &block)
5
- return super unless updated_since = options.delete(:updated_since)
5
+ return super unless (updated_since = options.delete(:updated_since))
6
+
6
7
  find_updated_since(updated_since, options, &block)
7
8
  end
8
9
 
9
10
  def find_updated_since(updated_since, options = {})
10
11
  per_page = options[:per_page] || PER_PAGE_DEFAULT
11
12
  params = { per_page: per_page }.merge(options[:params] || {})
12
- last_id = nil
13
+ last_id = options[:last_id] || nil
13
14
  loop do
14
15
  items = all(params: params.merge(
15
- updated_since: updated_since,
16
- from_id: last_id,
16
+ updated_since: updated_since,
17
+ from_id: last_id,
17
18
  ))
18
19
 
19
20
  raise(ActiveResource::ResourceNotFound.new(nil)) if items.nil?
@@ -22,6 +23,7 @@ module InsalesApi
22
23
 
23
24
  yield items
24
25
  return if items.count < per_page
26
+
25
27
  last_item = items.last
26
28
  last_id = last_item.id
27
29
  updated_since = last_item.updated_at
@@ -1,4 +1,5 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  module InsalesApi
3
4
  class StockCurrency < Base
4
5
  end
@@ -1,9 +1,7 @@
1
1
  module InsalesApi
2
2
  class Theme < Base
3
-
4
3
  def assets
5
- InsalesApi::Asset.all(params: {theme_id: id})
4
+ InsalesApi::Asset.all(params: { theme_id: id })
6
5
  end
7
-
8
6
  end
9
7
  end
@@ -1,8 +1,8 @@
1
1
  module InsalesApi
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 3
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
8
8
  end
data/lib/insales_api.rb CHANGED
@@ -26,6 +26,7 @@ module InsalesApi
26
26
  autoload :Collect
27
27
  autoload :Collection
28
28
  autoload :Currency
29
+ autoload :CustomStatus
29
30
  autoload :DeliveryVariant
30
31
  autoload :DiscountCode
31
32
  autoload :Domain
@@ -33,6 +34,7 @@ module InsalesApi
33
34
  autoload :File
34
35
  autoload :Image
35
36
  autoload :JsTag
37
+ autoload :Marketplace
36
38
  autoload :Notification
37
39
  autoload :OptionName
38
40
  autoload :OptionValue
@@ -40,6 +42,7 @@ module InsalesApi
40
42
  autoload :OrderLine
41
43
  autoload :Page
42
44
  autoload :PaymentGateway
45
+ autoload :PickUpSource
43
46
  autoload :PriceKind
44
47
  autoload :Product
45
48
  autoload :ProductField
@@ -55,7 +58,7 @@ module InsalesApi
55
58
  end
56
59
 
57
60
  class << self
58
- # Calls the supplied block. If the block raises <tt>ActiveResource::ServerError</tt> with 503
61
+ # Calls the supplied block. If the block raises <tt>ActiveResource::ServerError</tt> with 429
59
62
  # code which means Insales API request limit is reached, it will wait for the amount of seconds
60
63
  # specified in 'Retry-After' response header. The called block will receive a parameter with
61
64
  # current attempt number.
@@ -78,15 +81,16 @@ module InsalesApi
78
81
  # puts "Attempt ##{x}."
79
82
  # products = InsalesApi::Products.all
80
83
  # end
81
- def wait_retry(max_attempts = nil, callback = nil, &block)
84
+ def wait_retry(max_attempts = nil, callback = nil, &block) # rubocop:disable Lint/UnusedMethodArgument
82
85
  attempts = 0
83
86
 
84
87
  begin
85
88
  attempts += 1
86
89
  yield attempts
87
90
  rescue ActiveResource::ServerError => ex
88
- raise ex if '503' != ex.response.code.to_s
91
+ raise ex unless %w[429 503].include?(ex.response.code.to_s)
89
92
  raise ex if max_attempts && attempts >= max_attempts
93
+
90
94
  retry_after = (ex.response['Retry-After'] || 150).to_i
91
95
  callback.call(retry_after, attempts, max_attempts, ex) if callback
92
96
  sleep(retry_after)
@@ -94,7 +98,6 @@ module InsalesApi
94
98
  end
95
99
  end
96
100
  end
97
-
98
101
  end
99
102
 
100
103
  require 'insales_api/helpers/init_api'
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insales_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - InSales
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-31 00:00:00.000000000 Z
11
+ date: 2023-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: activesupport
14
+ name: activeresource
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: activeresource
28
+ name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,45 +39,41 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: 3.0.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.13.0
47
+ version: '10.3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2.13.0
54
+ version: '10.3'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '10.3'
61
+ version: '3.12'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '10.3'
68
+ version: '3.12'
69
69
  description: Gem for accessing the InSales REST web services
70
70
  email: dg@insales.ru
71
71
  executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
- - ".gitignore"
76
- - ".travis.yml"
77
75
  - CHANGELOG.md
78
- - Gemfile
79
76
  - README.md
80
- - Rakefile
81
77
  - insales_api.gemspec
82
78
  - lib/active_resource/singleton.rb
83
79
  - lib/insales.rb
@@ -101,6 +97,7 @@ files:
101
97
  - lib/insales_api/collect.rb
102
98
  - lib/insales_api/collection.rb
103
99
  - lib/insales_api/currency.rb
100
+ - lib/insales_api/custom_status.rb
104
101
  - lib/insales_api/delivery_variant.rb
105
102
  - lib/insales_api/discount_code.rb
106
103
  - lib/insales_api/domain.rb
@@ -110,6 +107,7 @@ files:
110
107
  - lib/insales_api/helpers/init_api.rb
111
108
  - lib/insales_api/image.rb
112
109
  - lib/insales_api/js_tag.rb
110
+ - lib/insales_api/marketplace.rb
113
111
  - lib/insales_api/notification.rb
114
112
  - lib/insales_api/option_name.rb
115
113
  - lib/insales_api/option_value.rb
@@ -118,6 +116,7 @@ files:
118
116
  - lib/insales_api/page.rb
119
117
  - lib/insales_api/password.rb
120
118
  - lib/insales_api/payment_gateway.rb
119
+ - lib/insales_api/pick_up_source.rb
121
120
  - lib/insales_api/price_kind.rb
122
121
  - lib/insales_api/product.rb
123
122
  - lib/insales_api/product_field.rb
@@ -133,14 +132,13 @@ files:
133
132
  - lib/insales_api/variant.rb
134
133
  - lib/insales_api/version.rb
135
134
  - lib/insales_api/webhook.rb
136
- - spec/lib/insales_api/active_resource_proxy_spec.rb
137
- - spec/lib/insales_api/app_spec.rb
138
- - spec/lib/insales_api_spec.rb
139
- - spec/spec_helper.rb
140
135
  homepage: https://github.com/insales/insales_api
141
136
  licenses: []
142
- metadata: {}
143
- post_install_message:
137
+ metadata:
138
+ homepage_uri: https://github.com/insales/insales_api
139
+ source_code_uri: https://github.com/insales/insales_api
140
+ changelog_uri: https://github.com/insales/insales_api/blob/master/CHANGELOG.md
141
+ post_install_message:
144
142
  rdoc_options: []
145
143
  require_paths:
146
144
  - lib
@@ -148,16 +146,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
146
  requirements:
149
147
  - - ">="
150
148
  - !ruby/object:Gem::Version
151
- version: '0'
149
+ version: '1.9'
152
150
  required_rubygems_version: !ruby/object:Gem::Requirement
153
151
  requirements:
154
152
  - - ">="
155
153
  - !ruby/object:Gem::Version
156
154
  version: '0'
157
155
  requirements: []
158
- rubyforge_project: insales_api
159
- rubygems_version: 2.5.1
160
- signing_key:
156
+ rubygems_version: 3.4.1
157
+ signing_key:
161
158
  specification_version: 4
162
159
  summary: Gem for accessing the InSales REST web services
163
160
  test_files: []
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.1.0
5
- notifications:
6
- email: false
7
- before_install:
8
- - gem update bundler
9
- - bundle install
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new do |t|
5
- t.pattern = 'spec/**/*_spec.rb'
6
- end
7
-
8
- task default: :spec
@@ -1,49 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe InsalesApi::ActiveResourceProxy do
4
- let(:proxy) { described_class.new(configurer, object) }
5
- let(:configurer) { Object.new.tap { |x| x.stub(:init_api).and_yield } }
6
-
7
- describe '#method_missing' do
8
- let(:object) { {} }
9
- let(:method_name) { :some_method }
10
- subject { proxy.send(method_name) }
11
-
12
- it 'should proxy method to object & pass result through #proxy_for' do
13
- result1 = {test: :resut1}
14
- result2 = {test: :resut2}
15
- object.should_receive(method_name).and_return(result1)
16
- proxy.should_receive(:proxy_for).with(result1).and_return(result2)
17
- subject.should eq(result2)
18
- end
19
- end
20
-
21
- describe '::need_proxy?' do
22
- subject { described_class.need_proxy?(object) }
23
-
24
- context 'for scalar' do
25
- let(:object) { true }
26
- it { should be false }
27
- end
28
-
29
- context 'for InsalesApi::Base class' do
30
- let(:object) { InsalesApi::Account }
31
- it { should be true }
32
- end
33
-
34
- context 'for InsalesApi::Base object' do
35
- let(:object) { InsalesApi::Account.new }
36
- it { should be true }
37
- end
38
-
39
- context 'for ActiveResource::Collection object' do
40
- let(:object) { ActiveResource::Collection.new }
41
- it { should be true }
42
- end
43
-
44
- context 'for ActiveResource::Base object' do
45
- let(:object) { ActiveResource::Base.new }
46
- it { should be false }
47
- end
48
- end
49
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe InsalesApi::App do
4
- let(:domain) { 'my.shop.com' }
5
- let(:password) { 'password' }
6
- let(:app) { InsalesApi::App.new(domain, password) }
7
-
8
- subject { app }
9
-
10
- describe '#initialize' do
11
- its(:domain) { should eq(domain) }
12
- its(:password) { should eq(password) }
13
- its(:authorized?) { should be false }
14
- end
15
-
16
- describe '#configure_api' do
17
- it 'configures InsalesApi::Base' do
18
- InsalesApi::Base.should_receive(:configure).with(described_class.api_key, domain, password)
19
- app.configure_api
20
- end
21
- end
22
-
23
- describe '#salt' do
24
- its(:salt) { should be }
25
- end
26
-
27
- describe '#auth_token' do
28
- its(:auth_token) { should eq(InsalesApi::Password.create(app.password, app.salt)) }
29
- end
30
-
31
- describe 'authorization_url' do
32
- subject { app.authorization_url }
33
- let(:expected) do
34
- URI::Generic.build(
35
- scheme: 'http',
36
- host: domain,
37
- path: "/admin/applications/#{app.api_key}/login",
38
- query: {
39
- token: app.salt,
40
- login: app.api_autologin_url,
41
- }.to_query,
42
- ).to_s
43
- end
44
- it { should eq(expected) }
45
- end
46
-
47
- describe '#authorize' do
48
- before { app.auth_token }
49
- subject { app.authorize(token) }
50
-
51
- context 'when valid token is given' do
52
- let(:token) { app.auth_token }
53
- it { should be true }
54
- end
55
-
56
- context 'when invalid token is given' do
57
- let(:token) { 'bad_token' }
58
- it { should be false }
59
- end
60
- end
61
-
62
- describe '::password_by_token' do
63
- let(:token) { 'test' }
64
- subject { InsalesApi::App.password_by_token(token) }
65
- it { should eq(InsalesApi::Password.create(InsalesApi::App.api_secret, token)) }
66
- end
67
- end
@@ -1,110 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe InsalesApi do
4
-
5
- describe '.wait_retry' do
6
-
7
- response_stub = Struct.new(:code, :retry_after) do
8
- def [](key)
9
- {'Retry-After' => retry_after}[key]
10
- end
11
- end
12
-
13
- it 'should not run without block' do
14
- expect do
15
- described_class.wait_retry(20, nil)
16
- end.to raise_error
17
- end
18
-
19
- it 'should handle succesfull request' do
20
- counter = 0
21
- described_class.wait_retry do
22
- counter += 1
23
- end
24
-
25
- expect(counter).to eq(1)
26
- end
27
-
28
- it 'should make specified amount of attempts' do
29
- counter = 0
30
- described_class.wait_retry(3) do
31
- counter += 1
32
-
33
- if counter < 3
34
- raise ActiveResource::ServerError.new(response_stub.new("503", "0"))
35
- end
36
- end
37
-
38
- expect(counter).to eq(3)
39
- end
40
-
41
- it 'should use callback proc' do
42
- callback = Proc.new{}
43
- counter = 0
44
- callback.should_receive(:call).with(0, 1, 3, instance_of(ActiveResource::ServerError))
45
- callback.should_receive(:call).with(0, 2, 3, instance_of(ActiveResource::ServerError))
46
-
47
- described_class.wait_retry(3, callback) do
48
- counter += 1
49
-
50
- if counter < 3
51
- raise ActiveResource::ServerError.new(response_stub.new("503", "0"))
52
- end
53
- end
54
- end
55
-
56
- it 'should pass attempt number to block' do
57
- last_attempt_no = 0
58
- described_class.wait_retry(3) do |x|
59
- last_attempt_no = x
60
-
61
- if last_attempt_no < 3
62
- raise ActiveResource::ServerError.new(response_stub.new("503", "0"))
63
- end
64
- end
65
-
66
- expect(last_attempt_no).to eq(3)
67
- end
68
-
69
- it 'should raise if no attempts left' do
70
- expect do
71
- described_class.wait_retry(3) do |x|
72
- raise ActiveResource::ServerError.new(response_stub.new("503", "0"))
73
- end
74
- end.to raise_error(ActiveResource::ServerError)
75
- end
76
-
77
- it 'should raise on user errors' do
78
- attempts = 0
79
- expect do
80
- described_class.wait_retry(3) do |x|
81
- attempts = x
82
- raise 'Some other error'
83
- end
84
- end.to raise_error(StandardError)
85
- expect(attempts).to eq(1)
86
- end
87
-
88
- it 'should raise on other server errors' do
89
- attempts = 0
90
- expect do
91
- described_class.wait_retry(3) do |x|
92
- attempts = x
93
- raise ActiveResource::ServerError.new(response_stub.new("502", "0"))
94
- end
95
- end.to raise_error(ActiveResource::ServerError)
96
- expect(attempts).to eq(1)
97
- end
98
-
99
- it 'should run until success' do |x|
100
- success = false
101
- described_class.wait_retry do |x|
102
- raise ActiveResource::ServerError.new(response_stub.new("503", "0")) if x < 10
103
- success = true
104
- end
105
-
106
- expect(success).to be_true
107
- end
108
- end
109
-
110
- end
data/spec/spec_helper.rb DELETED
@@ -1,18 +0,0 @@
1
- # This file is copied to spec/ when you run 'rails generate rspec:install'
2
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'insales_api'
4
-
5
- InsalesApi::App.api_key = 'test'
6
- InsalesApi::App.api_secret = 'test'
7
- InsalesApi::App.api_autologin_url = 'https://host.com/session/autologin'
8
-
9
- RSpec.configure do |config|
10
- # == Mock Framework
11
- #
12
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
13
- #
14
- # config.mock_with :mocha
15
- # config.mock_with :flexmock
16
- # config.mock_with :rr
17
- config.mock_with :rspec
18
- end