teamdrive_api 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 15376afa64dfc8c22ae13e7fa17a7db37a024c07
4
- data.tar.gz: 696fa1373cb02aaf07268a445826bfc812832e0d
3
+ metadata.gz: 4004e15801a70734a32aa812d2a8ab6d28f02998
4
+ data.tar.gz: 7fbb6b1045159a5dd4e0e94ce5668fd71d834913
5
5
  SHA512:
6
- metadata.gz: 7dadbf7786a00898f8dd1bcc7aa274287946885044ae70eef6f72a47cff262c7fdfadbc2856413ab03c6248092ae695997dc785ef9be404fa1794030b14f9fbb
7
- data.tar.gz: 9275a3033668d93e2b4807c80c1ced9bc393277d8efa65d9764f666a2b03248ca0a014addf8c88c226bf6c8dd48cac0f0767b64867c11b1d5f8aefa2cb119f2d
6
+ metadata.gz: 418127519db85d91e0956515bf2ddf7f7585f88e5964ad2eb2722ce9fbb7a84531f2b8f055014156cfbd63485191831b1e78bd5c7d487cf0ebc81fd671f71227
7
+ data.tar.gz: 75896c17dbbb51a0681c777216a406bcf41b3b2d286e4f187100e859aa4e0338026dfc71ba386056c930428a07ea8806f0f7c20cd164c7bcb440c90e7f3ed3d8
data/.travis.yml CHANGED
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.1
4
+ addons:
5
+ code_climate:
6
+ repo_token: e3716abd1175de1df9e93752138689064884581ad221e4d02d79c8ce734fe916
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # TeamdriveApi
2
2
 
