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.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +6 -0
  5. data/LICENCE.md +20 -0
  6. data/README.md +15 -0
  7. data/bin/bwapi +2 -0
  8. data/bwapi.gemspec +26 -0
  9. data/lib/bwapi.rb +28 -0
  10. data/lib/bwapi/authentication.rb +42 -0
  11. data/lib/bwapi/client.rb +54 -0
  12. data/lib/bwapi/client/admin.rb +35 -0
  13. data/lib/bwapi/client/admin/become.rb +21 -0
  14. data/lib/bwapi/client/admin/search.rb +41 -0
  15. data/lib/bwapi/client/admin/sub_clients.rb +109 -0
  16. data/lib/bwapi/client/admin/users.rb +95 -0
  17. data/lib/bwapi/client/admin/users/sharing.rb +35 -0
  18. data/lib/bwapi/client/brandwatch.rb +33 -0
  19. data/lib/bwapi/client/brandwatch/become.rb +19 -0
  20. data/lib/bwapi/client/brandwatch/client_modules.rb +26 -0
  21. data/lib/bwapi/client/client.rb +22 -0
  22. data/lib/bwapi/client/error_codes.rb +14 -0
  23. data/lib/bwapi/client/filters.rb +14 -0
  24. data/lib/bwapi/client/logout.rb +24 -0
  25. data/lib/bwapi/client/me.rb +42 -0
  26. data/lib/bwapi/client/oauth.rb +78 -0
  27. data/lib/bwapi/client/ping.rb +42 -0
  28. data/lib/bwapi/client/projects.rb +94 -0
  29. data/lib/bwapi/client/projects/categories.rb +70 -0
  30. data/lib/bwapi/client/projects/data.rb +62 -0
  31. data/lib/bwapi/client/projects/data_download.rb +49 -0
  32. data/lib/bwapi/client/projects/facebook_queries.rb +55 -0
  33. data/lib/bwapi/client/projects/queries.rb +99 -0
  34. data/lib/bwapi/client/projects/queries/backfill.rb +63 -0
  35. data/lib/bwapi/client/projects/queries/date_range.rb +67 -0
  36. data/lib/bwapi/client/projects/queries/mentions.rb +53 -0
  37. data/lib/bwapi/client/projects/query_groups.rb +70 -0
  38. data/lib/bwapi/client/projects/sharing.rb +57 -0
  39. data/lib/bwapi/client/projects/signals.rb +39 -0
  40. data/lib/bwapi/client/projects/summary.rb +21 -0
  41. data/lib/bwapi/client/projects/tags.rb +61 -0
  42. data/lib/bwapi/client/projects/users.rb +17 -0
  43. data/lib/bwapi/client/projects/workflow.rb +17 -0
  44. data/lib/bwapi/client/query_validation.rb +27 -0
  45. data/lib/bwapi/client/sso.rb +18 -0
  46. data/lib/bwapi/client/test_search.rb +14 -0
  47. data/lib/bwapi/client/user.rb +58 -0
  48. data/lib/bwapi/client/user/notifications.rb +36 -0
  49. data/lib/bwapi/configuration.rb +59 -0
  50. data/lib/bwapi/connection.rb +33 -0
  51. data/lib/bwapi/error.rb +42 -0
  52. data/lib/bwapi/request.rb +93 -0
  53. data/lib/bwapi/version.rb +3 -0
  54. data/lib/faraday/response/brandwatch_error.rb +25 -0
  55. data/lib/faraday/utils/utils.rb +25 -0
  56. data/spec/bwapi/authentication_spec.rb +57 -0
  57. data/spec/bwapi/client_spec.rb +205 -0
  58. data/spec/bwapi_spec.rb +23 -0
  59. data/spec/fixtures/.netrc +3 -0
  60. data/spec/helper.rb +12 -0
  61. metadata +178 -0
