zendesk_api 0.1.11 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +1 -3
  3. data/Gemfile +24 -0
  4. data/Gemfile.lock +75 -10
  5. data/Procfile +1 -0
  6. data/Rakefile +10 -3
  7. data/Readme.md +65 -0
  8. data/bin/zendesk +26 -0
  9. data/config.ru +6 -0
  10. data/config/mongoid.yml +81 -0
  11. data/lib/zendesk_api/actions.rb +2 -2
  12. data/lib/zendesk_api/collection.rb +15 -4
  13. data/lib/zendesk_api/console/base.rb +12 -0
  14. data/lib/zendesk_api/console/console.rb +144 -0
  15. data/lib/zendesk_api/console/extensions.rb +183 -0
  16. data/lib/zendesk_api/console/options.rb +41 -0
  17. data/lib/zendesk_api/resource.rb +12 -1
  18. data/lib/zendesk_api/resources.rb +28 -8
  19. data/lib/zendesk_api/server/base.rb +119 -0
  20. data/lib/zendesk_api/server/docs/account_settings.md +145 -0
  21. data/lib/zendesk_api/server/docs/activity_stream.md +121 -0
  22. data/lib/zendesk_api/server/docs/attachments.md +73 -0
  23. data/lib/zendesk_api/server/docs/autocomplete.md +29 -0
  24. data/lib/zendesk_api/server/docs/categories.md +193 -0
  25. data/lib/zendesk_api/server/docs/custom_roles.md +88 -0
  26. data/lib/zendesk_api/server/docs/forum_subscriptions.md +139 -0
  27. data/lib/zendesk_api/server/docs/forums.md +229 -0
  28. data/lib/zendesk_api/server/docs/group_memberships.md +229 -0
  29. data/lib/zendesk_api/server/docs/groups.md +212 -0
  30. data/lib/zendesk_api/server/docs/introduction.md +159 -0
  31. data/lib/zendesk_api/server/docs/job_statuses.md +86 -0
  32. data/lib/zendesk_api/server/docs/locales.md +124 -0
  33. data/lib/zendesk_api/server/docs/macros.md +287 -0
  34. data/lib/zendesk_api/server/docs/organizations.md +253 -0
  35. data/lib/zendesk_api/server/docs/problems.md +117 -0
  36. data/lib/zendesk_api/server/docs/requests.md +256 -0
  37. data/lib/zendesk_api/server/docs/satisfaction_ratings.md +136 -0
  38. data/lib/zendesk_api/server/docs/search.md +106 -0
  39. data/lib/zendesk_api/server/docs/sharing_agreements.md +57 -0
  40. data/lib/zendesk_api/server/docs/side_loading.md +125 -0
  41. data/lib/zendesk_api/server/docs/suspended_tickets.md +182 -0
  42. data/lib/zendesk_api/server/docs/tags.md +36 -0
  43. data/lib/zendesk_api/server/docs/ticket_audits.md +657 -0
  44. data/lib/zendesk_api/server/docs/ticket_export.md +121 -0
  45. data/lib/zendesk_api/server/docs/ticket_fields.md +277 -0
  46. data/lib/zendesk_api/server/docs/ticket_import.md +65 -0
  47. data/lib/zendesk_api/server/docs/ticket_metrics.md +125 -0
  48. data/lib/zendesk_api/server/docs/tickets.md +622 -0
  49. data/lib/zendesk_api/server/docs/topic_comments.md +221 -0
  50. data/lib/zendesk_api/server/docs/topic_subscriptions.md +140 -0
  51. data/lib/zendesk_api/server/docs/topic_votes.md +154 -0
  52. data/lib/zendesk_api/server/docs/topics.md +335 -0
  53. data/lib/zendesk_api/server/docs/triggers.md +199 -0
  54. data/lib/zendesk_api/server/docs/user_identities.md +279 -0
  55. data/lib/zendesk_api/server/docs/users.md +400 -0
  56. data/lib/zendesk_api/server/docs/views.md +505 -0
  57. data/lib/zendesk_api/server/helper.rb +104 -0
  58. data/lib/zendesk_api/server/html_renderer.rb +98 -0
  59. data/lib/zendesk_api/server/models/user_request.rb +16 -0
  60. data/lib/zendesk_api/server/models/zlib_json.rb +13 -0
  61. data/lib/zendesk_api/server/public/config.rb +26 -0
  62. data/lib/zendesk_api/server/public/favicon.ico +0 -0
  63. data/lib/zendesk_api/server/public/images/glyphicons-halflings-white.png +0 -0
  64. data/lib/zendesk_api/server/public/images/glyphicons-halflings.png +0 -0
  65. data/lib/zendesk_api/server/public/images/spinner.gif +0 -0
  66. data/lib/zendesk_api/server/public/images/zendesk_developers_bg.png +0 -0
  67. data/lib/zendesk_api/server/public/images/zendesk_developers_header.png +0 -0
  68. data/lib/zendesk_api/server/public/javascripts/application.js +186 -0
  69. data/lib/zendesk_api/server/public/javascripts/bootstrap-alert.js +90 -0
  70. data/lib/zendesk_api/server/public/javascripts/bootstrap-button.js +96 -0
  71. data/lib/zendesk_api/server/public/javascripts/bootstrap-carousel.js +169 -0
  72. data/lib/zendesk_api/server/public/javascripts/bootstrap-collapse.js +157 -0
  73. data/lib/zendesk_api/server/public/javascripts/bootstrap-dropdown.js +100 -0
  74. data/lib/zendesk_api/server/public/javascripts/bootstrap-modal.js +218 -0
  75. data/lib/zendesk_api/server/public/javascripts/bootstrap-popover.js +98 -0
  76. data/lib/zendesk_api/server/public/javascripts/bootstrap-scrollspy.js +151 -0
  77. data/lib/zendesk_api/server/public/javascripts/bootstrap-tab.js +135 -0
  78. data/lib/zendesk_api/server/public/javascripts/bootstrap-tooltip.js +275 -0
  79. data/lib/zendesk_api/server/public/javascripts/bootstrap-transition.js +61 -0
  80. data/lib/zendesk_api/server/public/javascripts/bootstrap-typeahead.js +285 -0
  81. data/lib/zendesk_api/server/public/sass/screen.scss +102 -0
  82. data/lib/zendesk_api/server/public/sass/styles.scss +5 -0
  83. data/lib/zendesk_api/server/public/stylesheets/developer.screen.css +836 -0
  84. data/lib/zendesk_api/server/public/stylesheets/screen.css +129 -0
  85. data/lib/zendesk_api/server/public/stylesheets/styles.css +6208 -0
  86. data/lib/zendesk_api/server/templates/footer.haml +13 -0
  87. data/lib/zendesk_api/server/templates/header.haml +20 -0
  88. data/lib/zendesk_api/server/templates/index.haml +68 -0
  89. data/lib/zendesk_api/server/templates/layout.haml +44 -0
  90. data/lib/zendesk_api/server/templates/param.haml +4 -0
  91. data/lib/zendesk_api/server/templates/search.haml +23 -0
  92. data/lib/zendesk_api/server/templates/sidebar.haml +7 -0
  93. data/lib/zendesk_api/version.rb +1 -1
  94. data/spec/{association_spec.rb → core/association_spec.rb} +1 -1
  95. data/spec/{client_spec.rb → core/client_spec.rb} +1 -1
  96. data/spec/{collection_spec.rb → core/collection_spec.rb} +1 -1
  97. data/spec/{configuration_spec.rb → core/configuration_spec.rb} +1 -1
  98. data/spec/{create_resource_spec.rb → core/create_resource_spec.rb} +1 -1
  99. data/spec/{data_resource_spec.rb → core/data_resource_spec.rb} +1 -1
  100. data/spec/{inflection_spec.rb → core/inflection_spec.rb} +1 -1
  101. data/spec/{lru_cache_spec.rb → core/lru_cache_spec.rb} +1 -1
  102. data/spec/{middleware → core/middleware}/request/etag_cache_spec.rb +1 -1
  103. data/spec/{middleware → core/middleware}/request/retry_spec.rb +1 -1
  104. data/spec/{middleware → core/middleware}/request/test.jpg +0 -0
  105. data/spec/{middleware → core/middleware}/request/upload_spec.rb +1 -1
  106. data/spec/{middleware → core/middleware}/response/callback_spec.rb +1 -1
  107. data/spec/{middleware → core/middleware}/response/deflate_spec.rb +1 -1
  108. data/spec/{middleware → core/middleware}/response/gzip_spec.rb +1 -1
  109. data/spec/{middleware → core/middleware}/response/parse_iso_dates_spec.rb +1 -1
  110. data/spec/{read_resource_spec.rb → core/read_resource_spec.rb} +1 -1
  111. data/spec/{rescue_spec.rb → core/rescue_spec.rb} +1 -1
  112. data/spec/{resource_spec.rb → core/resource_spec.rb} +1 -1
  113. data/spec/{search_spec.rb → core/search_spec.rb} +1 -1
  114. data/spec/{spec_helper.rb → core/spec_helper.rb} +5 -5
  115. data/spec/{trackie_spec.rb → core/trackie_spec.rb} +1 -1
  116. data/{live → spec/live}/Readme.md +0 -0
  117. data/{live → spec/live}/activity_spec.rb +1 -1
  118. data/{live → spec/live}/audit_spec.rb +1 -1
  119. data/{live → spec/live}/bookmark_spec.rb +1 -1
  120. data/{live → spec/live}/category_spec.rb +1 -1
  121. data/{live → spec/live}/collection_spec.rb +1 -1
  122. data/{live → spec/live}/crm_spec.rb +1 -1
  123. data/{live → spec/live}/custom_role_spec.rb +1 -1
  124. data/{live → spec/live}/forum_spec.rb +1 -1
  125. data/{live → spec/live}/forum_subscription_spec.rb +1 -1
  126. data/{live → spec/live}/group_membership_spec.rb +1 -1
  127. data/{live → spec/live}/group_spec.rb +1 -1
  128. data/{live → spec/live}/identity_spec.rb +1 -1
  129. data/{live → spec/live}/locale_spec.rb +1 -1
  130. data/{live → spec/live}/macro_spec.rb +1 -1
  131. data/{live → spec/live}/mobile_device_spec.rb +1 -1
  132. data/{live → spec/live}/organization_spec.rb +1 -1
  133. data/{live → spec/live}/request_spec.rb +1 -1
  134. data/{live → spec/live}/satisfaction_rating_spec.rb +1 -1
  135. data/{live → spec/live}/setting_spec.rb +1 -1
  136. data/{live → spec/live}/suspended_ticket_spec.rb +1 -1
  137. data/{live → spec/live}/ticket_field_spec.rb +1 -1
  138. data/{live → spec/live}/ticket_metrics_spec.rb +1 -1
  139. data/{live → spec/live}/ticket_spec.rb +1 -1
  140. data/spec/live/topic_comment_spec.rb +24 -0
  141. data/{live → spec/live}/topic_spec.rb +1 -1
  142. data/{live → spec/live}/topic_subscription_spec.rb +1 -1
  143. data/{live → spec/live}/topic_vote_spec.rb +1 -1
  144. data/{live → spec/live}/upload_spec.rb +1 -1
  145. data/{live → spec/live}/user_spec.rb +1 -1
  146. data/{live → spec/live}/view_spec.rb +1 -1
  147. data/spec/macros/resource_macros.rb +1 -1
  148. data/spec/server/app_spec.rb +140 -0
  149. data/spec/server/helper_spec.rb +97 -0
  150. data/spec/server/html_renderer_spec.rb +130 -0
  151. data/spec/server/spec_helper.rb +43 -0
  152. metadata +198 -77
  153. data/live/topic_comment_spec.rb +0 -13
