moysklad_integration 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 748a93a36dfb2341f6524ae16ce24329009a2f1366208972e6c85112d00534ea
4
- data.tar.gz: 54c11bc571d0008db2df2ea3e3274add9871e6ebadb19630f2ec922e864333e6
3
+ metadata.gz: 6a69f32287dc109d257cfa66e84bd423e06884fa595140b49a43edde163572bb
4
+ data.tar.gz: 5aa8b5c9aaceb5a090dcadbae816b8a7656fde958099d501dab8f77856a00923
5
5
  SHA512:
6
- metadata.gz: 7b5cbe1beed421534cf82787f58c2849d646781a5c48f3c13865dac5d3debc08522d018be3c88b86c87b16ca77f7a3bdbbc248cf6b82235ec9b352c97513d9bd
7
- data.tar.gz: f176b2ae4c02edc3a9093b295c3c7fbbf817b7480fd5fd7fe187c0b14ec751a3ccf6d6594fd345afaac2de42006e95158f6fa3777a1fb4d3052cac5921d95647
6
+ metadata.gz: 4ad9838079330c5ed115e58cfe922f31fd1343fd853b1a9977efd262d138dda15c3aa8645e6db7a31f11f35b9f2314076c8c4aefc61daf410a40126224f49649
7
+ data.tar.gz: efdbb28da30f24ec281fa2358486e3ff87b6e07dd21674c9357bf3ea8abae5f97cec889d88cd8f4f6db729c88ddd880101dd5f5d254ea21142cc33a38d46ff80
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- moysklad_integration (0.1.0)
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.1)
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.0)
34
+ zeitwerk (2.3.1)
35
35
 
36
36
  PLATFORMS
37
37
  ruby
data/README.md CHANGED
@@ -1,38 +1,103 @@
1
- # MoyskladIntegration
1
+ # Moysklad Integration
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/moysklad_integration`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
5
+ This gem works with API 1.1 of moysklad.ru
6
6
 
7
- ## Installation
7
+ ---
8
8
 
9
- Add this line to your application's Gemfile:
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
- ## Usage
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
- TODO: Write usage instructions here
74
+ #### Add positions to entity / Добавить позиции к сущности (объекту)
26
75
 
27
- ## Development
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
92
+ #### Creation / Создание
30
93
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/Vladislav Kalach/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/Vladislav Kalach/moysklad_integration/blob/master/CODE_OF_CONDUCT.md).
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/Vladislav Kalach/moysklad_integration/blob/master/CODE_OF_CONDUCT.md).
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, _id = nil)
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
- JSON.parse(response.body)['rows'].each_with_object([]) do |entity_params, arr|
39
- arr << Entity.new(entity_params)
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module MoyskladIntegration
2
- VERSION = "0.1.0"
4
+ VERSION = '0.1.1'
3
5
  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.0
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-06-15 00:00:00.000000000 Z
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport