Class: Apress::Moysklad::Api::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/apress/moysklad/api/client.rb

Overview

Клиент для взаимодействия с API МойСклад

Examples:

client = Apress::Moysklad::Api::Client.new('login', 'password')

client.get(:assortment, limit: 2)
=> {:context=>...}

Constant Summary collapse

API_URL =
'https://online.moysklad.ru/api/remap'.freeze
API_VERSION =
'1.1'.freeze
TIMEOUT =

seconds

60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(login, password) ⇒ Client



25
26
27
28
# File 'lib/apress/moysklad/api/client.rb', line 25

def initialize(, password)
  @login = 
  @password = password
end

Instance Attribute Details

#loginObject (readonly)

Returns the value of attribute login.



23
24
25
# File 'lib/apress/moysklad/api/client.rb', line 23

def 
  @login
end

#passwordObject (readonly)

Returns the value of attribute password.



23
24
25
# File 'lib/apress/moysklad/api/client.rb', line 23

def password
  @password
end

Instance Method Details

#get(entity, params = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/apress/moysklad/api/client.rb', line 30

def get(entity, params = {})
  uri = api_uri(entity)
  uri.query = URI.encode_www_form(params) unless params.empty?

  req = Net::HTTP::Get.new(uri)
  req.basic_auth , password

  res = Net::HTTP.start(uri.hostname, uri.port, http_options) do |http|
    http.request(req)
  end

  parse_response(res)
end