moysklad_integration 0.1.0 → 0.1.1
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 +4 -4
- data/Gemfile.lock +3 -3
- data/README.md +79 -14
- data/lib/moysklad_integration/entity.rb +7 -0
- data/lib/moysklad_integration/service.rb +8 -4
- data/lib/moysklad_integration/version.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a69f32287dc109d257cfa66e84bd423e06884fa595140b49a43edde163572bb
|
4
|
+
data.tar.gz: 5aa8b5c9aaceb5a090dcadbae816b8a7656fde958099d501dab8f77856a00923
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ad9838079330c5ed115e58cfe922f31fd1343fd853b1a9977efd262d138dda15c3aa8645e6db7a31f11f35b9f2314076c8c4aefc61daf410a40126224f49649
|
7
|
+
data.tar.gz: efdbb28da30f24ec281fa2358486e3ff87b6e07dd21674c9357bf3ea8abae5f97cec889d88cd8f4f6db729c88ddd880101dd5f5d254ea21142cc33a38d46ff80
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
moysklad_integration (0.1.
|
4
|
+
moysklad_integration (0.1.1)
|
5
5
|
activesupport (~> 6.0, >= 6.0.3.1)
|
6
6
|
addressable (~> 2.7)
|
7
7
|
faraday (~> 1.0, >= 1.0.1)
|
@@ -10,7 +10,7 @@ PATH
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
12
12
|
specs:
|
13
|
-
activesupport (6.0.3.
|
13
|
+
activesupport (6.0.3.2)
|
14
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
15
|
i18n (>= 0.7, < 2)
|
16
16
|
minitest (~> 5.1)
|
@@ -31,7 +31,7 @@ GEM
|
|
31
31
|
thread_safe (0.3.6)
|
32
32
|
tzinfo (1.2.7)
|
33
33
|
thread_safe (~> 0.1)
|
34
|
-
zeitwerk (2.3.
|
34
|
+
zeitwerk (2.3.1)
|
35
35
|
|
36
36
|
PLATFORMS
|
37
37
|
ruby
|
data/README.md
CHANGED
@@ -1,38 +1,103 @@
|
|
1
|
-
#
|
1
|
+
# Moysklad Integration
|
2
2
|
|
3
|
-
|
3
|
+
The main goal of this gem to make your work with moysklad.ru service much easier without the necessity of writing tons of code. You can use this gem to integrate any service through API with moysklad.ru I used it to make an app that will help Shopify communicates with moysklad.ru
|
4
4
|
|
5
|
-
|
5
|
+
This gem works with API 1.1 of moysklad.ru
|
6
6
|
|
7
|
-
|
7
|
+
---
|
8
8
|
|
9
|
-
|
9
|
+
Основная цель этой библиотеки (гема) - сделать работу с сервисом moysklad.ru намного проще без необходимости написания тонны кода. Вы можете использовать этот гем для интеграции любого сервиса через API с moysklad.ru. Я использовал его для создания приложения, которое поможет Shopify общаться с moysklad.ru
|
10
|
+
|
11
|
+
Этот гем работает с API 1.1 moysklad.ru
|
12
|
+
|
13
|
+
## Installation / Установка
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile: / Добавьте данную строчку в свой Gemfile
|
10
16
|
|
11
17
|
```ruby
|
12
18
|
gem 'moysklad_integration'
|
13
19
|
```
|
14
20
|
|
15
|
-
And then execute:
|
21
|
+
And then execute: / Затем выполните команду:
|
16
22
|
|
17
23
|
$ bundle install
|
18
24
|
|
19
|
-
Or install it yourself as:
|
25
|
+
Or install it yourself as: / Или установите напрямую в систему:
|
20
26
|
|
21
27
|
$ gem install moysklad_integration
|
22
28
|
|
23
|
-
|
29
|
+
Add to your .env file credentials for moysklad.ru: / Добавьте в .env файл данные для подключения к moysklad.ru
|
30
|
+
|
31
|
+
```
|
32
|
+
export MOYSKLAD_USERNAME=your_username
|
33
|
+
export MOYSKLAD_PASSWORD=your_password
|
34
|
+
```
|
35
|
+
|
36
|
+
## Usage / Использование
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
moysklad_service = MoyskladIntegration::Service.new
|
40
|
+
```
|
41
|
+
|
42
|
+
#### Create entity / Создания сущности (объекта)
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
moysklad_service.create(:entity_name, { entity_params: like_hash })
|
46
|
+
```
|
47
|
+
|
48
|
+
#### Get all entities of the certain type / Получение сущностей (объектов) определенного типа
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
moysklad_service.get(:entity_name)
|
52
|
+
```
|
53
|
+
|
54
|
+
#### Find all entities of a certain type with specific fields / Найти все сущности (объекты) определенного типа с определенными полями
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
moysklad_service.filter(:entity_name, { search_params: like_hash })
|
58
|
+
```
|
59
|
+
|
60
|
+
#### Update an entity / Обновить сущность (объект)
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
entity = moysklad_service.get(:entity_name)
|
64
|
+
entity.update({ name: :new_name })
|
65
|
+
```
|
66
|
+
|
67
|
+
#### Entity link / Ссылка на сущность (объект)
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
entity = moysklad_service.get(:entity_name)
|
71
|
+
entity.meta_link
|
72
|
+
```
|
24
73
|
|
25
|
-
|
74
|
+
#### Add positions to entity / Добавить позиции к сущности (объекту)
|
26
75
|
|
27
|
-
|
76
|
+
```ruby
|
77
|
+
entity = moysklad_service.get(:entity_name)
|
78
|
+
entity.add_positions([{ position_params: in_hash }])
|
79
|
+
```
|
80
|
+
|
81
|
+
#### Update positions of an entity / Обновить позиции в сущности (объекте)
|
82
|
+
|
83
|
+
```ruby
|
84
|
+
entity = moysklad_service.get(:entity_name)
|
85
|
+
entity.update_positions([{ position_params: in_hash }])
|
86
|
+
```
|
87
|
+
|
88
|
+
**Examples are below / Примеры ниже**
|
89
|
+
|
90
|
+
### Customer order / Договор: заказ покупателя
|
28
91
|
|
29
|
-
|
92
|
+
#### Creation / Создание
|
30
93
|
|
31
|
-
|
94
|
+
```ruby
|
95
|
+
moysklad_service.create(:customerorder, { name: 'Test Order', organization: organization.meta_link, agent: counterparty.meta_link })
|
96
|
+
```
|
32
97
|
|
33
98
|
## Contributing
|
34
99
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
100
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vkalach/moysklad_integration. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/vkalach/moysklad_integration/blob/master/CODE_OF_CONDUCT.md).
|
36
101
|
|
37
102
|
|
38
103
|
## License
|
@@ -41,4 +106,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
41
106
|
|
42
107
|
## Code of Conduct
|
43
108
|
|
44
|
-
Everyone interacting in the MoyskladIntegration project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
109
|
+
Everyone interacting in the MoyskladIntegration project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/vkalach/moysklad_integration/moysklad_integration/blob/master/CODE_OF_CONDUCT.md).
|
@@ -13,6 +13,13 @@ module MoyskladIntegration
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def update(params)
|
16
|
+
params.each do |key, val|
|
17
|
+
next if val.blank? || instance_variables.include?(:"@#{key}")
|
18
|
+
|
19
|
+
self.class.__send__(:define_method, key, -> { instance_variable_get("@#{key}") })
|
20
|
+
self.class.__send__(:define_method, "#{key}=", ->(val) { instance_variable_set("@#{key}", val) })
|
21
|
+
end
|
22
|
+
|
16
23
|
service.update(self, params)
|
17
24
|
end
|
18
25
|
|
@@ -31,12 +31,16 @@ module MoyskladIntegration
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def get(object_name,
|
35
|
-
@entity_path = "entity/#{object_name.downcase}"
|
34
|
+
def get(object_name, id = nil)
|
35
|
+
@entity_path = id ? "entity/#{object_name.downcase}/#{id}" : "entity/#{object_name.downcase}"
|
36
36
|
response = connection.get(entity_path)
|
37
37
|
if response.status == 200
|
38
|
-
|
39
|
-
|
38
|
+
if id
|
39
|
+
Entity.new(JSON.parse(response.body))
|
40
|
+
else
|
41
|
+
JSON.parse(response.body)['rows'].each_with_object([]) do |entity_params, arr|
|
42
|
+
arr << Entity.new(entity_params)
|
43
|
+
end
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moysklad_integration
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladislav Kalach
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|