bwapi 2.0.3 → 3.0.0.pre.88

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 65abb780f56fe5425751d96bcbe9ddbeebdf1f2f
4
- data.tar.gz: e0a39fbc3d4ec72672c6bf64b834ad6075b3443d
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTIxOTlhYmM3ZGYxNTk4NGZjMDk5NWE0M2NkODlhZTA3N2U5NDgwYQ==
5
+ data.tar.gz: !binary |-
6
+ ZDk0N2NhMGNkYmIwNTJjNzQxOWFmMzE5NjJhZjdlYjIxMjFjNjk1Zg==
5
7
  SHA512:
6
- metadata.gz: b18b820171841552772b9f684bc1963fdefc06c1e12bfe998b46b278cf1a59c0fa1e3417470bf176d41270ce00dc55c9b6c449b064be2b7b0bef28e7927b8804
7
- data.tar.gz: 7dfe0918011da80c34275f68539521df90bdfb23cfb7387d3ea6f4bba5d3bb8575f7bb4f54d67663e480be886ec62b0a8775dba809fed8ef8fa0209980f6c554
8
+ metadata.gz: !binary |-
9
+ YWI4NDJiNmQ3NGZhZDZhMGNhZTNhMDlkMzcxMGZmOTRmOTVhMzY3NjU2ZmQ1
10
+ NmY2OWQ1Nzk2MGNjNjMwOTM4YzI1M2I2ZjI4MTVkZWE1MDNkMTk5MTMxNjM1
11
+ ODE0NmI1ZDZiODI0M2JmNzM3ODlkY2MyNWQ0YTQxYzcyMGEzZmE=
12
+ data.tar.gz: !binary |-
13
+ NDM4ZGQ1ZDYzZTQzMjhlMzk1YjIzMzJlZmZlMDc2NmUyNmQxNzNjY2VkMWMw
14
+ NjEzOWQzYjA4ZjFjOWJlZGRhNjZmZmI3OWUyMzM4MDNkZDA3NjY2YTIzODBm
15
+ Y2YyYThiYjVlNjEyZGRmZjAxOTM1ZTk2NjgzZGRmNDExMWU1ODY=
@@ -4,9 +4,9 @@ Gem::Specification.new do |s|
4
4
  s.name = 'bwapi'
5
5
  s.version = BWAPI::VERSION
6
6
  s.version = BWAPI::VERSION + ".pre.#{ENV['TRAVIS_BUILD_NUMBER']}" if ENV['TRAVIS']
7
- s.date = '2013-11-21'
8
- s.summary = 'Brandwatch v2 API Wrapper'
9
- s.description = 'A Ruby wrapper for the Brandwatch v2 API'
7
+ s.date = '2013-11-30'
8
+ s.summary = 'Brandwatch API Wrapper'
9
+ s.description = 'A Ruby wrapper for the Brandwatch API'
10
10
  s.author = 'Jonathan Chrisp'
11
11
  s.email = 'jonathan@brandwatch.com'
12
12
  s.license = 'MIT'
@@ -10,7 +10,7 @@ module BWAPI
10
10
  # @param opts [Hash] options hash of parameters
11
11
  # @option opts [Integer] text Text expression
12
12
  # @return [Hashie::Mash] List of queries
13
- def search_query_text opts
13
+ def search_query_text opts={}
14
14
  get "admin/search/querytext"
15
15
  end
16
16
  alias :query_text :search_query_text
@@ -20,7 +20,7 @@ module BWAPI
20
20
  # @param opts [Hash] options hash of parameters
21
21
  # @option opts [Integer] text Text expression
22
22
  # @return [Hashie::Mash] List of query names
23
- def search_query_name opts
23
+ def search_query_name opts={}
24
24
  get "admin/search/queryname"
25
25
  end
26
26
  alias :query_name :search_query_name
@@ -30,7 +30,7 @@ module BWAPI
30
30
  # @param opts [Hash] options hash of parameters
31
31
  # @option opts [Integer] text Text expression
32
32
  # @return [Hashie::Mash] List of rules
33
- def search_rule_text opts
33
+ def search_rule_text opts={}
34
34
  get "admin/search/ruletext"
35
35
  end
36
36
  alias :rule_text :search_rule_text
