bwapi 10.0.0 → 11.0.0.pre.550

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +13 -5
  2. data/.editorconfig +1 -1
  3. data/.gitignore +1 -1
  4. data/lib/bwapi/client.rb +26 -3
  5. data/lib/bwapi/client/admin.rb +2 -0
  6. data/lib/bwapi/client/admin/demographics.rb +17 -0
  7. data/lib/bwapi/client/aggregates.rb +13 -0
  8. data/lib/bwapi/client/author.rb +56 -0
  9. data/lib/bwapi/client/brandwatch.rb +6 -0
  10. data/lib/bwapi/client/brandwatch/become.rb +0 -2
  11. data/lib/bwapi/client/brandwatch/clients.rb +2 -8
  12. data/lib/bwapi/client/brandwatch/clients/command_center.rb +20 -0
  13. data/lib/bwapi/client/brandwatch/clients/command_center/limits.rb +33 -0
  14. data/lib/bwapi/client/brandwatch/clients/command_center/scene_types.rb +26 -0
  15. data/lib/bwapi/client/brandwatch/clients/command_center/themes.rb +26 -0
  16. data/lib/bwapi/client/brandwatch/clients/command_center/users.rb +30 -0
  17. data/lib/bwapi/client/brandwatch/clients/command_center/users/access.rb +28 -0
  18. data/lib/bwapi/client/brandwatch/clients/users.rb +0 -2
  19. data/lib/bwapi/client/brandwatch/command_center.rb +14 -0
  20. data/lib/bwapi/client/brandwatch/command_center/scene_types.rb +31 -0
  21. data/lib/bwapi/client/brandwatch/command_center/themes.rb +17 -0
  22. data/lib/bwapi/client/brandwatch/log_level.rb +17 -0
  23. data/lib/bwapi/client/brandwatch/price_structures.rb +45 -0
  24. data/lib/bwapi/client/brandwatch/usage_report.rb +19 -0
  25. data/lib/bwapi/client/command_center.rb +12 -0
  26. data/lib/bwapi/client/command_center/category_colours.rb +15 -0
  27. data/lib/bwapi/client/command_center/colour_palette.rb +22 -0
  28. data/lib/bwapi/client/command_center/display_access.rb +12 -0
  29. data/lib/bwapi/client/command_center/display_access/users.rb +14 -0
  30. data/lib/bwapi/client/command_center/display_access/users/access.rb +21 -0
  31. data/lib/bwapi/client/command_center/displays/scenes.rb +1 -1
  32. data/lib/bwapi/client/command_center/projects.rb +16 -0
  33. data/lib/bwapi/client/command_center/projects/category_colours.rb +45 -0
  34. data/lib/bwapi/client/command_center/projects/data.rb +21 -0
  35. data/lib/bwapi/client/command_center/projects/tag_colours.rb +45 -0
  36. data/lib/bwapi/client/command_center/query_colours.rb +36 -0
  37. data/lib/bwapi/client/command_center/scene_types.rb +3 -3
  38. data/lib/bwapi/client/command_center/tag_colours.rb +15 -0
  39. data/lib/bwapi/client/dimensions.rb +13 -0
  40. data/lib/bwapi/client/oauth.rb +2 -1
  41. data/lib/bwapi/client/projects.rb +13 -11
  42. data/lib/bwapi/client/projects/{bulkactions.rb → bulk_actions.rb} +2 -2
  43. data/lib/bwapi/client/projects/{bulkactions → bulk_actions}/author.rb +0 -0
  44. data/lib/bwapi/client/projects/{bulkactions → bulk_actions}/mentions.rb +0 -0
  45. data/lib/bwapi/client/projects/data.rb +20 -0
  46. data/lib/bwapi/client/projects/data/audience.rb +21 -0
  47. data/lib/bwapi/client/projects/data/audience_activity.rb +21 -0
  48. data/lib/bwapi/client/projects/data/channel_metrics.rb +21 -0
  49. data/lib/bwapi/client/projects/data/emoticons.rb +23 -0
  50. data/lib/bwapi/client/projects/data/hashtags.rb +23 -0
  51. data/lib/bwapi/client/projects/data/headlines.rb +20 -0
  52. data/lib/bwapi/client/projects/data/impressions.rb +21 -0
  53. data/lib/bwapi/client/projects/data/mentioned_authors.rb +23 -0
  54. data/lib/bwapi/client/projects/data/mentions.rb +32 -2
  55. data/lib/bwapi/client/projects/data/owner_activity.rb +21 -0
  56. data/lib/bwapi/client/projects/data/urls.rb +23 -0
  57. data/lib/bwapi/client/projects/query/mentionfind.rb +21 -0
  58. data/lib/bwapi/client/projects/signals/groups.rb +18 -5
  59. data/lib/bwapi/client/user.rb +2 -0
  60. data/lib/bwapi/client/user/instagram_credentials.rb +32 -0
  61. data/lib/bwapi/configuration.rb +3 -2
  62. data/lib/bwapi/default.rb +7 -3
  63. data/lib/bwapi/error.rb +0 -2
  64. data/lib/bwapi/version.rb +1 -1
  65. data/spec/bwapi/client_spec.rb +29 -167
  66. data/spec/bwapi/configuration_spec.rb +499 -0
  67. data/spec/bwapi/default_spec.rb +242 -0
  68. metadata +72 -30
