bugsnag-api 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/.rubocop_todo.yml +271 -0
  4. data/.travis.yml +6 -3
  5. data/CHANGELOG.md +7 -0
  6. data/bugsnag-api.gemspec +1 -0
  7. data/lib/bugsnag/api/client.rb +12 -0
  8. data/lib/bugsnag/api/client/comments.rb +1 -1
  9. data/lib/bugsnag/api/client/errors.rb +3 -1
  10. data/lib/bugsnag/api/client/trends.rb +8 -4
  11. data/lib/bugsnag/api/configuration.rb +1 -1
  12. data/lib/bugsnag/api/version.rb +1 -1
  13. data/spec/bugsnag/api/client_spec.rb +69 -7
  14. data/spec/bugsnag/api_spec.rb +2 -0
  15. data/spec/cassettes/Bugsnag_Api_Client/_get/handles_query_params.yml +13 -21
  16. data/spec/cassettes/Bugsnag_Api_Client/_last_response/caches_the_last_agent_response.yml +13 -21
  17. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/_invitecollaborator/creates_and_returns_a_collaborator.yml +14 -26
  18. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/_invitecollaborator/invites_multiple_collaborators.yml +14 -26
  19. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_collaborator/returns_a_collaborator.yml +29 -53
  20. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_collaborators/returns_a_list_of_all_organization_collaborators.yml +30 -55
  21. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_collaborators/returns_a_list_of_all_project_collaborators.yml +30 -55
  22. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_collaborators/throws_an_argument_error_if_neither_org_id_or_project_id_are_provided.yml +14 -26
  23. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_delete_collaborator/deletes_a_collaborator.yml +14 -26
  24. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_update_collaborator_permissions/updates_and_returns_the_collaborator.yml +29 -53
  25. data/spec/cassettes/Bugsnag_Api_Client_Collaborators/given_a_collaborator_exists/_view_collaborator_projects/returns_a_list_of_projects_belonging_to_the_collaborator.yml +49 -55
  26. data/spec/cassettes/Bugsnag_Api_Client_Comments/_create_comment/creates_a_comment_on_the_error.yml +17 -29
  27. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_comment/retrieves_the_comment_specified.yml +32 -56
  28. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_comments/retrieves_all_comments_on_an_error.yml +33 -57
  29. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_delete_comment/deletes_the_comment_and_returns_true.yml +17 -29
  30. data/spec/cassettes/Bugsnag_Api_Client_Comments/given_a_comment_has_been_created/_update_comment/updates_the_message_on_a_comment.yml +32 -56
  31. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_organizations/when_using_auth_token/returns_the_organization_the_auth_token_belongs_to.yml +14 -27
  32. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_organizations/when_using_user_credentials/returns_users_organizations.yml +17 -31
  33. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_projects/when_using_auth_token/lists_current_user_s_projects_in_the_organization.yml +34 -28
  34. data/spec/cassettes/Bugsnag_Api_Client_CurrentUser/_list_projects/when_using_user_credentials/lists_current_user_s_projects_in_the_organization.yml +37 -32
  35. data/spec/cassettes/Bugsnag_Api_Client_Errors/_error/returns_a_single_error.yml +14 -28
  36. data/spec/cassettes/Bugsnag_Api_Client_Errors/_errors/returns_errors_on_the_project.yml +16 -30
  37. data/spec/cassettes/Bugsnag_Api_Client_Errors/_update_errors/updates_and_returns_the_updated_errors.yml +13 -25
  38. data/spec/cassettes/Bugsnag_Api_Client_Events/_error_events/lists_all_error_events.yml +19 -30
  39. data/spec/cassettes/Bugsnag_Api_Client_Events/_event/returns_the_specified_event.yml +16 -199
  40. data/spec/cassettes/Bugsnag_Api_Client_Events/_events/returns_the_a_list_of_project_errors.yml +19 -30
  41. data/spec/cassettes/Bugsnag_Api_Client_Events/_latest_event/returns_the_last_event_on_an_error.yml +16 -199
  42. data/spec/cassettes/Bugsnag_Api_Client_Organizations/_create_organization/creates_a_new_organization.yml +17 -30
  43. data/spec/cassettes/Bugsnag_Api_Client_Organizations/with_organization/_delete_organization/deletes_the_organization.yml +32 -58
  44. data/spec/cassettes/Bugsnag_Api_Client_Organizations/with_organization/_organization/returns_the_requested_organization.yml +35 -61
  45. data/spec/cassettes/Bugsnag_Api_Client_Organizations/with_organization/_update_organization/updates_and_returns_the_organization.yml +35 -61
  46. data/spec/cassettes/Bugsnag_Api_Client_Projects/_create_project/creates_a_new_project.yml +14 -26
  47. data/spec/cassettes/Bugsnag_Api_Client_Projects/given_a_project/_delete_project/deletes_the_project.yml +26 -50
  48. data/spec/cassettes/Bugsnag_Api_Client_Projects/given_a_project/_project/returns_the_requested_project.yml +29 -53
  49. data/spec/cassettes/Bugsnag_Api_Client_Projects/given_a_project/_regenerate_api_key/removes_the_current_api_key_and_replaces_it_with_a_new_api_key.yml +29 -53
  50. data/spec/cassettes/Bugsnag_Api_Client_Projects/given_a_project/_update_project/updates_and_returns_the_project.yml +29 -53
  51. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_buckets/returns_a_list_of_error_trends_in_bucket_form.yml +14 -26
  52. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_buckets/returns_a_list_of_project_trends_in_bucket_form.yml +14 -26
  53. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_resolution/returns_a_list_of_project_trends_in_resolution_form.yml +14 -26
  54. data/spec/cassettes/Bugsnag_Api_Client_Trends/_trends_resolution/returns_a_list_of_trends_in_resolution_form.yml +14 -26
  55. data/spec/spec_helper.rb +3 -3
  56. metadata +18 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4616f90142beb5163ce325dee92a393d3b990bac
