retailcrm-api 0.0.1 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecac159b5dfa1826977b6d2e158b7068fb41239d37cda2e9e7965a44f81bc886
4
- data.tar.gz: 1fde1dcc5a9c929c42147f1da8e3f4308473485e85f77a8e98efddb4fa9ff63d
3
+ metadata.gz: 2712dc46e40f6b40a8b1e575fb265e6b916f032fa030a633bf7ec465fdcc55ed
4
+ data.tar.gz: d5b8cbf0ebd40ee9fe2590351eb697aa2016b21cdb7f6220333f278e9d6d0bdb
5
5
  SHA512:
6
- metadata.gz: eedb55035f7278c8b11e7babc274270e3ee1bb4e4a2750b2a15bf6e40c678a604128e81dad3ec27a2a26609a4da23887ed0f4bf60cbd55acc6be6b2212d5f7f0
7
- data.tar.gz: 87c6371d1e6ec724f866278f8d23487fcb46ae75b619aed65c6df6abb50ee7746e1c331ca3db1f14605c68741bf55fd03cb6c28750a788d92eff76f33cd7cfb4
6
+ metadata.gz: 8a59a99080cfd637d0416e4c0185cca4e74c042df59486b01bcfa4fcbb8489361c9da4ba3a27f9b3b99debe0f225f459634212105927c8346d0da407ac304b77
7
+ data.tar.gz: c097801cf4d5c919fd5f760751f9cbc70183ba356a5c0ffc995e2f6eebf3328679aa17c926f87ed66f58f0cf0817d32a03b2bc29ee7f3629c322ff61d296ec04
data/README.markdown CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  API wrapper для RetailCRM
4
4
 
5
- # Установка Ruby
5
+ # Установка
6
6
 
7
7
  ## Ruby
8
8
  $ gem install retailcrm-api
@@ -66,7 +66,73 @@ RetailcrmApi::Request.logger = MyLogger.new
66
66
 
67
67
  # Примеры
68
68
 
69
+ ## Расходы
70
+
71
+ ### [Получение списка расходов, удовлетворяющих заданному фильтру](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-costs)
72
+ ```ruby
73
+ RetailcrmApi::Request.costs.retrieve.body
74
+ # => {:success=>true, :pagination=>{:limit=>20, :totalCount=>296, :currentPage=>1, :totalPageCount=>15}, :costs=>[{:id=>296, :dateFrom=>"2021-07-29", :dateTo=>"2021-07-29", :summ=>13996, :costItem=>"products-purchase-price", :createdAt=>"2021-07-29 00:34:35", :order=>{:id=>36, :number=>"36C"}, :sites=>["b12-skillum-ru"]}]}
75
+ ```
76
+
77
+ ## Клиенты
78
+ ### [Получение списка клиентов, удовлетворяющих заданному фильтру](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-customers)
69
79
  ```ruby
70
80
  RetailcrmApi::Request.customers.retrieve.body
71
81
  #=> {:success=>true, :pagination=>{:limit=>20, :totalCount=>0, :currentPage=>1, :totalPageCount=>0}, :customers=>[]}
82
+ ```
83
+ ### [Создание клиента](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-customers-create)
84
+ ```ruby
85
+ body = {
86
+ site: 'deppa-ru',
87
+ customer: {
88
+ externalId: 1,
89
+ firstName: 'Павел',
90
+ lastName: 'Осетров'
91
+ }
92
+ }
93
+ RetailcrmApi::Request.customers.create(body: body).body
94
+ #=> {:success=>true, :id=>54}
95
+ ```
96
+ ### [Пакетная загрузка клиентов](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-customers-upload)
97
+ ```ruby
98
+ body = {
99
+ site: 'deppa-ru',
100
+ customers: [
101
+ {
102
+ externalId: 3,
103
+ firstName: 'Имя',
104
+ lastName: 'Фамилия'
105
+ },
106
+ {
107
+ externalId: 4,
108
+ firstName: 'Имя2',
109
+ lastName: 'Фамилия2'
110
+ }
111
+ ]
112
+ }
113
+ RetailcrmApi::Request.customers.create(body: body, suffix: "upload").body
114
+ ```
115
+
116
+ ## Корпоративные клиенты
117
+ ### [Получение списка корпоративных клиентов, удовлетворяющих заданному фильтру](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#get--api-v5-customers-corporate)
118
+ ```ruby
119
+ RetailcrmApi::Request.customers_corporate.retrieve.body
120
+ # => {:success=>true, :pagination=>{:limit=>20, :totalCount=>0, :currentPage=>1, :totalPageCount=>0}, :customersCorporate=>[]}
121
+ ```
122
+
123
+ ### [Пакетная загрузка корпоративных клиентов](https://docs.retailcrm.ru/Developers/API/APIVersions/APIv5#post--api-v5-customers-corporate-upload)
124
+ ```ruby
125
+ body = {
126
+ site: 'deppa-ru"',
127
+ customersCorporate: [
128
+ {
129
+ externalId: 3,
130
+ nickName: 'test1'
131
+ },
132
+ {
133
+ externalId: 4,
134
+ nickName: 'test2'
135
+ }
136
+ ]
137
+ }
72
138
  ```
