bwapi 9.0.0.pre.349 → 9.0.0.pre.364

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +1 -1
  3. data/.rubocop.yml +3 -0
  4. data/.travis.yml +0 -3
  5. data/Gemfile +3 -3
  6. data/README.md +0 -1
  7. data/bin/bwapi +0 -1
  8. data/bwapi.gemspec +6 -9
  9. data/lib/bwapi.rb +16 -14
  10. data/lib/bwapi/client.rb +65 -16
  11. data/lib/bwapi/client/admin.rb +0 -2
  12. data/lib/bwapi/client/admin/become.rb +0 -2
  13. data/lib/bwapi/client/admin/search.rb +0 -2
  14. data/lib/bwapi/client/admin/sub_clients.rb +0 -2
  15. data/lib/bwapi/client/admin/users.rb +0 -2
  16. data/lib/bwapi/client/admin/users/sharing.rb +0 -2
  17. data/lib/bwapi/client/brandwatch.rb +0 -2
  18. data/lib/bwapi/client/brandwatch/become.rb +0 -2
  19. data/lib/bwapi/client/brandwatch/client_modules.rb +0 -1
  20. data/lib/bwapi/client/client.rb +0 -2
  21. data/lib/bwapi/client/command_center.rb +0 -2
  22. data/lib/bwapi/client/command_center/client.rb +0 -2
  23. data/lib/bwapi/client/command_center/displays.rb +0 -2
  24. data/lib/bwapi/client/command_center/displays/events.rb +0 -2
  25. data/lib/bwapi/client/command_center/displays/messages.rb +0 -1
  26. data/lib/bwapi/client/command_center/displays/scenes.rb +0 -2
  27. data/lib/bwapi/client/command_center/displays/screens.rb +0 -2
  28. data/lib/bwapi/client/command_center/displays/users.rb +0 -2
  29. data/lib/bwapi/client/command_center/displays/users/access.rb +0 -1
  30. data/lib/bwapi/client/command_center/scene_types.rb +0 -2
  31. data/lib/bwapi/client/command_center/themes.rb +0 -2
  32. data/lib/bwapi/client/command_center/users.rb +0 -2
  33. data/lib/bwapi/client/command_center/users/access.rb +0 -2
  34. data/lib/bwapi/client/error_codes.rb +0 -2
  35. data/lib/bwapi/client/filters.rb +0 -2
  36. data/lib/bwapi/client/languages.rb +0 -2
  37. data/lib/bwapi/client/locations.rb +0 -2
  38. data/lib/bwapi/client/logout.rb +0 -3
  39. data/lib/bwapi/client/me.rb +2 -11
  40. data/lib/bwapi/client/metrics.rb +0 -2
  41. data/lib/bwapi/client/oauth.rb +0 -3
  42. data/lib/bwapi/client/ping.rb +0 -2
  43. data/lib/bwapi/client/projects.rb +0 -2
  44. data/lib/bwapi/client/projects/bulkactions.rb +0 -2
  45. data/lib/bwapi/client/projects/bulkactions/author.rb +0 -2
  46. data/lib/bwapi/client/projects/bulkactions/mentions.rb +0 -2
  47. data/lib/bwapi/client/projects/categories.rb +0 -2
  48. data/lib/bwapi/client/projects/categories/copy.rb +0 -2
  49. data/lib/bwapi/client/projects/data.rb +0 -1
  50. data/lib/bwapi/client/projects/data/mentions.rb +0 -1
  51. data/lib/bwapi/client/projects/data/mentions/notes.rb +0 -2
  52. data/lib/bwapi/client/projects/data/volume.rb +0 -2
  53. data/lib/bwapi/client/projects/data_download.rb +0 -2
  54. data/lib/bwapi/client/projects/demographics.rb +0 -1
  55. data/lib/bwapi/client/projects/facebook_queries.rb +0 -2
  56. data/lib/bwapi/client/projects/group.rb +0 -1
  57. data/lib/bwapi/client/projects/group/author_group.rb +0 -2
  58. data/lib/bwapi/client/projects/group/location_group.rb +0 -1
  59. data/lib/bwapi/client/projects/group/site_group.rb +0 -1
  60. data/lib/bwapi/client/projects/queries.rb +0 -2
  61. data/lib/bwapi/client/projects/queries/backfill.rb +0 -1
  62. data/lib/bwapi/client/projects/queries/date_range.rb +0 -2
  63. data/lib/bwapi/client/projects/queries/mentions.rb +0 -1
  64. data/lib/bwapi/client/projects/query_groups.rb +0 -1
  65. data/lib/bwapi/client/projects/rules.rb +0 -1
  66. data/lib/bwapi/client/projects/rules/backfill.rb +0 -2
  67. data/lib/bwapi/client/projects/rules/copy.rb +0 -2
  68. data/lib/bwapi/client/projects/sharing.rb +0 -2
  69. data/lib/bwapi/client/projects/signals.rb +0 -2
  70. data/lib/bwapi/client/projects/stream_dashboards.rb +0 -2
  71. data/lib/bwapi/client/projects/stream_dashboards/streams.rb +0 -1
  72. data/lib/bwapi/client/projects/summary.rb +0 -2
  73. data/lib/bwapi/client/projects/tags.rb +0 -2
  74. data/lib/bwapi/client/projects/twitter_queries.rb +0 -2
  75. data/lib/bwapi/client/projects/users.rb +0 -2
  76. data/lib/bwapi/client/projects/workflow.rb +0 -2
  77. data/lib/bwapi/client/query_validation.rb +0 -2
  78. data/lib/bwapi/client/sso.rb +0 -2
  79. data/lib/bwapi/client/test_search.rb +0 -2
  80. data/lib/bwapi/client/user.rb +0 -2
  81. data/lib/bwapi/client/user/notifications.rb +0 -2
  82. data/lib/bwapi/configuration.rb +40 -56
  83. data/lib/bwapi/connection.rb +32 -14
  84. data/lib/bwapi/default.rb +91 -0
  85. data/lib/bwapi/error.rb +1 -3
  86. data/lib/bwapi/performance.rb +39 -0
  87. data/lib/bwapi/request.rb +6 -33
  88. data/lib/bwapi/response/error.rb +28 -0
  89. data/lib/bwapi/response/logger.rb +35 -0
  90. data/lib/bwapi/response/performance.rb +31 -0
  91. data/lib/bwapi/version.rb +0 -2
  92. data/spec/bwapi/client_spec.rb +55 -49
  93. data/spec/bwapi_spec.rb +1 -3
  94. data/spec/helper.rb +1 -4
  95. metadata +32 -47
  96. data/lib/bwapi/authentication.rb +0 -48
  97. data/lib/faraday/response/brandwatch_error.rb +0 -25
  98. data/spec/bwapi/authentication_spec.rb +0 -57
  99. data/spec/fixtures/.netrc +0 -3
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  # Me module for me endpoint and helper methods
@@ -14,21 +12,14 @@ module BWAPI
14
12
  # Get users client name