4
- data.tar.gz: 0e1f46dd0c4543abaf73fd39a6bd63fc9028ab80
3
+ metadata.gz: f1a072712b9388b873f8159b1da219c8cdb56e88
4
+ data.tar.gz: 7094b51bf0f0565b52e04515007dd0456b8766c4
5
5
  SHA512:
6
- metadata.gz: c5b44534d8d0b639c054ad67402fcd4d25bb8c2f985e06019135c36868cdddc518d2915a88eefc7fed3e0b5da76dc4cba79473fd92ab68f28ea54b7002362557
7
- data.tar.gz: fd9c7470df57b829520e4deb9609e1e3414da9e6d4f7e261ca8cb2b1253a596e3bef1668621cc2411eae805d4a765379056092423cd94e4dcaeec9763b37536a
6
+ metadata.gz: 505c72dc46ca8a41bcc3772e765508b0d26c6610810a73e7bc542ea7a3ed903c7622aa6e41bfd86a4322ee41e940678e53f1ee0ee3ebcbf302e1145c6cfbb7af
7
+ data.tar.gz: c187d9eb7dd6fe2f234652e9bf85e324ac5c0a1f436b0b35e528ae670d8fb8d520347a433fd23dea7a48af2988833a41f170d3fb66a8aa95a7c985099f8d8498
@@ -0,0 +1,2 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
@@ -0,0 +1,271 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-02-20 14:31:40 +0000 using RuboCop version 0.52.1.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ Layout/EmptyLines:
12
+ Exclude:
13
+ - 'lib/bugsnag/api.rb'
14
+
15
+ # Offense count: 3
16
+ # Cop supports --auto-correct.
17
+ Layout/EmptyLinesAroundAccessModifier:
18
+ Exclude:
19
+ - 'lib/bugsnag/api.rb'
20
+ - 'lib/bugsnag/api/client.rb'
21
+ - 'lib/bugsnag/api/response/raise_error.rb'
22
+
23
+ # Offense count: 12
24
+ # Cop supports --auto-correct.
25
+ # Configuration parameters: EnforcedStyle.
26
+ # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
27
+ Layout/EmptyLinesAroundClassBody:
28
+ Exclude:
29
+ - 'lib/bugsnag/api/client/collaborators.rb'
30
+ - 'lib/bugsnag/api/client/comments.rb'
31
+ - 'lib/bugsnag/api/client/currentuser.rb'
32
+ - 'lib/bugsnag/api/client/errors.rb'
33
+ - 'lib/bugsnag/api/client/eventfields.rb'
34
+ - 'lib/bugsnag/api/client/events.rb'
35
+ - 'lib/bugsnag/api/client/organizations.rb'
36
+ - 'lib/bugsnag/api/client/pivots.rb'
37
+ - 'lib/bugsnag/api/client/projects.rb'
38
+ - 'lib/bugsnag/api/client/trends.rb'
39
+ - 'lib/bugsnag/api/error.rb'
40
+ - 'lib/bugsnag/api/response/raise_error.rb'
41
+
42
+ # Offense count: 4
43
+ # Cop supports --auto-correct.
44
+ # Configuration parameters: EnforcedStyle.
45
+ # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
46
+ Layout/EmptyLinesAroundModuleBody:
47
+ Exclude:
48
+ - 'lib/bugsnag/api.rb'
49
+ - 'lib/bugsnag/api/client.rb'
50
+ - 'lib/bugsnag/api/configuration.rb'
51
+ - 'lib/bugsnag/api/response/raise_error.rb'
52
+
53
+ # Offense count: 2
54
+ # Cop supports --auto-correct.
55
+ # Configuration parameters: EnforcedStyle, IndentationWidth.
56
+ # SupportedStyles: aligned, indented
57
+ Layout/MultilineOperationIndentation:
58
+ Exclude:
59
+ - 'lib/bugsnag/api/error.rb'
60
+
61
+ # Offense count: 1
62
+ # Cop supports --auto-correct.
63
+ Layout/SpaceAfterComma:
64
+ Exclude:
65
+ - 'lib/bugsnag/api/configuration.rb'
66
+
67
+ # Offense count: 7
68
+ # Cop supports --auto-correct.
69
+ # Configuration parameters: EnforcedStyle.
70
+ # SupportedStyles: space, no_space
71
+ Layout/SpaceAroundEqualsInParameterDefault:
72
+ Exclude:
73
+ - 'lib/bugsnag/api/client/errors.rb'
74
+ - 'lib/bugsnag/api/client/pivots.rb'
75
+ - 'lib/bugsnag/api/client/trends.rb'
76
+ - 'lib/bugsnag/api/error.rb'
77
+
78
+ # Offense count: 1
79
+ # Cop supports --auto-correct.
80
+ # Configuration parameters: EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
81
+ # SupportedStyles: space, no_space
82
+ # SupportedStylesForEmptyBraces: space, no_space
83
+ Layout/SpaceInsideBlockBraces:
84
+ EnforcedStyle: no_space
85
+
86
+ # Offense count: 34
87
+ # Cop supports --auto-correct.
88
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
89
+ # SupportedStyles: space, no_space, compact
90
+ # SupportedStylesForEmptyBraces: space, no_space
91
+ Layout/SpaceInsideHashLiteralBraces:
92
+ Exclude:
93
+ - 'lib/bugsnag/api/client.rb'
94
+ - 'lib/bugsnag/api/client/collaborators.rb'
95
+ - 'lib/bugsnag/api/client/comments.rb'
96
+ - 'lib/bugsnag/api/client/errors.rb'
97
+ - 'lib/bugsnag/api/client/eventfields.rb'
98
+ - 'lib/bugsnag/api/client/organizations.rb'
99
+ - 'lib/bugsnag/api/client/projects.rb'
100
+ - 'lib/bugsnag/api/client/trends.rb'
101
+
102
+ # Offense count: 17
103
+ # Cop supports --auto-correct.
104
+ Layout/TrailingWhitespace:
105
+ Exclude:
106
+ - 'lib/bugsnag/api/client/collaborators.rb'
107
+ - 'lib/bugsnag/api/client/currentuser.rb'
108
+ - 'lib/bugsnag/api/client/errors.rb'
109
+ - 'lib/bugsnag/api/client/eventfields.rb'
110
+ - 'lib/bugsnag/api/client/events.rb'
111
+ - 'lib/bugsnag/api/client/organizations.rb'
112
+ - 'lib/bugsnag/api/client/pivots.rb'
113
+ - 'lib/bugsnag/api/client/projects.rb'
114
+ - 'lib/bugsnag/api/client/trends.rb'
115
+
116
+ # Offense count: 1
117
+ Lint/AmbiguousOperator:
118
+ Exclude:
119
+ - 'lib/bugsnag/api/configuration.rb'
120
+
121
+ # Offense count: 4
122
+ # Configuration parameters: AllowSafeAssignment.
123
+ Lint/AssignmentInCondition:
124
+ Exclude:
125
+ - 'lib/bugsnag/api/client.rb'
126
+ - 'lib/bugsnag/api/error.rb'
127
+ - 'lib/bugsnag/api/response/raise_error.rb'
128
+
129
+ # Offense count: 4
130
+ # Cop supports --auto-correct.
131
+ # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
132
+ Lint/UnusedMethodArgument:
133
+ Exclude:
134
+ - 'lib/bugsnag/api/client.rb'
135
+ - 'lib/bugsnag/api/client/errors.rb'
136
+ - 'lib/bugsnag/api/client/eventfields.rb'
137
+
138
+ # Offense count: 1
139
+ Lint/UriEscapeUnescape:
140
+ Exclude:
141
+ - 'lib/bugsnag/api/client.rb'
142
+
143
+ # Offense count: 2
144
+ Lint/UselessAssignment:
145
+ Exclude:
146
+ - 'lib/bugsnag/api/error.rb'
147
+
148
+ # Offense count: 3
149
+ Metrics/AbcSize:
150
+ Max: 27
151
+
152
+ # Offense count: 1
153
+ # Configuration parameters: CountBlocks.
154
+ Metrics/BlockNesting:
155
+ Max: 4
156
+
157
+ # Offense count: 1
158
+ # Configuration parameters: CountComments.
159
+ Metrics/ClassLength:
160
+ Max: 127
161
+
162
+ # Offense count: 2
163
+ Metrics/CyclomaticComplexity:
164
+ Max: 18
165
+
166
+ # Offense count: 5
167
+ # Configuration parameters: CountComments.
168
+ Metrics/MethodLength:
169
+ Max: 23
170
+
171
+ # Offense count: 2
172
+ Metrics/PerceivedComplexity:
173
+ Max: 10
174
+
175
+ # Offense count: 10
176
+ # Cop supports --auto-correct.
177
+ # Configuration parameters: EnforcedStyle.
178
+ # SupportedStyles: braces, no_braces, context_dependent
179
+ Style/BracesAroundHashParameters:
180
+ Exclude:
181
+ - 'lib/bugsnag/api/client/collaborators.rb'
182
+ - 'lib/bugsnag/api/client/comments.rb'
183
+ - 'lib/bugsnag/api/client/errors.rb'
184
+ - 'lib/bugsnag/api/client/eventfields.rb'
185
+ - 'lib/bugsnag/api/client/organizations.rb'
186
+ - 'lib/bugsnag/api/client/projects.rb'
187
+
188
+ # Offense count: 2
189
+ Style/DoubleNegation:
190
+ Exclude:
191
+ - 'lib/bugsnag/api/client.rb'
192
+
193
+ # Offense count: 1
194
+ # Cop supports --auto-correct.
195
+ # Configuration parameters: EnforcedStyle.
196
+ # SupportedStyles: empty, nil, both
197
+ Style/EmptyElse:
198
+ Exclude:
199
+ - 'lib/bugsnag/api/error.rb'
200
+
201
+ # Offense count: 1
202
+ # Configuration parameters: MinBodyLength.
203
+ Style/GuardClause:
204
+ Exclude:
205
+ - 'lib/bugsnag/api/response/raise_error.rb'
206
+
207
+ # Offense count: 26
208
+ # Cop supports --auto-correct.
209
+ # Configuration parameters: UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
210
+ # SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
211
+ Style/HashSyntax:
212
+ EnforcedStyle: hash_rockets
213
+
214
+ # Offense count: 1
215
+ Style/IfInsideElse:
216
+ Exclude:
217
+ - 'lib/bugsnag/api/client.rb'
218
+
219
+ # Offense count: 1
220
+ Style/MethodMissing:
221
+ Exclude:
222
+ - 'lib/bugsnag/api.rb'
223
+
224
+ # Offense count: 4
225
+ # Cop supports --auto-correct.
226
+ Style/MutableConstant:
227
+ Exclude:
228
+ - 'lib/bugsnag/api/configuration.rb'
229
+ - 'lib/bugsnag/api/version.rb'
230
+
231
+ # Offense count: 2
232
+ # Cop supports --auto-correct.
233
+ Style/RedundantSelf:
234
+ Exclude:
235
+ - 'lib/bugsnag/api/configuration.rb'
236
+
237
+ # Offense count: 31
238
+ # Cop supports --auto-correct.
239
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
240
+ # SupportedStyles: single_quotes, double_quotes
241
+ Style/StringLiterals:
242
+ Exclude:
243
+ - 'lib/bugsnag/api.rb'
244
+ - 'lib/bugsnag/api/client.rb'
245
+ - 'lib/bugsnag/api/client/collaborators.rb'
246
+ - 'lib/bugsnag/api/client/currentuser.rb'
247
+ - 'lib/bugsnag/api/client/errors.rb'
248
+ - 'lib/bugsnag/api/client/organizations.rb'
249
+ - 'lib/bugsnag/api/configuration.rb'
250
+ - 'lib/bugsnag/api/error.rb'
251
+ - 'lib/bugsnag/api/response/raise_error.rb'
252
+ - 'lib/bugsnag/api/version.rb'
253
+
254
+ # Offense count: 2
255
+ # Cop supports --auto-correct.
256
+ # Configuration parameters: MinSize.
257
+ # SupportedStyles: percent, brackets
258
+ Style/SymbolArray:
259
+ EnforcedStyle: brackets
260
+
261
+ # Offense count: 1
262
+ # Cop supports --auto-correct.
263
+ Style/UnneededInterpolation:
264
+ Exclude:
265
+ - 'lib/bugsnag/api/error.rb'
266
+
267
+ # Offense count: 80
268
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
269
+ # URISchemes: http, https
270
+ Metrics/LineLength:
271
+ Max: 146
@@ -7,11 +7,14 @@ rvm:
7
7
  - 1.9.3
