ekam-ruby 0.0.3

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGFiMTczNDA4ZGYyYjlmZDg0OTViMWE0MWQ5MjdlMTAyMzQ3YWMyNg==
5
+ data.tar.gz: !binary |-
6
+ ZDAxMDEzMmRiOWQ0NGRjM2M0YzYyN2MzMTNmNmNjMmQ4OGE5ZDVhMw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NTUzNTAxYTMzOTNlMTUwYjlmNzc1MzQxZjY4Yjg5NWY2ZmE4ZjA2MjFiMzBl
10
+ ZGRjN2VkNmFmMzA2ZmQ4MmZkZDdlN2E0ZTc5MDk3YmRiNTc5MmQxYThmZDk0
11
+ MWNjZWZiMjUzZmZlNmJlMDRkNjEwMTBjMzA4N2ZlNzhhYzI4MDc=
12
+ data.tar.gz: !binary |-
13
+ YWIyOTU5NDBhMGM4NGQ3YzYyMDZjN2E1MWVjMDFiNzE0YzgyZDhmMTU1Zjcx
14
+ Y2M2YjA2OGRiZjk2OGM2YmU4NGVmYTVkYTU4ZWU4NTYwNGRlNWFmMzFkYTU5
15
+ N2MzYzkzZmY4MjRmNGUyY2NmOGEzMGFjYzkyOGI4MjU5ZjljOGU=
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Convead
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # Ekam
2
+
3
+ Простейший клиент для API сервиса ЕКАМ:
4
+ * https://www.ekam.ru/page/online-api
5
+ * https://app.ekam.ru/online/swagger
6
+
7
+ ## Совместимость
8
+
9
+ Клиент работает с версией ЕКАМ API v0.0.1
10
+
11
+ ## Установка
12
+
13
+ Добавьте следующую строку в Gemfile вашего приложения:
14
+
15
+ ```
16
+ gem 'ecwid_api'
17
+ ```
18
+
19
+ Затем выполните команду:
20
+
21
+ ```
22
+ $ bundle
23
+ ```
24
+
25
+ Или установите gem самостоятельно:
26
+
27
+ ```
28
+ $ gem install ecwid_api
29
+ ```
30
+
31
+ ## Примеры использования
32
+
33
+ ### Инициализация:
34
+
35
+ ```ruby
36
+ require 'ekam-ruby'
37
+
38
+ client = Ekam::Client.new(token)
39
+ ```
40
+
41
+ Где `token` - авторизационный токен для вашего приложения ЕКАМ (подробнее тут: https://www.ekam.ru/page/online-api#creation).
42
+
43
+ ### Получение списка чеков
44
+
45
+ ```ruby
46
+ # Получить все чеки без ограничений
47
+ client.get_receipt_requests
48
+
49
+ # Получить последние 10 чеков
50
+ client.get_receipt_requests({limit: 10})
51
+
52
+ # Получить только возвраты
53
+ client.get_receipt_requests({type: 'returns'})
54
+
55
+ # Получить все продажи в статусе "error"
56
+ client.get_receipt_requests({type: 'sales', status: 'error'})
57
+
58
+ # Получить чек по заказу с указанным ID
59
+ order_id = '12345'
60
+ client.get_receipt_requests({order_id: order_id})
61
+ ```
62
+
63
+ ### Регистрация чека (продажа)
64
+
65
+ Описание параметров: https://www.ekam.ru/page/online-api#reg
66
+
67
+ ```ruby
68
+ receipt_params = {
69
+ "order_id" => "91421af3",
70
+ "order_number" => "1014",
71
+ "type" => "sale",
72
+ "email" => "john@example.net",
73
+ "phone_number" => "79650000000",
74
+ "should_print" => true,
75
+ "cash_amount" => 201.1,
76
+ "electron_amount" => 0,
77
+ "lines" => [
78
+ {
79
+ "price" => 10,
80
+ "quantity" => 2,
81
+ "title"=> "Плюшевый мишка",
82
+ "total_price" => 20,
83
+ "vat_rate" => null
84
+ }
85
+ ]
86
+ }
87
+
88
+ client.create_receipt_request!(receipt_params)
89
+ ```
90
+
91
+ ### Регистрация чека (возврат)
92
+
93
+ ```ruby
94
+ receipt_params = {
95
+ "order_id" => "91421af3",
96
+ "order_number" => "1014",
97
+ "type" => "return",
98
+ "email" => "john@example.net",
99
+ "phone_number" => "79650000000",
100
+ "should_print" => true,
101
+ "cash_amount" => 201.1,
102
+ "electron_amount" => 0,
103
+ "lines" => [
104
+ {
105
+ "price" => 10,
106
+ "quantity" => 2,
107
+ "title"=> "Плюшевый мишка",
108
+ "total_price" => 20,
109
+ "vat_rate" => null
110
+ }
111
+ ]
112
+ }
113
+
114
+ client.create_receipt_request!(receipt_params)
115
+ ```
116
+
117
+ ### Закрытие смены
118
+
119
+ ```ruby
120
+ client.close_shift!
121
+ ```
data/ekam-ruby.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ekam-ruby/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'ekam-ruby'
7
+ spec.version = Ekam::VERSION
8
+ spec.authors = ['Denis Lukyanov']
9
+ spec.email = ['d.lukyanov@secoint.ru']
10
+ spec.summary = 'Simple API client for EKAM'
11
+ spec.description = 'Implementation of EKAM API v0.0.1 (https://app.ekam.ru/online/swagger)'
12
+ spec.homepage = 'https://github.com/secoint/ekam-ruby'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_dependency 'httparty', '~> 0.11'
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.0'
21
+ end
data/lib/ekam-ruby.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "ekam-ruby/version"
2
+ require "ekam-ruby/client"
3
+ require "ekam-ruby/error"
@@ -0,0 +1,60 @@
1
+ require 'uri'
2
+ require 'httparty'
3
+
4
+ module Ekam
5
+ class Client
6
+ include HTTParty
7
+
8
+ base_uri "https://app.ekam.ru/api/online"
9
+
10
+ attr_reader :token
11
+
12
+ def initialize(token)
13
+ @token = token
14
+ end
15
+
16
+ def get_receipt_requests(params = {})
17
+ resource_url = "/v1/receipt_requests"
18
+ get_resource(resource_url, params)["items"]
19
+ end
20
+
21
+ def create_receipt_request!(params)
22
+ resource_url = "/v1/receipt_requests"
23
+ post_resource(resource_url, params)
24
+ end
25
+
26
+ def close_shift!
27
+ resource_url = "/v1/receipt_requests/close_retail_shift"
28
+ post_resource(resource_url)
29
+ end
30
+
31
+ private
32
+
33
+ def post_resource(resource_url, params = {})
34
+ response = self.class.post(resource_url, body: params.to_json, headers: request_headers)
35
+ status = response.code
36
+ if status != 201
37
+ raise Ekam::Error.new(status, response["error"], params)
38
+ end
39
+ response
40
+ end
41
+
42
+ def get_resource(resource_url, params = {})
43
+ response = self.class.get(resource_url, query: params, headers: request_headers)
44
+ status = response.code
45
+ if status != 200
46
+ raise Ekam::Error.new(status, response["error"], params)
47
+ end
48
+ response
49
+ end
50
+
51
+ def request_headers
52
+ {
53
+ 'Content-Type' => 'application/json',
54
+ 'Accept' => 'application/json',
55
+ 'X-Access-Token' => token
56
+ }
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,12 @@
1
+ module Ekam
2
+ class Error < StandardError
3
+ attr_reader :code, :error, :request_params
4
+
5
+ def initialize(code, error, request_params)
6
+ super "Ekam responded with status #{code} (#{error})"
7
+ @error = error
8
+ @code = code
9
+ @request_params = request_params
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Ekam
2
+ VERSION = '0.0.3'
3
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ekam-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Denis Lukyanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: Implementation of EKAM API v0.0.1 (https://app.ekam.ru/online/swagger)
42
+ email:
43
+ - d.lukyanov@secoint.ru
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE.txt
49
+ - README.md
50
+ - ekam-ruby.gemspec
51
+ - lib/ekam-ruby.rb
52
+ - lib/ekam-ruby/client.rb
53
+ - lib/ekam-ruby/error.rb
54
+ - lib/ekam-ruby/version.rb
55
+ homepage: https://github.com/secoint/ekam-ruby
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.6.12
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Simple API client for EKAM
79
+ test_files: []