3
+ [![Build Status](https://travis-ci.org/mhutter/teamdrive_api.svg?branch=master)](https://travis-ci.org/mhutter/teamdrive_api)
4
+ [![Code Climate](https://codeclimate.com/github/mhutter/teamdrive_api/badges/gpa.svg)](https://codeclimate.com/github/mhutter/teamdrive_api)
5
+ [![Test Coverage](https://codeclimate.com/github/mhutter/teamdrive_api/badges/coverage.svg)](https://codeclimate.com/github/mhutter/teamdrive_api)
6
+
3
7
  Client library for the TeamDrive XML API.
4
8
 
5
9
  ## Project State
data/Rakefile CHANGED
@@ -6,3 +6,5 @@ Rake::TestTask.new do |t|
6
6
  t.libs << 'test'
7
7
  t.verbose = true
8
8
  end
9
+
10
+ task default: [:test]
@@ -3,6 +3,7 @@ require 'httparty'
3
3
  require 'uri'
4
4
 
5
5
  module TeamdriveApi
6
+ # API-Baseclass for all XML RPC APIs
6
7
  class Base # :nodoc:
7
8
  include ::HTTParty
8
9
  attr_reader :uri
@@ -16,15 +17,15 @@ module TeamdriveApi
16
17
  # Generates the XML payload for the RPC
17
18
  def payload_for(command, query = {})
18
19
  out = ''
19
- out << %q{<?xml version='1.0' encoding='UTF-8' ?>}
20
+ out << "<?xml version='1.0' encoding='UTF-8' ?>"
20
21
  out << '<teamdrive>'
21
22
  out << "<apiversion>#{@api_version}</apiversion>"
22
23
  out << "<command>#{command}</command>"
23
24
  out << "<requesttime>#{Time.now.to_i}</requesttime>"
24
- query.each do |k,v|
25
+ query.each do |k, v|
25
26
  next if v.nil?
26
27
  v = v.to_s
27
- v = %w{true false}.include?(v) ? '$' + v : v
28
+ v = %w(true false).include?(v) ? '$' + v : v
28
29
  out << "<#{k}>#{v}</#{k}>"
29
30
  end
30
31
  out << '</teamdrive>'
@@ -32,21 +33,36 @@ module TeamdriveApi
32
33
 
33
34
  private
34
35
 
36
+ def check_for(method, hash, params, message)
37
+ keys = [params].flatten
38
+ return if keys.send(method) { |k| hash.key?(k) }
39
+ msg = keys.map { |k| %("#{k}") }.join(', ')
40
+ fail ArgumentError, "Provide #{message} of #{msg}"
41
+ end
42
+
43
+ # make sure at least one of the keys in +of+ exists in +in_hash+. Raise an
44
+ # +ArgumentError+ if not so.
45
+ def require_one(of: [], in_hash: {})
46
+ check_for(:any?, in_hash, of, 'at least one')
47
+ end
48
+
49
+ # make sure all of the keys in +of+ exists in +in_hash+. Raise an
50
+ # +ArgumentError+ if not so.
51
+ def require_all(of: [], in_hash: {})
52
+ check_for(:all?, in_hash, of, 'all')
53
+ end
54
+
35
55
  def send_request(command, data = {})
36
56
  body = payload_for(command, data)
37
57
  res = self.class.post @uri,
38
58
  headers: { 'User-Agent' => "TeamdriveApi v#{TeamdriveApi::VERSION}" },
39
59
  body: body,
40
- query: {
41
- checksum: Digest::MD5.hexdigest(body + @api_checksum_salt)
42
- }
60
+ query: { checksum: Digest::MD5.hexdigest(body + @api_checksum_salt) }
43
61
 
44
62
  res = res['teamdrive'].symbolize_keys
45
63
  unless res[:exception].nil?
46
- fail TeamdriveApi::Error.new(
47
- res[:exception][:primarycode],
48
- res[:exception][:message]
49
- )
64
+ fail TeamdriveApi::Error.new res[:exception][:primarycode],
65
+ res[:exception][:message]
50
66
  end
51
67
  res
52
68
  end
@@ -11,18 +11,56 @@ module TeamdriveApi
11
11
  @uri = URI.join(@host + '/', 'pbas/td2api/api/api.htm').to_s
12
12
  end
13
13
 
14
+ # Assign user to license (added in 1.0.003)
15
+ #
16
+ # @param [String] username
17
+ # @param [String] number License Number
18
+ def assign_user_to_license(username, number)
19
+ res = send_request :assignusertolicense, username: username, number: number
20
+ res[:intresult].eql?('0')
21
+ end
22
+
23
+ # Create license without user (added in 1.0.003)
24
+ #
25
+ # @param [Hash] opts license options
26
+ # @option opts [String] :productname +server+, +client+
27
+ # @option opts [String] :type +monthly+ / +yearly+ / +permanent+
28
+ # @option opts [String] :featurevalue one of +webdavs+, +personal+, +professional+, +enterprise+
29
+ # @option opts [String] :limit Amount (for a client license)
30
+ # @option opts [String] :licensereference An optional external reference. Added with v1.0.004
31
+ # @option opts [String] :contactnumber An optional contact number. Added with v1.0.004
32
+ # @option opts [String] :validuntil An optional valid-until date. Format must be +DD.MM.YYYY+. Added with v1.0.004
33
+ # @option opts [String] :changeid An optional change id for license changes. Added with v1.0.004
34
+ def create_license_without_user(opts = {})
35
+ require_all of: [:productname, :type, :featurevalue], in_hash: opts
36
+ res = send_request :createlicensewithoutuser, opts
37
+ res[:intresult].eql?('0')
38
+ end
39
+
40
+ # Get User Data
41
+ #
42
+ # @param [String] username
43
+ # @param [String] distributor (optional, added in API release 1.0.003)
44
+ def get_user_data(username, distributor = nil)
45
+ send_request(:getuserdata, {
46
+ username: username,
47
+ distributor: distributor
48
+ })
49
+ end
50
+
14
51
  # Remove user (added in +1.0.003+)
15
52
  #
16
53
  # @param [String] username to be deleted
17
54
  # @param [Boolean] delete the user's license aswell
18
- # @param [String] distributor will only be used if allowed by the API (see +APIAllowSettingDistributor+ in the Teamdrive Register docs).
55
+ # @param [String] distributor will only be used if allowed by the API (see
56
+ # +APIAllowSettingDistributor+ in the Teamdrive Register docs).
19
57
  def remove_user(username, delete_license = false, distributor = nil)
20
- res = send_request :removeuser, {
58
+ res = send_request :removeuser,
21
59
  username: username,
22
60
  delete_license: delete_license,
23
61
  distributor: distributor
24
- }
25
- return res[:intresult].eql?('0')
62
+
63
+ res[:intresult].eql?('0')
26
64
  end
27
65
 
28
66
  # Search user
@@ -34,7 +72,7 @@ module TeamdriveApi
34
72
  # @option query [Boolean] :showdevice (false)
35
73
  # @option query [Boolean] :onlyownusers (false)
36
74
  def search_user(query = {})
37
- fail ArgumentError if query.keys.length < 1
75
+ require_one of: [:username, :email], in_hash: query
38
76
  query = {
39
77
  showdevice: false,
40
78
  onlyownusers: false
@@ -1,3 +1,3 @@
1
1
  module TeamdriveApi
2
- VERSION = "0.1.1"
2
+ VERSION = '0.1.2'
3
3
  end
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_runtime_dependency "httparty", "~> 0.13"
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 1.8"
29
+ spec.add_development_dependency "codeclimate-test-reporter"
29
30
  spec.add_development_dependency "minitest", "~> 5.5"
30
31
  spec.add_development_dependency "pry", "~> 0.10"
31
32
  spec.add_development_dependency "rake", "~> 10.0"
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.1.1
4
+ version: 0.1.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-03-23 00:00:00.000000000 Z
11
+ date: 2015-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: minitest
43
57
  requirement: !ruby/object:Gem::Requirement