pritunl_api_client 1.2.0 → 1.4.0

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: 8893ac808d0c01beb6358428c5b63d8527463d55
4
- data.tar.gz: 626352f2e452a8d8eb162da04258d6866204acc2
3
+ metadata.gz: 9e7aab97574ccbc72cffee7ab7e38fff8d6cc087
4
+ data.tar.gz: ff948fea79a2d01158132c87a66004dc56121066
5
5
  SHA512:
6
- metadata.gz: 3d2cd77747daec9516ef5994738461a89ce87988d66616115f3b3f40a3fb626c855e569dfae3e158d356b755a667a3a7fc3a8682d91d5c5393736382d5bba4d3
7
- data.tar.gz: 989fc53e24ddd513854465ca42cbe318e87e5f62dd4131126e8e4f3df5b9c7d765d20232c10a05f83fb7e9b6cdac94e4119cfab19095f11c233e919035f2dbd5
6
+ metadata.gz: 93353f991868e733cf931697079040de1cec0de4e1c62a8ba95db34abc1d1ec2efb85f7228ee5f63b991c4b264457d5277fd092ec959b1d3dbabf709dfc15a56
7
+ data.tar.gz: 91da34ec454609c5a5a23abe3a83f71446e24e5a2d7c0005f67133307ae1df5525b9b9bac84918f9989a9b488a0a1dfee89a6e939228c7dc48700a34ccb33a1a
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## v1.4.0 (2016-02-17)
2
+ * Can now download OVPN key file directly from API (rather than just ZIP and TAR key files)
3
+ * Ability to get key files content directly (rather than just download the key files)
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # Pritunl API Client
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/pritunl_api_client.svg)](https://badge.fury.io/rb/pritunl_api_client)
4
+ ![](http://ruby-gem-downloads-badge.herokuapp.com/pritunl_api_client?type=total)
5
+ [![Inline docs](http://inch-ci.org/github/eterry1388/pritunl_api_client.svg?branch=master)](http://inch-ci.org/github/eterry1388/pritunl_api_client)
6
+ [![Dependency Status](https://gemnasium.com/eterry1388/pritunl_api_client.svg)](https://gemnasium.com/eterry1388/pritunl_api_client)
4
7
 
5
8
  API client for Pritunl written in Ruby.
6
9
 
@@ -315,18 +318,33 @@ require 'pritunl_api_client'
315
318
 
316
319
  ## Keys
317
320
 
321
+ If you omit the `path` parameter on any of the `key` APIs below, the file content will be directly returned
322
+ from the method rather than to a downloaded file.
323
+
324
+ ### Download a users key.
325
+
326
+ ```ruby
327
+ @pritunl.key.download( organization_id: org['id'], user_id: user['id'], path: 'output.ovpn' )
328
+ ```
329
+
318
330
  ### Download a users key tar archive.
319
331
 
320
332
  ```ruby
321
333
  @pritunl.key.download_tar( organization_id: org['id'], user_id: user['id'], path: 'output.tar' )
322
334
  ```
323
335
 
324
- ### Download a users onc key zip archive.
336
+ ### Download a users key zip archive.
325
337
 
326
338
  ```ruby
327
339
  @pritunl.key.download_zip( organization_id: org['id'], user_id: user['id'], path: 'output.zip' )
328
340
  ```
329
341
 
342
+ ### Download a users onc key Chromebook profile zip archive.
343
+
344
+ ```ruby
345
+ @pritunl.key.download_chromebook_profile( organization_id: org['id'], user_id: user['id'], path: 'output.zip' )
346
+ ```
347
+
330
348
  ### Generate a temporary url to download a users key archive.
331
349
 
332
350
  ```ruby
@@ -544,8 +562,14 @@ PritunlApiClient
544
562
  Generate two-step auth for user
545
563
  Delete user
546
564
  PritunlApiClient::Key
565
+ Download key
566
+ Get key
567
+ Download tar key
547
568
  Get tar key
569
+ Download zip key
548
570
  Get zip key
571
+ Download chromebook profile onc zip key
572
+ Get chromebook profile onc zip key
549
573
  Get key temporary url
550
574
  PritunlApiClient::Server
551
575
  Create server
@@ -564,8 +588,8 @@ PritunlApiClient
564
588
  Get all settings
565
589
  Update settings
566
590
 
567
- Finished in 1 minute 14.14 seconds (files took 0.12978 seconds to load)
568
- 32 examples, 0 failures
591
+ Finished in 1 minute 11.62 seconds (files took 0.17043 seconds to load)
592
+ 38 examples, 0 failures
569
593
  ```
570
594
 
571
595
  ## License
@@ -8,14 +8,37 @@ module PritunlApiClient
8
8
  @api = api
9
9
  end
10
10
 
11
+ # Download a users key
12
+ #
13
+ # @note User organization must be attached to a server
14
+ # @param organization_id [String]
15
+ # @param user_id [String]
16
+ # @param path [String] Local path to save downloaded file (if omitted, file content fill be returned)
17
+ # @raise [StandardError] if user or servers cannot be found
18
+ # @return [String] Local path to downloaded file or file contents if 'path' was omitted
19
+ def download( organization_id:, user_id:, path: nil )
20
+ temporary_url_id = temporary_url( organization_id: organization_id, user_id: user_id )['id']
21
+ all_users = @api.get( "/user/#{organization_id}" )
22
+ user = all_users.find { |user| user['id'] == user_id }
23
+ fail StandardError, 'Could not find user!' unless user
24
+ servers = user['servers']
25
+ fail StandardError, 'Could not find servers attached to user!' unless servers && servers.count >= 1
26
+ server_id = servers.first['id']
27
+ data = @api.get( "/key/#{temporary_url_id}/#{server_id}.key" )
28
+ return data unless path
29
+ File.write( path, data.force_encoding( 'utf-8' ) )
30
+ path
31
+ end
32
+
11
33
  # Download a users key tar archive
12
34
  #
13
35
  # @param organization_id [String]
14
36
  # @param user_id [String]
15
- # @param path [String] Local path to save downloaded file
16
- # @return [String] Local path to downloaded file
17
- def download_tar( organization_id:, user_id:, path: )
37
+ # @param path [String] Local path to save downloaded file (if omitted, file content fill be returned)
38
+ # @return [String] Local path to downloaded file or file contents if 'path' was omitted
39
+ def download_tar( organization_id:, user_id:, path: nil )
18
40
  data = @api.get( "/key/#{organization_id}/#{user_id}.tar" )
41
+ return data unless path
19
42
  File.write( path, data.force_encoding( 'utf-8' ) )
20
43
  path
21
44
  end
@@ -24,10 +47,11 @@ module PritunlApiClient
24
47
  #
25
48
  # @param organization_id [String]
26
49
  # @param user_id [String]
27
- # @param path [String] Local path to save downloaded file
28
- # @return [String] Local path to downloaded file
29
- def download_zip( organization_id:, user_id:, path: )
50
+ # @param path [String] Local path to save downloaded file (if omitted, file content fill be returned)
51
+ # @return [String] Local path to downloaded file or file contents if 'path' was omitted
52
+ def download_zip( organization_id:, user_id:, path: nil )
30
53
  data = @api.get( "/key/#{organization_id}/#{user_id}.zip" )
54
+ return data unless path
31
55
  File.write( path, data.force_encoding( 'utf-8' ) )
32
56
  path
33
57
  end
@@ -36,10 +60,11 @@ module PritunlApiClient
36
60
  #
37
61
  # @param organization_id [String]
38
62
  # @param user_id [String]
39
- # @param path [String] Local path to save downloaded file
40
- # @return [String] Local path to downloaded file
41
- def download_chromebook_profile( organization_id:, user_id:, path: )
63
+ # @param path [String] Local path to save downloaded file (if omitted, file content fill be returned)
64
+ # @return [String] Local path to downloaded file or file contents if 'path' was omitted
65
+ def download_chromebook_profile( organization_id:, user_id:, path: nil )
42
66
  data = @api.get( "/key_onc/#{organization_id}/#{user_id}.zip" )
67
+ return data unless path
43
68
  File.write( path, data.force_encoding( 'utf-8' ) )
44
69
  path
45
70
  end
@@ -1,3 +1,3 @@
1
1
  module PritunlApiClient
2
- VERSION = '1.2.0'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -15,7 +15,6 @@ Gem::Specification.new do |spec|
15
15
  spec.license = 'MIT'
16
16
 
17
17
  spec.files = `git ls-files -z`.split( "\x0" ).reject { |f| f.match( %r{^(test|spec|features)/} ) }
18
- spec.executables = spec.files.grep( %r{^bin/} ) { |f| File.basename( f ) }
19
18
  spec.require_paths = ['lib']
20
19
 
21
20
  spec.required_ruby_version = '>= 2.1.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pritunl_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Terry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-27 00:00:00.000000000 Z
11
+ date: 2016-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -85,20 +85,17 @@ description: 'API client for Pritunl written in Ruby. Pritunl is a distributed e
85
85
  here: https://pritunl.com/api.html. I am not affiliated with Pritunl.'
86
86
  email:
87
87
  - eterry1388@aol.com
88
- executables:
89
- - console
90
- - setup
88
+ executables: []
91
89
  extensions: []
92
90
  extra_rdoc_files: []
93
91
  files:
94
92
  - ".gitignore"
95
93
  - ".rspec"
94
+ - CHANGELOG.md
96
95
  - Gemfile
97
96
  - LICENSE
98
97
  - README.md
99
98
  - Rakefile
100
- - bin/console
101
- - bin/setup
102
99
  - lib/pritunl_api_client.rb
103
100
  - lib/pritunl_api_client/api.rb
104
101
  - lib/pritunl_api_client/key.rb
@@ -128,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
125
  version: '0'
129
126
  requirements: []
130
127
  rubyforge_project:
131
- rubygems_version: 2.4.8
128
+ rubygems_version: 2.5.1
132
129
  signing_key:
133
130
  specification_version: 4
134
131
  summary: Pritunl Ruby API Client
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'pritunl_api_client'
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
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require 'pry'
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here