15
13
  #
16
14
  # @return [String] Users client name
17
- def client_name
15
+ def user_client_name
18
16
  me.client.name
19
17
  end
20
18
 
21
19
  # Get users client id
22
20
  #
23
21
  # @return [String] Users client id
24
- def client_id
25
- me.client.id
26
- end
27
-
28
- # Get users client id
29
- #
30
- # @return [String] Users client id
31
- def client_id
22
+ def user_client_name
32
23
  me.client.id
33
24
  end
34
25
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  # Metrics module for metrics endpoints
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  # OAuth module for oauth/token endpoint
@@ -64,7 +62,6 @@ module BWAPI
64
62
  def oauth_request(opts = {})
65
63
  creds = post 'oauth/token', opts
66
64
  self.access_token = creds.access_token
67
- self.expires_in = creds.expires_in
68
65
  self.refresh_token = creds.refresh_token if application_client?
69
66
  creds
70
67
  end
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  # Ping module for ping endpoints
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bwapi/client/projects/bulkactions'
4
2
  require 'bwapi/client/projects/categories'
5
3
  require 'bwapi/client/projects/data'
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bwapi/client/projects/bulkactions/mentions'
4
2
  require 'bwapi/client/projects/bulkactions/author'
5
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bwapi/client/projects/categories/copy'
4
2
 
