Class: DogapiDemo::V1::UserService

Inherits:
APIService show all
Defined in:
lib/dogapi-demo/v1/user.rb

Constant Summary collapse

API_VERSION =
"v1"

Instance Method Summary collapse

Methods inherited from APIService

#connect, #initialize, #request, #suppress_error_if_silent

Constructor Details

This class inherits a constructor from DogapiDemo::APIService

Instance Method Details

#create_user(description = {}) ⇒ Object

Create a user

:description => Hash: user description containing ‘handle’ and ‘name’ properties



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dogapi-demo/v1/user.rb', line 33

def create_user(description = {})
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }

    request(Net::HTTP::Post, "/api/#{API_VERSION}/user", params, description, true)
  rescue Exception => e
    suppress_error_if_silent e
  end
end

#disable_user(handle) ⇒ Object

Disable a user

:handle => String: user handle



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/dogapi-demo/v1/user.rb', line 97

def disable_user(handle)
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }

    request(Net::HTTP::Delete, "/api/#{API_VERSION}/user/#{handle}", params, nil, false)
  rescue Exception => e
    suppress_error_if_silent e
  end
end

#get_all_usersObject

Retrieve all users



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/dogapi-demo/v1/user.rb', line 63

def get_all_users()
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }

    request(Net::HTTP::Get, "/api/#{API_VERSION}/user", params, nil, false)
  rescue Exception => e
    suppress_error_if_silent e
  end
end

#get_user(handle) ⇒ Object

Retrieve user information

:handle => String: user handle



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dogapi-demo/v1/user.rb', line 49

def get_user(handle)
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }

    request(Net::HTTP::Get, "/api/#{API_VERSION}/user/#{handle}", params, nil, false)
  rescue Exception => e
    suppress_error_if_silent e
  end
end

#invite(emails, options = {}) ⇒ Object

DEPRECATED: Going forward, we’re using a new and more restful API, the new methods are get_user, create_user, update_user, disable_user



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dogapi-demo/v1/user.rb', line 12

def invite(emails, options = {})
  warn "[DEPRECATION] DogapiDemo::V1::UserService::invite has been deprecated in favor of DogapiDemo::V1::UserService::create_user"
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }

    body = {
      'emails' => emails,
    }.merge options

    request(Net::HTTP::Post, "/api/#{API_VERSION}/invite_users", params, body, true)
  rescue Exception => e
    suppress_error_if_silent e
  end
end

#update_user(handle, description = {}) ⇒ Object

Update a user

:handle => String: user handle :description => Hash: user description optionally containing ‘name’, ‘email’, ‘is_admin’, ‘disabled’ properties



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/dogapi-demo/v1/user.rb', line 81

def update_user(handle, description = {})
  begin
    params = {
      :api_key => @api_key,
      :application_key => @application_key
    }

    request(Net::HTTP::Put, "/api/#{API_VERSION}/user/#{handle}", params, description, true)
  rescue Exception => e
    suppress_error_if_silent e
  end
end