code42 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +82 -64
- data/Rakefile +5 -0
- data/code42.gemspec +6 -6
- data/lib/code42/api/computer.rb +22 -0
- data/lib/code42/api/org.rb +60 -0
- data/lib/code42/api/role.rb +24 -0
- data/lib/code42/api/token.rb +32 -0
- data/lib/code42/api/user.rb +72 -0
- data/lib/code42/client.rb +7 -178
- data/lib/code42/user.rb +8 -0
- data/lib/code42/version.rb +1 -1
- data/spec/cassettes/Code42_Client/_create_org/returns_created_org.yml +8 -8
- data/spec/cassettes/Code42_Client/_create_user/returns_created_user.yml +6 -6
- data/spec/cassettes/Code42_Client/_create_user/when_sending_an_invalid_email/raises_an_exception.yml +2 -2
- data/spec/cassettes/Code42_Client/_find_org_by_name/returns_the_org_with_the_specified_name.yml +12 -58
- data/spec/cassettes/Code42_Client/_get_token/returns_valid_tokens.yml +5 -5
- data/spec/cassettes/Code42_Client/_get_token/when_providing_invalid_credentials/should_raise_an_exception.yml +2 -2
- data/spec/cassettes/Code42_Client/_org/when_ID_is_not_passed/returns_my_org.yml +11 -11
- data/spec/cassettes/Code42_Client/_org/when_ID_is_passed_in/returns_a_specific_org.yml +11 -11
- data/spec/cassettes/Code42_Client/_ping/returns_a_ping.yml +5 -5
- data/spec/cassettes/Code42_Client/_user/when_ID_is_not_passed/returns_my_user.yml +10 -10
- data/spec/cassettes/Code42_Client/_user/when_ID_is_passed_in/returns_a_specific_user.yml +10 -10
- data/spec/cassettes/Code42_Client/_user/when_blocked/returns_the_blocked_status.yml +84 -0
- data/spec/cassettes/Code42_Client/_user/when_unblocked/returns_the_blocked_status.yml +113 -0
- data/spec/cassettes/Code42_Client/_user_roles/returns_an_enumerable.yml +7 -7
- data/spec/cassettes/Code42_Client/_validate_token/returns_a_valid_response.yml +10 -10
- data/spec/{crashplan → code42}/client_spec.rb +26 -5
- data/spec/{crashplan → code42}/connection_spec.rb +0 -0
- data/spec/{crashplan → code42}/org_spec.rb +0 -0
- data/spec/{crashplan → code42}/ping_spec.rb +0 -0
- data/spec/{crashplan → code42}/resource_spec.rb +0 -0
- data/spec/{crashplan → code42}/role_spec.rb +0 -0
- data/spec/{crashplan → code42}/settings_spec.rb +0 -0
- data/spec/{crashplan → code42}/token_spec.rb +0 -0
- data/spec/{crashplan → code42}/user_spec.rb +0 -0
- metadata +49 -66
- data/spec/cassettes/Crashplan_Client/_create_org/returns_created_org.yml +0 -47
- data/spec/cassettes/Crashplan_Client/_create_user/returns_created_user.yml +0 -44
- data/spec/cassettes/Crashplan_Client/_create_user/when_sending_an_invalid_email/raises_an_exception.yml +0 -37
- data/spec/cassettes/Crashplan_Client/_find_org_by_name/returns_the_org_with_the_specified_name.yml +0 -55
- data/spec/cassettes/Crashplan_Client/_get_token/returns_valid_tokens.yml +0 -38
- data/spec/cassettes/Crashplan_Client/_get_token/when_providing_invalid_credentials/should_raise_an_exception.yml +0 -37
- data/spec/cassettes/Crashplan_Client/_org/when_ID_is_not_passed/returns_my_org.yml +0 -54
- data/spec/cassettes/Crashplan_Client/_org/when_ID_is_passed_in/returns_a_specific_org.yml +0 -54
- data/spec/cassettes/Crashplan_Client/_ping/returns_a_ping.yml +0 -48
- data/spec/cassettes/Crashplan_Client/_user/when_ID_is_not_passed/returns_my_user.yml +0 -99
- data/spec/cassettes/Crashplan_Client/_user/when_ID_is_passed_in/returns_a_specific_user.yml +0 -53
- data/spec/cassettes/Crashplan_Client/_user_roles/returns_an_enumerable.yml +0 -50
- data/spec/cassettes/Crashplan_Client/_validate_token/returns_a_valid_response.yml +0 -128
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -6,42 +6,52 @@ A Ruby interface to the Code 42 API
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
|
9
|
+
```ruby
|
10
|
+
gem 'code42'
|
11
|
+
```
|
10
12
|
|
11
13
|
And then execute:
|
12
14
|
|
13
|
-
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
14
18
|
|
15
19
|
Or install it yourself as:
|
16
20
|
|
17
|
-
|
21
|
+
```bash
|
22
|
+
$ gem install code42
|
23
|
+
```
|
18
24
|
|
19
25
|
## Configuration
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
```ruby
|
28
|
+
client = Code42::Client.new(
|
29
|
+
host: 'staging.code42.com',
|
30
|
+
port: 1234,
|
31
|
+
https: true,
|
32
|
+
api_root: '/api/',
|
33
|
+
username: 'testuser',
|
34
|
+
password: 'letmein'
|
35
|
+
)
|
36
|
+
```
|
29
37
|
|
30
38
|
### Authentication
|
31
39
|
|
32
|
-
```
|
40
|
+
```ruby
|
33
41
|
token = client.get_token
|
34
42
|
```
|
35
43
|
|
36
44
|
Then you can pass this token for further requests:
|
37
45
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
```ruby
|
47
|
+
client = Code42::Client.new(
|
48
|
+
host: 'staging.code42.com',
|
49
|
+
port: 1234,
|
50
|
+
https: true,
|
51
|
+
api_root: '/api/',
|
52
|
+
token: token
|
53
|
+
)
|
54
|
+
```
|
45
55
|
|
46
56
|
## Resources
|
47
57
|
|
@@ -49,85 +59,89 @@ Then you can pass this token for further requests:
|
|
49
59
|
|
50
60
|
attributes:
|
51
61
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
62
|
+
```ruby
|
63
|
+
[:id,
|
64
|
+
:uid,
|
65
|
+
:status,
|
66
|
+
:username,
|
67
|
+
:email,
|
68
|
+
:first_name,
|
69
|
+
:last_name,
|
70
|
+
:quota_in_bytes,
|
71
|
+
:org_id,
|
72
|
+
:org_uid,
|
73
|
+
:org_name,
|
74
|
+
:active,
|
75
|
+
:blocked,
|
76
|
+
:email_promo,
|
77
|
+
:invited,
|
78
|
+
:org_type,
|
79
|
+
:username_is_an_email,
|
80
|
+
:created_at,
|
81
|
+
:updated_at]
|
82
|
+
```
|
71
83
|
|
72
84
|
### Org
|
73
85
|
|
74
86
|
attributes:
|
75
87
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
88
|
+
```ruby
|
89
|
+
[:id,
|
90
|
+
:uid,
|
91
|
+
:name,
|
92
|
+
:status,
|
93
|
+
:active,
|
94
|
+
:blocked,
|
95
|
+
:parent_id,
|
96
|
+
:type,
|
97
|
+
:external_id,
|
98
|
+
:hierarchy_counts,
|
99
|
+
:config_inheritance_counts,
|
100
|
+
:created_at,
|
101
|
+
:updated_at,
|
102
|
+
:registration_key,
|
103
|
+
:reporting,
|
104
|
+
:custom_config,
|
105
|
+
:settings,
|
106
|
+
:settings_inherited,
|
107
|
+
:settings_summary]
|
108
|
+
```
|
95
109
|
|
96
110
|
## Usage
|
97
111
|
|
98
112
|
### Ping a host
|
99
113
|
|
100
|
-
```
|
114
|
+
```ruby
|
101
115
|
success = client.ping.success?
|
102
116
|
```
|
103
117
|
|
104
118
|
### Fetch the currently authorized API user
|
105
119
|
|
106
|
-
```
|
120
|
+
```ruby
|
107
121
|
user = client.user
|
108
122
|
```
|
109
123
|
|
110
|
-
###
|
124
|
+
### Fetch a user by ID
|
111
125
|
|
112
|
-
```
|
126
|
+
```ruby
|
113
127
|
user = client.user(42)
|
114
128
|
```
|
115
129
|
|
116
130
|
### Fetch the Org for the currently authorized API user
|
117
131
|
|
118
|
-
```
|
132
|
+
```ruby
|
119
133
|
org = client.org
|
120
134
|
```
|
121
135
|
|
122
136
|
### Fetch a specific Org by ID
|
123
137
|
|
124
|
-
```
|
138
|
+
```ruby
|
125
139
|
org = client.org(42)
|
126
140
|
```
|
127
141
|
|
128
142
|
### Validate a token
|
129
143
|
|
130
|
-
```
|
144
|
+
```ruby
|
131
145
|
client.validate_token(token).valid?
|
132
146
|
```
|
133
147
|
|
@@ -149,6 +163,10 @@ https://github.com/code42/code42_api_ruby/wiki
|
|
149
163
|
|
150
164
|
[@melissavoegeli](http://github.com/melissavoegeli)
|
151
165
|
|
166
|
+
## Contributors
|
167
|
+
|
168
|
+
[@jrmehle](http://github.com/jrmehle)
|
169
|
+
|
152
170
|
# Code 42 README
|
153
171
|
|
154
172
|
## What is this?
|
data/Rakefile
CHANGED
data/code42.gemspec
CHANGED
@@ -12,12 +12,12 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.summary = %q{...}
|
13
13
|
gem.homepage = ""
|
14
14
|
|
15
|
-
gem.add_development_dependency 'rspec'
|
16
|
-
gem.add_development_dependency 'webmock'
|
17
|
-
gem.add_development_dependency 'vcr'
|
18
|
-
gem.add_dependency 'faraday'
|
19
|
-
gem.add_dependency 'activesupport',
|
20
|
-
gem.add_dependency 'faraday_middleware'
|
15
|
+
gem.add_development_dependency 'rspec', '~> 2.11.0'
|
16
|
+
gem.add_development_dependency 'webmock', '~> 1.11.0'
|
17
|
+
gem.add_development_dependency 'vcr', '~> 2.4.0'
|
18
|
+
gem.add_dependency 'faraday', '~> 0.8.7'
|
19
|
+
gem.add_dependency 'activesupport', '~> 3.2.0'
|
20
|
+
gem.add_dependency 'faraday_middleware', '~> 0.9.0'
|
21
21
|
|
22
22
|
gem.files = `git ls-files`.split($/)
|
23
23
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Code42
|
2
|
+
module API
|
3
|
+
module Computer
|
4
|
+
### Computers :get, :put ###
|
5
|
+
|
6
|
+
# Returns one computer or http status 404
|
7
|
+
# @return [Code42::Computer] The requested computer
|
8
|
+
# @param id [String, Integer] A computer ID
|
9
|
+
def computer(id, params = {})
|
10
|
+
object_from_response(Code42::Computer, :get, "computer/#{id}", params)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns a list of computers
|
14
|
+
# @return [Array] The list of computers
|
15
|
+
# @param params [Hash] A hash of valid search parameters for computers
|
16
|
+
def computers(params = {})
|
17
|
+
params.merge!(key: 'computers')
|
18
|
+
objects_from_response(Code42::Computer, :get, 'computer', params)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Code42
|
2
|
+
module API
|
3
|
+
module Org
|
4
|
+
### Orgs :post, :get, :put, :delete ###
|
5
|
+
|
6
|
+
# Creates blue org as well as user for the org
|
7
|
+
# @return [Code42::Org] The created org
|
8
|
+
# @param attrs [Hash] A hash of attributes to assign to created org
|
9
|
+
# @example
|
10
|
+
# client.create_org(:company => "test", :email => "test@test.com", :firstname => "test", :lastname => "test")
|
11
|
+
def create_pro_org(attrs = {})
|
12
|
+
object_from_response(Code42::Org, :post, "proOrgChannel", attrs)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Creates an org
|
16
|
+
# @return [Code42::Org] The created org
|
17
|
+
# @param attrs [Hash] A hash of attributes to assign to created org
|
18
|
+
# @example
|
19
|
+
# client.create_org(:name => 'Acme Org', :parent_id => 2)
|
20
|
+
def create_org(attrs = {})
|
21
|
+
object_from_response(Code42::Org, :post, "org", attrs)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns information for a given org
|
25
|
+
# @return [Code42::Org] The requested org
|
26
|
+
# @param id [String, Integer] A code42 user ID
|
27
|
+
def org(id = "my", params = {})
|
28
|
+
object_from_response(Code42::Org, :get, "org/#{id}", params)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns an org for a given name
|
32
|
+
# @return [Code42::Org] The requested org
|
33
|
+
# @param name [String] A Code42 org name
|
34
|
+
# FIXME: This needs to change when the API implements a better way.
|
35
|
+
def find_org_by_name(name)
|
36
|
+
search_orgs(name).select { |o| o.name == name }.first
|
37
|
+
end
|
38
|
+
|
39
|
+
# Searches orgs for a query string
|
40
|
+
# @return [Array] An array of matching orgs
|
41
|
+
# @param query [String] A string to search for
|
42
|
+
def search_orgs(query)
|
43
|
+
orgs(q: query)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns a list of up to 100 orgs
|
47
|
+
# @return [Array] An array of matching orgs
|
48
|
+
# @param params [Hash] A hash of parameters to match results against
|
49
|
+
def orgs(params = {})
|
50
|
+
params.merge!(key: 'orgs')
|
51
|
+
objects_from_response(Code42::Org, :get, 'org', params)
|
52
|
+
end
|
53
|
+
|
54
|
+
def update_org(id = 'my', attrs = {})
|
55
|
+
object_from_response(Code42::Org, :put, "org/#{id}", attrs)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Code42
|
2
|
+
module API
|
3
|
+
module Role
|
4
|
+
### Roles :post, :get ###
|
5
|
+
|
6
|
+
# Assigns a role to a user
|
7
|
+
# @return [Code42::Role] The assigned role
|
8
|
+
# @param attrs [Hash] A hash of attributes for assigning a user role
|
9
|
+
# @example
|
10
|
+
# client.assign_role(:user_id => 2, :role_name => 'Admin')
|
11
|
+
def assign_role(attrs = {})
|
12
|
+
object_from_response(Code42::Role, :post, 'UserRole', attrs)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a list of roles for a given user
|
16
|
+
# @return [Code42::RoleCollection] A collection of matching roles
|
17
|
+
# @param id [String, Integer] The id of the user to return roles for
|
18
|
+
def user_roles(id = 'my')
|
19
|
+
collection_from_response(Code42::RoleCollection, Code42::Role, :get, "userRole/#{id}")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Code42
|
2
|
+
module API
|
3
|
+
module Token
|
4
|
+
### Authentication With Tokens :post, :get, :delete ###
|
5
|
+
|
6
|
+
# Gets a token for the currently authorized user
|
7
|
+
def get_token
|
8
|
+
object_from_response(Code42::Token, :post, "authToken")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns LoginToken and ServerUrl
|
12
|
+
# @return [CrashPlan::Token] Token to pass to ServerUrl's AuthToken resource
|
13
|
+
def get_login_token
|
14
|
+
object_from_response(Code42::Token, :post, "loginToken")
|
15
|
+
end
|
16
|
+
|
17
|
+
# Validates an authorization token
|
18
|
+
# @return [Code42::TokenValidation]
|
19
|
+
# @param token [Code42::Token, String] The token to validate
|
20
|
+
def validate_token(token)
|
21
|
+
object_from_response(Code42::TokenValidation, :get, "authToken/#{token.to_s}")
|
22
|
+
end
|
23
|
+
|
24
|
+
# Manually expires a token
|
25
|
+
# @param token [Code42::Token, String] A token to expire (leave blank to expire currently used token)
|
26
|
+
def delete_token(token = nil)
|
27
|
+
token = token || settings.token
|
28
|
+
delete "authToken/#{token.to_s}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Code42
|
2
|
+
module API
|
3
|
+
module User
|
4
|
+
### Users :post, :get ###
|
5
|
+
|
6
|
+
# Creates a user
|
7
|
+
# @return [Code42::User] The created user
|
8
|
+
# @param attrs [Hash] A hash of attributes to assign to created user
|
9
|
+
# @example
|
10
|
+
# client.create_user(:username => 'testuser', password: 'letmein', email: 'test@example.com', org_id: 3)
|
11
|
+
def create_user(attrs = {})
|
12
|
+
object_from_response(Code42::User, :post, "user", attrs)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns information for a given user
|
16
|
+
# @return [Code42::User] The requested user
|
17
|
+
# @param id_or_username [String, Integer] A code42 user ID or username
|
18
|
+
def user(id_or_username = "my", params = {})
|
19
|
+
if id_or_username.is_a?(Fixnum) || id_or_username == 'my'
|
20
|
+
find_user_by_id id_or_username, params
|
21
|
+
else
|
22
|
+
find_user_by_username id_or_username, params
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns a user for a given id
|
27
|
+
def find_user_by_id(id = 'my', params = {})
|
28
|
+
object_from_response(Code42::User, :get, "user/#{id}", params)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns a user for a given username
|
32
|
+
def find_user_by_username(username, params = {})
|
33
|
+
params.merge!(username: username)
|
34
|
+
users(params).first
|
35
|
+
end
|
36
|
+
|
37
|
+
# Returns a user for a given channel id
|
38
|
+
# @return [Code42::User] The requested user
|
39
|
+
# @param channel_id [String, Integer] A code42 User
|
40
|
+
def find_user_by_channel_id(channel_id = 1)
|
41
|
+
object_from_response(Code42::User, :get, "userChannel?channelCustomerId=#{channel_id}")
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns a list of up to 100 users
|
45
|
+
# @return [Array] An array of matching users
|
46
|
+
# @param params [Hash] A hash of parameters to match results against
|
47
|
+
def users(params = {})
|
48
|
+
params.merge!(key: 'users')
|
49
|
+
objects_from_response(Code42::User, :get, 'user', params)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Check if user exists with given username.
|
53
|
+
def user_exists?(username)
|
54
|
+
users(username: username).present?
|
55
|
+
end
|
56
|
+
|
57
|
+
# Block a user from logging in
|
58
|
+
# @return true if blocked
|
59
|
+
# @params id [Integer, String] The user ID you want to block
|
60
|
+
def block_user(id)
|
61
|
+
put("UserBlock/#{id}")
|
62
|
+
end
|
63
|
+
|
64
|
+
# Unblock a previously blocked user
|
65
|
+
# @return true if unblocked
|
66
|
+
# @params id [Integer, String] The user ID you want to unblock
|
67
|
+
def unblock_user(id)
|
68
|
+
delete("UserBlock/#{id}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|