data/.gitignore CHANGED
@@ -6,3 +6,6 @@ spec/fixtures/credentials.yml
6
6
  coverage
7
7
  .yardoc
8
8
  example.rb
9
+ bin/*.yml
10
+ .sass-cache
11
+ config/mongod
data/.travis.yml CHANGED
@@ -3,6 +3,4 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - jruby
6
- branches:
7
- except:
8
- - zendesk_console
6
+ bundler_args: --without=server console
data/Gemfile CHANGED
@@ -5,4 +5,28 @@ gem "jruby-openssl", :platforms => :jruby
5
5
  gem "hashie", :git => "git://github.com/intridea/hashie.git"
6
6
  gem "multipart-post", :git => "git://github.com/steved555/multipart-post.git"
7
7
 
8
+ group :server do
9
+ gem "rack-ssl-enforcer"
10
+
11
+ gem "sinatra"
12
+ gem "sinatra-contrib"
13
+
14
+ gem "haml"
15
+
16
+ gem "compass"
17
+ gem "bootstrap-sass"
18
+
19
+ gem "coderay"
20
+ gem "coderay_bash"
21
+
22
+ gem "redcarpet"
23
+
24
+ gem "mongoid"
25
+ gem "database_cleaner"
26
+ end
27
+
28
+ group :console do
29
+ gem "ripl"
30
+ end
31
+
8
32
  gemspec
data/Gemfile.lock CHANGED
@@ -6,14 +6,14 @@ GIT
6
6
 
7
7
  GIT
8
8
  remote: git://github.com/steved555/multipart-post.git
9
- revision: f5bc9450fad3895542a7cf18dbdd9af4ba5ab031
9
+ revision: 57c66998c05143a684c13694937c8adfd335cae1
10
10
  specs:
11
11
  multipart-post (1.1.5)
12
12
 
13
13
  PATH
14
14
  remote: .
15
15
  specs:
16
- zendesk_api (0.1.11)
16
+ zendesk_api (0.2.0)
17
17
  faraday (>= 0.8.0)
18
18
  faraday_middleware (>= 0.8.7)
19
19
  hashie
@@ -25,19 +25,58 @@ PATH
25
25
  GEM
26
26
  remote: https://rubygems.org/
27
27
  specs:
28
+ activemodel (3.2.8)
29
+ activesupport (= 3.2.8)
30
+ builder (~> 3.0.0)
31
+ activesupport (3.2.8)
32
+ i18n (~> 0.6)
33
+ multi_json (~> 1.0)
28
34
  addressable (2.3.2)
29
- bump (0.3.3)
35
+ backports (2.6.5)
36
+ bond (0.4.2)
37
+ bootstrap-sass (2.1.1.0)
38
+ builder (3.0.4)
39
+ bump (0.3.5)
40
+ chunky_png (1.2.6)
41
+ coderay (1.0.8)
42
+ coderay_bash (1.0.4)
43
+ coderay (>= 1.0)
44
+ compass (0.12.2)
45
+ chunky_png (~> 1.2)
46
+ fssm (>= 0.2.7)
47
+ sass (~> 3.1)
30
48
  crack (0.3.1)
49
+ database_cleaner (0.9.1)
31
50
  diff-lcs (1.1.3)
51
+ eventmachine (1.0.0)
32
52
  faraday (0.8.4)
33
53
  multipart-post (~> 1.1)
34
54
  faraday_middleware (0.9.0)
35
55
  faraday (>= 0.7.4, < 0.9)
56
+ fssm (0.2.9)
57
+ haml (3.1.7)
58
+ i18n (0.6.1)
36
59
  inflection (1.0.0)
37
60
  json (1.7.5)
38
61
  mime-types (1.19)
39
- multi_json (1.3.6)
62
+ mongoid (3.0.11)
63
+ activemodel (~> 3.1)
64
+ moped (~> 1.1)
65
+ origin (~> 1.0)
66
+ tzinfo (~> 0.3.22)
67
+ moped (1.2.8)
68
+ multi_json (1.3.7)
69
+ origin (1.0.10)
70
+ rack (1.4.1)
71
+ rack-protection (1.2.0)
72
+ rack
73
+ rack-ssl-enforcer (0.2.4)
74
+ rack-test (0.6.2)
75
+ rack (>= 1.0)
40
76
  rake (0.9.2.2)
77
+ redcarpet (2.2.2)
78
+ ripl (0.7.0)
79
+ bond (~> 0.4.2)
41
80
  rspec (2.11.0)
42
81
  rspec-core (~> 2.11.0)
43
82
  rspec-expectations (~> 2.11.0)
@@ -46,27 +85,53 @@ GEM
46
85
  rspec-expectations (2.11.3)
47
86
  diff-lcs (~> 1.1.3)
48
87
  rspec-mocks (2.11.3)
49
- simplecov (0.6.4)
88
+ sass (3.2.2)
89
+ simplecov (0.7.1)
50
90
  multi_json (~> 1.0)
51
- simplecov-html (~> 0.5.3)
52
- simplecov-html (0.5.3)
53
- vcr (2.2.5)
54
- webmock (1.8.11)
91
+ simplecov-html (~> 0.7.1)
92
+ simplecov-html (0.7.1)
93
+ sinatra (1.3.3)
94
+ rack (~> 1.3, >= 1.3.6)
95
+ rack-protection (~> 1.2)
96
+ tilt (~> 1.3, >= 1.3.3)
97
+ sinatra-contrib (1.3.2)
98
+ backports (>= 2.0)
99
+ eventmachine
100
+ rack-protection
101
+ rack-test
102
+ sinatra (~> 1.3.0)
103
+ tilt (~> 1.3)
104
+ tilt (1.3.3)
105
+ tzinfo (0.3.35)
106
+ vcr (2.3.0)
107
+ webmock (1.9.0)
55
108
  addressable (>= 2.2.7)
56
109
  crack (>= 0.1.7)
57
- yard (0.8.2.1)
110
+ yard (0.8.3)
58
111
 
59
112
  PLATFORMS
60
113
  ruby
61
114
 
62
115
  DEPENDENCIES
116
+ bootstrap-sass
63
117
  bump
118
+ coderay
119
+ coderay_bash
120
+ compass
121
+ database_cleaner
122
+ haml
64
123
  hashie!
65
124
  jruby-openssl
125
+ mongoid
66
126
  multipart-post!
127
+ rack-ssl-enforcer
67
128
  rake
129
+ redcarpet
130
+ ripl
68
131
  rspec
69
132
  simplecov
133
+ sinatra
134
+ sinatra-contrib
70
135
  vcr
71
136
  webmock
72
137
  yard
data/Procfile ADDED
@@ -0,0 +1 @@
1
+ web: bundle exec rackup config.ru -p $PORT
data/Rakefile CHANGED
@@ -9,11 +9,18 @@ end
9
9
 
10
10
  if defined?(RSpec)
11
11
  desc "Run specs"
12
- RSpec::Core::RakeTask.new(:spec)
12
+ RSpec::Core::RakeTask.new("spec") do |t|
13
+ t.pattern = "spec/core/**/*_spec.rb"
14
+ end
15
+
16
+ desc "Run server specs"
17
+ RSpec::Core::RakeTask.new("spec:server") do |t|
18
+ t.pattern = "spec/server/**/*_spec.rb"
19
+ end
13
20
 