@@ -12,8 +12,8 @@ module BWAPI
12
12
  # @option opts [Integer] page Page of projects to retrieve
13
13
  # @option opts [Integer] pageSize Results per page of results
14
14
  # @return [Hashie::Mash] All sub clients for client
15
- def client_sub_clients client_id
16
- get "admin/clients/#{client_id}/subclients"
15
+ def client_sub_clients client_id, opts={}
16
+ get "admin/clients/#{client_id}/subclients", opts
17
17
  end
18
18
  alias :sub_clients :client_sub_clients
19
19
 
@@ -58,7 +58,7 @@ module BWAPI
58
58
  # @option opts [Integer] maximumSubscribedBrands The maximum subscribed brands for the client
59
59
  # @option opts [String] contactMobile The mobile number for the client
60
60
  # @return [Hashie::Mash] New sub client
61
- def create_client_sub_client client_id, opts
61
+ def create_client_sub_client client_id, opts={}
62
62
  post "admin/clients/#{client_id}/subclients", opts
63
63
  end
64
64
  alias :create_sub_client :create_client_sub_client
@@ -95,7 +95,7 @@ module BWAPI
95
95
  # @option opts [Integer] maximumSubscribedBrands The maximum subscribed brands for the client
96
96
  # @option opts [String] contactMobile The mobile number for the client
97
97
  # @return [Hashie::Mash] Edited sub client
98
- def update_client_sub_client client_id, sub_client_id, opts
98
+ def update_client_sub_client client_id, sub_client_id, opts={}
99
99
  put "admin/clients/#{client_id}/subclients/#{sub_client_id}", opts
100
100
  end
101
101
  alias :update_sub_client :update_client_sub_client
@@ -50,7 +50,7 @@ module BWAPI
50
50
  # @option opts [String] mobile The users mobile number
51
51
  # @option opts [Date] creationDate Date the user was created on
52
52
  # @return [Hashie::Mash] New user
53
- def create_client_user client_id, opts
53
+ def create_client_user client_id, opts={}
54
54
  post "admin/clients/#{client_id}/users", opts
55
55
  end
56
56
 
@@ -78,7 +78,7 @@ module BWAPI
78
78
  # @option opts [String] mobile The users mobile number
79
79
  # @option opts [Date] creationDate Date the user was created on
80
80
  # @return [Hashie::Mash] New user
81
- def update_client_user client_id, user_id, opts
81
+ def update_client_user client_id, user_id, opts={}
82
82
  put "admin/clients/#{client_id}/users/#{user_id}", opts
83
83
  end
84
84
 
@@ -21,7 +21,7 @@ module BWAPI
21
21
  # @option opts [String] downloadLinkCSV The link to download the CSV format
22
22
  # @option opts [Array] additionalColumns The additional columns for the data download
23
23
  # @return [Hashie::Mash] New data download
24
- def brandwatch_data_download project_id, opts
24
+ def brandwatch_data_download project_id, opts={}
25
25
  post "brandwatch/#{project_id}/datadownload", opts
26
26
  end
27
27
 
@@ -17,7 +17,7 @@ module BWAPI
17
17
  # @param opts [Hash] options Hash of parameters
18
18
  # @option opts [Array] ClientModules Client Modules to edit
19
19
  # @return [Hashie::Mash] Update client modules
20
- def update_brandwatch_client_module opts
20
+ def update_brandwatch_client_module opts={}
21
21
  put "brandwatch/clientModules", opts
22
22
  end
23
23
 
