yclients-api 0.1.3 → 0.1.4

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: ac063b314f0ce73b6002eb107b6139d9c4a78683368b8fb46d6594e0351e1e49
4
- data.tar.gz: f22ebbbd7069dbd44e898420d7b83ed83fa3eec393bdc52a1e928f4dd137fb9d
3
+ metadata.gz: 3b0e3e2f5e6ae543e8d68b46dc44be299de9ff7efd1b95afda195da7b9064994
4
+ data.tar.gz: f5729fc2e6376e186b79622bbc53c69478fbf89f7200c83f81a450dd09d34d09
5
5
  SHA512:
6
- metadata.gz: 5c45302bfdae788712c04454a73719970e6d0c12387b72a2e4f048b5b6efd7a255eec6d498a26e777f20a3b56465c9f3b99628c431071a26773b46158cf67eba
7
- data.tar.gz: 2b4dc229a2d047abddb542876c5da6c038265c19ef91d904522d23bcc30da54e1d9fa23e13e1fcc030da568c697afcbdc1e7bc36f87fadbdbb28d4530bbdb99a
6
+ metadata.gz: 3012035d54aa17f2b8ae3a420c1cef98d35239d0750d06a99a5251a166a361bff18b70938de2049a9822853cbc2cd967148918150e69a2891eb3dfcf28cea68a
7
+ data.tar.gz: eb2d7c9ccf7d6a650b0fefebeb86e45ba46cc34e4a95a18bca72467f8395207e52ee4b20d0ae3d2d6c90bd0343d6fa5e1332d0f4553fb907b1ca65021132f74c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yclients-api (0.1.0)
4
+ yclients-api (0.1.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -4,5 +4,6 @@ require 'json'
4
4
  require "yclients/api/version"
5
5
  require 'yclients/api/exception'
6
6
  require 'yclients/api/auth'
7
+ require 'yclients/api/service_categories'
7
8
  require 'yclients/api/companies'
8
9
  require "yclients/api/client"
@@ -2,6 +2,7 @@ module Yclients::Api
2
2
  class Client
3
3
  include Auth
4
4
  include Companies
5
+ include ServiceCategories
5
6
 
6
7
  attr_accessor :partner_token, :user_token, :login, :password
7
8
 
@@ -70,6 +70,7 @@ module Yclients::Api
70
70
  end
71
71
 
72
72
  =begin TODO
73
+ def new_company(args={}); end
73
74
  def edit_company(id, args={}); end
74
75
  def delete_company(id); end
75
76
  =end
@@ -7,4 +7,5 @@ module Yclients::Api
7
7
 
8
8
  class AuthError < Exception; end
9
9
  class CompaniesAccessError < Exception; end
10
+ class ServiceCategoriesAccessError < Exception; end
10
11
  end
@@ -0,0 +1,53 @@
1
+ ### Категории услуг
2
+ ### https://yclients.docs.apiary.io/#reference/3
3
+ module Yclients::Api
4
+ module ServiceCategories
5
+ URL1 = 'https://api.yclients.com/api/v1/service_category'
6
+ URL2 = 'https://api.yclients.com/api/v1/service_categories'
7
+
8
+ # id (Number, 1234) ID категории услуг (для работы с конкретной категорией)
9
+ # staff_id (Number, 1234) ID сотрудника (для получения категорий, привязанных к сотруднику)
10
+ def service_categories(company_id, args={})
11
+ id = query_param(:id, args[:id], :numeric)[:id] if args.key?(:id)
12
+ uri = URI(id.nil? ? "#{URL2}/#{company_id}" : "#{URL2}/#{company_id}/#{id}")
13
+ params = {}
14
+ params.merge!(query_param(:staff_id, args[:staff_id], :numeric)) if args.key?(:staff_id)
15
+ uri.query = URI.encode_www_form(params)
16
+
17
+ req = Net::HTTP::Get.new(uri, headers({ auth: false }))
18
+
19
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
20
+ http.request(req)
21
+ end
22
+
23
+ json = JSON.parse(res.body)
24
+ if json.kind_of?(Array)
25
+ json
26
+ else
27
+ raise ServiceCategoriesAccessError, json.to_s
28
+ end
29
+ end
30
+
31
+ def service_category(company_id, id)
32
+ uri = URI("#{URL1}/#{company_id}/#{id}")
33
+ req = Net::HTTP::Get.new(uri, headers({ auth: false }))
34
+
35
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
36
+ http.request(req)
37
+ end
38
+
39
+ json = JSON.parse(res.body)
40
+ if json.kind_of?(Hash) && json.key?('id')
41
+ json
42
+ else
43
+ raise ServiceCategoriesAccessError, json.to_s
44
+ end
45
+ end
46
+
47
+ =begin TODO
48
+ def new_service_category(company_id, args={}); end
49
+ def edit_service_category(company_id, id=nil, args={}); end
50
+ def delete_service_category(company_id, id=nil); end
51
+ =end
52
+ end
53
+ end
@@ -1,5 +1,5 @@
1
1
  module Yclients
2
2
  module Api
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yclients-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maksim Akkuzin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-01 00:00:00.000000000 Z
11
+ date: 2019-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -45,6 +45,7 @@ files:
45
45
  - lib/yclients/api/client.rb
46
46
  - lib/yclients/api/companies.rb
47
47
  - lib/yclients/api/exception.rb
48
+ - lib/yclients/api/service_categories.rb
48
49
  - lib/yclients/api/version.rb
49
50
  - yclients-api.gemspec
50
51
  homepage: https://github.com/makkuzin/yclients-api