14
21
  desc "Run live specs"
15
22
  RSpec::Core::RakeTask.new("spec:live") do |t|
16
- t.pattern = "live/*_spec.rb"
23
+ t.pattern = "spec/live/**/*_spec.rb"
17
24
  end
18
25
 
19
26
  task :clean_live do
@@ -29,7 +36,7 @@ if defined?(RSpec)
29
36
  end
30
37
 
31
38
  desc 'Default: run specs.'
32
- task :default => :spec
39
+ task :default => "spec"
33
40
  end
34
41
 
35
42
  # extracted from https://github.com/grosser/project_template
data/Readme.md CHANGED
@@ -99,6 +99,26 @@ The methods under ZendeskAPI::Client (such as .tickets) return an instance of Ze
99
99
  Actual requests may not be sent until an explicit ZendeskAPI::Collection#fetch, ZendeskAPI::Collection#to_a, or an applicable methods such
100
100
  as #each.
101
101
 
102
+ ### Caveats
103
+
104
+ Resource updating is implemented by sending only the `changed?` attributes to the server (see `ZendeskAPI::TrackChanges`).
105
+ Unfortunately, this module only hooks into `Hash` meaning any changes to an `Array`not resulting in a new instance will not be tracked and sent.
106
+
107
+ ```
108
+ zendesk_api_client_rb $ bundle console
109
+ > a = ZendeskAPI::Trackie.new(:tags => []).tap(&:clear_changes)
110
+ > a.changed?(:tags)
111
+ => false
112
+ > a.tags << "my_new_tag"
113
+ => ["my_new_tag"]
114
+ > a.changed?(:tags)
115
+ => false
116
+ > a.tags += %w{my_other_tag}
117
+ => ["my_new_tag", "my_other_tag"]
118
+ > a.changed?(:tags)
119
+ => true
120
+ ```
121
+
102
122
  ### Pagination