5
3
  module BWAPI
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  require 'bwapi/client/projects/data/mentions'
3
2
  require 'bwapi/client/projects/data/volume'
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  require 'bwapi/client/projects/data/mentions/notes'
3
2
 
4
3
  module BWAPI
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  module BWAPI
3
2
  class Client
4
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  require 'bwapi/client/projects/group/author_group'
3
2
  require 'bwapi/client/projects/group/location_group'
4
3
  require 'bwapi/client/projects/group/site_group'
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  module BWAPI
3
2
  class Client
4
3
  module Projects
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  module BWAPI
3
2
  class Client
4
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bwapi/client/projects/queries/backfill'
4
2
  require 'bwapi/client/projects/queries/date_range'
5
3
  require 'bwapi/client/projects/queries/mentions'
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  module BWAPI
3
2
  class Client
4
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  module BWAPI
3
2
  class Client
4
3
  module Projects
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  module BWAPI
3
2
  class Client
4
3
  module Projects
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  require 'bwapi/client/projects/rules/backfill'
3
2
  require 'bwapi/client/projects/rules/copy'
4
3
 
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bwapi/client/projects/stream_dashboards/streams'
4
2
 
5
3
  module BWAPI
@@ -1,4 +1,3 @@
1
- # encoding: utf-8
2
1
  module BWAPI
3
2
  class Client
4
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module Projects
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  # QueryValidation module for queryValidation endpoints
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  # SSO module for sso endpoint
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  # TestSearch module for testSearch endpoint
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'bwapi/client/user/notifications'
4
2
 
5
3
  module BWAPI
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module BWAPI
4
2
  class Client
5
3
  module User
@@ -1,42 +1,32 @@
1
- # encoding: utf-8
2
-
3
- require 'logger'
4
- require 'faraday'
5
-
6
1
  module BWAPI
7
2
  # Configuration module to set default and custom client credentials
8
3
  module Configuration
9
- OPTION_KEYS = [
10
- :api_endpoint,
11
- :user_agent,
12
- :adapter,
13
- :username,
14
- :password,
15
- :grant_type,
16
- :access_token,
17
- :refresh_token,
18
- :expires_in,
19
- :client_id,
20
- :client_secret,
21
- :verify_ssl,
22
- :netrc,
23
- :netrc_file,
24
- :debug,
25
- :log
26
- ].freeze
27
-
28
- DEFAULT_ADAPTER = Faraday.default_adapter
29
- DEFAULT_API_ENDPOINT = ENV['BWAPI_API_ENDPOINT'] || 'https://newapi.brandwatch.com/'
30
- DEFAULT_CLIENT_ID = 'brandwatch-api-client'
31
- DEFAULT_USER_AGENT = "BWAPI Ruby Gem #{BWAPI::VERSION}".freeze
32
- DEFAULT_NETRC_FILE = File.join(ENV['HOME'], '.netrc')
33
- DEFAULT_LOGGER_FILE = Logger.new("#{Dir.pwd}/bwapi.log")
34
-
35
- attr_accessor(*OPTION_KEYS)
36
-
37
- # Extend hook
38
- def self.extended(base)
39
- base.reset
4
+ attr_accessor :access_token, :adapter, :api_endpoint, :client_id, :debug, :grant_type,
5
+ :logger, :performance, :refresh_token, :user_agent, :username, :verify_ssl
6
+
7
+ attr_writer :client_secret, :password
8
+
9
+ class << self
10
+ # Configuration keys
11
+ def keys
12
+ @keys ||= [
13
+ :access_token,
14
+ :adapter,
15
+ :api_endpoint,
16
+ :client_id,
17
+ :client_secret,
18
+ :connection_options,
19
+ :debug,
20
+ :grant_type,
21
+ :logger,
22
+ :password,
23
+ :performance,
24
+ :refresh_token,
25
+ :user_agent,
26
+ :username,
27
+ :verify_ssl
28
+ ]
29
+ end
40
30
  end
