teamdrive_api 0.3.1 → 0.3.2
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 +4 -4
- data/.rubocop.yml +3 -0
- data/bin/console +3 -3
- data/lib/teamdrive_api/base.rb +28 -17
- data/lib/teamdrive_api/core_ext/array.rb +4 -4
- data/lib/teamdrive_api/core_ext/hash.rb +8 -7
- data/lib/teamdrive_api/error.rb +3 -1
- data/lib/teamdrive_api/register.rb +66 -40
- data/lib/teamdrive_api/version.rb +2 -1
- data/lib/teamdrive_api.rb +1 -0
- data/teamdrive_api.gemspec +17 -17
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d8d46801ef006ccd36dfefe91ee157089896aa6
|
4
|
+
data.tar.gz: d121207c9faece16f2ea037a9297dd27d0a5b1d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87e474fd5a313073ceb3968afd8922dfa3eee16de8141fe231dd7af688272317a6fcbf9bfcb43db086681457978d58b05419b57d5d0491051555b6b9d8ee9337
|
7
|
+
data.tar.gz: 00dd0e749bb1756e9f1058d6b8c992d24a213066dbd382e54847d68cba10de9b2b830f55b24b85a0f05806326747636fdeb9858212e4f21c48624bcb10d61508
|
data/.rubocop.yml
ADDED
data/bin/console
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'teamdrive_api'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
|
-
require
|
9
|
+
require 'pry'
|
10
10
|
Pry.start
|
data/lib/teamdrive_api/base.rb
CHANGED
@@ -4,28 +4,24 @@ require 'uri'
|
|
4
4
|
|
5
5
|
module TeamdriveApi
|
6
6
|
# API-Baseclass for all XML RPC APIs
|
7
|
-
class Base
|
7
|
+
class Base
|
8
8
|
include ::HTTParty
|
9
9
|
attr_reader :uri
|
10
10
|
format :xml
|
11
11
|
|
12
12
|
def initialize(host, api_checksum_salt, api_version)
|
13
|
-
@api_checksum_salt
|
13
|
+
@api_checksum_salt = api_checksum_salt
|
14
|
+
@api_version = api_version
|
14
15
|
@host = host.start_with?('http') ? host : 'https://' + host
|
15
16
|
end
|
16
17
|
|
17
18
|
# Generates the XML payload for the RPC
|
18
19
|
def payload_for(command, query = {})
|
19
|
-
out =
|
20
|
-
out << "<?xml version='1.0' encoding='UTF-8' ?>"
|
21
|
-
out << '<teamdrive>'
|
22
|
-
out << "<apiversion>#{@api_version}</apiversion>"
|
23
|
-
out << "<command>#{command}</command>"
|
24
|
-
out << "<requesttime>#{Time.now.to_i}</requesttime>"
|
20
|
+
out = header_for(command)
|
25
21
|
query.each do |k, v|
|
26
22
|
next if v.nil?
|
27
23
|
v = v.to_s
|
28
|
-
v = %w(true false).include?(v)
|
24
|
+
v = '$' + v if %w(true false).include?(v)
|
29
25
|
out << "<#{k}>#{v}</#{k}>"
|
30
26
|
end
|
31
27
|
out << '</teamdrive>'
|
@@ -33,6 +29,15 @@ module TeamdriveApi
|
|
33
29
|
|
34
30
|
private
|
35
31
|
|
32
|
+
# Generates the XML header for the RPC
|
33
|
+
def header_for(command)
|
34
|
+
out = "<?xml version='1.0' encoding='UTF-8' ?>"
|
35
|
+
out << '<teamdrive>'
|
36
|
+
out << "<apiversion>#{@api_version}</apiversion>"
|
37
|
+
out << "<command>#{command}</command>"
|
38
|
+
out << "<requesttime>#{Time.now.to_i}</requesttime>"
|
39
|
+
end
|
40
|
+
|
36
41
|
def check_for(method, hash, params, message)
|
37
42
|
keys = [params].flatten
|
38
43
|
return if keys.send(method) { |k| hash.key?(k) }
|
@@ -52,20 +57,26 @@ module TeamdriveApi
|
|
52
57
|
check_for(:all?, in_hash, of, 'all')
|
53
58
|
end
|
54
59
|
|
60
|
+
# actually send a HTTP request
|
55
61
|
def send_request(command, data = {})
|
56
62
|
body = payload_for(command, data)
|
57
|
-
res = self.class.post
|
63
|
+
res = self.class.post(
|
64
|
+
@uri,
|
58
65
|
headers: { 'User-Agent' => "TeamdriveApi v#{TeamdriveApi::VERSION}" },
|
59
66
|
body: body,
|
60
67
|
query: { checksum: Digest::MD5.hexdigest(body + @api_checksum_salt) }
|
68
|
+
)
|
61
69
|
|
62
|
-
res
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
return_or_fail(res['teamdrive'].symbolize_keys)
|
71
|
+
end
|
72
|
+
|
73
|
+
# raise TeamdriveApi::Error if +response+ contains an exception, return
|
74
|
+
# +response+ otherwise
|
75
|
+
def return_or_fail(response)
|
76
|
+
return response if response[:exception].nil?
|
77
|
+
fail TeamdriveApi::Error.new response[:exception][:primarycode],
|
78
|
+
response[:exception][:secondarycode],
|
79
|
+
response[:exception][:message]
|
69
80
|
end
|
70
81
|
end
|
71
82
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
class Array
|
1
|
+
class Array # :nodoc:
|
2
2
|
# Returns an Array with all elements' keys converted to symbols, as long as
|
3
3
|
# they respond to +symbolize_keys+.
|
4
4
|
def symbolize_keys
|
5
|
-
|
5
|
+
map { |e| e.respond_to?(:symbolize_keys) ? e.symbolize_keys : e }
|
6
6
|
end
|
7
7
|
|
8
8
|
# Converts the keys of all elements to symbols, as long as the elements
|
9
9
|
# respond to +symbolize_keys!+
|
10
10
|
def symbolize_keys!
|
11
|
-
|
12
|
-
e.symbolize_keys!
|
11
|
+
each do |e|
|
12
|
+
e.symbolize_keys! if e.respond_to?(:symbolize_keys!)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class Hash
|
1
|
+
class Hash # :nodoc:
|
2
2
|
# Returns a new hash with all keys converted to symbols, as long as
|
3
3
|
# they respond to +to_sym+.
|
4
4
|
#
|
@@ -10,9 +10,9 @@ class Hash
|
|
10
10
|
# Borrowed from ActiveSupport.
|
11
11
|
def symbolize_keys
|
12
12
|
result = self.class.new
|
13
|
-
|
14
|
-
new_key = key.to_sym
|
15
|
-
new_value =
|
13
|
+
each do |key, val|
|
14
|
+
new_key = key.respond_to?(:to_sym) ? key.to_sym : key
|
15
|
+
new_value = val.respond_to?(:symbolize_keys) ? val.symbolize_keys : val
|
16
16
|
result[new_key] = new_value
|
17
17
|
end
|
18
18
|
result
|
@@ -23,10 +23,11 @@ class Hash
|
|
23
23
|
#
|
24
24
|
# Borrowed from ActiveSupport.
|
25
25
|
def symbolize_keys!
|
26
|
+
# we have to use `keys.each` because we can't modify a Hash during `each`
|
26
27
|
keys.each do |key|
|
27
|
-
new_key = key.to_sym
|
28
|
-
|
29
|
-
new_value =
|
28
|
+
new_key = key.respond_to?(:to_sym) ? key.to_sym : key
|
29
|
+
val = delete(key)
|
30
|
+
new_value = val.respond_to?(:symbolize_keys!) ? val.symbolize_keys! : val
|
30
31
|
self[new_key] = new_value
|
31
32
|
end
|
32
33
|
self
|
data/lib/teamdrive_api/error.rb
CHANGED
@@ -4,7 +4,9 @@ module TeamdriveApi
|
|
4
4
|
attr_reader :code, :secondarycode, :message
|
5
5
|
def initialize(code, secondarycode, message)
|
6
6
|
super message
|
7
|
-
@code
|
7
|
+
@code = code
|
8
|
+
@secondarycode = secondarycode
|
9
|
+
@message = message
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module TeamdriveApi
|
2
|
-
# API Client for the TeamDrive Register Server. See the TeamDrive Register
|
2
|
+
# API Client for the TeamDrive Register Server. See the TeamDrive Register
|
3
|
+
# docs for more informations on specific commands.
|
3
4
|
class Register < Base
|
4
5
|
# Create a new Register API Client.
|
5
6
|
#
|
6
7
|
# @param [String] host the API Server
|
7
|
-
# @param [String] api_checksum_salt the +APIChecksumSalt+ system setting
|
8
|
+
# @param [String] api_checksum_salt the +APIChecksumSalt+ system setting
|
9
|
+
# ("Edit Settings -> RegServer").
|
8
10
|
# @param [String] api_version optionally overwrite the api_version
|
9
11
|
def initialize(host, api_checksum_salt, api_version = '1.0.005')
|
10
12
|
super
|
@@ -15,11 +17,16 @@ module TeamdriveApi
|
|
15
17
|
#
|
16
18
|
# @param [String] username
|
17
19
|
# @param [String] number License Number
|
18
|
-
# @param [Array] devices optional list of devices the user posses. If
|
20
|
+
# @param [Array] devices optional list of devices the user posses. If
|
21
|
+
# empty, all of the user's devices will be used
|
19
22
|
# @return [Boolean] success?
|
20
23
|
def assign_license_to_client(username, number, devices = [])
|
21
|
-
res = send_request :assignlicensetoclient,
|
22
|
-
|
24
|
+
res = send_request :assignlicensetoclient,
|
25
|
+
username: username,
|
26
|
+
number: number,
|
27
|
+
devices: devices
|
28
|
+
|
29
|
+
res[:intresult].eql?('0')
|
23
30
|
end
|
24
31
|
|
25
32
|
# Assign user to license (added in RegServ API v1.0.003)
|
@@ -28,37 +35,57 @@ module TeamdriveApi
|
|
28
35
|
# @param [String] number License Number
|
29
36
|
# @return [Boolean] success?
|
30
37
|
def assign_user_to_license(username, number)
|
31
|
-
res = send_request :assignusertolicense,
|
38
|
+
res = send_request :assignusertolicense,
|
39
|
+
username: username,
|
40
|
+
number: number
|
41
|
+
|
32
42
|
res[:intresult].eql?('0')
|
33
43
|
end
|
34
44
|
|
35
|
-
# Create license
|
45
|
+
# Create a license and assign it to a user.
|
36
46
|
#
|
37
47
|
# @param [Hash] opts license options
|
48
|
+
# @option opts [String] :username User to assign license to
|
38
49
|
# @option opts [String] :productname +server+, +client+
|
39
50
|
# @option opts [String] :type +monthly+ / +yearly+ / +permanent+
|
40
|
-
# @option opts [String] :featurevalue one of +webdavs+, +personal+,
|
41
|
-
#
|
42
|
-
# @option opts [String] :
|
43
|
-
# @option opts [String] :
|
44
|
-
#
|
45
|
-
# @option opts [String] :
|
46
|
-
#
|
51
|
+
# @option opts [String] :featurevalue one of +webdavs+, +personal+,
|
52
|
+
# +professional+, +enterprise+
|
53
|
+
# @option opts [String] :limit Amount, only for client licenses
|
54
|
+
# @option opts [String] :licensereference An _optional_ external reference.
|
55
|
+
# Added with v1.0.004
|
56
|
+
# @option opts [String] :contactnumber An optional contact number. Added
|
57
|
+
# with v1.0.004
|
58
|
+
# @option opts [String] :validuntil An optional valid-until date. Format
|
59
|
+
# must be +DD.MM.YYYY+. Added with v1.0.004
|
60
|
+
# @option opts [String] :changeid An optional change id for license changes.
|
61
|
+
# Added with v1.0.004
|
62
|
+
# @return [String] The license number of the created license
|
63
|
+
def create_license(opts = {})
|
64
|
+
require_all of: [:username, :productname, :type, :featurevalue],
|
65
|
+
in_hash: opts
|
66
|
+
res = send_request :createlicense, opts
|
67
|
+
res[:licensedata][:number]
|
68
|
+
end
|
69
|
+
|
70
|
+
# Create license without user (added in RegServ API v1.0.003)
|
71
|
+
#
|
72
|
+
# @see #create_license
|
47
73
|
def create_license_without_user(opts = {})
|
48
74
|
require_all of: [:productname, :type, :featurevalue], in_hash: opts
|
49
|
-
send_request :createlicensewithoutuser, opts
|
75
|
+
res = send_request :createlicensewithoutuser, opts
|
76
|
+
res[:licensedata][:number]
|
50
77
|
end
|
51
78
|
|
52
79
|
# Get default-license for a user
|
53
80
|
#
|
54
81
|
# @param [String] username
|
55
|
-
# @param [String] distributor
|
82
|
+
# @param [String] distributor _optional_
|
56
83
|
# @return [Hash] the license data
|
57
84
|
def get_default_license_for_user(username, distributor = nil)
|
58
|
-
res = send_request
|
59
|
-
|
60
|
-
|
61
|
-
|
85
|
+
res = send_request :getdefaultlicense,
|
86
|
+
username: username,
|
87
|
+
distributor: distributor
|
88
|
+
|
62
89
|
res[:licensedata]
|
63
90
|
end
|
64
91
|
|
@@ -68,10 +95,10 @@ module TeamdriveApi
|
|
68
95
|
# @param [String] distributor (optional)
|
69
96
|
# @return [Hash] the license data
|
70
97
|
def get_license_data_for_user(username, distributor = nil)
|
71
|
-
res = send_request
|
72
|
-
|
73
|
-
|
74
|
-
|
98
|
+
res = send_request :getlicensedata,
|
99
|
+
username: username,
|
100
|
+
distributor: distributor
|
101
|
+
|
75
102
|
res[:licensedata]
|
76
103
|
end
|
77
104
|
|
@@ -81,10 +108,9 @@ module TeamdriveApi
|
|
81
108
|
# @param [String] distributor (optional, added in RegServ API v1.0.003)
|
82
109
|
# @return [Hash] the user data
|
83
110
|
def get_user_data(username, distributor = nil)
|
84
|
-
send_request
|
85
|
-
|
86
|
-
|
87
|
-
})
|
111
|
+
send_request :getuserdata,
|
112
|
+
username: username,
|
113
|
+
distributor: distributor
|
88
114
|
end
|
89
115
|
|
90
116
|
# Create a new Account
|
@@ -96,34 +122,34 @@ module TeamdriveApi
|
|
96
122
|
# when creating a new account, they will not be checked when a user
|
97
123
|
# attempts to log in.
|
98
124
|
#
|
99
|
-
# @param [Hash] Data for the new user.
|
125
|
+
# @param [Hash] opts Data for the new user.
|
100
126
|
# @option opts [String] :username
|
101
127
|
# @option opts [String] :useremail
|
102
128
|
# @option opts [String] :password
|
103
|
-
# @option opts [String] :language
|
104
|
-
# @option opts [String] :reference
|
105
|
-
# @option opts [String] :department
|
106
|
-
# @option opts [String] :distributor
|
129
|
+
# @option opts [String] :language _optional_
|
130
|
+
# @option opts [String] :reference _optional_
|
131
|
+
# @option opts [String] :department _optional_
|
132
|
+
# @option opts [String] :distributor _optional_
|
107
133
|
# @return [Boolean] +true+ if the User has been created
|
108
134
|
def register_user(opts = {})
|
109
135
|
require_all of: [:username, :useremail, :password], in_hash: opts
|
110
|
-
send_request(:registeruser, opts)
|
136
|
+
res = send_request(:registeruser, opts)
|
111
137
|
res[:intresult].eql?('0')
|
112
138
|
end
|
113
139
|
alias_method :create_account, :register_user
|
114
140
|
|
115
141
|
# Remove user (added in RegServ API v1.0.003)
|
116
142
|
#
|
117
|
-
# @param [String] username to be deleted
|
118
|
-
# @param [Boolean] delete the user's license aswell
|
119
|
-
# @param [String] distributor
|
143
|
+
# @param [String] username User to be deleted
|
144
|
+
# @param [Boolean] delete_license delete the user's license aswell
|
145
|
+
# @param [String] distributor Distributor. Will only be used if allowed by the API (see
|
120
146
|
# +APIAllowSettingDistributor+ in the Teamdrive Register docs).
|
121
147
|
# @return [Boolean] success?
|
122
148
|
def remove_user(username, delete_license = false, distributor = nil)
|
123
149
|
res = send_request :removeuser,
|
124
|
-
|
125
|
-
|
126
|
-
|
150
|
+
username: username,
|
151
|
+
delete_license: delete_license,
|
152
|
+
distributor: distributor
|
127
153
|
|
128
154
|
res[:intresult].eql?('0')
|
129
155
|
end
|
data/lib/teamdrive_api.rb
CHANGED
data/teamdrive_api.gemspec
CHANGED
@@ -4,31 +4,31 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'teamdrive_api/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'teamdrive_api'
|
8
8
|
spec.version = TeamdriveApi::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Manuel Hutter']
|
10
|
+
spec.email = ['git@mhutter.net']
|
11
11
|
|
12
12
|
if spec.respond_to?(:metadata)
|
13
|
-
# spec.metadata['allowed_push_host'] =
|
13
|
+
# spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server.'
|
14
14
|
end
|
15
15
|
|
16
|
-
spec.summary =
|
17
|
-
spec.description =
|
18
|
-
spec.homepage =
|
19
|
-
spec.license =
|
16
|
+
spec.summary = 'TeamDrive API Client'
|
17
|
+
spec.description = 'Client library for the TeamDrive XML API. Currently only supports the RegServer API'
|
18
|
+
spec.homepage = 'https://github.com/mhutter/teamdrive_api'
|
19
|
+
spec.license = 'MIT'
|
20
20
|
|
21
21
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
-
spec.bindir =
|
22
|
+
spec.bindir = 'exe'
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
-
spec.require_paths = [
|
24
|
+
spec.require_paths = ['lib']
|
25
25
|
|
26
|
-
spec.add_runtime_dependency
|
26
|
+
spec.add_runtime_dependency 'httparty', '~> 0.13'
|
27
27
|
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
28
|
+
spec.add_development_dependency 'bundler', '~> 1.8'
|
29
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
30
|
+
spec.add_development_dependency 'minitest', '~> 5.5'
|
31
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
32
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
33
|
+
spec.add_development_dependency 'webmock', '~> 1.20'
|
34
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teamdrive_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Hutter
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -117,6 +117,7 @@ extensions: []
|
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
|
+
- ".rubocop.yml"
|
120
121
|
- ".travis.yml"
|
121
122
|
- Gemfile
|
122
123
|
- LICENSE.txt
|
@@ -157,3 +158,4 @@ signing_key:
|
|
157
158
|
specification_version: 4
|
158
159
|
summary: TeamDrive API Client
|
159
160
|
test_files: []
|
161
|
+
has_rdoc:
|