MyOffice 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +60 -0
- data/.rubocop.yml +142 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +86 -0
- data/LICENSE +21 -0
- data/MyOffice.gemspec +35 -0
- data/README.md +1 -0
- data/Rakefile +16 -0
- data/lib/MyOffice/client.rb +32 -0
- data/lib/MyOffice/collection.rb +22 -0
- data/lib/MyOffice/error.rb +5 -0
- data/lib/MyOffice/object.rb +25 -0
- data/lib/MyOffice/objects/user.rb +5 -0
- data/lib/MyOffice/resource.rb +59 -0
- data/lib/MyOffice/resources/users.rb +9 -0
- data/lib/MyOffice/version.rb +8 -0
- data/lib/MyOffice.rb +16 -0
- metadata +198 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 34409128a9e5b31aeeedebb9eed195b0d5528879562df2b14f6eeed474d00996
|
4
|
+
data.tar.gz: be1549e4340c4719e5278656f957fe6c93e7f84381b0fe47dbdd89916e5f4895
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 21957277a9974515602afadd8d06a71be9f8a9a8119fa4cc8e512ced5cdeef9ed749115c814fe8fffc39f505451c3e3d25e0887de7bbb65d2a6fb11f0abfcafa
|
7
|
+
data.tar.gz: e59a33994213773f93e838f70cf1da4c40a461cf9d4495643c5fb9b4450b48da03a3e29c1a95548142101a8e130816a278363978e9b4778a368f2d3a89233ef1
|
data/.gitignore
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
57
|
+
|
58
|
+
# macOS
|
59
|
+
.DS_Store
|
60
|
+
dev
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
---
|
2
|
+
AllCops:
|
3
|
+
NewCops: disable # TODO: change to enable after refactoring
|
4
|
+
|
5
|
+
# Commonly used screens these days easily fit more than 80 characters.
|
6
|
+
Layout/LineLength:
|
7
|
+
Max: 120
|
8
|
+
|
9
|
+
# Too short methods lead to extraction of single-use methods, which can make
|
10
|
+
# the code easier to read (by naming things), but can also clutter the class
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Max: 20
|
13
|
+
|
14
|
+
# The guiding principle of classes is SRP, SRP can't be accurately measured by LoC
|
15
|
+
Metrics/ClassLength:
|
16
|
+
Max: 1500
|
17
|
+
|
18
|
+
# No space makes the method definition shorter and differentiates
|
19
|
+
# from a regular assignment.
|
20
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
21
|
+
EnforcedStyle: no_space
|
22
|
+
|
23
|
+
# Single quotes being faster is hardly measurable and only affects parse time.
|
24
|
+
# Enforcing double quotes reduces the times where you need to change them
|
25
|
+
# when introducing an interpolation. Use single quotes only if their semantics
|
26
|
+
# are needed.
|
27
|
+
Style/StringLiterals:
|
28
|
+
EnforcedStyle: double_quotes
|
29
|
+
|
30
|
+
# We do not need to support Ruby 1.9, so this is good to use.
|
31
|
+
Style/SymbolArray:
|
32
|
+
Enabled: true
|
33
|
+
|
34
|
+
# Most readable form.
|
35
|
+
Style/OptionHash:
|
36
|
+
# A list of parameter names that will be flagged by this cop.
|
37
|
+
SuspiciousParamNames:
|
38
|
+
- options
|
39
|
+
- opts
|
40
|
+
- args
|
41
|
+
- paramsgit sttus
|
42
|
+
- parameters
|
43
|
+
|
44
|
+
# Mixing the styles looks just silly.
|
45
|
+
Style/HashSyntax:
|
46
|
+
EnforcedStyle: ruby19_no_mixed_keys
|
47
|
+
|
48
|
+
# has_key? and has_value? are far more readable than key? and value?
|
49
|
+
Style/PreferredHashMethods:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
# String#% is by far the least verbose and only object oriented variant.
|
53
|
+
Style/FormatString:
|
54
|
+
EnforcedStyle: percent
|
55
|
+
|
56
|
+
Style/CollectionMethods:
|
57
|
+
Enabled: true
|
58
|
+
PreferredMethods:
|
59
|
+
# inject seems more common in the community.
|
60
|
+
reduce: "inject"
|
61
|
+
|
62
|
+
|
63
|
+
# Either allow this style or don't. Marking it as safe with parenthesis
|
64
|
+
# is silly. Let's try to live without them for now.
|
65
|
+
Style/ParenthesesAroundCondition:
|
66
|
+
AllowSafeAssignment: false
|
67
|
+
Lint/AssignmentInCondition:
|
68
|
+
AllowSafeAssignment: false
|
69
|
+
|
70
|
+
# A specialized exception class will take one or more arguments and construct the message from it.
|
71
|
+
# So both variants make sense.
|
72
|
+
Style/RaiseArgs:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
# Indenting the chained dots beneath each other is not supported by this cop,
|
76
|
+
# see https://github.com/bbatsov/rubocop/issues/1633
|
77
|
+
Layout/MultilineOperationIndentation:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
# Fail is an alias of raise. Avoid aliases, it's more cognitive load for no gain.
|
81
|
+
# The argument that fail should be used to abort the program is wrong too,
|
82
|
+
# there's Kernel#abort for that.
|
83
|
+
Style/SignalException:
|
84
|
+
EnforcedStyle: only_raise
|
85
|
+
|
86
|
+
# Suppressing exceptions can be perfectly fine, and be it to avoid to
|
87
|
+
# explicitly type nil into the rescue since that's what you want to return,
|
88
|
+
# or suppressing LoadError for optional dependencies
|
89
|
+
Lint/SuppressedException:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
Layout/SpaceInsideBlockBraces:
|
93
|
+
# The space here provides no real gain in readability while consuming
|
94
|
+
# horizontal space that could be used for a better parameter name.
|
95
|
+
# Also {| differentiates better from a hash than { | does.
|
96
|
+
SpaceBeforeBlockParameters: false
|
97
|
+
|
98
|
+
# No trailing space differentiates better from the block:
|
99
|
+
# foo} means hash, foo } means block.
|
100
|
+
Layout/SpaceInsideHashLiteralBraces:
|
101
|
+
EnforcedStyle: no_space
|
102
|
+
|
103
|
+
# { ... } for multi-line blocks is okay, follow Weirichs rule instead:
|
104
|
+
# https://web.archive.org/web/20140221124509/http://onestepback.org/index.cgi/Tech/Ruby/BraceVsDoEnd.rdoc
|
105
|
+
Style/BlockDelimiters:
|
106
|
+
Enabled: false
|
107
|
+
|
108
|
+
# do / end blocks should be used for side effects,
|
109
|
+
# methods that run a block for side effects and have
|
110
|
+
# a useful return value are rare, assign the return
|
111
|
+
# value to a local variable for those cases.
|
112
|
+
Style/MethodCalledOnDoEndBlock:
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
# Enforcing the names of variables? To single letter ones? Just no.
|
116
|
+
Style/SingleLineBlockParams:
|
117
|
+
Enabled: false
|
118
|
+
|
119
|
+
# Shadowing outer local variables with block parameters is often useful
|
120
|
+
# to not reinvent a new name for the same thing, it highlights the relation
|
121
|
+
# between the outer variable and the parameter. The cases where it's actually
|
122
|
+
# confusing are rare, and usually bad for other reasons already, for example
|
123
|
+
# because the method is too long.
|
124
|
+
Lint/ShadowingOuterLocalVariable:
|
125
|
+
Enabled: false
|
126
|
+
|
127
|
+
# Check with yard instead.
|
128
|
+
Style/Documentation:
|
129
|
+
Enabled: false
|
130
|
+
|
131
|
+
# This is just silly. Calling the argument `other` in all cases makes no sense.
|
132
|
+
Naming/BinaryOperatorParameterName:
|
133
|
+
Enabled: false
|
134
|
+
|
135
|
+
# There are valid cases, for example debugging Cucumber steps,
|
136
|
+
# also they'll fail CI anyway
|
137
|
+
Lint/Debugger:
|
138
|
+
Enabled: false
|
139
|
+
|
140
|
+
# Style preference
|
141
|
+
Style/MethodDefParentheses:
|
142
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
MyOffice (0.0.0)
|
5
|
+
addressable (~> 2.3, >= 2.3.7)
|
6
|
+
faraday (~> 1.7)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.8.1)
|
12
|
+
public_suffix (>= 2.0.2, < 6.0)
|
13
|
+
crack (0.4.5)
|
14
|
+
rexml
|
15
|
+
diff-lcs (1.5.0)
|
16
|
+
docile (1.4.0)
|
17
|
+
faraday (1.10.2)
|
18
|
+
faraday-em_http (~> 1.0)
|
19
|
+
faraday-em_synchrony (~> 1.0)
|
20
|
+
faraday-excon (~> 1.1)
|
21
|
+
faraday-httpclient (~> 1.0)
|
22
|
+
faraday-multipart (~> 1.0)
|
23
|
+
faraday-net_http (~> 1.0)
|
24
|
+
faraday-net_http_persistent (~> 1.0)
|
25
|
+
faraday-patron (~> 1.0)
|
26
|
+
faraday-rack (~> 1.0)
|
27
|
+
faraday-retry (~> 1.0)
|
28
|
+
ruby2_keywords (>= 0.0.4)
|
29
|
+
faraday-em_http (1.0.0)
|
30
|
+
faraday-em_synchrony (1.0.0)
|
31
|
+
faraday-excon (1.1.0)
|
32
|
+
faraday-httpclient (1.0.1)
|
33
|
+
faraday-multipart (1.0.4)
|
34
|
+
multipart-post (~> 2)
|
35
|
+
faraday-net_http (1.0.1)
|
36
|
+
faraday-net_http_persistent (1.2.0)
|
37
|
+
faraday-patron (1.0.0)
|
38
|
+
faraday-rack (1.0.0)
|
39
|
+
faraday-retry (1.0.3)
|
40
|
+
hashdiff (1.0.1)
|
41
|
+
multipart-post (2.2.3)
|
42
|
+
public_suffix (5.0.0)
|
43
|
+
rake (12.3.3)
|
44
|
+
rexml (3.2.5)
|
45
|
+
rspec (3.11.0)
|
46
|
+
rspec-core (~> 3.11.0)
|
47
|
+
rspec-expectations (~> 3.11.0)
|
48
|
+
rspec-mocks (~> 3.11.0)
|
49
|
+
rspec-core (3.11.0)
|
50
|
+
rspec-support (~> 3.11.0)
|
51
|
+
rspec-expectations (3.11.1)
|
52
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
+
rspec-support (~> 3.11.0)
|
54
|
+
rspec-mocks (3.11.1)
|
55
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
+
rspec-support (~> 3.11.0)
|
57
|
+
rspec-support (3.11.1)
|
58
|
+
ruby2_keywords (0.0.5)
|
59
|
+
simplecov (0.21.2)
|
60
|
+
docile (~> 1.1)
|
61
|
+
simplecov-html (~> 0.11)
|
62
|
+
simplecov_json_formatter (~> 0.1)
|
63
|
+
simplecov-html (0.12.3)
|
64
|
+
simplecov-lcov (0.7.0)
|
65
|
+
simplecov_json_formatter (0.1.4)
|
66
|
+
vcr (6.1.0)
|
67
|
+
webmock (3.18.1)
|
68
|
+
addressable (>= 2.8.0)
|
69
|
+
crack (>= 0.3.2)
|
70
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
71
|
+
|
72
|
+
PLATFORMS
|
73
|
+
x86_64-darwin-17
|
74
|
+
|
75
|
+
DEPENDENCIES
|
76
|
+
MyOffice!
|
77
|
+
bundler
|
78
|
+
rake (~> 12.3.3)
|
79
|
+
rspec (~> 3.0)
|
80
|
+
simplecov (~> 0.9)
|
81
|
+
simplecov-lcov (~> 0.7.0)
|
82
|
+
vcr (~> 6.1)
|
83
|
+
webmock (~> 3.18, >= 3.18.1)
|
84
|
+
|
85
|
+
BUNDLED WITH
|
86
|
+
2.3.22
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Ruby API clients
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/MyOffice.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require "MyOffice/version"
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.name = "MyOffice"
|
10
|
+
s.version = MyOffice::VERSION
|
11
|
+
s.summary = "MyOffice API client"
|
12
|
+
s.description = "MyOffice API wrapper written in Ruby"
|
13
|
+
s.authors = ["Ilya Brin"]
|
14
|
+
s.email = "ilya@codeplay.ru"
|
15
|
+
s.files = `git ls-files -z`.split("\x0")
|
16
|
+
s.executables = s.files.grep(%r{^bin/}) {|f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
s.homepage = "https://github.com/ruby-api-client/MyOffice"
|
19
|
+
s.license = "MIT"
|
20
|
+
|
21
|
+
s.required_ruby_version = ">= 2.6"
|
22
|
+
|
23
|
+
s.metadata["rubygems_mfa_required"] = "true"
|
24
|
+
|
25
|
+
s.add_dependency "addressable", "~> 2.3", ">= 2.3.7"
|
26
|
+
s.add_dependency "faraday", "~> 1.7"
|
27
|
+
|
28
|
+
s.add_development_dependency "bundler"
|
29
|
+
s.add_development_dependency "rake", "~> 12.3.3"
|
30
|
+
s.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
s.add_development_dependency "simplecov", "~> 0.9"
|
32
|
+
s.add_development_dependency "simplecov-lcov", "~> 0.7.0"
|
33
|
+
s.add_development_dependency "vcr", "~> 6.1"
|
34
|
+
s.add_development_dependency "webmock", "~> 3.18", ">= 3.18.1"
|
35
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# MyOffice
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
task default: :test
|
13
|
+
|
14
|
+
task :console do
|
15
|
+
exec "irb -I lib -r MyOffice.rb"
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MyOffice
|
4
|
+
class Client
|
5
|
+
BASE_URL = "https://api.myoffice.ru/v1"
|
6
|
+
|
7
|
+
attr_reader :token, :adapter
|
8
|
+
|
9
|
+
# new client
|
10
|
+
def initialize(token:, adapter: Faraday.default_adapter, stubs: nil)
|
11
|
+
@token = token
|
12
|
+
@adapter = adapter
|
13
|
+
@stubs = stubs # Test stubs for requests
|
14
|
+
end
|
15
|
+
|
16
|
+
def users
|
17
|
+
UsersResource.new(self)
|
18
|
+
end
|
19
|
+
|
20
|
+
def connection
|
21
|
+
@connection ||= Faraday.new(BASE_URL) do |conn|
|
22
|
+
conn.request :authorization, :OAuth, token
|
23
|
+
conn.request :json
|
24
|
+
conn.request :url_encoded
|
25
|
+
|
26
|
+
conn.response :json, content_type: "application/json"
|
27
|
+
|
28
|
+
conn.adapter adapter, @stubs
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MyOffice
|
4
|
+
class Collection
|
5
|
+
attr_reader :data, :items, :total
|
6
|
+
|
7
|
+
def self.from_response(response, key:, type:)
|
8
|
+
body = response.body
|
9
|
+
new(
|
10
|
+
data: body[key].map {|attrs| type.new(attrs) },
|
11
|
+
items: body["items"],
|
12
|
+
total: body["total"]
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(data:, items:, total:)
|
17
|
+
@data = data
|
18
|
+
@items = items
|
19
|
+
@total = total
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
module MyOffice
|
6
|
+
class Object < OpenStruct
|
7
|
+
def initialize(attributes)
|
8
|
+
super to_ostruct(attributes)
|
9
|
+
end
|
10
|
+
|
11
|
+
# Convert Array or Hash to OpenStruct
|
12
|
+
def to_ostruct(obj)
|
13
|
+
case obj
|
14
|
+
when Hash
|
15
|
+
# rubocop:disable Style/HashTransformValues
|
16
|
+
OpenStruct.new(obj.map {|key, val| [key, to_ostruct(val)] }.to_h)
|
17
|
+
# rubocop:enable Style/HashTransformValues
|
18
|
+
when Array
|
19
|
+
obj.map {|o| to_ostruct(o) }
|
20
|
+
else
|
21
|
+
obj
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MyOffice
|
4
|
+
class Resource
|
5
|
+
attr_reader :client
|
6
|
+
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def get(url, params: {}, headers: {})
|
14
|
+
handle_response client.connection.get(url, params, headers)
|
15
|
+
end
|
16
|
+
|
17
|
+
def post(url, body:, headers: {})
|
18
|
+
handle_response client.connection.post(url, body, headers)
|
19
|
+
end
|
20
|
+
|
21
|
+
def patch(url, body:, headers: {})
|
22
|
+
handle_response client.connection.patch(url, body, headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
def put(url, body:, headers: {})
|
26
|
+
handle_response client.connection.put(url, body, headers)
|
27
|
+
end
|
28
|
+
|
29
|
+
def delete(url, params: {}, headers: {})
|
30
|
+
handle_response client.connection.delete(url, params, headers)
|
31
|
+
end
|
32
|
+
alias delete_request delete
|
33
|
+
|
34
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
35
|
+
# rubocop:disable Metrics/AbcSize
|
36
|
+
def handle_response(response)
|
37
|
+
case response.status
|
38
|
+
when 400
|
39
|
+
raise Error, "Your request was malformed. #{response.body['error']}"
|
40
|
+
when 401
|
41
|
+
raise Error, "You did not supply valid authentication credentials. #{response.body['error']}"
|
42
|
+
when 403
|
43
|
+
raise Error, "You are not allowed to perform that action. #{response.body['error']}"
|
44
|
+
when 404
|
45
|
+
raise Error, "No results were found for your request. #{response.body['error']}"
|
46
|
+
when 429
|
47
|
+
raise Error, "Your request exceeded the API rate limit. #{response.body['error']}"
|
48
|
+
when 500
|
49
|
+
raise Error, "We were unable to perform the request due to server-side problems. #{response.body['error']}"
|
50
|
+
when 503
|
51
|
+
raise Error, "You have been rate limited for sending more requests per second. #{response.body['error']}"
|
52
|
+
end
|
53
|
+
|
54
|
+
response
|
55
|
+
end
|
56
|
+
# rubocop:enable Metrics/AbcSize
|
57
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
58
|
+
end
|
59
|
+
end
|
data/lib/MyOffice.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "addressable/uri"
|
4
|
+
require "faraday"
|
5
|
+
require "MyOffice/version"
|
6
|
+
|
7
|
+
module MyOffice
|
8
|
+
autoload :Client, "MyOffice/client"
|
9
|
+
autoload :Object, "MyOffice/object"
|
10
|
+
autoload :Resource, "MyOffice/resource"
|
11
|
+
autoload :Collection, "MyOffice/collection"
|
12
|
+
autoload :Error, "MyOffice/error"
|
13
|
+
|
14
|
+
autoload :User, "MyOffice/objects/user"
|
15
|
+
autoload :UsersResource, "MyOffice/resources/users"
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: MyOffice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ilya Brin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.3.7
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.3.7
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: faraday
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.7'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.7'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 12.3.3
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 12.3.3
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: simplecov
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.9'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.9'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: simplecov-lcov
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.7.0
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 0.7.0
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: vcr
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '6.1'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - "~>"
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '6.1'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: webmock
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '3.18'
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 3.18.1
|
141
|
+
type: :development
|
142
|
+
prerelease: false
|
143
|
+
version_requirements: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - "~>"
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '3.18'
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 3.18.1
|
151
|
+
description: MyOffice API wrapper written in Ruby
|
152
|
+
email: ilya@codeplay.ru
|
153
|
+
executables: []
|
154
|
+
extensions: []
|
155
|
+
extra_rdoc_files: []
|
156
|
+
files:
|
157
|
+
- ".gitignore"
|
158
|
+
- ".rubocop.yml"
|
159
|
+
- Gemfile
|
160
|
+
- Gemfile.lock
|
161
|
+
- LICENSE
|
162
|
+
- MyOffice.gemspec
|
163
|
+
- README.md
|
164
|
+
- Rakefile
|
165
|
+
- lib/MyOffice.rb
|
166
|
+
- lib/MyOffice/client.rb
|
167
|
+
- lib/MyOffice/collection.rb
|
168
|
+
- lib/MyOffice/error.rb
|
169
|
+
- lib/MyOffice/object.rb
|
170
|
+
- lib/MyOffice/objects/user.rb
|
171
|
+
- lib/MyOffice/resource.rb
|
172
|
+
- lib/MyOffice/resources/users.rb
|
173
|
+
- lib/MyOffice/version.rb
|
174
|
+
homepage: https://github.com/ruby-api-client/MyOffice
|
175
|
+
licenses:
|
176
|
+
- MIT
|
177
|
+
metadata:
|
178
|
+
rubygems_mfa_required: 'true'
|
179
|
+
post_install_message:
|
180
|
+
rdoc_options: []
|
181
|
+
require_paths:
|
182
|
+
- lib
|
183
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '2.6'
|
188
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - ">="
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0'
|
193
|
+
requirements: []
|
194
|
+
rubygems_version: 3.2.3
|
195
|
+
signing_key:
|
196
|
+
specification_version: 4
|
197
|
+
summary: MyOffice API client
|
198
|
+
test_files: []
|