41
31
 
42
32
  # Set configuration options using a block
@@ -44,28 +34,22 @@ module BWAPI
44
34
  yield self
45
35
  end
46
36
 
47
- # Convert option_keys to hash and return
48
- def options
49
- OPTION_KEYS.reduce({}) { |a, e| a.merge!(e => send(e)) }
37
+ def reset
38
+ BWAPI::Configuration.keys.each { |key| instance_variable_set(:"@#{key}", BWAPI::Default.options[key]) }
39
+ self
50
40
  end
51
41
 
52
- # Reset the configuration options
53
- def reset
54
- self.adapter = DEFAULT_ADAPTER
55
- self.user_agent = DEFAULT_USER_AGENT
56
- self.api_endpoint = DEFAULT_API_ENDPOINT
57
- self.username = nil
58
- self.password = nil
59
- self.grant_type = nil
60
- self.access_token = nil
61
- self.refresh_token = nil
62
- self.client_id = DEFAULT_CLIENT_ID
63
- self.client_secret = nil
64
- self.verify_ssl = true
65
- self.netrc = false
66
- self.netrc_file = DEFAULT_NETRC_FILE
67
- self.debug = false
68
- self.log = DEFAULT_LOGGER_FILE
42
+ def destroy
43
+ BWAPI::Configuration.keys.each { |key| instance_variable_set(:"@#{key}", nil) }
44
+ self
45
+ end
46
+
47
+ private
48
+
49
+ attr_reader :client_secret, :password
50
+
51
+ def options
52
+ Hash[BWAPI::Configuration.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }]
69
53
  end
70
54
  end
71
55
  end
@@ -1,27 +1,45 @@
1
- # encoding: utf-8
2
-
1
+ require 'bwapi/response/error'
2
+ require 'bwapi/response/logger'
3
+ require 'bwapi/response/performance'
3
4
  require 'faraday_middleware'
4
- require 'faraday/response/brandwatch_error'
5
5
 
6
6
  module BWAPI
7
- # Connection module to handle requests
7
+ # Configuration module to set default and custom client credentials
8
8
  module Connection
9
+ RACK_BUILDER_CLASS = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder
10
+
9
11
  private
10
12
 
11
- # Create a connection to send request
12
- def connection(opts = {})
13
- connection = Faraday.new(opts) do |c|
14
- c.request :json
13
+ def connection
14
+ @connection ||= Faraday.new(faraday_options)
15
+ end
16
+
17
+ def reset_connection
18
+ @connection = nil
19
+ end
20
+
21
+ def faraday_options
22
+ opts = @connection_options
23
+ opts[:headers][:authorization] = "bearer #{@access_token}" if @access_token
24
+ opts[:builder] = middleware
25
+ opts[:ssl] = { verify: @verify_ssl }
26
+ opts[:url] = @api_endpoint
27
+ opts
28
+ end
29
+
30
+ def middleware
31
+ RACK_BUILDER_CLASS.new do |builder|
32
+ builder.use FaradayMiddleware::Mashify
15
33
 
16
- c.use BrandwatchError
34
+ builder.use BWAPI::Response::Performance, self if debug
35
+ builder.use BWAPI::Response::Error
36
+ builder.use BWAPI::Response::Logger, self if debug
17
37
 
18
- c.response :mashify
19
- c.response :follow_redirects
20
- c.response :json, content_type: /\bjson$/
38
+ builder.use FaradayMiddleware::FollowRedirects
39
+ builder.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
21
40
 
22
- c.adapter adapter
41
+ builder.adapter Faraday.default_adapter
23
42
  end
24
- connection
25
43
  end
26
44
  end
27
45
  end