@@ -0,0 +1,94 @@
1
+ require 'bwapi/client/projects/categories'
2
+ require 'bwapi/client/projects/data'
3
+ require 'bwapi/client/projects/data_download'
4
+ require 'bwapi/client/projects/facebook_queries'
5
+ require 'bwapi/client/projects/signals'
6
+ require 'bwapi/client/projects/summary'
7
+ require 'bwapi/client/projects/sharing'
8
+ require 'bwapi/client/projects/queries'
9
+ require 'bwapi/client/projects/query_groups'
10
+ require 'bwapi/client/projects/tags'
11
+ require 'bwapi/client/projects/users'
12
+ require 'bwapi/client/projects/workflow'
13
+
14
+ module BWAPI
15
+ class Client
16
+ module Projects
17
+
18
+ # Get all projects
19
+ #
20
+ # @param opts [Hash] options hash of parameters
21
+ # @option opts [Integer] page Page of projects to retrieve
22
+ # @option opts [Integer] pageSize Results per page of results
23
+ # @return [Hashie::Mash] All projects
24
+ def projects opts={}
25
+ projects = get "projects", opts
26
+ end
27
+
28
+ # Get a specific project
29
+ #
30
+ # @param id [Integer] Id of the existing project
31
+ # @return [Hashie::Mash] Specific project
32
+ def project id
33
+ get "projects/#{id}"
34
+ end
35
+
36
+ # Create new project
37
+ #
38
+ # @param opts [Hash] options hash of parameters
39
+ # @option opts [String] id Id of the project
40
+ # @option opts [String] name Name of the project
41
+ # @option opts [String] description Description of the project
42
+ # @option opts [String] clientName Client name of the project
43
+ # @option opts [String] clientId Client id of the project
44
+ # @option opts [Array] defaultIndustry Default industry of the project
45
+ # @option opts [Array] defaultLangCodes Default languages of the project
46
+ # @option opts [Date] creationDate Date the project was created on
47
+ # @option opts [Integer] creationUserId User ID of the user who created the project
48
+ # @return [Hashie::Mash] New project
49
+ def create_project opts
50
+ post "projects", opts
51
+ end
52
+
53
+ # Update an existing project
54
+ #
55
+ # @param id [Integer] id Id of the existing project
56
+ # @param opts [Hash] options Hash of parameters
57
+ # @option opts [String] id Id of the project
58
+ # @option opts [String] name Name of the project
59
+ # @option opts [String] description Description of the project
60
+ # @option opts [String] clientName Client name of the project
61
+ # @option opts [String] clientId Client id of the project
62
+ # @option opts [Array] defaultIndustry Default industry of the project
63
+ # @option opts [Array] defaultLangCodes Default languages of the project
64
+ # @option opts [Date] creationDate Date the project was created on
65
+ # @option opts [Integer] creationUserId User ID of the user who created the project
66
+ # @return [Hashie::Mash] Updated project
67
+ def update_project id, opts
68
+ put "projects/#{id}", opts
69
+ end
70
+
71
+ # Delete an existing project
72
+ #
73
+ # @param id [Integer] id Id of the existing project
74
+ # @return [Hashie::Mash] Deleted project
75
+ def delete_project id
76
+ delete "projects/#{id}"
77
+ end
78
+
79
+ include BWAPI::Client::Projects::Categories
80
+ include BWAPI::Client::Projects::Data
81
+ include BWAPI::Client::Projects::DataDownload
82
+ include BWAPI::Client::Projects::FacebookQueries
83
+ include BWAPI::Client::Projects::Signals
84
+ include BWAPI::Client::Projects::Summary
85
+ include BWAPI::Client::Projects::Sharing
86
+ include BWAPI::Client::Projects::Queries
87
+ include BWAPI::Client::Projects::QueryGroups
88
+ include BWAPI::Client::Projects::Tags
89
+ include BWAPI::Client::Projects::Users
90
+ include BWAPI::Client::Projects::Workflow
91
+
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,70 @@
1
+ module BWAPI
2
+ class Client
3
+ module Projects
4
+ module Categories
5
+
6
+ # Get all categories in project
7
+ #
8
+ # @param id [Integer] Id of project
9
+ # @param opts [Hash] options hash of parameters
10
+ # @option opts [Integer] page Page of projects to retrieve
11
+ # @option opts [Integer] pageSize Results per page of results
12
+ # @return [Hashie::Mash] All categories in project
13
+ def categories id, opts={}
14
+ get "projects/#{id}/categories", opts
15
+ end
16
+
17
+ # TODO: Uncomment this code when endpoint is created
18
+ #
19
+ # Get a specific category in project
20
+ #
21
+ # @param project_id [Integer] Id of project
22
+ # @param category_id [Integer] Id of category
23
+ # @return [Hashie::Mash] Specific category
24
+ #def get_category project_id, category_id
25
+ # get "projects/#{project_id}/categories/#{category_id}", opts
26
+ #end
27
+ #alias :category :get_category
28
+
29
+ # Create a new category in project
30
+ #
31
+ # @param id [Integer] Id of project
32
+ # @param opts [Hash] options hash of parameters
33
+ # @option opts [Integer] id Id of the category
34
+ # @option opts [String] name Name of the category
35
+ # @option opts [Array] children The children of the category
36
+ # @option opts [Boolean] multiple Whether multiple sub categories can be selected
37
+ # @return [Hashie::Mash] New category
38
+ def create_category id, opts={}
39
+ post "projects/#{id}/categories", opts
40
+ end
41
+
42
+ # Update an existing category in project
43
+ #
44
+ # @param project_id [Integer] Id of project
45
+ # @param category_id [Integer] Id of category
46
+ # @param opts [Hash] options hash of parameters
47
+ # @option opts [Integer] projectId Id of the project
48
+ # @option opts [Integer] id Id of the category
49
+ # @option opts [String] name Name of the category
50
+ # @option opts [Array] children The children of the category
51
+ # @option opts [Boolean] multiple Whether multiple sub categories can be selected
52
+ # @return [Hashie::Mash] Updated category
53
+ def update_category project_id, category_id, opts={}
54
+ put "projects/#{project_id}/categories/#{category_id}", opts
55
+ end
56
+
57
+
58
+ # Delete and existing category in project
59
+ #
60
+ # @param project_id [Integer] Id of project
61
+ # @param category_id [Integer] Id of query group
62
+ # @return [Hashie::Mash] Deleted category
63
+ def delete_category project_id, category_id
64
+ delete "projects/#{project_id}/categories/#{category_id}"
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,62 @@
1
+ module BWAPI
2
+ class Client
3
+ module Projects
4
+ module Data
5
+
6
+ # Get all chart data for the requested dimensions
7
+ #
8
+ # @param id [Integer] Id of project
9
+ # @param aggregate [String] Aggregate value
10
+ # @param dimension_one [String] Dimension 1 value
11
+ # @param dimension_two [String] Dimension 2 value
12
+ # @param opts [Hash] options hash of parameters
13
+ # @option opts [Integer] projectId Id of the project
14
+ # @option opts [Hash] filter The filters to apply
15
+ # @return [Hashie::Mash] All Chart data mentions
16
+ def data id, aggregate, dimension_one, dimension_two, opts={}
17
+ get "projects/#{id}/data/#{aggregate}/#{dimension_one}/#{dimension_two}", opts
18
+ end
19
+
20
+ # Get all chart data for date ranges broken down by days
21
+ #
22
+ # @param id [Integer] Id of project
23
+ # @param opts [Hash] options hash of parameters
24
+ # @option opts [Integer] projectId Id of the project
25
+ # @option opts [Hash] filter The filters to apply
26
+ # @option opts [Array] dateRanges Date range ids
27
+ # @return [Hashie::Mash] All Chart data mentions
28
+ def data_date_ranges_days id, opts
29
+ get "projects/#{id}/data/volume/dataRanges/days", opts
30
+ end
31
+
32
+ # Get mentions that fall within the submitted filters
33
+ #
34
+ # @param id [Integer] Id of project
35
+ # @param opts [Hash] options hash of parameters
36
+ # @option opts [Integer] projectId Id of the project
37
+ # @option opts [Hash] filter The filters to apply
38
+ # @option opts [Integer] page Page of projects to retrieve
39
+ # @option opts [Integer] pageSize Results per page of results
40
+ # @option opts [String] :orderBy Parameter to sort by
41
+ # @option opts [String] :orderDirection Direction of sort
42
+ # @option opts [Integer] :orderByCategory Category to sort by when orderBy category
43
+ # @return [Hashie::Mash] All Mentions
44
+ def data_mentions id, opts={}
45
+ get "projects/#{id}/data/mentions", opts
46
+ end
47
+
48
+ # Update mentions for project
49
+ #
50
+ # @param id [Integer] Id of project
51
+ # @param opts [Hash] options hash of parameters
52
+ # @option opts [Integer] projectId Id of the project
53
+ # @option opts [Hash] List The patches to be applied
54
+ # @return [Hashie::Mash] Updated mentions
55
+ def update_data_mentions id, opts={}
56
+ patch "projects/#{id}/data/mentions", opts
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,49 @@
1
+ module BWAPI
2
+ class Client
3
+ module Projects
4
+ module DataDownload
5
+
6
+ # Get all data downloads in project
7
+ #
8
+ # @param id [Integer] Id of project
9
+ # @option opts [Integer] page Page of projects to retrieve
10
+ # @option opts [Integer] pageSize Results per page of results
11
+ # @return [Hashie::Mash] All data downloads in project
12
+ def data_downloads id, opts={}
13
+ get "projects/#{id}/datadownload", opts
14
+ end
15
+
16
+ # Get a specific data download in project
17
+ #
18
+ # @param project_id [Integer] Id of project
19
+ # @param data_download_id [Integer] Id of data download
20
+ # @return [Hashie::Mash] Specific data download
21
+ def get_data_download project_id, data_download_id
22
+ get "projects/#{project_id}/datadownload#{data_download_id}"
23
+ end
24
+ alias :data_download :get_data_download
25
+
26
+ # Create a new data download in project
27
+ #
28
+ # @param id [Integer] Id of project
29
+ # @param opts [Hash] options hash of parameters
30
+ # @option opts [Integer] projectId Id of the project
31
+ # @option opts [Integer] id Id of the data download
32
+ # @option opts [Integer] queryId Id of the query
33
+ # @option opts [Int] percentComplete The percentage complete of data download
34
+ # @option opts [String] status The status of the download
35
+ # @option opts [String] queryName The query name of the data download
36
+ # @option opts [Date] endDate The end date of the data download
37
+ # @option opts [Date] requestDate The request date of the data download
38
+ # @option opts [String] downloadLinkXLS The link to download the XLS format
39
+ # @option opts [String] downloadLinkCSV The link to download the CSV format
40
+ # @option opts [Array] additionalColumns The additional columns for the data download
41
+ # @return [Hashie::Mash] New data download
42
+ def create_datadownload id, opts={}
43
+ get "projects/#{id}/datadownload", opts
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,55 @@
1
+ module BWAPI
2
+ class Client
3
+ module Projects
4
+ module FacebookQueries
5
+
6
+ # Get all facebook queries in project
7
+ #
8
+ # @param id [Integer] Id of project
9
+ # @return [Hashie::Mash] All facebook queries in project
10
+ def facebook_queries id
11
+ get "projects/#{id}/facebookqueries"
12
+ end
13
+
14
+ # Get a specific facebook query in project
15
+ #
16
+ # @param project_id [Integer] Id of project
17
+ # @param query_id [Integer] Id of facebook query
18
+ # @return [Hashie::Mash] Specific facebook query
19
+ def get_facebook_queries project_id, query_id
20
+ get "projects/#{project_id}/facebookqueries/#{query_id}"
21
+ end
22
+ alias :facebook_query :get_facebook_queries
23
+
24
+ # Update an existing facebook query in project
25
+ #
26
+ # @param project_id [Integer] Id of project
27
+ # @param query_id [Integer] Id of query
28
+ # @param opts [Hash] options hash of parameters
29
+ # @option opts [Integer] id Id of the query
30
+ # @option opts [Integer] facebookPageId Id of the facebook page
31
+ # @option opts [String] name Name of the project
32
+ # @option opts [String] facebookPageName Name of the facebook page
33
+ # @option opts [String] facebookPageURL URL of the facebook page
34
+ # @option opts [Boolean] facebookCrawlComplete Facebook initial crawling status
35
+ # @option opts [Integer] dailyLimit Daily limit of the query
36
+ # @option opts [Integer] twitterLimit Twitter limit of the query
37
+ # @option opts [Integer] averageMonthlyMentions Average monthly mentions
38
+ # @option opts [String] type Query type
39
+ # @option opts [Array] includedTerms Included terms of terms query
40
+ # @option opts [Array] contextTerms Content terms of the query
41
+ # @option opts [Array] excludedTerms Excluded terms of thequery
42
+ # @option opts [Array] languages Query languages
43
+ # @option opts [String] twitterScreenName Tracked twitter screen name
44
+ # @option opts [String] industry Industry of the query
45
+ # @option opts [Date] creationDate Date the query was created on
46
+ # @option opts [Date] lastModificationDate Modification date of the query
47
+ # @return [Hashie::Mash] Updated query
48
+ def update_facebook_query project_id, query_id, opts={}
49
+ put "projects/#{project_id}/facebookqueries/#{query_id}", opts
50
+ end
51
+
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,99 @@
1
+ require 'bwapi/client/projects/queries/backfill'
2
+ require 'bwapi/client/projects/queries/date_range'
3
+ require 'bwapi/client/projects/queries/mentions'
4
+
5
+ module BWAPI
6
+ class Client
7
+ module Projects
8
+ module Queries
9
+
10
+ # Get all queries in project
11
+ #
12
+ # @param id [Integer] Id of project
13
+ # @return [Hashie::Mash] All queries in project
14
+ def queries id
15
+ get "projects/#{id}/queries"
16
+ end
17
+
18
+ # Get summary of all queries in project
19
+ #
20
+ # @param id [Integer] Id of project
21
+ # @return [Hashie::Mash] Summary of all queries in project
22
+ def queries_summary id
23
+ get "projects/#{id}/queries/summary"
24
+ end
25
+
26
+ # Get a specific query in project
27
+ #
28
+ # @param project_id [Integer] Id of project
29
+ # @param query_id [Integer] Id of query
30
+ # @return [Hashie::Mash] Specific query
31
+ def get_query project_id, query_id
32
+ get "projects/#{project_id}/queries/#{query_id}"
33
+ end
34
+ alias :query :get_query
35
+
36
+ # Create a new query in project
37
+ #
38
+ # @param id [Integer] Id of project
39
+ # @param opts [Hash] options hash of parameters
40
+ # @option opts [String] id Id of the query
41
+ # @option opts [String] name Name of the project
42
+ # @option opts [Integer] dailyLimit Daily limit of the query
43
+ # @option opts [Integer] twitterLimit Twitter limit of the query
44
+ # @option opts [Integer] averageMonthlyMentions Average monthly mentions
45
+ # @option opts [String] type Query type
46
+ # @option opts [Array] includedTerms Included terms of terms query
47
+ # @option opts [Array] contextTerms Content terms of the query
48
+ # @option opts [Array] excludedTerms Excluded terms of thequery
49
+ # @option opts [Array] languages Query languages
50
+ # @option opts [String] twitterScreenName Tracked twitter screen name
51
+ # @option opts [String] industry Industry of the query
52
+ # @option opts [Date] creationDate Date the query was created on
53
+ # @option opts [Date] lastModificationDate Modification date of the query
54
+ # @return [Hashie::Mash] New query
55
+ def create_query id, opts={}
56
+ post "projects/#{id}/queries", opts
57
+ end
58
+
59
+ # Update an existing query in project
60
+ #
61
+ # @param project_id [Integer] Id of project
62
+ # @param query_id [Integer] Id of query
63
+ # @param opts [Hash] options hash of parameters
64
+ # @option opts [Integer] id Id of the query
65
+ # @option opts [String] name Name of the project
66
+ # @option opts [Integer] dailyLimit Daily limit of the query
67
+ # @option opts [Integer] twitterLimit Twitter limit of the query
68
+ # @option opts [Integer] averageMonthlyMentions Average monthly mentions
69
+ # @option opts [String] type Query type
70
+ # @option opts [Array] includedTerms Included terms of terms query
71
+ # @option opts [Array] contextTerms Content terms of the query
72
+ # @option opts [Array] excludedTerms Excluded terms of thequery
73
+ # @option opts [Array] languages Query languages
74
+ # @option opts [String] twitterScreenName Tracked twitter screen name
75
+ # @option opts [String] industry Industry of the query
76
+ # @option opts [Date] creationDate Date the query was created on
77
+ # @option opts [Date] lastModificationDate Modification date of the query
78
+ # @return [Hashie::Mash] Updated query
79
+ def update_query project_id, query_id, opts={}
80
+ put "projects/#{project_id}/queries/#{query_id}", opts
81
+ end
82
+
83
+ # Delete an existing query project
84
+ #
85
+ # @param project_id [Integer] Id of project
86
+ # @param query_id [Integer] Id of query
87
+ # @return [Hashie::Mash] Deleted query
88
+ def delete_query project_id, query_id
89
+ delete "projects/#{project_id}/queries/#{query_id}"
90
+ end
91
+
92
+ include BWAPI::Client::Projects::Queries::Backfill
93
+ include BWAPI::Client::Projects::Queries::DateRange
94
+ include BWAPI::Client::Projects::Queries::Mentions
95
+
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,63 @@
1
+ module BWAPI
2
+ class Client
3
+ module Projects
4
+ module Queries
5
+ module Backfill
6
+
7
+ # Get all backfills for query
8
+ #
9
+ # @param project_id [Integer] Id of project
10
+ # @param query_id [Integer] Id of query
11
+ # @param opts [Hash] options hash of parameters
12
+ # @option opts [Integer] page Page of results to retrieve
13
+ # @option opts [Integer] pageSize Results per page
14
+ # @return [Hashie::Mash] All backfills for query
15
+ def backfills project_id, query_id, opts={}
16
+ get "projects/#{project_id}/queries/#{query_id}/backfill"
17
+ end
18
+
19
+ # Get specific backfill for query
20
+ #
21
+ # @param project_id [Integer] Id of project
22
+ # @param query_id [Integer] Id of query
23
+ # @param backfill_id [Integer] Id of backfill
24
+ # @return [Hashie::Mash] Backfill for query
25
+ def get_backfill project_id, query_id, backfill_id
26
+ get "projects/#{project_id}/queries/#{query_id}/backfill/#{backfill_id}"
27
+ end
28
+ alias :backfill :get_backfill
29
+
30
+ # Create new backfill for query
31
+ #
32
+ # @param project_id [Integer] Id of project
33
+ # @param query_id [Integer] Id of query
34
+ # @param opts [Hash] options hash of parameters
35
+ # @option opts [Integer] projectId Id of the project
36
+ # @option opts [Integer] queryId Id of the query
37
+ # @option opts [Integer] id Id of the backfill
38
+ # @option opts [Integer] mentionsFound Mentions found from the backfill
39
+ # @option opts [Date] maxDate Max date for the backfill
40
+ # @option opts [Date] minDate Min date for the backfill
41
+ # @option opts [String] status Status of backfill
42
+ # @option opts [Integer] queryId Query id of backfill
43
+ # @option opts [String] statusMessages Current status message of backfill
44
+ # @return [Hashie::Mash] New backfill for query
45
+ def create_backfill project_id, query_id, opts
46
+ post "projects/#{project_id}/queries/#{query_id}/backfill", opts
47
+ end
48
+
49
+ # Delete backfill for query
50
+ #
51
+ # @param project_id [Integer] Id of project
52
+ # @param query_id [Integer] Id of query
53
+ # @param backfill_id [Integer] Id of backfill
54
+ # @return [Hashie::Mash] Deleted backfill for query
55
+ def delete_backfill project_id, query_id, backfill_id
56
+ delete "projects/#{project_id}/queries/#{query_id}/backfill/#{backfill_id}"
57
+ end
58
+
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end