@@ -0,0 +1,21 @@
1
+ module BWAPI
2
+ class Client
3
+ module Projects
4
+ module Query
5
+ # mentionfind module for projects/project_id/query/query_id/mentionfind endpoint
6
+ module MentionFind
7
+ # Returns the mention for a specific URL
8
+ #
9
+ # @param project_id [Integer] Id of project
10
+ # @param query id [Integer] Id of the query
11
+ # @param opts [hash] options Hash of parameters
12
+ # @option opts [string] URL of the mention
13
+ # @return [Hash] Returns whether a URL is in a query
14
+ def mention_find(project_id, query_id, opts = {})
15
+ get "projects/#{project_id}/query/#{query_id}/mentionfind", opts
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -10,20 +10,22 @@ module BWAPI
10
10
  # @param projectId [Integer] Id of the existing project
11
11
  # @option opts [Integer] page Page of results to retrieve
12
12
  # @option opts [Integer] pageSize Results per page of results
13
- # @return [Hash] All signal groups for project
13
+ # @return [Hash] Returns All signal groups for project
14
14
  def signal_groups(project_id, opts = {})
15
15
  get "/projects/#{project_id}/signals/groups", opts
16
16
  end
17
17
 
18
18
  # Get a specific signal group
19
+ #
19
20
  # @param projectId [Integer] Id of project
20
21
  # @param groupId [Integer] Id of group
21
- # @return [Hash] specific signals group
22
+ # @return [Hash] Returns a specific signals group
22
23
  def get_signal_group(project_id, group_id)
23
24
  get "/projects/#{project_id}/signals/groups/#{group_id}"
24
25
  end
25
26
 
26
27
  # Create a new signal group
28
+ #
27
29
  # @param projectId [Integer] Project ID of the Signal Group to be updated
28
30
  # @param opts [Hash] options hash of parameters
29
31
  # @option opts [Integer] projectId Project ID of Signal Group
@@ -33,12 +35,13 @@ module BWAPI
33
35
  # @option opts [Date] lastModified Last modified date of the Signal Group
34
36
  # @option opts [Integer] id ID of Signal Group
35
37
  # @option opts [String] creator Creator of the Signal Group
36
- # @return [Hash] new signal group
38
+ # @return [Hash] Retuns the new signal group
37
39
  def create_signal_group(project_id, opts = {})
38
40
  post "/projects/#{project_id}/signals/groups", opts
39
41
  end
40
42
 
41
43
  # Update a signal group
44
+ #
42
45
  # @param projectId [Integer] Project ID of the Signal Group to be updated
43
46
  # @param groupId [Integer] Id of group
44
47
  # @param opts [Hash] options hash of parameters
@@ -49,18 +52,28 @@ module BWAPI
49
52
  # @option opts [Date] lastModified Last modified date of the Signal Group
50
53
  # @option opts [Integer] id ID of Signal Group
51
54
  # @option opts [String] creator Creator of the Signal Group
52
- # @return [Hash] updated signal group
55
+ # @return [Hash] Returns the updated signal group
53
56
  def update_signal_group(project_id, group_id, opts = {})
54
57
  put "/projects/#{project_id}/signals/groups/#{group_id}", opts
55
58
  end
56
59
 
57
60
  # Delete a signal group
61
+ #
58
62
  # @param projectId [Integer] Id of project
59
63
  # @param groupId [Integer] Id of group
60
- # @return [Hash] deleted signal group
64
+ # @return [Hash] Returns the deleted signal group
61
65
  def delete_signal_group(project_id, group_id)
62
66
  delete "/projects/#{project_id}/signals/groups/#{group_id}"
63
67
  end
68
+
69
+ # Get all signals for a specific group
70
+ #
71
+ # @param projectId [Integer] Id of project
72
+ # @param groupId [Integer] Id of group
73
+ # @return [Hash] Returns a specific signal group signals
74
+ def get_signal_group_signals(project_id, group_id)
75
+ get "/projects/#{project_id}/signals/groups/#{group_id}/signals"
76
+ end
64
77
  end
65
78
  end
66
79
  end
@@ -1,3 +1,4 @@
1
+ require 'bwapi/client/user/instagram_credentials'
1
2
  require 'bwapi/client/user/notifications'
2
3
 
3
4
  module BWAPI
@@ -51,6 +52,7 @@ module BWAPI
51
52
  user.uiRole
52
53
  end
53
54
 
55
+ include BWAPI::Client::User::InstagramCredentials
54
56
  include BWAPI::Client::User::Notifications
55
57
  end
56
58
  end
