Class: OzonApi::Client
- Inherits:
-
Object
- Object
- OzonApi::Client
- Defined in:
- lib/ozon_api/client.rb
Constant Summary collapse
- ApiError =
Class.new(StandardError)
- SUCCESS_STATUS =
2
Instance Method Summary collapse
- #get(path, params = {}) ⇒ Object
-
#initialize(configuration) ⇒ Client
constructor
A new instance of Client.
- #post(path, params) ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Client
Returns a new instance of Client.
12 13 14 |
# File 'lib/ozon_api/client.rb', line 12 def initialize(configuration) @config = configuration end |
Instance Method Details
#get(path, params = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ozon_api/client.rb', line 16 def get(path, params = {}) uri = URI("#{scheme}://#{host}/#{base_path}/#{path}/") uri.query = URI.encode_www_form(default_params.merge(params)) response = Net::HTTP.get(uri) if out out << "Ozon get:\n" out << uri.to_s out << "\n" out << "Ozon plain response:\n" out << response out << "\n" end parse_response(response) end |
#post(path, params) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ozon_api/client.rb', line 33 def post(path, params) query = URI.encode_www_form(default_params.merge(params)) uri = URI("#{scheme}://#{host}/#{base_path}/#{path}/?#{query}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(uri) response = http.request(request) if out out << "Ozon post:\n" out << uri.to_s out << "\n" out << "Ozon response:\n" out << response out << "\n" end parse_response(response.read_body) end |