103
123
 
104
124
  ZendeskAPI::Collections can be paginated:
@@ -189,6 +209,15 @@ ticket.requester # => #<ZendeskAPI::User id=...>
189
209
  Currently, this feature is limited to only a few resources and their associations.
190
210
  They are documented on [developer.zendesk.com](http://developer.zendesk.com/documentation/rest_api/introduction.html#side-loading-\(beta\)).
191
211
 
212
+ ### Search
213
+
214
+ Searching is done through the client. Returned is an instance of ZendeskAPI::Collection:
215
+
216
+ ```ruby
217
+ client.search(:query => "my search query") # /api/v2/search.json?query=...
218
+ client.users.search(:query => "my new query") # /api/v2/users/search.json?query=...
219
+ ```
220
+
192
221
  ### Special case: Custom resources paths
193
222
 
194
223
  API endpoints such as tickets/recent or topics/show_many can be accessed through chaining.
@@ -230,6 +259,42 @@ ticket.comment.uploads << File.new("img.jpg")
230
259
  ticket.save
231
260
  ```
232
261
 
262
+ ## Extras
263
+
264
+ The following projects are still works in progress and require checking out the repository,
265
+ using ruby 1.9.3, and running `bundle install`.
266
+
267
+ ### Zendesk API Test Server
268
+
269
+ Included in this repository is the code for the [Zendesk API Tester](https://zendesk-api.herokuapp.com/) website.
270
+
271
+ ```sh
272
+ bin/zendesk server --help
273
+ ```
274
+
275
+ Additional Dependencies:
276
+
277
+ * sinatra
278
+ * sinatra-contrib
279
+ * haml
280
+ * compass
281
+ * coderay
282
+ * coderay_bash
283
+ * redcarpet
284
+ * mongoid (and a working MongoDB instance)
285
+
286
+ ### Zendesk Console
287
+
288
+ WIP
289
+
290
+ ```sh
291
+ bin/zendesk console --help
292
+ ```
293
+
294
+ Additional Dependencies:
295
+
296
+ * ripl
297
+
233
298
  ## Note on Patches/Pull Requests
234
299
  1. Fork the project.
235
300
  2. Make your feature addition or bug fix.
data/bin/zendesk ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler'
3
+
4
+ ARGV[0] ||= "console"
5
+
6
+ if %w(s server).include?(ARGV[0])
7
+ Bundler.setup(:default, :server)
8
+
9
+ require 'zendesk_api'
10
+ require 'zendesk_api/server/base'
11
+
12
+ OptionParser.new do |op|
13
+ op.banner = "Usage: zendesk s[erver] [options]"
14
+
15
+ op.on('-e env', 'Set the environment') {|val| ZendeskAPI::Server::App.set(:environment, val.to_sym)}
16
+ op.on('-p port', 'Bind to a port') {|val| ZendeskAPI::Server::App.set(:port, val.to_i)}
17
+ op.on('-o addr', 'Bind to a location') {|val| ZendeskAPI::Server::App.set(:bind, val)}
18
+ end.parse!(ARGV.dup)
19
+
20
+ ZendeskAPI::Server::App.run!
21
+ else
22
+ Bundler.setup(:default, :console)
23
+
24
+ require 'zendesk_api'
25
+ require 'zendesk_api/console/base'
26
+ end
data/config.ru ADDED
@@ -0,0 +1,6 @@
1
+ require 'rack/ssl-enforcer'
2
+ require 'zendesk_api'
3
+ require 'zendesk_api/server/base'
4
+
5
+ use Rack::SslEnforcer if ZendeskAPI::Server::App.production?
6
+ run ZendeskAPI::Server::App
@@ -0,0 +1,81 @@
1
+ development: &defaults
2
+ # Configure available database sessions. (required)
3
+ sessions:
4
+ # Defines the default session. (required)
5
+ default: &default_session
6
+ # Defines the name of the default database that Mongoid can connect to.
7
+ # (required).
8
+ database: zendesk_api_development
9
+ # Provides the hosts the default session can connect to. Must be an array
10
+ # of host:port pairs. (required)
11
+ hosts:
12
+ - localhost:27017
13
+ options:
14
+ # Change whether the session persists in safe mode by default.
15
+ # (default: false)
16
+ # safe: false
17
+
18
+ # Change the default consistency model to :eventual or :strong.
19
+ # :eventual will send reads to secondaries, :strong sends everything
20
+ # to master. (default: :eventual)
21
+ # consistency: :strong
22
+ # Configure Mongoid specific options. (optional)
23
+ options:
24
+ # Configuration for whether or not to allow access to fields that do
25
+ # not have a field definition on the model. (default: true)
26
+ # allow_dynamic_fields: true
27
+
28
+ # Enable the identity map, needed for eager loading. (default: false)
29
+ # identity_map_enabled: false
30
+
31
+ # Includes the root model name in json serialization. (default: false)
32
+ # include_root_in_json: false
33
+
34
+ # Include the _type field in serializaion. (default: false)
35
+ # include_type_for_serialization: false
36
+
37
+ # Preload all models in development, needed when models use
38
+ # inheritance. (default: false)
39
+ preload_models: true
40
+
41
+ # Protect id and type from mass assignment. (default: true)
42
+ # protect_sensitive_fields: true
43
+
44
+ # Raise an error when performing a #find and the document is not found.
45
+ # (default: true)
46
+ raise_not_found_error: false
47
+
48
+ # Raise an error when defining a scope with the same name as an
49
+ # existing method. (default: false)
50
+ # scope_overwrite_exception: false
51
+
52
+ # Skip the database version check, used when connecting to a db without
53
+ # admin access. (default: false)
54
+ # skip_version_check: false
55
+
56
+ # User Active Support's time zone in conversions. (default: true)
57
+ # use_activesupport_time_zone: true
58
+
59
+ # Ensure all times are UTC in the app side. (default: false)
60
+ # use_utc: false
61
+
62
+ test:
63
+ <<: *defaults
64
+ sessions:
65
+ default:
66
+ <<: *default_session
67
+ database: zendesk_api_test
68
+
69
+ <% if ENV['MONGOLAB_URI'] %>
70
+ <% uri = URI.parse(ENV['MONGOLAB_URI']) %>
71
+ production:
72
+ <<: *defaults
73
+ sessions:
74
+ default:
75
+ <<: *default_session
76
+ database: <%= uri.path.sub('/','') %>
77
+ username: <%= uri.user %>
78
+ password: <%= uri.password %>
79
+ hosts:
80
+ - <%= uri.host %>:<%= uri.port %>
81
+ <% end %>
@@ -19,7 +19,7 @@ module ZendeskAPI
19
19
 
20
20
  save_associations
21
21
 
22
- response = @client.connection.send(method, req_path) do |req|
22
+ @response = @client.connection.send(method, req_path) do |req|
23
23
  req.body = if self.class.unnested_params
24
24
  attributes.changes
25
25
  else
@@ -27,7 +27,7 @@ module ZendeskAPI
27
27
  end
28
28
  end
29
29
 
30
- @attributes.replace @attributes.deep_merge(response.body[self.class.singular_resource_name] || {})
30
+ @attributes.replace @attributes.deep_merge(@response.body[self.class.singular_resource_name] || {})
31
31
  @attributes.clear_changes
32
32
  clear_associations
33
33
  true
@@ -84,7 +84,7 @@ module ZendeskAPI
84
84
  # @return [Number] The total number of resources server-side (disregarding pagination).
85
85
  def count
86
86
  fetch
87
- @count
87
+ @count || -1
88
88
  end
89
89
 
90
90
  # Changes the per_page option. Returns self, so it can be chained. No execution.
@@ -103,6 +103,14 @@ module ZendeskAPI
103
103
  self
104
104
  end
105
105
 
106
+ def first_page?
107
+ !@options["page"] || @options["page"].to_i <= 1
108
+ end
109
+
110
+ def last_page?
111
+ !@options["page"] || @options["page"].to_i * @options["per_page"].to_i >= count
112
+ end
113
+
106
114
  # Saves all newly created resources stored in this collection.
107
115
  # @return [Collection] self
108
116
  def save
@@ -282,17 +290,20 @@ module ZendeskAPI
282
290
  end
283
291
  end
284
292
 
285
- alias :orig_to_s :to_s
286
-
287
293
  # @private
288
294
  def to_s
289
295
  if @resources
290
296
  @resources.inspect
291
297
  else
292
- orig_to_s
298
+ inspect = []
299
+ inspect << "options=#{@options.inspect}" if @options.any?
300
+ inspect << "path=#{path}"
301
+ "#{Inflection.singular(@resource)} collection [#{inspect.join(",")}]"
293
302
  end
294
303
  end
295
304
 
305
+ alias :to_str :to_s
306
+
296
307
  private
297
308
 
298
309
  def set_page_and_count(body)