8
8
  - jruby-19mode
9
9
 
10
- before_install:
11
- - echo YOLO
12
-
13
10
  install:
14
11
  - bundle install --with "$GEMSETS"
15
12
 
13
+ jobs:
14
+ include:
15
+ - stage: test
16
+ rvm: 2.4.1
17
+ script: bundle exec rubocop lib/
18
+
16
19
  script:
17
20
  - bundle exec rake spec
@@ -1,6 +1,13 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## 2.0.2 (21 Feb 2018)
5
+
6
+ ### Fixes
7
+
8
+ * Fixes issue with custom query parameters being overridden
9
+ | [#13](https://github.com/bugsnag/bugsnag-api-ruby/pull/13)
10
+
4
11
  ## 2.0.1 (15 Nov 2017)
5
12
 
6
13
  ### Fixes
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "faker", RUBY_VERSION <= '2.0.0' ? '1.3.0' : '>1.7.3'
28
28
  spec.add_development_dependency "vcr", "~> 2.9"
29
29
  spec.add_development_dependency "json"
30
+ spec.add_development_dependency "rubocop", RUBY_VERSION <= '2.1.0' ? '0.41.2': '~>0.52.1'
30
31
  end
@@ -143,6 +143,18 @@ module Bugsnag
143
143
  !!configuration.auth_token
144
144
  end
145
145
 
146
+ # Merges hashes together cleanly, favouring RHS values
147
+ #
148
+ # @return [Hash]
149
+ def deep_merge(l_hash, r_hash)
150
+ l_hash.merge(r_hash) do |_key, l_val, r_val|
151
+ if l_val.is_a?(Hash) && r_val.is_a?(Hash)
152
+ deep_merge(l_val, r_val)
153
+ else
154
+ r_val
155
+ end
156
+ end
157
+ end
146
158
 
147
159
  private
148
160
  def agent
@@ -44,7 +44,7 @@ module Bugsnag
44
44
 
45
45
  # Delete a Comment
46
46
  #
47
- # @return
47
+ # @return
48
48
  # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors/comments/delete-a-comment
49
49
  def delete_comment(id, options = {})
50
50
  boolean_from_response :delete, "comments/#{id}", options
@@ -42,7 +42,9 @@ module Bugsnag
42
42
  when String
43
43
  patch "projects/#{project_id}/errors/#{ids}", options.merge({:operation => operation})
44
44
  when Array
45
- patch "projects/#{project_id}/errors", options.merge({:operation => operation, :query => {:error_ids => ids.join(' ')}})
45
+ defaults = {:operation => operation, :query => {:error_ids => ids.join(' ')}}
46
+ merged_opts = deep_merge(defaults, options)
47
+ patch "projects/#{project_id}/errors", merged_opts
46
48
  else
47
49
  raise ArgumentError, "ids must be a String or an Array"
48
50
  end
@@ -12,10 +12,12 @@ module Bugsnag
12
12
  # @return [Array<Sawyer::Resource>] List of Trends as requested
13
13
  # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors/trends/list-the-trends-for-an-error-(buckets)
14
14
  def trends_buckets(project_id, buckets_count, error_id=nil, options = {})
15
+ defaults = {:query => {:buckets_count => buckets_count}}
16
+ merged_opts = deep_merge(defaults, options)
15
17
  if !error_id.nil?
16
- get "projects/#{project_id}/errors/#{error_id}/trend", options.merge({:query => {:buckets_count => buckets_count}})
18
+ get "projects/#{project_id}/errors/#{error_id}/trend", merged_opts
17
19
  else
18
- get "projects/#{project_id}/trend", options.merge({:query => {:buckets_count => buckets_count}})
20
+ get "projects/#{project_id}/trend", merged_opts
19
21
  end
20
22
  end
21
23
 
@@ -25,10 +27,12 @@ module Bugsnag
25
27
  # @return [Array<Sawyer::Resource>] List of Trends as requested
26
28
  # @see http://docs.bugsnagapiv2.apiary.io/#reference/errors/trends/list-the-trends-for-an-error-(buckets)
27
29
  def trends_resolution(project_id, resolution, error_id=nil, options = {})
30
+ defaults = {:query => {:resolution => resolution}}
31
+ merged_opts = deep_merge(defaults, options)
28
32
  if !error_id.nil?
29
- get "projects/#{project_id}/errors/#{error_id}/trend", options.merge({:query => {:resolution => resolution}})
33
+ get "projects/#{project_id}/errors/#{error_id}/trend", merged_opts
30
34
  else
31
- get "projects/#{project_id}/trend", options.merge({:query => {:resolution => resolution}})
35
+ get "projects/#{project_id}/trend", merged_opts
32
36
  end
33
37
  end
34
38
  end
@@ -45,7 +45,7 @@ module Bugsnag
45
45
 
46
46
  # Load configuration from hash
47
47
  def load(options = {})
48
- options.each {|k,v| self.send("#{k}=", v) if self.respond_to?("#{k}=") && !v.nil?}
48
+ options.each { |k,v| self.send("#{k}=", v) if self.respond_to?("#{k}=") && !v.nil?}
49
49
  end
50
50
  end
51
51
  end
@@ -1,5 +1,5 @@
1
1
  module Bugsnag
2
2
  module Api
3
- VERSION = "2.0.1"
3
+ VERSION = "2.0.2"
4
4
  end
5
5
  end
@@ -1,3 +1,4 @@
1
+ require "spec_helper"
1
2
  require "json"
2
3
 
3
4
  describe Bugsnag::Api::Client do
@@ -45,7 +46,7 @@ describe Bugsnag::Api::Client do
45
46
 
46
47
  it "handles query params", :vcr do
47
48
  Bugsnag::Api.get bugsnag_url("/"), :foo => "bar"
48
- assert_requested :get, "https://api.bugsnag.com?foo=bar"
49
+ assert_requested :get, bugsnag_url("?foo=bar")
49
50
  end
50
51
 
51
52
  it "handles headers" do
@@ -81,20 +82,81 @@ describe Bugsnag::Api::Client do
81
82
  end
82
83
  end
83
84
 
85
+ describe ".deep_merge" do
86
+ it "returns a merged hash" do
87
+ client = Bugsnag::Api::Client.new(:auth_token => "example")
88
+ lhs = {
89
+ :foo => "foo"
90
+ }
91
+ rhs = {
92
+ :bar => "bar"
93
+ }
94
+ merged = client.deep_merge(lhs, rhs)
95
+ expect(merged).to_not eq(lhs)
96
+ expect(merged).to_not eq(rhs)
97
+ expect(merged).to eq({
98
+ :foo => "foo",
99
+ :bar => "bar"
100
+ })
101
+ end
102
+
103
+ it "favors rhs over lhs" do
104
+ client = Bugsnag::Api::Client.new(:auth_token => "example")
105
+ lhs = {
106
+ :foo => "foo"
107
+ }
108
+ rhs = {
109
+ :foo => "bar"
110
+ }
111
+ merged = client.deep_merge(lhs, rhs)
112
+ expect(merged).to eq({:foo => "bar"})
113
+ end
114
+
115
+ it "recursively merges hashes" do
116
+ client = Bugsnag::Api::Client.new(:auth_token => "example")
117
+ lhs = {
118
+ :foo => {
119
+ :bar => "bar"
120
+ }
121
+ }
122
+ rhs = {
123
+ :foo => {
124
+ :foobar => "foobar"
125
+ }
126
+ }
127
+ merged = client.deep_merge(lhs, rhs)
128
+ expect(merged).to eq(
129
+ {:foo => {
130
+ :bar => "bar",
131
+ :foobar => "foobar"
132
+ }
133
+ })
134
+ end
135
+ end
136
+
84
137
  context "error handling" do
138
+
139
+ before do
140
+ VCR.turn_off!
141
+ end
142
+
143
+ after do
144
+ VCR.turn_on!
145
+ end
146
+
85
147
  it "raises on 404" do
86
148
  stub_get('/booya').to_return(:status => 404)
87
- expect { Bugsnag::Api.get('/booya') }.to raise_error(Bugsnag::Api::NotFound)
149
+ expect { Bugsnag::Api.get(bugsnag_url('/booya')) }.to raise_error(Bugsnag::Api::NotFound)
88
150
  end
89
151
 
90
152
  it "raises on 429" do
91
153
  stub_get('/test').to_return(:status => 429)
92
- expect { Bugsnag::Api.get('/test') }.to raise_error(Bugsnag::Api::RateLimitExceeded)
154
+ expect { Bugsnag::Api.get(bugsnag_url('/test')) }.to raise_error(Bugsnag::Api::RateLimitExceeded)
93
155
  end
94
156
 
95
157
  it "raises on 500" do
96
158
  stub_get('/boom').to_return(:status => 500)
97
- expect { Bugsnag::Api.get('/boom') }.to raise_error(Bugsnag::Api::InternalServerError)
159
+ expect { Bugsnag::Api.get(bugsnag_url('/boom')) }.to raise_error(Bugsnag::Api::InternalServerError)
98
160
  end
99
161
 
100
162
  it "includes an error" do
@@ -106,7 +168,7 @@ describe Bugsnag::Api::Client do
106
168
  },
