yclients-api 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +57 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/lib/yclients/api.rb +8 -0
- data/lib/yclients/api/auth.rb +33 -0
- data/lib/yclients/api/client.rb +61 -0
- data/lib/yclients/api/companies.rb +77 -0
- data/lib/yclients/api/exception.rb +10 -0
- data/lib/yclients/api/version.rb +5 -0
- data/yclients-api.gemspec +22 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 33627f7c7369e4a4da37d19a43b2939cd3306ae5ff32c06287cbd428acde0717
|
4
|
+
data.tar.gz: 1dfd416c56bf993e8329588df7e6af20064b91408742b82e1a03e789954315f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 54dbbd9dd7ee404b154adb9114b904dcfa0e72412f77541bf554ddf41622913d3849c80ecb81f44051e45d293c51901aba4796fd3db110c5dfbb470fd7502d05
|
7
|
+
data.tar.gz: c3cbe3957b7fd3a98e6bdd2c67071c1610d2d916f0da0b67e27636aa6afd4ded98e6b25f7860f040958c5b479f251771de69b8660788119e1b80c4e7e8273c17
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
gem "rake", "~> 12.0"
|
7
|
+
gem 'pry'
|
8
|
+
gem 'rb-readline'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem "rspec", "~> 3.0"
|
13
|
+
gem 'vcr'
|
14
|
+
gem 'webmock'
|
15
|
+
end
|
16
|
+
|
17
|
+
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yclients-api (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
addressable (2.6.0)
|
10
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
|
+
coderay (1.1.2)
|
12
|
+
crack (0.4.3)
|
13
|
+
safe_yaml (~> 1.0.0)
|
14
|
+
diff-lcs (1.3)
|
15
|
+
hashdiff (0.3.8)
|
16
|
+
method_source (0.9.2)
|
17
|
+
pry (0.12.2)
|
18
|
+
coderay (~> 1.1.0)
|
19
|
+
method_source (~> 0.9.0)
|
20
|
+
public_suffix (3.0.3)
|
21
|
+
rake (12.3.2)
|
22
|
+
rb-readline (0.5.5)
|
23
|
+
rspec (3.8.0)
|
24
|
+
rspec-core (~> 3.8.0)
|
25
|
+
rspec-expectations (~> 3.8.0)
|
26
|
+
rspec-mocks (~> 3.8.0)
|
27
|
+
rspec-core (3.8.0)
|
28
|
+
rspec-support (~> 3.8.0)
|
29
|
+
rspec-expectations (3.8.2)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-mocks (3.8.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-support (3.8.0)
|
36
|
+
safe_yaml (1.0.5)
|
37
|
+
vcr (4.0.0)
|
38
|
+
webmock (3.5.1)
|
39
|
+
addressable (>= 2.3.6)
|
40
|
+
crack (>= 0.3.2)
|
41
|
+
hashdiff
|
42
|
+
|
43
|
+
PLATFORMS
|
44
|
+
ruby
|
45
|
+
|
46
|
+
DEPENDENCIES
|
47
|
+
bundler (~> 1.17)
|
48
|
+
pry
|
49
|
+
rake (~> 12.0)
|
50
|
+
rb-readline
|
51
|
+
rspec (~> 3.0)
|
52
|
+
vcr
|
53
|
+
webmock
|
54
|
+
yclients-api!
|
55
|
+
|
56
|
+
BUNDLED WITH
|
57
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Maksim Akkuzin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Yclients::Api
|
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/yclients/api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'yclients-api'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install yclients-api
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/makkuzin/yclients-api.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "yclients/api"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require "pry"
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
data/lib/yclients/api.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
### Авторизация
|
2
|
+
### https://yclients.docs.apiary.io/#reference/0
|
3
|
+
module Yclients::Api
|
4
|
+
module Auth
|
5
|
+
URL = 'https://api.yclients.com/api/v1/auth'
|
6
|
+
|
7
|
+
def auth
|
8
|
+
@user_token || auth!
|
9
|
+
end
|
10
|
+
|
11
|
+
def auth!
|
12
|
+
unless @login || @password
|
13
|
+
raise AuthError, "Отсутствует логин или пароль"
|
14
|
+
end
|
15
|
+
|
16
|
+
uri = URI(URL)
|
17
|
+
req = Net::HTTP::Post.new(uri, headers)
|
18
|
+
|
19
|
+
req.body = { "login" => @login, "password" => @password }.to_json
|
20
|
+
|
21
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
22
|
+
http.request(req)
|
23
|
+
end
|
24
|
+
json = JSON.parse(res.body)
|
25
|
+
|
26
|
+
if json.key?('user_token')
|
27
|
+
@user_token = json['user_token']
|
28
|
+
else
|
29
|
+
raise AuthError, json.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Yclients::Api
|
2
|
+
class Client
|
3
|
+
include Auth
|
4
|
+
include Companies
|
5
|
+
|
6
|
+
attr_accessor :partner_token, :user_token, :login, :password
|
7
|
+
|
8
|
+
def initialize(args={})
|
9
|
+
@partner_token = args[:partner_token] or raise NoPartnerToken
|
10
|
+
@user_token = args[:user_token]
|
11
|
+
@login = args[:login]
|
12
|
+
@password = args[:password]
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_user_token?
|
16
|
+
!!@user_token
|
17
|
+
end
|
18
|
+
|
19
|
+
def query_param(key, value, type)
|
20
|
+
case type
|
21
|
+
when :numeric
|
22
|
+
if value.respond_to?(:to_i) && value.to_i > 0
|
23
|
+
{ key => value }
|
24
|
+
else
|
25
|
+
{}
|
26
|
+
end
|
27
|
+
when :boolean
|
28
|
+
if value == true
|
29
|
+
{ key => 1 }
|
30
|
+
elsif value == false
|
31
|
+
{ key => 0 }
|
32
|
+
else
|
33
|
+
{}
|
34
|
+
end
|
35
|
+
when :string
|
36
|
+
if value.kind_of?(String) && value.length > 0
|
37
|
+
{ key => value }
|
38
|
+
else
|
39
|
+
{}
|
40
|
+
end
|
41
|
+
else
|
42
|
+
{}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def headers(args={auth: false})
|
47
|
+
if args[:auth]
|
48
|
+
{
|
49
|
+
'Authorization' => "Bearer #{@partner_token}, User #{@user_token}",
|
50
|
+
"Content-Type" => 'application/json'
|
51
|
+
}
|
52
|
+
else
|
53
|
+
{
|
54
|
+
'Authorization' => "Bearer #{@partner_token}",
|
55
|
+
"Content-Type" => 'application/json'
|
56
|
+
}
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
### Компании
|
2
|
+
### https://yclients.docs.apiary.io/#reference/2
|
3
|
+
module Yclients::Api
|
4
|
+
module Companies
|
5
|
+
URL1 = 'https://api.yclients.com/api/v1/company'
|
6
|
+
URL2 = 'https://api.yclients.com/api/v1/companies'
|
7
|
+
|
8
|
+
# group_id (Number, 83): ID сети компаний. Фильтр по идентификатору сети компаний Default: 83
|
9
|
+
# my (Number, 1): Только для авторизованного пользователя. Если нужно компании, на управление которыми пользователь имеет права
|
10
|
+
# active (Number, 1): Если нужно получить только активные для онлайн-записи компании
|
11
|
+
# moderated (Number, 1): Если нужно получить только прошедшие модерацию компании. Т.е. чей контент проверен для публикации
|
12
|
+
# for_booking (Number, 1): Если нужно получить поле next_slot по каждой компании
|
13
|
+
# show_groups (Number, 1): Включить в обьект компании список сетей в которые входит эта компания
|
14
|
+
# title: Поиск по вхождению подстроки в название компании
|
15
|
+
# distance: Радиус поиска
|
16
|
+
# coordinate_lat: Широта центра поиска по координатам
|
17
|
+
# coordinate_lon: Долгота центра поиска по координатам
|
18
|
+
def companies(args={})
|
19
|
+
uri = URI(URL2)
|
20
|
+
params = {}
|
21
|
+
params.merge!(query_param(:group_id, args[:group_id], :numeric)) if args.key?(:group_id)
|
22
|
+
params.merge!(query_param(:my, args[:my], :boolean)) if args.key?(:my)
|
23
|
+
params.merge!(query_param(:active, args[:active], :boolean)) if args.key?(:active)
|
24
|
+
params.merge!(query_param(:moderated, args[:moderated], :boolean)) if args.key?(:moderated)
|
25
|
+
params.merge!(query_param(:forBooking, args[:for_booking], :boolean)) if args.key?(:for_booking)
|
26
|
+
params.merge!(query_param(:show_groups, args[:show_groups], :boolean)) if args.key?(:show_groups)
|
27
|
+
params.merge!(query_param(:title, args[:title], :string)) if args.key?(:title)
|
28
|
+
# params.merge!(query_param(:distance, args[:distance], :string)) if args.key?(:distance)
|
29
|
+
# params.merge!(query_param(:coordinate_lat, args[:coordinate_lat], :string)) if args.key?(:coordinate_lat)
|
30
|
+
# params.merge!(query_param(:coordinate_lon, args[:coordinate_lon], :string)) if args.key?(:coordinate_lon)
|
31
|
+
uri.query = URI.encode_www_form(params)
|
32
|
+
|
33
|
+
req = Net::HTTP::Get.new(uri, headers({
|
34
|
+
auth: args.key?(:my) && [true, false].include?(args[:my])
|
35
|
+
}))
|
36
|
+
|
37
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
38
|
+
http.request(req)
|
39
|
+
end
|
40
|
+
|
41
|
+
json = JSON.parse(res.body)
|
42
|
+
if json.kind_of?(Array)
|
43
|
+
json
|
44
|
+
else
|
45
|
+
raise CompaniesAccessError, json.to_s
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# for_booking (Number, 1): Если нужно получить поле next_slot по каждой компании
|
50
|
+
# show_groups (Number, 1): Включить в обьект компании список сетей в которые входит эта компания
|
51
|
+
def company(id, args={})
|
52
|
+
uri = URI("#{URL1}/#{id}/")
|
53
|
+
params = {}
|
54
|
+
params.merge!(query_param(:forBooking, args[:for_booking], :boolean)) if args.key?(:for_booking)
|
55
|
+
params.merge!(query_param(:show_groups, args[:show_groups], :boolean)) if args.key?(:show_groups)
|
56
|
+
uri.query = URI.encode_www_form(params)
|
57
|
+
|
58
|
+
req = Net::HTTP::Get.new(uri, headers({ auth: false }))
|
59
|
+
|
60
|
+
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
61
|
+
http.request(req)
|
62
|
+
end
|
63
|
+
|
64
|
+
json = JSON.parse(res.body)
|
65
|
+
if json.kind_of?(Hash) && json.key?('id')
|
66
|
+
json
|
67
|
+
else
|
68
|
+
raise CompaniesAccessError, json.to_s
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
=begin TODO
|
73
|
+
def edit_company(id, args={}); end
|
74
|
+
def delete_company(id); end
|
75
|
+
=end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "yclients/api/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "yclients-api"
|
7
|
+
spec.version = Yclients::Api::VERSION
|
8
|
+
spec.authors = ["Maksim Akkuzin"]
|
9
|
+
spec.email = ["maksim.akkuzin@yandex.ru"]
|
10
|
+
|
11
|
+
spec.summary = %q{Yclients API}
|
12
|
+
spec.description = %q{Ruby interface to the Yclients API}
|
13
|
+
spec.homepage = "https://github.com/makkuzin/yclients-api"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^spec/}) }
|
18
|
+
end
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yclients-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maksim Akkuzin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
description: Ruby interface to the Yclients API
|
28
|
+
email:
|
29
|
+
- maksim.akkuzin@yandex.ru
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- Gemfile
|
37
|
+
- Gemfile.lock
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- bin/console
|
42
|
+
- bin/setup
|
43
|
+
- lib/yclients/api.rb
|
44
|
+
- lib/yclients/api/auth.rb
|
45
|
+
- lib/yclients/api/client.rb
|
46
|
+
- lib/yclients/api/companies.rb
|
47
|
+
- lib/yclients/api/exception.rb
|
48
|
+
- lib/yclients/api/version.rb
|
49
|
+
- yclients-api.gemspec
|
50
|
+
homepage: https://github.com/makkuzin/yclients-api
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.0.1
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Yclients API
|
73
|
+
test_files: []
|