ozon_api 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f207018794cd0a9da1d4966e956f6310ddd1336
4
+ data.tar.gz: f18991ec0433963ec9db14b8899c1b679e0b60eb
5
+ SHA512:
6
+ metadata.gz: 64fb4cba96dba280c2e0698c98ed717d9e34f8224e03b0a06c3637744b0d4f1a53a560924af3ae16cfde2ceb7a8150212f2fc935502e55fbdb92e8d64ec3d2e6
7
+ data.tar.gz: 8d420d87e60ec1613c18b0b610d2ebe6205333d2ec23ef97617dd677c44bbb4cc87427e173e5eeb161cf7f76512cbd3df7806a54fa01cbe4961ed0256517f924
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # OzonApi
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ozon_api'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install ozon_api
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ module OzonApi
3
+ class AddressService
4
+ BASE_PATH = 'AddressService'
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def search_cities(search_text:, limit: 20)
11
+ @client.get(
12
+ [BASE_PATH, 'SearchCities'].join('/'),
13
+ 'searchText': search_text,
14
+ 'limit': limit
15
+ )
16
+ end
17
+
18
+ def get_cities(city_ids:)
19
+ @client.get(
20
+ [BASE_PATH, 'GetCities'].join('/'),
21
+ 'citiIds': city_ids.map(&:to_s).join(',')
22
+ )
23
+ end
24
+
25
+ def search_streets(
26
+ city_id:,
27
+ search_text:,
28
+ search_text_match_preferred:,
29
+ limit: 20
30
+ )
31
+ @client.get(
32
+ [BASE_PATH, 'SearchStreets'].join('/'),
33
+ 'cityId': city_id,
34
+ 'searchText': search_text,
35
+ 'searchTextMatchPreferred': search_text_match_preferred,
36
+ 'limit': limit
37
+ )
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ module OzonApi
3
+ class CartService
4
+ BASE_PATH = 'CartService'
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def cart_get(partner_client_id:)
11
+ @client.get([BASE_PATH, 'CartGet'].join('/'), 'partnerClientId': partner_client_id)
12
+ end
13
+
14
+ def cart_add(partner_client_id:, cart_items:, partner_agent_id: nil, delay_cart_update: false)
15
+ params = {
16
+ 'partnerClientId': partner_client_id,
17
+ 'cartItems': Array(cart_items).map { |i| "#{i[:partner_id]}:#{i[:quantity]}" }.join(','),
18
+ 'partnerAgentId': partner_agent_id,
19
+ 'delayCartUpdate': delay_cart_update
20
+ }
21
+
22
+ @client.post([BASE_PATH, 'CartAdd'].join('/'), params)
23
+ end
24
+
25
+ def cart_remove(partner_client_id:, cart_item_ids:)
26
+ params = {
27
+ 'partnerClientId': partner_client_id,
28
+ 'cartItems': Array(cart_item_ids).map(&:to_s).join(',')
29
+ }
30
+
31
+ @client.post([BASE_PATH, 'CartRemove'].join('/'), params)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,216 @@
1
+ # frozen_string_literal: true
2
+ module OzonApi
3
+ class CheckoutService
4
+ BASE_PATH = 'CheckoutService'
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def checkout_start(partner_client_id:, is_pred_release: false)
11
+ @client.get(
12
+ [BASE_PATH, 'CheckoutStart'].join('/'),
13
+ 'partnerClientId': partner_client_id,
14
+ 'isPredRelease': is_pred_release
15
+ )
16
+ end
17
+
18
+ def checkout_favourites_get(partner_client_id:, order_guid:)
19
+ @client.get(
20
+ [BASE_PATH, 'CheckoutFavouritesGet'].join('/'),
21
+ 'partnerClientId': partner_client_id,
22
+ 'guidValue': order_guid
23
+ )
24
+ end
25
+
26
+ def delivery_addresses_get(partner_client_id:, order_guid:)
27
+ @client.get(
28
+ [BASE_PATH, 'DeliveryAddressesGet'].join('/'),
29
+ 'partnerClientId': partner_client_id,
30
+ 'guidValue': order_guid
31
+ )
32
+ end
33
+
34
+ def delivery_variants_get(partner_client_id:, order_guid:, area_id:, address_id: 0)
35
+ @client.get(
36
+ [BASE_PATH, 'DeliveryVariantsGet'].join('/'),
37
+ 'partnerClientId': partner_client_id,
38
+ 'guidValue': order_guid,
39
+ 'areaId': area_id,
40
+ 'addressId': address_id
41
+ )
42
+ end
43
+
44
+ def payments_variants_get(partner_client_id:,
45
+ order_guid:,
46
+ area_id:,
47
+ address_id: 0,
48
+ delivery_variant_id:)
49
+ @client.get(
50
+ [BASE_PATH, 'PaymentsVariantsGet'].join('/'),
51
+ 'partnerClientId': partner_client_id,
52
+ 'guidValue': order_guid,
53
+ 'areaId': area_id,
54
+ 'addressId': address_id,
55
+ 'deliveryVariantId': delivery_variant_id
56
+ )
57
+ end
58
+
59
+ def order_parameters_get_for_collect(partner_client_id:,
60
+ order_guid:,
61
+ area_id:,
62
+ address_id: 0,
63
+ delivery_variant_id:,
64
+ payment_type_id:,
65
+ zip_code: nil)
66
+ @client.get(
67
+ [BASE_PATH, 'OrderParametersGetForCollect'].join('/'),
68
+ 'partnerClientId': partner_client_id,
69
+ 'guidValue': order_guid,
70
+ 'areaId': area_id,
71
+ 'addressId': address_id,
72
+ 'deliveryVariantId': delivery_variant_id,
73
+ 'paymentTypeId': payment_type_id,
74
+ 'zipCode': zip_code
75
+ )
76
+ end
77
+
78
+ def order_parameters_save(partner_client_id:,
79
+ order_guid:,
80
+ area_id:,
81
+ address_id: 0,
82
+ delivery_variant_id:,
83
+ payment_type_id:,
84
+ zip_code:,
85
+ country:,
86
+ region:,
87
+ district: nil,
88
+ city:,
89
+ address_tail: nil,
90
+ comment: nil,
91
+ phone:,
92
+ metro_id: 0,
93
+ first_name:,
94
+ middle_name: nil,
95
+ last_name:,
96
+ street: nil,
97
+ house: nil,
98
+ entrance: nil,
99
+ apartment: nil,
100
+ intercom: nil,
101
+ floor: nil)
102
+ params = {
103
+ 'partnerClientId': partner_client_id,
104
+ 'guidValue': order_guid,
105
+ 'areaId': area_id,
106
+ 'addressId': address_id,
107
+ 'deliveryVariantId': delivery_variant_id,
108
+ 'paymentTypeId': payment_type_id,
109
+ 'zipCode': zip_code,
110
+ 'country': country,
111
+ 'region': region,
112
+ 'district': district,
113
+ 'city': city,
114
+ 'addressTail': address_tail,
115
+ 'comment': comment,
116
+ 'phone': phone,
117
+ 'metroId': metro_id,
118
+ 'firstName': first_name,
119
+ 'middleName': middle_name,
120
+ 'lastName': last_name,
121
+ 'street': street,
122
+ 'house': house,
123
+ 'entrance': entrance,
124
+ 'apartment': apartment,
125
+ 'intercom': intercom,
126
+ 'floor': floor
127
+ }
128
+ params.delete_if { |_, v| v.nil? }
129
+ @client.post([BASE_PATH, 'OrderParametersSave'].join('/'), params)
130
+ end
131
+
132
+ def delivery_choices_get
133
+ @client.get([BASE_PATH, 'DeliveryChoicesGet'].join('/'))
134
+ end
135
+
136
+ def order_parameters_check(partner_client_id:,
137
+ order_guid:,
138
+ address_id:,
139
+ delivery_variant_id:,
140
+ payment_type_id:,
141
+ delivery_choice_id:,
142
+ client_account_sum:,
143
+ is_pred_release: false)
144
+ @client.get(
145
+ [BASE_PATH, 'OrderParametersCheck'].join('/'),
146
+ 'partnerClientId': partner_client_id,
147
+ 'guidValue': order_guid,
148
+ 'addressId': address_id,
149
+ 'deliveryVariantId': delivery_variant_id,
150
+ 'paymentTypeId': payment_type_id,
151
+ 'deliveryChoiceId': delivery_choice_id,
152
+ 'clientAccountSum': client_account_sum,
153
+ 'isPredRelease': is_pred_release
154
+ )
155
+ end
156
+
157
+ def order_summary_get(partner_client_id:,
158
+ order_guid:,
159
+ address_id:,
160
+ delivery_variant_id:,
161
+ payment_type_id:,
162
+ delivery_choice_id:,
163
+ client_account_sum:,
164
+ user_score:)
165
+ @client.get(
166
+ [BASE_PATH, 'OrderSummaryGet'].join('/'),
167
+ 'partnerClientId': partner_client_id,
168
+ 'guidValue': order_guid,
169
+ 'addressId': address_id,
170
+ 'deliveryVariantId': delivery_variant_id,
171
+ 'paymentTypeId': payment_type_id,
172
+ 'deliveryChoiceId': delivery_choice_id,
173
+ 'clientAccountSum': client_account_sum,
174
+ 'userScore': user_score
175
+ )
176
+ end
177
+
178
+ def order_create(partner_client_id:,
179
+ order_guid:,
180
+ address_id:,
181
+ delivery_variant_id:,
182
+ delivery_choice_id:,
183
+ payment_type_id:,
184
+ is_pred_release: false,
185
+ client_account_sum:,
186
+ email:,
187
+ phone:,
188
+ first_name:,
189
+ middle_name: nil,
190
+ last_name:,
191
+ comment: nil,
192
+ use_score:,
193
+ metro_id: 0)
194
+ params = {
195
+ 'partnerClientId': partner_client_id,
196
+ 'guidValue': order_guid,
197
+ 'addressId': address_id,
198
+ 'deliveryVariantId': delivery_variant_id,
199
+ 'deliveryChoiceId': delivery_choice_id,
200
+ 'paymentTypeId': payment_type_id,
201
+ 'isPredRelease': is_pred_release,
202
+ 'clientAccountSum': client_account_sum,
203
+ 'email': email,
204
+ 'phone': phone,
205
+ 'firstName': first_name,
206
+ 'middleName': middle_name,
207
+ 'lastName': last_name,
208
+ 'comment': comment,
209
+ 'useScore': use_score,
210
+ 'metroId': metro_id
211
+ }
212
+ params.delete_if { |_, v| v.nil? }
213
+ @client.post([BASE_PATH, 'OrderCreate'].join('/'), params)
214
+ end
215
+ end
216
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+
6
+ module OzonApi
7
+ class Client
8
+ InvalidConfigurationError = Class.new(StandardError)
9
+ ApiError = Class.new(StandardError)
10
+
11
+ CONFIGURATION_KEYS = [:scheme, :host, :base_path, :login, :password, :out].freeze
12
+ SUCCESS_STATUS = 2
13
+
14
+ def initialize(hsh = {})
15
+ @config = hsh.select do |key, _|
16
+ CONFIGURATION_KEYS.include? key.to_sym
17
+ end
18
+ end
19
+
20
+ def get(path, params = {})
21
+ uri = URI("#{scheme}://#{host}/#{base_path}/#{path}/")
22
+ uri.query = URI.encode_www_form(default_params.merge(params))
23
+ response = Net::HTTP.get(uri)
24
+
25
+ if out
26
+ out << "Ozon get:\n"
27
+ out << uri.to_s
28
+ out << "\n"
29
+ out << "Ozon response:\n"
30
+ out << response
31
+ out << "\n"
32
+ end
33
+
34
+ parse_response(response)
35
+ end
36
+
37
+ def post(path, params)
38
+ query = URI.encode_www_form(default_params.merge(params))
39
+ uri = URI("#{scheme}://#{host}/#{base_path}/#{path}/?#{query}")
40
+
41
+ http = Net::HTTP.new(uri.host, uri.port)
42
+ http.use_ssl = true
43
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
44
+
45
+ request = Net::HTTP::Post.new(uri)
46
+ response = http.request(request)
47
+
48
+ if out
49
+ out << "Ozon post:\n"
50
+ out << uri.to_s
51
+ out << "\n"
52
+ out << "Ozon response:\n"
53
+ out << response
54
+ out << "\n"
55
+ end
56
+
57
+ parse_response(response.read_body)
58
+ end
59
+
60
+ private
61
+
62
+ def default_params
63
+ @default_params ||= {
64
+ login: login,
65
+ password: password
66
+ }.freeze
67
+ end
68
+
69
+ def base_path
70
+ @base_path ||= @config[:base_path] || 'PartnerService'
71
+ end
72
+
73
+ def scheme
74
+ @scheme ||= @config[:scheme] || 'https'
75
+ end
76
+
77
+ def host
78
+ @host ||= @config[:host] || 'ows.ozon.ru'
79
+ end
80
+
81
+ 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
86
+ end
87
+
88
+ 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
93
+ end
94
+
95
+ def out
96
+ @config[:out]
97
+ end
98
+
99
+ def parse_response(data)
100
+ result = JSON.parse(data)
101
+
102
+ if result['Status'] == SUCCESS_STATUS && result['Error'].nil?
103
+ result
104
+ else
105
+ raise ApiError, result
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ module OzonApi
3
+ class ClientService
4
+ BASE_PATH = 'ClientService'
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def client_check_email(email)
11
+ @client.get([BASE_PATH, 'ClientCheckEmail'].join('/'), 'email': email)
12
+ end
13
+
14
+ def client_registration(id, email, password, first_name, last_name)
15
+ params = {
16
+ 'partnerClientId': id,
17
+ 'email': email,
18
+ 'clientPassword': password,
19
+ 'firstName': first_name,
20
+ 'lastName': last_name,
21
+ 'spamSubscribe': false,
22
+ 'userIp': "''",
23
+ 'userAgent': "''"
24
+ }
25
+
26
+ @client.post([BASE_PATH, 'PartnerClientRegistration'].join('/'), params)
27
+ end
28
+
29
+ def client_login(id, email, password)
30
+ params = {
31
+ 'partnerClientId': id,
32
+ 'clientLogin': email,
33
+ 'clientPassword': password
34
+ }
35
+
36
+ @client.get([BASE_PATH, 'ClientLogin'].join('/'), params)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module OzonApi
3
+ class DetailService
4
+ BASE_PATH = 'DetailService'
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def detail_get(id)
11
+ @client.get([BASE_PATH, 'DetailGet'].join('/'), 'detailId': id)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ module OzonApi
3
+ class ItemService
4
+ BASE_PATH = 'ItemService'
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def item_availabilities_get
11
+ @client.get([BASE_PATH, 'ItemAvailabilitiesGet'].join('/'))
12
+ end
13
+
14
+ def item_get(id)
15
+ @client.get([BASE_PATH, 'ItemGet'].join('/'), 'ItemId': id)
16
+ end
17
+
18
+ def items_by_id_list_get(item_ids:, items_on_page: 50, page_number:, only_for_sale:, partner_client_id:)
19
+ @client.get(
20
+ [BASE_PATH, 'ItemsByIdListGet'].join('/'),
21
+ 'items': item_ids.join(','),
22
+ 'itemsOnPage': items_on_page,
23
+ 'pageNumber': page_number,
24
+ 'onlyForSale': only_for_sale,
25
+ 'partnerClientId': partner_client_id
26
+ )
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ module OzonApi
3
+ class OrderService
4
+ BASE_PATH = 'OrderService'
5
+
6
+ def initialize(client)
7
+ @client = client
8
+ end
9
+
10
+ def orders_get(partner_client_id:)
11
+ @client.get(
12
+ [BASE_PATH, 'OrdersGet'].join('/'), 'partnerClientId': partner_client_id
13
+ )
14
+ end
15
+
16
+ def order_get(partner_client_id:, order_number:)
17
+ @client.get(
18
+ [BASE_PATH, 'OrderGet'].join('/'),
19
+ 'partnerClientId': partner_client_id,
20
+ 'orderNumber': order_number
21
+ )
22
+ end
23
+
24
+ def cancel_reasons_get
25
+ @client.get([BASE_PATH, 'CancelReasonsGet'].join('/'))
26
+ end
27
+
28
+ def order_cancel(partner_client_id:,
29
+ order_number:,
30
+ items:,
31
+ reason_id:)
32
+ @client.post(
33
+ [BASE_PATH, 'OrderCancel'].join('/'),
34
+ 'partnerClientId': partner_client_id,
35
+ 'orderNumber': order_number,
36
+ 'itemString': Array(items).map { |i| "#{i[:partner_id]}:#{i[:quantity]}" }.join(','),
37
+ 'reasonId': reason_id
38
+ )
39
+ end
40
+
41
+ def posting_cancel(partner_client_id:,
42
+ order_number:,
43
+ posting_id:,
44
+ reason_id:)
45
+ @client.post(
46
+ [BASE_PATH, 'PostingCancel'].join('/'),
47
+ 'partnerClientId': partner_client_id,
48
+ 'orderNumber': order_number,
49
+ 'postingId': posting_id,
50
+ 'reasonId': reason_id
51
+ )
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module OzonApi
3
+ VERSION = '0.1.0'
4
+ end
data/lib/ozon_api.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OzonApi
4
+ require 'ozon_api/client'
5
+ require 'ozon_api/item_service'
6
+ require 'ozon_api/detail_service'
7
+ require 'ozon_api/client_service'
8
+ require 'ozon_api/cart_service'
9
+ require 'ozon_api/checkout_service'
10
+ require 'ozon_api/order_service'
11
+ require 'ozon_api/address_service'
12
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ozon_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yury Kotov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby Ozon API wrapper.
14
+ email:
15
+ - non.gi.suong@ya.ru
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - lib/ozon_api.rb
22
+ - lib/ozon_api/address_service.rb
23
+ - lib/ozon_api/cart_service.rb
24
+ - lib/ozon_api/checkout_service.rb
25
+ - lib/ozon_api/client.rb
26
+ - lib/ozon_api/client_service.rb
27
+ - lib/ozon_api/detail_service.rb
28
+ - lib/ozon_api/item_service.rb
29
+ - lib/ozon_api/order_service.rb
30
+ - lib/ozon_api/version.rb
31
+ homepage: https://github.com/httplab/ozon_api
32
+ licenses:
33
+ - MIT
34
+ metadata: {}
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubyforge_project:
51
+ rubygems_version: 2.5.1
52
+ signing_key:
53
+ specification_version: 4
54
+ summary: Ruby Ozon API wrapper.
55
+ test_files: []