107
169
  :body => {:error => "Comments must contain a message"}.to_json
108
170
  begin
109
- Bugsnag::Api.get('/boom')
171
+ Bugsnag::Api.get(bugsnag_url('/boom'))
110
172
  rescue Bugsnag::Api::UnprocessableEntity => e
111
173
  expect(e.message).to include("Error: Comments must contain a message")
112
174
  end
@@ -119,7 +181,7 @@ describe Bugsnag::Api::Client do
119
181
  :content_type => "application/json",
120
182
  },
121
183
  :body => {:message => "I'm a teapot"}.to_json
122
- expect { Bugsnag::Api.get('/user') }.to raise_error(Bugsnag::Api::ClientError)
184
+ expect { Bugsnag::Api.get(bugsnag_url('/user')) }.to raise_error(Bugsnag::Api::ClientError)
123
185
  end
124
186
 
125
187
  it "raises on unknown server errors" do
@@ -129,7 +191,7 @@ describe Bugsnag::Api::Client do
129
191
  :content_type => "application/json",
130
192
  },
131
193
  :body => {:message => "Bandwidth exceeded"}.to_json
132
- expect { Bugsnag::Api.get('/user') }.to raise_error(Bugsnag::Api::ServerError)
194
+ expect { Bugsnag::Api.get(bugsnag_url('/user')) }.to raise_error(Bugsnag::Api::ServerError)
133
195
  end
134
196
  end
135
197
  end