@@ -0,0 +1,32 @@
1
+ module BWAPI
2
+ class Client
3
+ module User
4
+ # InstagramCredentials module for user/instagramcredentials endpoints
5
+ module InstagramCredentials
6
+ # Get current user Instagram credentials
7
+ #
8
+ # @return [Hash] Current user Instagram credentials
9
+ def instagram_credentials
10
+ get '/user/instagramcredentials'
11
+ end
12
+
13
+ # Delete current user Instagram credentials
14
+ #
15
+ # @return [Hash] Current users deleted Instagram credentials
16
+ def delete_instagram_credentials
17
+ delete '/user/instagramcredentials'
18
+ end
19
+
20
+ # Store the current user's Instagram credentials
21
+ #
22
+ # @param opts [Hash] options Hash of parameters
23
+ # @option opts [String] accessToken Instagram API access token
24
+ # @option opts [String] clientId Instagram API client id
25
+ # @return [Hash] Current user Instagram credentials
26
+ def update_instagram_credentials(opts = {})
27
+ put '/user/instagramcredentials', opts
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,8 +1,8 @@
1
1
  module BWAPI
2
2
  # Configuration module
3
3
  module Configuration
4
- attr_accessor :access_token, :adapter, :api_endpoint, :client_id, :debug, :grant_type,
5
- :logger, :performance, :refresh_token, :user_agent, :username, :verify_ssl
4
+ attr_accessor :access_token, :access_token_expiry, :adapter, :api_endpoint, :client_id, :debug,
5
+ :grant_type, :logger, :performance, :refresh_token, :user_agent, :username, :verify_ssl
6
6
 
7
7
  attr_writer :client_secret, :password
8
8
 
@@ -11,6 +11,7 @@ module BWAPI
11
11
  def keys
