bwapi 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.travis.yml +10 -0
- data/Gemfile +6 -0
- data/LICENCE.md +20 -0
- data/README.md +15 -0
- data/bin/bwapi +2 -0
- data/bwapi.gemspec +26 -0
- data/lib/bwapi.rb +28 -0
- data/lib/bwapi/authentication.rb +42 -0
- data/lib/bwapi/client.rb +54 -0
- data/lib/bwapi/client/admin.rb +35 -0
- data/lib/bwapi/client/admin/become.rb +21 -0
- data/lib/bwapi/client/admin/search.rb +41 -0
- data/lib/bwapi/client/admin/sub_clients.rb +109 -0
- data/lib/bwapi/client/admin/users.rb +95 -0
- data/lib/bwapi/client/admin/users/sharing.rb +35 -0
- data/lib/bwapi/client/brandwatch.rb +33 -0
- data/lib/bwapi/client/brandwatch/become.rb +19 -0
- data/lib/bwapi/client/brandwatch/client_modules.rb +26 -0
- data/lib/bwapi/client/client.rb +22 -0
- data/lib/bwapi/client/error_codes.rb +14 -0
- data/lib/bwapi/client/filters.rb +14 -0
- data/lib/bwapi/client/logout.rb +24 -0
- data/lib/bwapi/client/me.rb +42 -0
- data/lib/bwapi/client/oauth.rb +78 -0
- data/lib/bwapi/client/ping.rb +42 -0
- data/lib/bwapi/client/projects.rb +94 -0
- data/lib/bwapi/client/projects/categories.rb +70 -0
- data/lib/bwapi/client/projects/data.rb +62 -0
- data/lib/bwapi/client/projects/data_download.rb +49 -0
- data/lib/bwapi/client/projects/facebook_queries.rb +55 -0
- data/lib/bwapi/client/projects/queries.rb +99 -0
- data/lib/bwapi/client/projects/queries/backfill.rb +63 -0
- data/lib/bwapi/client/projects/queries/date_range.rb +67 -0
- data/lib/bwapi/client/projects/queries/mentions.rb +53 -0
- data/lib/bwapi/client/projects/query_groups.rb +70 -0
- data/lib/bwapi/client/projects/sharing.rb +57 -0
- data/lib/bwapi/client/projects/signals.rb +39 -0
- data/lib/bwapi/client/projects/summary.rb +21 -0
- data/lib/bwapi/client/projects/tags.rb +61 -0
- data/lib/bwapi/client/projects/users.rb +17 -0
- data/lib/bwapi/client/projects/workflow.rb +17 -0
- data/lib/bwapi/client/query_validation.rb +27 -0
- data/lib/bwapi/client/sso.rb +18 -0
- data/lib/bwapi/client/test_search.rb +14 -0
- data/lib/bwapi/client/user.rb +58 -0
- data/lib/bwapi/client/user/notifications.rb +36 -0
- data/lib/bwapi/configuration.rb +59 -0
- data/lib/bwapi/connection.rb +33 -0
- data/lib/bwapi/error.rb +42 -0
- data/lib/bwapi/request.rb +93 -0
- data/lib/bwapi/version.rb +3 -0
- data/lib/faraday/response/brandwatch_error.rb +25 -0
- data/lib/faraday/utils/utils.rb +25 -0
- data/spec/bwapi/authentication_spec.rb +57 -0
- data/spec/bwapi/client_spec.rb +205 -0
- data/spec/bwapi_spec.rb +23 -0
- data/spec/fixtures/.netrc +3 -0
- data/spec/helper.rb +12 -0
- metadata +178 -0
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'bwapi/client/admin/users/sharing'
|
2
|
+
|
3
|
+
module BWAPI
|
4
|
+
class Client
|
5
|
+
module Admin
|
6
|
+
module Clients
|
7
|
+
module Users
|
8
|
+
|
9
|
+
# Get all users for client
|
10
|
+
#
|
11
|
+
# @param id [Integer] Id of the client
|
12
|
+
# @param opts [Hash] options hash of parameters
|
13
|
+
# @option opts [Integer] page Page of projects to retrieve
|
14
|
+
# @option opts [Integer] pageSize Results per page of results
|
15
|
+
# @return [Hashie::Mash] All client users
|
16
|
+
def client_users id, opts={}
|
17
|
+
get "admin/clients/#{id}/users", opts
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get a specific user in client
|
21
|
+
#
|
22
|
+
# @param client_id [Integer] Id of the client
|
23
|
+
# @param user_id [Integer] Id of the user
|
24
|
+
# @return [Hashie::Mash] Specific client user
|
25
|
+
def get_client_user client_id, user_id
|
26
|
+
get "admin/clients/#{client_id}/users/#{user_id}"
|
27
|
+
end
|
28
|
+
alias :get_user :get_client_user
|
29
|
+
|
30
|
+
|
31
|
+
# Create a new client user
|
32
|
+
#
|
33
|
+
# @param id [Integer] Id of the client
|
34
|
+
# @param opts [Hash] options Hash of parameters
|
35
|
+
# @option opts [Integer] id Id of the user
|
36
|
+
# @option opts [Hash] tags The users assigned tags
|
37
|
+
# @option opts [String] passwordConfirmation The confirmed password
|
38
|
+
# @option opts [Boolean] enabled The status of the user
|
39
|
+
# @option opts [String] lastName The last name of the user
|
40
|
+
# @option opts [String] phone The users phone number
|
41
|
+
# @option opts [String] department The users department
|
42
|
+
# @option opts [String] job The users job
|
43
|
+
# @option opts [String] messenger The users IM details
|
44
|
+
# @option opts [String] password The password of the user
|
45
|
+
# @option opts [Integer] clientId The users client id
|
46
|
+
# @option opts [String] username The users username
|
47
|
+
# @option opts [String] address The users address
|
48
|
+
# @option opts [String] uiRole The users ui role
|
49
|
+
# @option opts [Array] apiRole The users api role
|
50
|
+
# @option opts [String] firstName The users first name
|
51
|
+
# @option opts [String] mobile The users mobile number
|
52
|
+
# @option opts [Date] creationDate Date the user was created on
|
53
|
+
# @return [Hashie::Mash] New user
|
54
|
+
def create_client_user id, opts
|
55
|
+
post "admin/clients/#{id}/users", opts
|
56
|
+
end
|
57
|
+
alias :create_user :create_client_user
|
58
|
+
|
59
|
+
# Update an existing client user
|
60
|
+
#
|
61
|
+
# @param client_id [Integer] Id of the client
|
62
|
+
# @param user_id [Integer] Id of the user
|
63
|
+
# @param opts [Hash] options Hash of parameters
|
64
|
+
# @option opts [Integer] id Id of the user
|
65
|
+
# @option opts [Hash] tags The users assigned tags
|
66
|
+
# @option opts [String] passwordConfirmation The confirmed password
|
67
|
+
# @option opts [Boolean] enabled The status of the user
|
68
|
+
# @option opts [String] lastName The last name of the user
|
69
|
+
# @option opts [String] phone The users phone number
|
70
|
+
# @option opts [String] department The users department
|
71
|
+
# @option opts [String] job The users job
|
72
|
+
# @option opts [String] messenger The users IM details
|
73
|
+
# @option opts [String] password The password of the user
|
74
|
+
# @option opts [Integer] clientId The users client id
|
75
|
+
# @option opts [String] username The users username
|
76
|
+
# @option opts [String] address The users address
|
77
|
+
# @option opts [String] uiRole The users ui role
|
78
|
+
# @option opts [Array] apiRole The users api role
|
79
|
+
# @option opts [String] firstName The users first name
|
80
|
+
# @option opts [String] mobile The users mobile number
|
81
|
+
# @option opts [Date] creationDate Date the user was created on
|
82
|
+
# @return [Hashie::Mash] New user
|
83
|
+
def update_client_user client_id, user_id, opts
|
84
|
+
put "admin/clients/#{client_id}/users/#{user_id}", opts
|
85
|
+
end
|
86
|
+
alias :update_user :update_client_user
|
87
|
+
|
88
|
+
|
89
|
+
include BWAPI::Client::Admin::Clients::Users::Sharing
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module BWAPI
|
2
|
+
class Client
|
3
|
+
module Admin
|
4
|
+
module Clients
|
5
|
+
module Users
|
6
|
+
module Sharing
|
7
|
+
|
8
|
+
# Get a list of project shares for user
|
9
|
+
#
|
10
|
+
# @param client_id [Integer] Id of the client
|
11
|
+
# @param user_id [Integer] Id of the user
|
12
|
+
# @return [Hashie::Mash] All shares for client user
|
13
|
+
def client_users_sharing client_id, user_id
|
14
|
+
get "admin/client/#{client_id}/users/#{user_id}/sharing"
|
15
|
+
end
|
16
|
+
alias :users_sharing :client_users_sharing
|
17
|
+
|
18
|
+
# Update a list of project shares for user
|
19
|
+
#
|
20
|
+
# @param client_id [Integer] Id of the client
|
21
|
+
# @param user_id [Integer] Id of the user
|
22
|
+
# @param opts [Hash] options Hash of parameters
|
23
|
+
# @option opts [Array] ProjectShareDTO The shares of the user
|
24
|
+
# @return [Hashie::Mash] Updated shares for client user
|
25
|
+
def update_client_users_sharing client_id, user_id, opts
|
26
|
+
get "admin/client/#{client_id}/users/#{user_id}/sharing", opts
|
27
|
+
end
|
28
|
+
alias :update_users_sharing :update_client_users_sharing
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'bwapi/client/brandwatch/become'
|
2
|
+
require 'bwapi/client/brandwatch/client_modules'
|
3
|
+
|
4
|
+
module BWAPI
|
5
|
+
class Client
|
6
|
+
module Brandwatch
|
7
|
+
|
8
|
+
# Create a new data download in project
|
9
|
+
#
|
10
|
+
# @param id [Integer] Id of project
|
11
|
+
# @param opts [Hash] options hash of parameters
|
12
|
+
# @option opts [Integer] projectId Id of the project
|
13
|
+
# @option opts [Integer] id Id of the data download
|
14
|
+
# @option opts [Integer] queryId Id of the query
|
15
|
+
# @option opts [Int] percentComplete The percentage complete of data download
|
16
|
+
# @option opts [String] status The status of the download
|
17
|
+
# @option opts [String] queryName The query name of the data download
|
18
|
+
# @option opts [Date] endDate The end date of the data download
|
19
|
+
# @option opts [Date] requestDate The request date of the data download
|
20
|
+
# @option opts [String] downloadLinkXLS The link to download the XLS format
|
21
|
+
# @option opts [String] downloadLinkCSV The link to download the CSV format
|
22
|
+
# @option opts [Array] additionalColumns The additional columns for the data download
|
23
|
+
# @return [Hashie::Mash] New data download
|
24
|
+
def brandwatch_data_download id, opts
|
25
|
+
post "brandwatch/#{project_id}/datadownload", opts
|
26
|
+
end
|
27
|
+
|
28
|
+
include BWAPI::Client::Brandwatch::Become
|
29
|
+
include BWAPI::Client::Brandwatch::ClientModules
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module BWAPI
|
2
|
+
class Client
|
3
|
+
module Brandwatch
|
4
|
+
module Become
|
5
|
+
|
6
|
+
# Become user
|
7
|
+
#
|
8
|
+
# @note must be a super admin user
|
9
|
+
#
|
10
|
+
# @param id [Integer] The user id
|
11
|
+
# @return [Hashie::Mash] User credentials
|
12
|
+
def brandwatch_become id
|
13
|
+
get "brandwatch/become/#{id}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module BWAPI
|
2
|
+
class Client
|
3
|
+
module Brandwatch
|
4
|
+
module ClientModules
|
5
|
+
|
6
|
+
# Get a specific clients modules
|
7
|
+
#
|
8
|
+
# @param id [Integer] Id of the client
|
9
|
+
# @return [Hashie::Mash] Specific clients modules
|
10
|
+
def brandwatch_client_modules id
|
11
|
+
get "brandwatch/clientModules/#{id}"
|
12
|
+
end
|
13
|
+
|
14
|
+
# Update brandwatch client modules
|
15
|
+
#
|
16
|
+
# @param opts [Hash] options Hash of parameters
|
17
|
+
# @option opts [Array] ClientModules Client Modules to edit
|
18
|
+
# @return [Hashie::Mash] Update client modules
|
19
|
+
def update_brandwatch_client_module opts
|
20
|
+
put "brandwatch/clientModules", opts
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BWAPI
|
2
|
+
class Client
|
3
|
+
module Client
|
4
|
+
|
5
|
+
# Get the current users client
|
6
|
+
#
|
7
|
+
# @return [Hashie::Mash] Client information
|
8
|
+
def client
|
9
|
+
get "client"
|
10
|
+
end
|
11
|
+
|
12
|
+
# Get the current users client modules
|
13
|
+
#
|
14
|
+
# @return [Hashie::Mash] Client module information
|
15
|
+
def client_modules
|
16
|
+
get "client/modules"
|
17
|
+
end
|
18
|
+
alias :modules :client_modules
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module BWAPI
|
2
|
+
class Client
|
3
|
+
module Logout
|
4
|
+
|
5
|
+
# Logout user
|
6
|
+
#
|
7
|
+
# @return [Hashie::Mash] Logout information
|
8
|
+
def logout
|
9
|
+
begin
|
10
|
+
get "logout"
|
11
|
+
ensure
|
12
|
+
self.username = nil
|
13
|
+
self.password = nil
|
14
|
+
self.access_token = nil
|
15
|
+
self.client_id = nil
|
16
|
+
self.access_token = nil
|
17
|
+
self.refresh_token = nil
|
18
|
+
self.expires_in = nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module BWAPI
|
2
|
+
class Client
|
3
|
+
module Me
|
4
|
+
|
5
|
+
# Get user information
|
6
|
+
#
|
7
|
+
# @return [Hashie::Mash] User information
|
8
|
+
def me
|
9
|
+
get 'me'
|
10
|
+
end
|
11
|
+
|
12
|
+
# Get users client name
|
13
|
+
#
|
14
|
+
# @return [String] Users client name
|
15
|
+
def client_name
|
16
|
+
me.client.name
|
17
|
+
end
|
18
|
+
|
19
|
+
# Get users client id
|
20
|
+
#
|
21
|
+
# @return [String] Users client id
|
22
|
+
def client_id
|
23
|
+
me.client.id
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get users client id
|
27
|
+
#
|
28
|
+
# @return [String] Users client id
|
29
|
+
def client_id
|
30
|
+
me.client.id
|
31
|
+
end
|
32
|
+
|
33
|
+
# Get users id
|
34
|
+
#
|
35
|
+
# @return [String] Users role
|
36
|
+
def user_id
|
37
|
+
me.id
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module BWAPI
|
2
|
+
class Client
|
3
|
+
module OAuth
|
4
|
+
|
5
|
+
# Authenticate a user
|
6
|
+
#
|
7
|
+
# @param opts [Hash] options hash of parameters
|
8
|
+
# @option opts [String] username User name of user
|
9
|
+
# @option opts [String] password User name of user
|
10
|
+
# @option opts [String] grant_type Grant type of user
|
11
|
+
# @option opts [String] client_secret Client secret
|
12
|
+
# @option opts [String] client_id Client id
|
13
|
+
# @option opts [String] force_urlencoded Force urlencoded
|
14
|
+
def oauth_token opts={}
|
15
|
+
opts = {
|
16
|
+
username: username,
|
17
|
+
password: password,
|
18
|
+
grant_type: 'password',
|
19
|
+
client_secret: client_secret,
|
20
|
+
client_id: client_id,
|
21
|
+
force_urlencoded: true
|
22
|
+
}.merge opts
|
23
|
+
|
24
|
+
begin
|
25
|
+
creds = post 'oauth/token', opts
|
26
|
+
rescue BWAPI::BWError
|
27
|
+
return false
|
28
|
+
else
|
29
|
+
self.access_token = creds.access_token
|
30
|
+
self.expires_in = creds.expires_in
|
31
|
+
|
32
|
+
if application_client?
|
33
|
+
self.refresh_token = creds.refresh_token
|
34
|
+
end
|
35
|
+
|
36
|
+
return true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
alias :login :oauth_token
|
40
|
+
|
41
|
+
# Refresh a authenticated users oauth_token
|
42
|
+
#
|
43
|
+
# @param opts [Hash] options hash of parameters
|
44
|
+
# @option opts [String] username User name of user
|
45
|
+
# @option opts [String] password User name of user
|
46
|
+
# @option opts [String] grant_type Grant type of user
|
47
|
+
# @option opts [String] client_id Client id
|
48
|
+
# @option opts [String] force_urlencoded Force urlencoded
|
49
|
+
def oauth_refresh_token opts={}
|
50
|
+
opts = {
|
51
|
+
username: username,
|
52
|
+
password: password,
|
53
|
+
refresh_token: refresh_token,
|
54
|
+
grant_type: 'refresh_token',
|
55
|
+
client_id: client_id,
|
56
|
+
force_urlencoded: true
|
57
|
+
}.merge opts
|
58
|
+
|
59
|
+
begin
|
60
|
+
creds = post 'oauth/token', opts
|
61
|
+
rescue BWAPI::BWError
|
62
|
+
return false
|
63
|
+
else
|
64
|
+
self.access_token = creds.access_token
|
65
|
+
self.expires_in = creds.expires_in
|
66
|
+
|
67
|
+
if application_client?
|
68
|
+
self.access_token = creds.access_token
|
69
|
+
end
|
70
|
+
|
71
|
+
return true
|
72
|
+
end
|
73
|
+
end
|
74
|
+
alias :refresh :oauth_refresh_token
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module BWAPI
|
2
|
+
class Client
|
3
|
+
module Ping
|
4
|
+
|
5
|
+
# Get ping checking access and available HTTP verbs
|
6
|
+
#
|
7
|
+
# @return [Hashie::Mash] User id and name
|
8
|
+
def get_ping
|
9
|
+
get "ping"
|
10
|
+
end
|
11
|
+
|
12
|
+
# Post ping checking access and available HTTP verbs
|
13
|
+
#
|
14
|
+
# @return [Hashie::Mash] User id and name
|
15
|
+
def create_ping
|
16
|
+
post "ping"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Put ping checking access and available HTTP verbs
|
20
|
+
#
|
21
|
+
# @return [Hashie::Mash] User id and name
|
22
|
+
def update_ping
|
23
|
+
put "ping"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Patch ping checking access and available HTTP verbs
|
27
|
+
#
|
28
|
+
# @return [Hashie::Mash] User id and name
|
29
|
+
def patch_ping
|
30
|
+
patch "ping"
|
31
|
+
end
|
32
|
+
|
33
|
+
# Delete ping checking access and available HTTP verbs
|
34
|
+
#
|
35
|
+
# @return [Hashie::Mash] User id and name
|
36
|
+
def delete_ping
|
37
|
+
delete "ping"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|