@@ -16,7 +16,7 @@ module BWAPI
16
16
  opts = {
17
17
  username: username,
18
18
  password: password,
19
- grant_type: grant_type ? grant_type : 'password',
19
+ grant_type: determine_grant_type,
20
20
  client_secret: client_secret,
21
21
  client_id: client_id,
22
22
  force_urlencoded: true
@@ -39,7 +39,6 @@ module BWAPI
39
39
  opts = {
40
40
  username: username,
41
41
  password: password,
42
-
43
42
  refresh_token: refresh_token,
44
43
  grant_type: 'refresh_token',
45
44
  client_id: client_id,
@@ -50,24 +49,23 @@ module BWAPI
50
49
  end
51
50
  alias :refresh :oauth_refresh_token
52
51
 
52
+ # Determines grant-type used for client
53
+ #
54
+ # @return [String] relevant grant type for client
55
+ def determine_grant_type
56
+ return grant_type unless grant_type.nil?
57
+ api_client? ? 'api-password' : 'password'
58
+ end
59
+
53
60
  # Sends a oauth request
54
61
  #
55
62
  # @param opts [Hash] options hash of parameters
56
- def oauth_request opts
57
- begin
58
- creds = post 'oauth/token', opts
59
- rescue BWAPI::BWError
60
- false
61
- else
62
- self.access_token = creds.access_token
63
- self.expires_in = creds.expires_in
64
-
65
- if application_client?
66
- self.refresh_token = creds.refresh_token
67
- end
68
-
69
- true
70
- end
63
+ def oauth_request opts={}
64
+ creds = post 'oauth/token', opts
65
+ self.access_token = creds.access_token
66
+ self.expires_in = creds.expires_in
67
+ self.refresh_token = creds.refresh_token if application_client?
68
+ creds
71
69
  end
72
70
 
73
71
  end
@@ -47,7 +47,7 @@ module BWAPI
47
47
  # @option opts [Date] creationDate Date the project was created on
48
48
  # @option opts [Integer] creationUserId User ID of the user who created the project
49
49
  # @return [Hashie::Mash] New project
50
- def create_project opts
50
+ def create_project opts={}
51
51
  post "projects", opts
52
52
  end
53
53
 
@@ -64,7 +64,7 @@ module BWAPI
64
64
  # @option opts [Date] creationDate Date the project was created on
65
65
  # @option opts [Integer] creationUserId User ID of the user who created the project
66
66
  # @return [Hashie::Mash] Updated project
67
- def update_project project_id, opts
67
+ def update_project project_id, opts={}
68
68
  put "projects/#{project_id}", opts
69
69
  end
70
70
 
@@ -25,7 +25,7 @@ module BWAPI
25
25
  # @option opts [Hash] filter The filters to apply
26
26
  # @option opts [Array] dateRanges Date range ids
27
27
  # @return [Hashie::Mash] All Chart data mentions
28
- def data_date_ranges_days project_id, opts
28
+ def data_date_ranges_days project_id, opts={}
29
29
  get "projects/#{project_id}/data/volume/dataRanges/days", opts
30
30
  end
31
31
 
@@ -43,7 +43,7 @@ module BWAPI
43
43
  # @option opts [Integer] queryId Query id of backfill
44
44
  # @option opts [String] statusMessages Current status message of backfill
45
45
  # @return [Hashie::Mash] New backfill for query
46
- def create_backfill project_id, query_id, opts
46
+ def create_backfill project_id, query_id, opts={}
47
47
  post "projects/#{project_id}/queries/#{query_id}/backfill", opts
48
48
  end
49
49
 
@@ -33,7 +33,7 @@ module BWAPI
33
33
  # @option opts [Integer] queryId Id of the query
34
34
  # @option opts [Array] StoredDateRangeDTO Date ranges to be stored
35
35
  # @return [Hashie::Mash] New date range
36
- def create_date_range project_id, query_id, opts
36
+ def create_date_range project_id, query_id, opts={}
37
37
  post "projects/#{project_id}/#{query_id}/date-range", opts
38
38
  end
39
39
 
@@ -47,7 +47,7 @@ module BWAPI
47
47
  # @option opts [Integer] dateRangeId Id of the date range
48
48
  # @option opts [Array] StoredDateRangeDTO Date ranges to be edited
49
49
  # @return [Hashie::Mash] Update date range
50
- def update_date_range project_id, query_id, opts
50
+ def update_date_range project_id, query_id, opts={}
51
51
  put "projects/#{project_id}/#{query_id}/date-range/#{date_range_id}", opts
52
52
  end
53
53
 
@@ -28,7 +28,7 @@ module BWAPI
28
28
  # @option opts [Integer] id Id of the mention
29
29
  # @option opts [Hash] MentionPatchDTO patch to be applied
30
30
  # @return [Hashie::Mash] Updated query mention
31
- def update_query_mention project_id, query_id, mention_id, opts
31
+ def update_query_mention project_id, query_id, mention_id, opts={}
32
32
  patch "projects/#{project_id}/queries/#{query_id}/mentions/#{mention_id}", opts
33
33
  end
34
34
 
@@ -43,7 +43,7 @@ module BWAPI
43
43
  # @option opts [Integer] id Id of the mention
44
44
  # @option opts [Hash] Map patch to be applied
45
45
  # @return [Hashie::Mash] Deleted query mention
46
- def delete_query_mention project_id, query_id, mention_id, opts
46
+ def delete_query_mention project_id, query_id, mention_id, opts={}
47
47
  delete "projects/#{project_id}/queries/#{query_id}/mentions/#{mention_id}", opts
48
48
  end
49
49
 
@@ -15,7 +15,7 @@ module BWAPI
15
15
  # @option opts [String] type Type of signal
16
16
  # @option opts [Hash] filter The filter(s) to apply
17
17
  # @return [Hashie::Mash] All signals for user in project
18
- def signals project_id, opts
18
+ def signals project_id, opts={}
19
19
  get "projects/#{project_id}/signals", opts
20
20
  end
21
21
 
@@ -28,7 +28,7 @@ module BWAPI
28
28
  # @option opts [String] comment User comment
29
29
  # @option opts [Integer] signalId Id of signal
30
30
  # @return [Hashie::Mash] Update signal for given user
31
- def set_signal_vote project_id, opts
31
+ def set_signal_vote project_id, opts={}
32
32
  post "projects/#{project_id}/signals/vote", opts
33
33
  end
34
34
 
@@ -31,7 +31,7 @@ module BWAPI
31
31
  # @option opts [Integer] id Id of the tag
32
32
  # @option opts [String] name Name of the tag
33
33
  # @return [Hashie::Mash] New tag
34
- def create_tag project_id, opts
34
+ def create_tag project_id, opts={}
35
35
  post "projects/#{project_id}/tags", opts
36
36
  end
37
37
 
@@ -43,7 +43,7 @@ module BWAPI
43
43
  # @option opts [Integer] id Id of the tag
44
44
  # @option opts [String] name Name of the tag
45
45
  # @return [Hashie::Mash] Updated tag
46
- def update_tag project_id, tag_id, opts
46
+ def update_tag project_id, tag_id, opts={}
47
47
  put "projects/#{project_id}/tags/#{tag_id}", opts
48
48
  end
49
49
 
@@ -9,7 +9,7 @@ module BWAPI
9
9
  # @option opts [String] query Query string
10
10
  # @option opts [Array] language Languages for query string
11
11
  # @return [Hashie::Mash] Query string validation results
12
- def query_validation opts
12
+ def query_validation opts={}
13
13
  get "query-validation", opts
14
14
  end
15
15
 
@@ -19,7 +19,7 @@ module BWAPI
19
19
  # @option opts [String] query Query string
20
20
  # @option opts [Array] language Languages for query string
21
21
  # @return [Hashie::Mash] Query string validation results
22
- def search_within opts
22
+ def search_within opts={}
23
23
  get "query-validation/searchwithin", opts
24
24
  end
25
25
 
@@ -34,7 +34,7 @@ module BWAPI
34
34
  # @option opts [String] mobile The users mobile number
35
35
  # @option opts [Date] creationDate Date the user was created on
36
36
  # @return [Hashie::Mash] Updated user information
37
- def update_user opts
37
+ def update_user opts={}
38
38
  put "user", opts
39
39
  end
40
40
 
@@ -19,7 +19,7 @@ module BWAPI
19
19
  # @param opts [Hash] options Hash of parameters
20
20
  # @option opts [Array] list User notifications to be edited
21
21
  # @return [Hashie::Mash] Updated user notifications
22
- def update_notification opts
22
+ def update_notification opts={}
23
23
  put "user/notifications", opts
24
24
  end
25
25
 
@@ -2,16 +2,67 @@ module BWAPI
2
2
 
3
3
  # BW error class to capture BWAPI error responses
4
4
  class BWError < StandardError
5
- def initialize response=nil
6
- if response.is_a? Hash
7
- errors = []
8
- response[:body]["errors"].each do |error|
9
- errors.push error['message']
10
- end
11
- response = errors.join(', ')
5
+ def initialize response = nil
6
+ errors_object = determine_errors(response)
7
+ super() if errors_object.nil?
8
+ super(generate_error_messages(errors_object))
9
+ end
10
+
11
+ # Determines from response and returns error(s)
12
+ def determine_errors response
13
+ return nil if response.nil?
14
+ return nil unless response.is_a?(Hash) && response.has_key?(:body)
15
+ return nil unless response[:body].is_a?(Hash)
16
+
17
+ # Determine if response body has known error keys and return
18
+ if response[:body].has_key?('error') && response[:body].has_key?('error_description')
19
+ return response[:body]
20
+ elsif response[:body].has_key?('errors')
21
+ return response[:body]['errors']
22
+ else
23
+ return nil
24
+ end
25
+ end
26
+
27
+ # Generates error messsages based on error object passed
28
+ #
29
+ # @param errors_object [Hash] errors
30
+ def generate_error_messages errors_object
31
+ @error_messages = []
32
+ verify_object_class errors_object
33
+ return @error_messages.join(', ')
34
+ end
35
+
36
+ # Verifies objects class
37
+ #
38
+ # @param object [Object] object to determine
39
+ def verify_object_class object
40
+ case object
41
+ when Array
42
+ split_array_errors(object)
43
+ when Hash, Hashie::Mash
44
+ split_hash_errors(object)
45
+ when String
46
+ @error_messages << object
12
47
  end
48
+ end
13
49
 
14
- super(response)
50
+ # Iterates through errors in array
51
+ #
52
+ # @param array [Array] array to iterate
53
+ def split_array_errors array
54
+ array.each_with_index do |e, i|
55
+ verify_object_class array[i]
56
+ end
57
+ end
58
+
59
+ # Iterates through errors in hash
60
+ #
61
+ # @param hash [Hash] hash to iterate
62
+ def split_hash_errors hash
63
+ message = []
64
+ hash.each {|k,v| message << "%s: %s" % [k, v]}
65
+ @error_messages << message.flatten.join(' with ')
15
66
  end
16
67
  end
17
68
 
@@ -19,11 +70,7 @@ module BWAPI
19
70
  class BadRequest < BWError; end
20
71
 
21
72
  # Raised when Brandwatch returns a 401 HTTP status code
22
- class Unauthorized < BWError
23
- def initialize response=nil
24
- response.nil? ? super() : super("#{response[:body]['error_description'] }")
25
- end
26
- end
73
+ class Unauthorized < BWError; end
27
74
 
28
75
  # Raised when Brandwatch returns a 403 HTTP status code
29
76
  class Forbidden < BWError; end
@@ -1,3 +1,3 @@
1
1
  module BWAPI
2
- VERSION = "2.0.3"
2
+ VERSION = "3.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bwapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 3.0.0.pre.88
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Chrisp
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-21 00:00:00.000000000 Z
11
+ date: 2013-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
96
  version: 2.0.5
97
- description: A Ruby wrapper for the Brandwatch v2 API
97
+ description: A Ruby wrapper for the Brandwatch API
98
98
  email: jonathan@brandwatch.com
99
99
  executables:
100
100
  - bwapi
@@ -172,24 +172,23 @@ require_paths:
172
172
  - lib
173
173
  required_ruby_version: !ruby/object:Gem::Requirement
174
174
  requirements:
175
- - - '>='
175
+ - - ! '>='
176
176
  - !ruby/object:Gem::Version
177
177
  version: 1.9.2
178
178
  required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  requirements:
180
- - - '>='
180
+ - - ! '>'
181
181
  - !ruby/object:Gem::Version
182
- version: '0'
182
+ version: 1.3.1
183
183
  requirements: []
184
184
  rubyforge_project:
185
- rubygems_version: 2.1.10
185
+ rubygems_version: 2.1.11
186
186
  signing_key:
187
187
  specification_version: 4
188
- summary: Brandwatch v2 API Wrapper
188
+ summary: Brandwatch API Wrapper
189
189
  test_files:
190
190
  - spec/bwapi/authentication_spec.rb
191
191
  - spec/bwapi/client_spec.rb
192
192
  - spec/bwapi_spec.rb
193
193
  - spec/fixtures/.netrc
194
194
  - spec/helper.rb
195
- has_rdoc: