ozon_api 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9cc0bbb7b66282d595c194d1b9c54f4dc69c3e8e
4
- data.tar.gz: faa8202488649df9015ce7e17b96c9f2d8b7e88f
3
+ metadata.gz: 29b82b33e617de476fe7ffc47ac4a73ced8c4e33
4
+ data.tar.gz: 6b2c1d8d172f7b8a83cc81f1f88c5354e0c42617
5
5
  SHA512:
6
- metadata.gz: 75d72afcbe16f8e59b57117d40573f110cff22585450156527da75c6234079d565eb809309ce228f40b2c2b5247a8977f0ec7a0b96a4bb4a16d622b8780ad66d
7
- data.tar.gz: abbc421a602352598072e7a957af64d1b2521b274b5a036776d1cf42f42ccd9fd2786e9e8473894d200028aaca11a3ab5aaafdd89d1d7c61c97b74f4f81915ed
6
+ metadata.gz: de3bfa78a25a5151f4ef1a3b2d2ce22a21c1fd6ad21222742f225c5d6b37db266676cea034df12ccd497398a61ccc976b158896ad4d06ea99c89e54ffeebded9
7
+ data.tar.gz: c754f6c6e32ad284f582200fc470f50c862016ae49c9db3aa98c0ec65f50e144d3d9c9f6e11b6586d17a3a8d5ffaca1bcc84bac8e251c3b8c455415cc5b824c7
@@ -27,7 +27,7 @@ module OzonApi
27
27
  search_text:,
28
28
  search_text_match_preferred:,
29
29
  limit: 20
30
- )
30
+ )
31
31
  @client.get(
32
32
  [BASE_PATH, 'SearchStreets'].join('/'),
33
33
  'cityId': city_id,
@@ -36,6 +36,5 @@ module OzonApi
36
36
  'limit': limit
37
37
  )
38
38
  end
39
-
40
39
  end
41
40
  end
@@ -5,16 +5,12 @@ require 'json'
5
5
 
6
6
  module OzonApi
7
7
  class Client
8
- InvalidConfigurationError = Class.new(StandardError)
9
8
  ApiError = Class.new(StandardError)
10
9
 
11
- CONFIGURATION_KEYS = [:scheme, :host, :base_path, :login, :password, :out].freeze
12
10
  SUCCESS_STATUS = 2
13
11
 
14
- def initialize(hsh = {})
15
- @config = hsh.select do |key, _|
16
- CONFIGURATION_KEYS.include? key.to_sym
17
- end
12
+ def initialize(configuration)
13
+ @config = configuration
18
14
  end
19
15
 
20
16
  def get(path, params = {})
@@ -67,33 +63,27 @@ module OzonApi
67
63
  end
68
64
 
69
65
  def base_path
70
- @base_path ||= @config[:base_path] || 'PartnerService'
66
+ @config.base_path
71
67
  end
72
68
 
73
69
  def scheme
74
- @scheme ||= @config[:scheme] || 'https'
70
+ @config.scheme
75
71
  end
76
72
 
77
73
  def host
78
- @host ||= @config[:host] || 'ows.ozon.ru'
74
+ @config.host
79
75
  end
80
76
 
81
77
  def login
82
- return @login if @login
83
- @login = @config[:login] || ENV['OZON_LOGIN']
84
- raise InvalidConfigurationError, 'Missing OZON_LOGIN' if @login.nil?
85
- @login
78
+ @config.login
86
79
  end
87
80
 
88
81
  def password
89
- return @password if @password
90
- @password = @config[:password] || ENV['OZON_PASSWORD']
91
- raise InvalidConfigurationError, 'Missing OZON_PASSWORD' if @password.nil?
92
- @password
82
+ @config.password
93
83
  end
94
84
 
95
85
  def out
96
- @config[:out]
86
+ @config.out
97
87
  end
98
88
 
99
89
  def parse_response(data)
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ require 'active_model'
3
+
4
+ module OzonApi
5
+ class Configuration
6
+ include ActiveModel::Validations
7
+
8
+ def self.attribute_names
9
+ [:scheme, :host, :base_path, :login, :password, :out]
10
+ end
11
+
12
+ def attribute_names
13
+ self.class.attribute_names
14
+ end
15
+
16
+ attr_accessor *attribute_names
17
+
18
+ validates :scheme, :host, :base_path, :login, :password, presence: true
19
+
20
+ def initialize
21
+ @base_path = 'PartnerService'
22
+ @scheme = 'https'
23
+ @host = 'ows.ozon.ru'
24
+ @login = ENV['OZON_LOGIN']
25
+ @password = ENV['OZON_PASSWORD']
26
+ @out = STDOUT
27
+
28
+ yield(self) if block_given?
29
+
30
+ [
31
+ @base_path,
32
+ @scheme,
33
+ @host,
34
+ @login,
35
+ @password
36
+ ].each(&:freeze)
37
+ end
38
+ end
39
+ end
@@ -50,6 +50,5 @@ module OzonApi
50
50
  'reasonId': reason_id
51
51
  )
52
52
  end
53
-
54
53
  end
55
54
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module OzonApi
3
- VERSION = '0.1.1'
3
+ VERSION = '0.2.0'
4
4
  end
data/lib/ozon_api.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
-
3
2
  module OzonApi
3
+ require 'ozon_api/configuration'
4
4
  require 'ozon_api/client'
5
5
  require 'ozon_api/item_service'
6
6
  require 'ozon_api/detail_service'
@@ -9,4 +9,53 @@ module OzonApi
9
9
  require 'ozon_api/checkout_service'
10
10
  require 'ozon_api/order_service'
11
11
  require 'ozon_api/address_service'
12
+
13
+ InvalidConfigurationError = Class.new(StandardError)
14
+
15
+ def self.setup(&blk)
16
+ @config ||= OzonApi::Configuration.new(&blk)
17
+
18
+ if @config.invalid?
19
+ msg = "OzonApi configuration ERROR:\n"
20
+ raise InvalidConfigurationError, msg + @config.errors.full_messages.join("\n")
21
+ end
22
+
23
+ @config
24
+ end
25
+
26
+ def self.reset
27
+ @config = nil
28
+ end
29
+
30
+ def self.client
31
+ @client ||= OzonApi::Client.new(@config)
32
+ end
33
+
34
+ def self.item_service
35
+ @item_service ||= OzonApi::ItemService.new(client)
36
+ end
37
+
38
+ def self.detail_service
39
+ @detail_service ||= OzonApi::DetailService.new(client)
40
+ end
41
+
42
+ def self.client_service
43
+ @client_service ||= OzonApi::ClientService.new(client)
44
+ end
45
+
46
+ def self.cart_service
47
+ @cart_service ||= OzonApi::CartService.new(client)
48
+ end
49
+
50
+ def self.checkout_service
51
+ @checkout_service ||= OzonApi::CheckoutService.new(client)
52
+ end
53
+
54
+ def self.order_service
55
+ @order_service ||= OzonApi::OrderService.new(client)
56
+ end
57
+
58
+ def self.address_service
59
+ @address_service ||= OzonApi::AddressService.new(client)
60
+ end
12
61
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ozon_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Kotov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-28 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2016-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Ruby Ozon API wrapper.
14
28
  email:
15
29
  - non.gi.suong@ya.ru
@@ -24,6 +38,7 @@ files:
24
38
  - lib/ozon_api/checkout_service.rb
25
39
  - lib/ozon_api/client.rb
26
40
  - lib/ozon_api/client_service.rb
41
+ - lib/ozon_api/configuration.rb
27
42
  - lib/ozon_api/detail_service.rb
28
43
  - lib/ozon_api/item_service.rb
29
44
  - lib/ozon_api/order_service.rb