@@ -5,20 +5,20 @@ module RetailcrmApi
5
5
  @request_builder = builder
6
6
  end
7
7
 
8
- def post(params: nil, headers: nil, suffix: nil, body: {}, first_time: true)
8
+ def post(params: nil, headers: nil, suffix: nil, body: {})
9
9
  validate_api_key
10
-
11
10
  begin
12
11
  response = self.rest_client(suffix).post do |request|
13
- configure_request(request: request, params: params, headers: headers, body: MultiJson.dump(body))
12
+ configure_request(request: request, params: params, headers: headers, body: body)
14
13
  end
15
- parse_response(response)
14
+ #parse_response(response)
15
+ response
16
16
  rescue => e
17
17
  handle_error(e)
18
18
  end
19
19
  end
20
20
 
21
- def get(params: nil, headers: nil, first_time: true)
21
+ def get(params: nil, headers: nil)
22
22
  validate_api_key
23
23
 
24
24
  begin
@@ -97,11 +97,14 @@ module RetailcrmApi
97
97
  def configure_request(request: nil, params: nil, headers: nil, body: nil)
98
98
  if request
99
99
  request.params.merge!(params) if params
100
- request.headers['Content-Type'] = 'application/json'
100
+ request.headers['Content-Type'] = 'application/x-www-form-urlencoded'
101
101
  request.headers['X-API-KEY'] = "#{self.api_key}"
102
102
  request.headers['User-Agent'] = "RetailCrmApi/#{RetailcrmApi::VERSION} Ruby gem"
103
103
  request.headers.merge!(headers) if headers
104
- request.body = body if body
104
+ if body
105
+ body.each { |k, v| body[k] = MultiJson.dump(v) }
106
+ request.body = URI.encode_www_form(body)
107
+ end
105
108
  request.options.timeout = self.timeout
106
109
  request.options.open_timeout = self.open_timeout
107
110
  end
@@ -6,8 +6,6 @@ module RetailcrmApi
6
6
  DEFAULT_OPEN_TIMEOUT = 60
7
7
 
8
8
  def initialize(api_key: nil, api_endpoint: nil, timeout: nil, open_timeout: nil, proxy: nil, faraday_adapter: nil, symbolize_keys: false, debug: false, logger: nil, test: false)
9
- p "Request initialize #{api_key}"
10
-
11
9
  @path_parts = []
12
10
  @api_key = api_key || self.class.api_key || ENV['RETAILCRM_API_KEY']
13
11
  @api_key = @api_key.strip if @api_key
@@ -25,7 +23,7 @@ module RetailcrmApi
25
23
  end
26
24
 
27
25
  def method_missing(method, *args)
28
- @path_parts << method.to_s.downcase
26
+ @path_parts << method.to_s.gsub("_", "-").downcase
29
27
  @path_parts << args if args.length > 0
30
28
  @path_parts.flatten!
31
29
  self
@@ -47,8 +45,8 @@ module RetailcrmApi
47
45
  @path_parts.join('/')
48
46
  end
49
47
 
50
- def create(params: nil, headers: nil, body: {})
51
- APIRequest.new(builder: self).post(params: params, headers: headers, suffix: 'update', body: body, suffix: 'create')
48
+ def create(params: nil, headers: nil, body: {}, suffix: 'create')
49
+ APIRequest.new(builder: self).post(params: params, headers: headers, suffix: suffix, body: body)
52
50
  ensure
53
51
  reset
54
52
  end
@@ -1,3 +1,3 @@
1
1
  module RetailcrmApi
2
- VERSION = "0.0.1"
3
- end
2
+ VERSION = "0.0.5"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retailcrm-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Osetrov
@@ -57,7 +57,7 @@ files:
57
57
  - lib/retailcrm-api/retailcrm_api_error.rb
58
58
  - lib/retailcrm-api/retailcrm_error.rb
59
59
  - lib/retailcrm-api/version.rb
60
- homepage: https://github.com/osetrov/retailcrm-api
60
+ homepage: https://github.com/osetrov/retailcrm
61
61
  licenses:
62
62
  - MIT
63
63
  metadata: {}
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubygems_version: 3.2.22
79
+ rubygems_version: 3.1.4
80
80
  signing_key:
81
81
  specification_version: 4
82
82
  summary: RetailCRM API