12
12
  @keys ||= [
13
13
  :access_token,
14
+ :access_token_expiry,
14
15
  :adapter,
15
16
  :api_endpoint,
16
17
  :client_id,
@@ -26,8 +26,12 @@ module BWAPI
26
26
  ENV['BWAPI_ACCESS_TOKEN']
27
27
  end
28
28
 
29
+ def access_token_expiry
30
+ nil
31
+ end
32
+
29
33
  def adapter
30
- ENV['BWAPI_ADAPTER'] || ADAPTER
34
+ ENV['BWAPI_ADAPTER'].is_a?(String) ? ENV['BWAPI_ADAPTER'].to_sym : ADAPTER
31
35
  end
32
36
 
33
37
  def api_endpoint
@@ -54,7 +58,7 @@ module BWAPI
54
58
  end
55
59
 
56
60
  def debug
57
- ENV['BWAPI_DEBUG'] || false
61
+ ENV['BWAPI_DEBUG'] == 'true' ? true : false
58
62
  end
59
63
 
60
64
  def grant_type
@@ -86,7 +90,7 @@ module BWAPI
86
90
  end
87
91
 
88
92
  def verify_ssl
89
- ENV['BWAPI_VERIFY_SSL'] || false
93
+ ENV['BWAPI_VERIFY_SSL'] == 'true' ? true : false
90
94
  end
91
95
  end
92
96
  end
@@ -25,8 +25,6 @@ module BWAPI
25
25
  body
26
26
  elsif body.key?('errors')
27
27
  body['errors']
28
- else
29
- nil
30
28
  end
31
29
  end
32
30
 
@@ -1,4 +1,4 @@
1
1
  # BWAPI Version
2
2
  module BWAPI
3
- VERSION = '10.0.0'
3
+ VERSION = '11.0.0'
4
4
  end
@@ -1,9 +1,7 @@
1
1
  require 'helper'
2
2
 
3
3
  describe BWAPI::Client do
4
- before do
5
- BWAPI.reset
6
- end
4
+ before { BWAPI.reset }
7
5
 
8
6
  describe 'when called' do
9
7
  it 'should be a client class instance' do
@@ -12,16 +10,37 @@ describe BWAPI::Client do
12
10
  end
13
11
 
14
12
  describe '.authenticated?' do
15
- it 'returns true when authenticated' do
13
+ it 'returns false when not authenticated' do
16
14
  expect(BWAPI::Client.new.authenticated?).to eql(false)
17
15
  end
18
16
 
19
- it 'returns false when not authenticated' do
20
- bw = BWAPI::Client.new access_token: 'abcdef-ghijkl-123456-789012'
17
+ it 'returns true when authenticated' do
18
+ bw = BWAPI::Client.new access_token: 'abcdef-ghijkl-123456-789012', access_token_expiry: (Time.now + 3600).iso8601
21
19
  expect(bw.authenticated?).to eql(true)
22
20
  end
23
21
  end
24
22
 
23
+ describe '.access_token_expired?' do
24
+ it 'returns true if access_token is set to nil' do
25
+ expect(BWAPI::Client.new.access_token_expired?).to eql(true)
26
+ end
27
+
28
+ it 'returns true if access_token_expiry is set to nil' do
29
+ bw = BWAPI::Client.new access_token: 'abcdef-ghijkl-123456-789012'
30
+ expect(bw.access_token_expired?).to eql(true)
31
+ end
32
+
33
+ it 'returns true if access token has expired' do
34
+ bw = BWAPI::Client.new access_token: 'abcdef-ghijkl-123456-789012', access_token_expiry: (Time.now - 3600).iso8601
35
+ expect(bw.access_token_expired?).to eql(true)
36
+ end
37
+
38
+ it 'returns false if access token has not expired' do
39
+ bw = BWAPI::Client.new access_token: 'abcdef-ghijkl-123456-789012', access_token_expiry: (Time.now + 3600).iso8601
40
+ expect(bw.access_token_expired?).to eql(false)
41
+ end
42
+ end
43
+
25
44
  describe '.application_client?' do
26
45
  it 'returns true when client is a brandwatch-application-client' do
27
46
  bw = BWAPI::Client.new client_id: 'brandwatch-application-client'
@@ -45,167 +64,10 @@ describe BWAPI::Client do
45
64
  end
46
65
  end
47
66
 
48
- describe 'configuration' do
49
- describe 'instance variables' do
50
- it 'should create a api_endpoint instance variable' do
51
- expect(BWAPI::Client.new.respond_to?(:api_endpoint)).to eq(true)
52
- end
53
-
54
- it 'should create a user_agent instance variable' do
55
- expect(BWAPI::Client.new.respond_to?(:user_agent)).to eq(true)
56
- end
57
-
58
- it 'should create a adapter instance variable' do
59
- expect(BWAPI::Client.new.respond_to?(:adapter)).to eq(true)
60
- end
61
-
62
- it 'should create a username instance variable' do
63
- expect(BWAPI::Client.new.respond_to?(:username)).to eq(true)
64
- end
65
-
66
- it 'should create a password instance variable which cannot be accessed' do
67
- expect(BWAPI::Client.new.respond_to?(:password)).to eq(false)
68
- end
69
-
70
- it 'should create a grant_type instance variable' do
71
- expect(BWAPI::Client.new.respond_to?(:grant_type)).to eq(true)
72
- end
73
-
74
- it 'should create a access_token instance variable' do
75
- expect(BWAPI::Client.new.respond_to?(:access_token)).to eq(true)
76
- end
77
-
78
- it 'should create a refresh_token instance variable' do
79
- expect(BWAPI::Client.new.respond_to?(:refresh_token)).to eq(true)
80
- end
81
-
82
- it 'should create a client_id instance variable' do
83
- expect(BWAPI::Client.new.respond_to?(:client_id)).to eq(true)
84
- end
85
-
86
- it 'should create a client_secret instance variable which cannot accessed' do
87
- expect(BWAPI::Client.new.respond_to?(:client_secret)).to eq(false)
88
- end
89
-
90
- it 'should create a logger instance variable' do
91
- expect(BWAPI::Client.new.respond_to?(:logger)).to eq(true)
92
- end
93
- end
94
-
95
- describe 'configuration values' do
96
- describe 'default_adapter' do
97
- it 'should have a default default_adapter value' do
98
- expect(BWAPI::Client.new.adapter).to eql(:net_http)
99
- end
100
-
101
- it 'should allow a user to set a default_adapter value' do
102
- bw = BWAPI::Client.new adapter: 'custom_adapter'
103
- expect(bw.adapter).to eql('custom_adapter')
104
- end
105
- end
106
-
107
- describe 'user_agent' do
108
- it 'should have a default user_agent value' do
109
- expect(BWAPI::Client.new.user_agent).to eql("BWAPI Ruby Gem #{BWAPI::VERSION}")
110
- end
111
-
112
- it 'should allow a user to set a user_agent value' do
113
- bw = BWAPI::Client.new user_agent: 'custom_user_agent'
114
- expect(bw.user_agent).to eql('custom_user_agent')
115
- end
116
- end
117
-
118
- describe 'api_endpoint' do
119
- it 'should have a default api_endpoint value' do
120
- expect(BWAPI::Client.new.api_endpoint).to eql('https://newapi.brandwatch.com/')
121
- end
122
-
123
- it 'should allow a user to set a api_endpoint value' do
124
- bw = BWAPI::Client.new api_endpoint: 'http://newapi.custom.brandwatch.com'
125
- expect(bw.api_endpoint).to eql('http://newapi.custom.brandwatch.com')
126
- end
127
- end
128
-
129
- describe 'client_id' do
130
- it 'should have a default client_id value' do
131
- expect(BWAPI::Client.new.client_id).to eql('brandwatch-api-client')
132
- end
133
-
134
- it 'should allow a user to set a client_id value' do
135
- bw = BWAPI::Client.new client_id: 'custom_client_id'
136
- expect(bw.client_id).to eql('custom_client_id')
137
- end
138
- end
139
-
140
- describe 'username' do
141
- it 'should have a default value of nil for username' do
142
- expect(BWAPI::Client.new.username).to eql(nil)
143
- end
144
-
145
- it 'should allow a user to set a username value' do
146
- bw = BWAPI::Client.new username: 'jonathan@brandwatch.com'
147
- expect(bw.username).to eql('jonathan@brandwatch.com')
148
- end
149
- end
150
-
151
- describe 'password' do
152
- it 'should allow a user to set a password value' do
153
- bw = BWAPI::Client.new password: 'pa55w0rd'
154
- expect(bw.instance_eval { @password }).to eql('pa55w0rd')
155
- end
156
- end
157
-
158
- describe 'grant_type' do
159
- it 'should have a default value of api-password for grant_type' do
160
- expect(BWAPI::Client.new.grant_type).to eql('api-password')
161
- end
162
-
163
- it 'should allow a user to set a grant_type value' do
164
- bw = BWAPI::Client.new grant_type: 'custom_grant_type'
165
- expect(bw.grant_type).to eql('custom_grant_type')
166
- end
167
- end
168
-
169
- describe 'access_token' do
170
- it 'should have a default value of nil for access_token' do
171
- expect(BWAPI::Client.new.access_token).to eql(nil)
172
- end
173
-
174
- it 'should allow a user to set a access_token value' do
175
- bw = BWAPI::Client.new access_token: 'abcdef-ghijkl-123456-789012'
176
- expect(bw.access_token).to eql('abcdef-ghijkl-123456-789012')
177
- end
178
- end
179
-
180
- describe 'refresh_token' do
181
- it 'should have a default value of nil for refresh_token' do
182
- expect(BWAPI::Client.new.refresh_token).to eql(nil)
183
- end
184
-
185
- it 'should allow a user to set a refresh_token value' do
186
- bw = BWAPI::Client.new refresh_token: 'abcdef-ghijkl-123456-789012'
187
- expect(bw.refresh_token).to eql('abcdef-ghijkl-123456-789012')
188
- end
189
- end
190
-
191
- describe 'client_secret' do
192
- it 'should allow a user to set a client_secret value' do
193
- bw = BWAPI::Client.new client_secret: 'custom_client_secret'
194
- expect(bw.instance_eval { @client_secret }).to eql('custom_client_secret')
195
- end
196
- end
197
-
198
- describe 'logger' do
199
- it 'should have a default value of nil for logger' do
200
- expect(BWAPI::Client.new.logger).to eql(nil)
201
- end
202
-
203
- it 'should allow a user to set a logger value' do
204
- logger = Object.new
205
- bw = BWAPI::Client.new logger: logger
206
- expect(bw.logger).to eql(logger)
207
- end
208
- end
67
+ describe '.seconds_until_access_token_expires' do
68
+ it 'should return the number of seconds until the access token expires' do
69
+ bw = BWAPI::Client.new access_token_expiry: (Time.now + 3600).iso8601
70
+ expect(bw.send(:seconds_until_access_token_expires)).to eql(3600)
209
71
  end
210
72
  end
211
73
  end
@@ -0,0 +1,499 @@
1
+ require 'helper'
2
+ require 'logger'
3
+
4
+ describe BWAPI::Configuration do
5
+ let(:bwapi) { BWAPI::Client.new }
6
+
7
+ describe 'instance variables' do
8
+ it 'should create a access_token instance variable' do
9
+ expect(bwapi.respond_to?(:access_token)).to eq(true)
10
+ end
11
+
12
+ it 'should create a access_token_expiry instance variable' do
13
+ expect(bwapi.respond_to?(:access_token_expiry)).to eq(true)
14
+ end
15
+
16
+ it 'should create a adapter instance variable' do
17
+ expect(bwapi.respond_to?(:adapter)).to eq(true)
18
+ end
19
+
20
+ it 'should create a api_endpoint instance variable' do
21
+ expect(bwapi.respond_to?(:api_endpoint)).to eq(true)
22
+ end
23
+
24
+ it 'should create a client_id instance variable' do
25
+ expect(bwapi.respond_to?(:client_id)).to eq(true)
26
+ end
27
+
28
+ it 'should create a client_secret instance variable which cannot accessed' do
29
+ expect(bwapi.respond_to?(:client_secret)).to eq(false)
30
+ end
31
+
32
+ it 'should create a debug instance variable' do
33
+ expect(bwapi.respond_to?(:debug)).to eq(true)
34
+ end
35
+
36
+ it 'should create a grant_type instance variable' do
37
+ expect(bwapi.respond_to?(:grant_type)).to eq(true)
38
+ end
39
+
40
+ it 'should create a logger instance variable' do
41
+ expect(bwapi.respond_to?(:logger)).to eq(true)
42
+ end
43
+
44
+ it 'should create a password instance variable which cannot be accessed' do
45
+ expect(bwapi.respond_to?(:password)).to eq(false)
46
+ end
47
+
48
+ it 'should create a performance instance variable' do
49
+ expect(bwapi.respond_to?(:performance)).to eq(true)
50
+ end
51
+
52
+ it 'should create a refresh_token instance variable' do
53
+ expect(bwapi.respond_to?(:refresh_token)).to eq(true)
54
+ end
55
+
56
+ it 'should create a user_agent instance variable' do
57
+ expect(bwapi.respond_to?(:user_agent)).to eq(true)
58
+ end
59
+
60
+ it 'should create a username instance variable' do
61
+ expect(bwapi.respond_to?(:username)).to eq(true)
62
+ end
63
+
64
+ it 'should create a logger instance variable' do
65
+ expect(bwapi.respond_to?(:logger)).to eq(true)
66
+ end
67
+
68
+ it 'should create a verify_ssl instance variable' do
69
+ expect(bwapi.respond_to?(:verify_ssl)).to eq(true)
70
+ end
71
+ end
72
+
73
+ describe 'default and custom values' do
74
+ before { bwapi.reset }
75
+
76
+ describe 'access_token' do
77
+ it 'should have a default value of nil for access_token' do
78
+ expect(bwapi.access_token).to eql(nil)
79
+ end
80
+
81
+ it 'should allow a user to set a access_token value' do
82
+ bwapi.access_token = 'abcdef-ghijkl-123456-789012'
83
+ expect(bwapi.access_token).to eql('abcdef-ghijkl-123456-789012')
84
+ end
85
+ end
86
+
87
+ describe 'access_token_expiry' do
88
+ it 'should have a default value of nil for access_token_expiry' do
89
+ expect(bwapi.access_token_expiry).to eql(nil)
90
+ end
91
+
92
+ it 'should allow a user to set a access_token_expiry value' do
93
+ bwapi.access_token_expiry = '2015-01-08T16:13:03-08:00'
94
+ expect(bwapi.access_token_expiry).to eql('2015-01-08T16:13:03-08:00')
95
+ end
96
+ end
97
+
98
+ describe 'adapter' do
99
+ it 'should have a default adapter value' do
100
+ expect(bwapi.adapter).to eql(:net_http)
101
+ end
102
+
103
+ it 'should allow a user to set a default_adapter value' do
104
+ bwapi.adapter = 'custom_adapter'
105
+ expect(bwapi.adapter).to eql('custom_adapter')
106
+ end
107
+ end
108
+
109
+ describe 'api_endpoint' do
110
+ it 'should have a default api_endpoint value' do
111
+ expect(bwapi.api_endpoint).to eql('https://newapi.brandwatch.com/')
112
+ end
113
+
114
+ it 'should allow a user to set a api_endpoint value' do
115
+ bwapi.api_endpoint = 'http://newapi.custom.brandwatch.com'
116
+ expect(bwapi.api_endpoint).to eql('http://newapi.custom.brandwatch.com')
117
+ end
118
+ end
119
+
120
+ describe 'client_id' do
121
+ it 'should have a default client_id value' do
122
+ expect(bwapi.client_id).to eql('brandwatch-api-client')
123
+ end
124
+
125
+ it 'should allow a user to set a client_id value' do
126
+ bwapi.client_id = 'custom_client_id'
127
+ expect(bwapi.client_id).to eql('custom_client_id')
128
+ end
129
+ end
130
+
131
+ describe 'client_secret' do
132
+ it 'should allow a user to set a client_secret value' do
133
+ bwapi.client_secret = 'custom_client_secret'
134
+ expect(bwapi.instance_eval { @client_secret }).to eql('custom_client_secret')
135
+ end
136
+ end
137
+
138
+ describe 'debug' do
139
+ it 'should have a default debug value' do
140
+ expect(bwapi.debug).to eql(false)
141
+ end
142
+
143
+ it 'should allow a user to set a debug value' do
144
+ bwapi.debug = true
145
+ expect(bwapi.debug).to eql(true)
146
+ end
147
+ end
148
+
149
+ describe 'grant_type' do
150
+ it 'should have a default value of api-password for grant_type' do
151
+ expect(bwapi.grant_type).to eql('api-password')
152
+ end
153
+
154
+ it 'should allow a user to set a grant_type value' do
155
+ bwapi.grant_type = 'custom_grant_type'
156
+ expect(bwapi.grant_type).to eql('custom_grant_type')
157
+ end
158
+ end
159
+
160
+ describe 'logger' do
161
+ it 'should have a default value of nil for logger' do
162
+ expect(bwapi.logger).to eql(nil)
163
+ end
164
+
165
+ it 'should allow a user to set a logger value' do
166
+ logger = Logger.new(STDOUT)
167
+ bwapi.logger = logger
168
+ expect(bwapi.logger).to eql(logger)
169
+ end
170
+ end
171
+
172
+ describe 'password' do
173
+ it 'should allow a user to set a password value' do
174
+ bwapi.password = 'pa55w0rd'
175
+ expect(bwapi.instance_eval { @password }).to eql('pa55w0rd')
176
+ end
177
+ end
178
+
179
+ describe 'performance' do
180
+ it 'should have a default performance value' do
181
+ expect(bwapi.performance).to eql({})
182
+ end
183
+ end
184
+
185
+ describe 'refresh_token' do
186
+ it 'should have a default value of nil for refresh_token' do
187
+ expect(bwapi.refresh_token).to eql(nil)
188
+ end
189
+
190
+ it 'should allow a user to set a refresh_token value' do
191
+ bwapi.refresh_token = 'abcdef-ghijkl-123456-789012'
192
+ expect(bwapi.refresh_token).to eql('abcdef-ghijkl-123456-789012')
193
+ end
194
+ end
195
+
196
+ describe 'user_agent' do
197
+ it 'should have a default user_agent value' do
198
+ expect(bwapi.user_agent).to eql("BWAPI Ruby Gem #{BWAPI::VERSION}")
199
+ end
200
+
201
+ it 'should allow a user to set a user_agent value' do
202
+ bwapi.user_agent = 'custom_user_agent'
203
+ expect(bwapi.user_agent).to eql('custom_user_agent')
204
+ end
205
+ end
206
+
207
+ describe 'username' do
208
+ it 'should have a default value of nil for username' do
209
+ expect(bwapi.username).to eql(nil)
210
+ end
211
+
212
+ it 'should allow a user to set a username value' do
213
+ bwapi.username = 'jonathan@brandwatch.com'
214
+ expect(bwapi.username).to eql('jonathan@brandwatch.com')
215
+ end
216
+ end
217
+
218
+ describe 'verify_ssl' do
219
+ it 'should have a default verify_ssl value' do
220
+ expect(bwapi.verify_ssl).to eql(false)
221
+ end
222
+
223
+ it 'should allow a user to set a verify_ssl value' do
224
+ bwapi.verify_ssl = true
225
+ expect(bwapi.verify_ssl).to eql(true)
226
+ end
227
+ end
228
+ end
229
+
230
+ describe '.keys' do
231
+ it 'should return the correct list of keys' do
232
+ expect(BWAPI::Configuration.keys).to eql([
233
+ :access_token,
234
+ :access_token_expiry,
235
+ :adapter,
236
+ :api_endpoint,
237
+ :client_id,
238
+ :client_secret,
239
+ :connection_options,
240
+ :debug,
241
+ :grant_type,
242
+ :logger,
243
+ :password,
244
+ :performance,
245
+ :refresh_token,
246
+ :user_agent,
247
+ :username,
248
+ :verify_ssl
249
+ ])
250
+ end
251
+ end
252
+
253
+ describe '.configure' do
254
+ before do
255
+ bwapi.configure do |c|
256
+ c.access_token = '1234-5678-9010-1112'
257
+ c.access_token_expiry = '2015-01-08 14:09:16 -0800'
258
+ c.adapter = :test
259
+ c.api_endpoint = 'http://newapi.test.brandwatch.com'
260
+ c.client_id = 'brandwatch-test-client'
261
+ c.client_secret = 'test'
262
+ c.debug = true
263
+ c.grant_type = 'test-grant'
264
+ c.logger = Logger.new(STDOUT)
265
+ c.password = 'password123'
266
+ c.refresh_token = '1234-5678-9010-1112'
267
+ c.user_agent = 'Test User Agent'
268
+ c.username = 'testing@brandwatch.com'
269
+ c.verify_ssl = true
270
+ end
271
+ end
272
+
273
+ after { bwapi.reset }
274
+
275
+ it 'should set the configured access_token' do
276
+ expect(bwapi.access_token).to eql('1234-5678-9010-1112')
277
+ end
278
+
279
+ it 'should set the configured access_token_expiry' do
280
+ expect(bwapi.access_token_expiry).to eql('2015-01-08 14:09:16 -0800')
281
+ end
282
+
283
+ it 'should set the configured adapter' do
284
+ expect(bwapi.adapter).to eql(:test)
285
+ end
286
+
287
+ it 'should set the configured api_endpoint' do
288
+ expect(bwapi.api_endpoint).to eql('http://newapi.test.brandwatch.com')
289
+ end
290
+
291
+ it 'should set the configured client_id' do
292
+ expect(bwapi.client_id).to eql('brandwatch-test-client')
293
+ end
294
+
295
+ it 'should set the configured client_secret' do
296
+ expect(bwapi.instance_variable_get(:@client_secret)).to eql('test')
297
+ end
298
+
299
+ it 'should set the configured debug flag' do
300
+ expect(bwapi.debug).to eql(true)
301
+ end
302
+
303
+ it 'should set the configured grant type' do
304
+ expect(bwapi.grant_type).to eql('test-grant')
305
+ end
306
+
307
+ it 'should set the configured logger' do
308
+ expect(bwapi.logger).to be_an_instance_of Logger
309
+ end
310
+
311
+ it 'should set the configured password' do
312
+ expect(bwapi.instance_variable_get(:@password)).to eql('password123')
313
+ end
314
+
315
+ it 'should set the configured refresh_token' do
316
+ expect(bwapi.refresh_token).to eql('1234-5678-9010-1112')
317
+ end
318
+
319
+ it 'should set the configured user agent' do
320
+ expect(bwapi.user_agent).to eql('Test User Agent')
321
+ end
322
+
323
+ it 'should set the configured username' do
324
+ expect(bwapi.username).to eql('testing@brandwatch.com')
325
+ end
326
+
327
+ it 'should set the configured verify_ssl flag' do
328
+ expect(bwapi.verify_ssl).to eql(true)
329
+ end
330
+ end
331
+
332
+ describe '.reset' do
333
+ before { bwapi.reset }
334
+
335
+ it 'should reset the access token value' do
336
+ expect(bwapi.access_token).to eql(nil)
337
+ end
338
+
339
+ it 'should reset the access token expiry value' do
340
+ expect(bwapi.access_token_expiry).to eql(nil)
341
+ end
342
+
343
+ it 'should reset the adapter value' do
344
+ expect(bwapi.adapter).to eql(:net_http)
345
+ end
346
+
347
+ it 'should reset the api_endpoint value' do
348
+ expect(bwapi.api_endpoint).to eql('https://newapi.brandwatch.com/')
349
+ end
350
+
351
+ it 'should reset the client_id value' do
352
+ expect(bwapi.client_id).to eql('brandwatch-api-client')
353
+ end
354
+
355
+ it 'should reset the client_secret value' do
356
+ expect(bwapi.instance_variable_get(:@client_secret)).to eql(nil)
357
+ end
358
+
359
+ it 'should reset the connection value' do
360
+ expect(bwapi.instance_variable_get(:@connection)).to eql(nil)
361
+ end
362
+
363
+ it 'should reset the debug value' do
364
+ expect(bwapi.debug).to eql(false)
365
+ end
366
+
367
+ it 'should reset the grant_type value' do
368
+ expect(bwapi.grant_type).to eql('api-password')
369
+ end
370
+
371
+ it 'should reset the logger value' do
372
+ expect(bwapi.logger).to eql(nil)
373
+ end
374
+
375
+ it 'should reset the password value' do
376
+ expect(bwapi.instance_variable_get(:@password)).to eql(nil)
377
+ end
378
+
379
+ it 'should reset the performance value' do
380
+ expect(bwapi.performance).to eql({})
381
+ end
382
+
383
+ it 'should reset the refresh_token value' do
384
+ expect(bwapi.refresh_token).to eql(nil)
385
+ end
386
+
387
+ it 'should reset the user_agent value' do
388
+ expect(bwapi.user_agent).to eql('BWAPI Ruby Gem 11.0.0')
389
+ end
390
+
391
+ it 'should reset the username value' do
392
+ expect(bwapi.username).to eql(nil)
393
+ end
394
+
395
+ it 'should reset the verify_ssl value' do
396
+ expect(bwapi.verify_ssl).to eql(false)
397
+ end
398
+ end
399
+
400
+ describe '.destroy' do
401
+ before { bwapi.destroy }
402
+
403
+ it 'should reset the access token value' do
404
+ expect(bwapi.access_token).to eql(nil)
405
+ end
406
+
407
+ it 'should reset the access token expiry value' do
408
+ expect(bwapi.access_token_expiry).to eql(nil)
409
+ end
410
+
411
+ it 'should reset the adapter value' do
412
+ expect(bwapi.adapter).to eql(nil)
413
+ end
414
+
415
+ it 'should reset the api_endpoint value' do
416
+ expect(bwapi.api_endpoint).to eql(nil)
417
+ end
418
+
419
+ it 'should reset the client_id value' do
420
+ expect(bwapi.client_id).to eql(nil)
421
+ end
422
+
423
+ it 'should reset the client_secret value' do
424
+ expect(bwapi.instance_variable_get(:@client_secret)).to eql(nil)
425
+ end
426
+
427
+ it 'should reset the connection value' do
428
+ expect(bwapi.instance_variable_get(:@connection)).to eql(nil)
429
+ end
430
+
431
+ it 'should reset the debug value' do
432
+ expect(bwapi.debug).to eql(nil)
433
+ end
434
+
435
+ it 'should reset the grant_type value' do
436
+ expect(bwapi.grant_type).to eql(nil)
437
+ end
438
+
439
+ it 'should reset the logger value' do
440
+ expect(bwapi.logger).to eql(nil)
441
+ end
442
+
443
+ it 'should reset the password value' do
444
+ expect(bwapi.instance_variable_get(:@password)).to eql(nil)
445
+ end
446
+
447
+ it 'should reset the performance value' do
448
+ expect(bwapi.performance).to eql(nil)
449
+ end
450
+
451
+ it 'should reset the refresh_token value' do
452
+ expect(bwapi.refresh_token).to eql(nil)
453
+ end
454
+
455
+ it 'should reset the user_agent value' do
456
+ expect(bwapi.user_agent).to eql(nil)
457
+ end
458
+
459
+ it 'should reset the username value' do
460
+ expect(bwapi.username).to eql(nil)
461
+ end
462
+
463
+ it 'should reset the verify_ssl value' do
464
+ expect(bwapi.verify_ssl).to eql(nil)
465
+ end
466
+ end
467
+
468
+ describe '.options' do
469
+ before { bwapi.reset }
470
+
471
+ it 'should return the current configuration set' do
472
+ expect(bwapi.send(:options)).to eql(
473
+ access_token: nil,
474
+ access_token_expiry: nil,
475
+ adapter: :net_http,
476
+ api_endpoint: 'https://newapi.brandwatch.com/',
477
+ client_id: 'brandwatch-api-client',
478
+ client_secret: nil,
479
+ connection_options: {
480
+ headers: {
481
+ user_agent: 'BWAPI Ruby Gem 11.0.0'
482
+ },
483
+ request: {
484
+ params_encoder: Faraday::FlatParamsEncoder
485
+ }
486
+ },
487
+ debug: false,
488
+ grant_type: 'api-password',
489
+ logger: nil,
490
+ password: nil,
491
+ performance: {},
492
+ refresh_token: nil,
493
+ user_agent: 'BWAPI Ruby Gem 11.0.0',
494
+ username: nil,
495
+ verify_ssl: false
496
+ )
497
+ end
498
+ end
499
+ end