Module: Crowdin::ApiResources::Users

Defined in:
lib/crowdin-api/api_resources/users.rb

Instance Method Summary collapse

Instance Method Details

#add_project_member(query = {}, project_id = config.project_id) ⇒ Object

– For Enterprise mode only –



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/crowdin-api/api_resources/users.rb', line 41

def add_project_member(query = {}, project_id = config.project_id)
  enterprise_mode? || raise_only_for_enterprise_mode_error
  project_id       || raise_project_id_is_required_error

  request = Web::Request.new(
    connection,
    :post,
    "#{config.target_api_url}/projects/#{project_id}/members",
    { params: query }
  )
  Web::SendRequest.new(request).perform
end

#delete_member_from_project(member_id = nil, query = {}, project_id = config.project_id) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/crowdin-api/api_resources/users.rb', line 81

def delete_member_from_project(member_id = nil, query = {}, project_id = config.project_id)
  enterprise_mode? || raise_only_for_enterprise_mode_error
  member_id        || raise_parameter_is_required_error(:member_id)
  project_id       || raise_project_id_is_required_error

  response = ::RestClient::Request.execute(
    {
      method: :delete,
      url: config.base_url + config.target_api_url + "/projects/#{project_id}/members/#{member_id}",
      payload: query.to_json
    }.merge(@options)
  )

  response.body.empty? ? response.code : JSON.parse(response.body)
rescue StandardError => e
  e.message
end

#delete_user(user_id = nil) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
# File 'lib/crowdin-api/api_resources/users.rb', line 135

def delete_user(user_id = nil)
  enterprise_mode? || raise_only_for_enterprise_mode_error
  user_id          || raise_parameter_is_required_error(:user_id)

  request = Web::Request.new(
    connection,
    :delete,
    "#{config.target_api_url}/users/#{user_id}"
  )
  Web::SendRequest.new(request).perform
end

#edit_user(user_id = nil, query = {}) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/crowdin-api/api_resources/users.rb', line 147

def edit_user(user_id = nil, query = {})
  enterprise_mode? || raise_only_for_enterprise_mode_error
  user_id          || raise_parameter_is_required_error(:user_id)

  request = Web::Request.new(
    connection,
    :patch,
    "#{config.target_api_url}/users/#{user_id}",
    { params: query }
  )
  Web::SendRequest.new(request).perform
end

#get_authenticated_userObject



6
7
8
9
10
11
12
13
# File 'lib/crowdin-api/api_resources/users.rb', line 6

def get_authenticated_user
  request = Web::Request.new(
    connection,
    :get,
    "#{config.target_api_url}/user"
  )
  Web::SendRequest.new(request).perform
end

#get_member_info(member_id = nil, project_id = config.project_id) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/crowdin-api/api_resources/users.rb', line 27

def get_member_info(member_id = nil, project_id = config.project_id)
  member_id  || raise_parameter_is_required_error(:member_id)
  project_id || raise_project_id_is_required_error

  request = Web::Request.new(
    connection,
    :get,
    "#{config.target_api_url}/projects/#{project_id}/members/#{member_id}"
  )
  Web::SendRequest.new(request).perform
end

#get_project_member_permissions(member_id = nil, project_id = config.project_id) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/crowdin-api/api_resources/users.rb', line 54

def get_project_member_permissions(member_id = nil, project_id = config.project_id)
  enterprise_mode? || raise_only_for_enterprise_mode_error
  member_id        || raise_parameter_is_required_error(:member_id)
  project_id       || raise_project_id_is_required_error

  request = Web::Request.new(
    connection,
    :get,
    "#{config.target_api_url}/projects/#{project_id}/members/#{member_id}"
  )
  Web::SendRequest.new(request).perform
end

#get_user(user_id = nil) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
# File 'lib/crowdin-api/api_resources/users.rb', line 123

def get_user(user_id = nil)
  enterprise_mode? || raise_only_for_enterprise_mode_error
  user_id          || raise_parameter_is_required_error(:user_id)

  request = Web::Request.new(
    connection,
    :get,
    "#{config.target_api_url}/users/#{user_id}"
  )
  Web::SendRequest.new(request).perform
end

#invite_user(query = {}) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/crowdin-api/api_resources/users.rb', line 111

def invite_user(query = {})
  enterprise_mode? || raise_only_for_enterprise_mode_error

  request = Web::Request.new(
    connection,
    :post,
    "#{config.target_api_url}/users",
    { params: query }
  )
  Web::SendRequest.new(request).perform
end

#list_project_members(query = {}, project_id = config.project_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/crowdin-api/api_resources/users.rb', line 15

def list_project_members(query = {}, project_id = config.project_id)
  project_id || raise_project_id_is_required_error

  request = Web::Request.new(
    connection,
    :get,
    "#{config.target_api_url}/projects/#{project_id}/members",
    { params: query }
  )
  Web::SendRequest.new(request).perform
end

#list_users(query = {}) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/crowdin-api/api_resources/users.rb', line 99

def list_users(query = {})
  enterprise_mode? || raise_only_for_enterprise_mode_error

  request = Web::Request.new(
    connection,
    :get,
    "#{config.target_api_url}/users",
    { params: query }
  )
  Web::SendRequest.new(request).perform
end

#replace_project_permissions(member_id = nil, query = {}, project_id = config.project_id) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/crowdin-api/api_resources/users.rb', line 67

def replace_project_permissions(member_id = nil, query = {}, project_id = config.project_id)
  enterprise_mode? || raise_only_for_enterprise_mode_error
  member_id        || raise_parameter_is_required_error(:member_id)
  project_id       || raise_project_id_is_required_error

  request = Web::Request.new(
    connection,
    :put,
    "#{config.target_api_url}/projects/#{project_id}/members/#{member_id}",
    { params: query }
  )
  Web::SendRequest.new(request).perform
end