helpscout 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  group :development do
4
- gem "bundler", "~> 1.1.3"
4
+ gem "bundler", "~> 1.2.3"
5
5
  gem "jeweler", "~> 1.8.4"
6
6
  gem "httparty"
7
7
  gem 'simplecov', :require => false
@@ -1,6 +1,6 @@
1
1
  # Helpscout Developers API gem
2
2
 
3
- This gem is in alpha.
3
+ This gem is in beta.
4
4
 
5
5
  ## Usage
6
6
 
@@ -9,25 +9,25 @@ This gem is in alpha.
9
9
  2. Initialize your HelpScout client
10
10
 
11
11
  ```ruby
12
- HelpScout::Base.load!(HELPSCOUT_API_KEY)
12
+ helpscout = HelpScout::Client.new(HELPSCOUT_API_KEY)
13
13
  ```
14
14
 
15
15
  #### Fetching Users
16
16
 
17
17
  ```ruby
18
- users = HelpScout::Base.users
18
+ users = helpscout.users
19
19
  ```
20
20
 
21
21
  #### Fetching Mailboxes
22
22
 
23
23
  ```ruby
24
- mailboxes = HelpScout::Base.mailboxes
24
+ mailboxes = helpscout.mailboxes
25
25
  ```
26
26
 
27
27
  #### Fetching Customers
28
28
 
29
29
  ```ruby
30
- customers = HelpScout::Base.customers
30
+ customers = helpscout.customers
31
31
  ```
32
32
 
33
33
  #### Fetching Conversations
@@ -35,6 +35,6 @@ customers = HelpScout::Base.customers
35
35
  To fetch active conversations:
36
36
 
37
37
  ```ruby
38
- conversations = HelpScout::Base.conversations(mailboxId, "active", nil)
38
+ conversations = helpscout.conversations(mailboxId, "active", nil)
39
39
  ```
40
40
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "helpscout"
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["H\u{e9}ctor Ramos"]
12
- s.date = "2012-08-15"
12
+ s.date = "2013-02-11"
13
13
  s.description = ""
14
14
  s.email = "hector@hectorramos.com"
15
15
  s.extra_rdoc_files = [
@@ -22,13 +22,13 @@ Gem::Specification.new do |s|
22
22
  "VERSION",
23
23
  "helpscout.gemspec",
24
24
  "lib/helpscout.rb",
25
- "lib/helpscout/base.rb",
25
+ "lib/helpscout/client.rb",
26
26
  "lib/helpscout/models.rb"
27
27
  ]
28
28
  s.homepage = "http://github.com/hramos/helpscout"
29
29
  s.licenses = ["MIT"]
30
30
  s.require_paths = ["lib"]
31
- s.rubygems_version = "1.8.24"
31
+ s.rubygems_version = "1.8.11"
32
32
  s.summary = "HelpScout API Wrapper"
33
33
 
34
34
  if s.respond_to? :specification_version then
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
36
36
 
37
37
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
38
38
  s.add_runtime_dependency(%q<httparty>, [">= 0"])
39
- s.add_development_dependency(%q<bundler>, ["~> 1.1.3"])
39
+ s.add_development_dependency(%q<bundler>, ["~> 1.2.3"])
40
40
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
41
41
  s.add_development_dependency(%q<httparty>, [">= 0"])
42
42
  s.add_development_dependency(%q<simplecov>, [">= 0"])
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
44
44
  s.add_development_dependency(%q<rdoc>, [">= 0"])
45
45
  else
46
46
  s.add_dependency(%q<httparty>, [">= 0"])
47
- s.add_dependency(%q<bundler>, ["~> 1.1.3"])
47
+ s.add_dependency(%q<bundler>, ["~> 1.2.3"])
48
48
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
49
49
  s.add_dependency(%q<httparty>, [">= 0"])
50
50
  s.add_dependency(%q<simplecov>, [">= 0"])
@@ -53,7 +53,7 @@ Gem::Specification.new do |s|
53
53
  end
54
54
  else
55
55
  s.add_dependency(%q<httparty>, [">= 0"])
56
- s.add_dependency(%q<bundler>, ["~> 1.1.3"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.2.3"])
57
57
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
58
58
  s.add_dependency(%q<httparty>, [">= 0"])
59
59
  s.add_dependency(%q<simplecov>, [">= 0"])
@@ -1,5 +1,5 @@
1
+ require 'helpscout/client.rb'
1
2
  require 'helpscout/models.rb'
2
- require 'helpscout/base.rb'
3
3
 
4
4
  module HelpScout
5
5
 
@@ -0,0 +1,758 @@
1
+ # Help Scout API V1 Client
2
+ # http://developer.helpscout.net/
3
+ #
4
+ # Authentication
5
+ # This is an HTTPS-only API. Authentication will be based on API Keys, which can
6
+ # be generated the Help Scout UI in the User Profile. Each API Key will map to
7
+ # an existing Help Scout user. Results returned from various responses will be
8
+ # based upon the role of the user to which the API key is tied.
9
+ #
10
+ # The API Key will be passed via HTTP Basic Authentication. The API Key will go
11
+ # in the username field and a dummy password, such as X, in the password field.
12
+ #
13
+ # Rate Limiting
14
+ # Requests will be limited to 200 requests per minute. Response code 429 will
15
+ # be returned when throttle limit has been reached. A "Retry-After" header will
16
+ # be returned indicating how many seconds to wait until retry.
17
+ #
18
+ # Formats
19
+ # Each endpoint will specify the response format in the URL. However, the API
20
+ # will only support JSON at this time.
21
+ #
22
+ # Usage
23
+ # 1. Follow the instructions at Help Scout's Developers site to generate an API
24
+ # key: http://developer.helpscout.net/
25
+ # 2. Add your API Key to config/helpscout.yml:
26
+ # api_key: XXXXXX
27
+ # 3. Initialize your Help Scout client:
28
+ # HelpScout::Client.new
29
+ # 4. You may now query the Help Scout API:
30
+ # mailboxes = HelpScout::Client.mailboxes
31
+ #
32
+ # You may also initialize a client without using helpscout.yml by passing the
33
+ # API Key to new:
34
+ # HelpScout::Client.new(XXXXXX)
35
+
36
+ require "erb"
37
+ require "httparty"
38
+ require "yaml"
39
+
40
+ module HelpScout
41
+ class Client
42
+ include HTTParty
43
+
44
+ # All API requests will be made to: https://api.helpscout.net/. All
45
+ # requests are served over HTTPS. The current version is v1.
46
+ base_uri 'https://api.helpscout.net/v1'
47
+
48
+ @@settings ||= nil
49
+
50
+ # Returns the current Help Scout Client settings.
51
+ # If no settings have been loaded yet, this function will load its
52
+ # configuration from helpscout.yml
53
+ #
54
+ # Settings
55
+ # api_key String Help Scout API Key. The API is currently available for
56
+ # paying Help Scout accounts (Basic or Standard plan). You
57
+ # can generate a key from your User Profile, on the API
58
+ # Keys tab.
59
+
60
+ def self.settings
61
+ if @@settings.nil?
62
+ path = "config/helpscout.yml"
63
+ if File.exist?(path)
64
+ @@settings = YAML.load(ERB.new(File.new(path).read).result)
65
+ end
66
+ end
67
+ @@settings
68
+ end
69
+
70
+
71
+ # Requests a single item from the Help Scout API. Should return either an
72
+ # item from the SingleItemEnvelope, or raise an error with an
73
+ # ErrorEnvelope.
74
+ #
75
+ # url String A string representing the url for the REST endpoint to be
76
+ # queried.
77
+ # params Hash A hash of GET parameters to use for this particular
78
+ # request.
79
+ #
80
+ # Response
81
+ # Name Type Notes
82
+ # Header Status Int 200
83
+ # Body item
84
+
85
+ def self.requestItem(auth, url, params={})
86
+ item = nil
87
+
88
+ request_url = ""
89
+ request_url << url
90
+ if params
91
+ request_url << "?" + params.to_query
92
+ end
93
+
94
+ begin
95
+ response = Client.get(request_url, {:basic_auth => auth})
96
+ rescue SocketError => se
97
+ raise StandardError, se.message
98
+ end
99
+
100
+ if 200 <= response.code && response.code < 300
101
+ envelope = SingleItemEnvelope.new(response)
102
+ if envelope.item
103
+ item = envelope.item
104
+ end
105
+ elsif 400 <= response.code && response.code < 500
106
+ if response["message"]
107
+ envelope = ErrorEnvelope.new(response)
108
+ raise StandardError, envelope.message
109
+ else
110
+ raise StandardError, response["error"]
111
+ end
112
+ else
113
+ raise StandardError, "Server Response: #{response.code}"
114
+ end
115
+
116
+ item
117
+ end
118
+
119
+
120
+ # Requests a collections of items from the Help Scout API. Should return
121
+ # either an array of items from the CollectionsEnvelope, or raise an error
122
+ # with an ErrorEnvelope.
123
+ #
124
+ # Collections return a maximum of 50 records per page.
125
+ #
126
+ # url String A string representing the url for the REST endpoint to be
127
+ # queried.
128
+ # params Hash A hash of GET parameters to use for this particular
129
+ # request.
130
+ #
131
+ # Response
132
+ # Name Type Notes
133
+ # Header Status Int 200
134
+ # Body page Int Current page that was passed in on the request
135
+ # pages Int Total number of pages available
136
+ # count Int Total number of objects available
137
+ # items Array Collection of objects
138
+
139
+ def self.requestItems(auth, url, params={})
140
+ items = []
141
+
142
+ request_url = ""
143
+ request_url << url
144
+ if params
145
+ query = ""
146
+ params.each { |k,v| query += "#{k}=#{v}&" }
147
+ request_url << "?" + query
148
+ end
149
+
150
+ begin
151
+ response = Client.get(request_url, {:basic_auth => auth})
152
+ rescue SocketError => se
153
+ raise StandardError, se.message
154
+ end
155
+
156
+ if 200 <= response.code && response.code < 300
157
+ envelope = CollectionsEnvelope.new(response)
158
+ if envelope.items
159
+ envelope.items.each do |item|
160
+ items << item
161
+ end
162
+ end
163
+ elsif 400 <= response.code && response.code < 500
164
+ if response["message"]
165
+ envelope = ErrorEnvelope.new(response)
166
+ raise StandardError, envelope.message
167
+ else
168
+ raise StandardError, response["error"]
169
+ end
170
+ else
171
+ raise StandardError, "Server Response: #{response.code}"
172
+ end
173
+
174
+ items
175
+ end
176
+
177
+
178
+ # Requests a collections of items from the Help Scout API. Should return
179
+ # the total count for this collection, or raise an error with an
180
+ # ErrorEnvelope.
181
+ #
182
+ # url String A string representing the url for the REST endpoint to be
183
+ # queried.
184
+ # params Hash A hash of GET parameters to use for this particular
185
+ # request.
186
+ #
187
+ # Response
188
+ # Name Type Notes
189
+ # Header Status Int 200
190
+ # Body page Int Current page that was passed in on the request
191
+ # pages Int Total number of pages available
192
+ # count Int Total number of objects available
193
+ # items Array Collection of objects
194
+
195
+ def self.requestCount(auth, url, params={})
196
+ request_url = ""
197
+ request_url << url
198
+ if params
199
+ query = ""
200
+ params.each { |k,v| query += "#{k}=#{v}&" }
201
+ request_url << "?" + query
202
+ end
203
+
204
+ begin
205
+ response = Client.get(request_url, {:basic_auth => auth})
206
+ rescue SocketError => se
207
+ raise StandardError, se.message
208
+ end
209
+
210
+ if 200 <= response.code && response.code < 300
211
+ envelope = CollectionsEnvelope.new(response)
212
+ envelope.count
213
+ elsif 400 <= response.code && response.code < 500
214
+ if response["message"]
215
+ envelope = ErrorEnvelope.new(response)
216
+ raise StandardError, envelope.message
217
+ else
218
+ raise StandardError, response["error"]
219
+ end
220
+ else
221
+ raise StandardError, "Server Response: #{response.code}"
222
+ end
223
+ end
224
+
225
+ # HelpScout::Client.new
226
+ #
227
+ # Initializes the Help Scout Client. Once called, you may use any of the
228
+ # HelpScout::Client methods to query the Help Scout API.
229
+ #
230
+ # key String Help Scout API Key. Optional. If not passed, the key will be
231
+ # loaded from @@settings, which defaults to helpscout.yml.
232
+
233
+ def initialize(key = nil)
234
+ Client.settings
235
+
236
+ if key.nil?
237
+ key = @@settings["api_key"]
238
+ end
239
+
240
+ # The Help Scout API uses Basic Auth, where username is your API Key.
241
+ # Password can be any arbitrary non-zero-length string.
242
+ @auth = { :username => key, :password => "X" }
243
+ end
244
+
245
+
246
+ # Get User
247
+ # http://developer.helpscout.net/users/
248
+ #
249
+ # Fetches a single user by id.
250
+ #
251
+ # userId Int id of the User being requested
252
+ #
253
+ # Request
254
+ # REST Method: GET
255
+ # URL: https://api.helpscout.net/v1/users/{id}.json
256
+ #
257
+ # Response
258
+ # Name Type
259
+ # item User
260
+
261
+ def user(userId)
262
+ url = "/users/#{userId}.json"
263
+ item = Client.requestItem(@auth, url, nil)
264
+ user = nil
265
+ if item
266
+ user = User.new(item)
267
+ end
268
+ user
269
+ end
270
+
271
+
272
+ # List Users
273
+ # http://developer.helpscout.net/users/
274
+ #
275
+ # Fetches all users
276
+ #
277
+ # Request
278
+ # REST Method: GET
279
+ # URL: https://api.helpscout.net/v1/users.json
280
+ #
281
+ # Parameters:
282
+ # Name Type Required Default Notes
283
+ # page Int No 1
284
+ #
285
+ # Response
286
+ # Name Type
287
+ # items Array Collection of User objects
288
+
289
+ def users
290
+ url = "/users.json"
291
+ items = Client.requestItems(@auth, url, :page => 1)
292
+ users = []
293
+ items.each do |item|
294
+ users << User.new(item)
295
+ end
296
+ users
297
+ end
298
+
299
+
300
+ # List Users by Mailbox
301
+ # http://developer.helpscout.net/users/
302
+ #
303
+ # Fetches all users in a single mailbox
304
+ #
305
+ # mailboxId Int id of the Mailbox being requested
306
+ #
307
+ # Request
308
+ # REST Method: GET
309
+ # URL: https://api.helpscout.net/v1/mailboxes/{id}/users.json
310
+ #
311
+ # Parameters:
312
+ # Name Type Required Default Notes
313
+ # page Int No 1
314
+ #
315
+ # Response
316
+ # Name Type
317
+ # items Array Collection of User objects
318
+
319
+ def usersInMailbox(mailboxId)
320
+ url ="/mailboxes/#{mailboxId}/users.json"
321
+ items = Client.requestItems(@auth, url, :page => 1)
322
+ users = []
323
+ items.each do |item|
324
+ users << User.new(item)
325
+ end
326
+ users
327
+ end
328
+
329
+
330
+ # List Mailboxes
331
+ # http://developer.helpscout.net/mailboxes/
332
+ #
333
+ # Fetches all mailboxes
334
+ #
335
+ # Request
336
+ # REST Method: GET
337
+ # URL: https://api.helpscout.net/v1/mailboxes.json
338
+ #
339
+ # Parameters:
340
+ # Name Type Required Default Notes
341
+ # page Int No 1
342
+ #
343
+ # Response
344
+ # Name Type
345
+ # items Array Collection of Mailbox objects
346
+
347
+ def mailboxes
348
+ url = "/mailboxes.json"
349
+ mailboxes = []
350
+ begin
351
+ items = Client.requestItems(@auth, url, {})
352
+ items.each do |item|
353
+ mailboxes << Mailbox.new(item)
354
+ end
355
+ rescue StandardError => e
356
+ print "List Mailbox Request failed: " + e.message
357
+ end
358
+ mailboxes
359
+ end
360
+
361
+
362
+ # Get Mailbox
363
+ # http://developer.helpscout.net/mailboxes/
364
+ #
365
+ # Fetches a single Mailbox
366
+ #
367
+ # mailboxId Int id of the Mailbox being requested
368
+ #
369
+ # Request
370
+ # REST Method: GET
371
+ # URL: https://api.helpscout.net/v1/mailboxes/{id}.json
372
+ #
373
+ # Response
374
+ # Name Type
375
+ # item Mailbox
376
+
377
+ def mailbox(mailboxId)
378
+ url = "/mailboxes/#{mailboxId}.json"
379
+ item = Client.requestItem(@auth, url, nil)
380
+ mailbox = nil
381
+ if item
382
+ mailbox = Mailbox.new(item)
383
+ end
384
+ mailbox
385
+ end
386
+
387
+
388
+ # Get Folders
389
+ # http://developer.helpscout.net/mailboxes/
390
+ #
391
+ # Fetches all Folders in a given mailbox
392
+ #
393
+ # mailboxId Int id of the Mailbox being requested
394
+ #
395
+ # Request
396
+ # REST Method: GET
397
+ # URL: https://api.helpscout.net/v1/mailboxes/{id}/folders.json
398
+ #
399
+ # Parameters:
400
+ # Name Type Required Default Notes
401
+ # page Int No 1
402
+ #
403
+ # Response
404
+ # Name Type
405
+ # items Array Collection of Mailbox objects
406
+
407
+ def foldersInMailbox(mailboxId)
408
+ url = "/mailboxes/#{mailboxId}/folders.json"
409
+ items = Client.requestItems(@auth, url, :page => 1)
410
+ folders = []
411
+ items.each do |item|
412
+ folders << Folder.new(item)
413
+ end
414
+ folders
415
+ end
416
+
417
+
418
+ # Get Conversation
419
+ # http://developer.helpscout.net/conversations/
420
+ #
421
+ # Fetches a single Conversation
422
+ #
423
+ # conversationId Int id of the Conversation being requested
424
+ #
425
+ # Request
426
+ # REST Method: GET
427
+ # URL: https://api.helpscout.net/v1/conversations/{id}.json
428
+ #
429
+ # Response
430
+ # Name Type
431
+ # item Conversation
432
+
433
+ def conversation(conversationId)
434
+ url = "/conversations/#{conversationId}.json"
435
+
436
+ begin
437
+ item = Client.requestItem(@auth, url, nil)
438
+ conversation = nil
439
+ if item
440
+ conversation = Conversation.new(item)
441
+ end
442
+ rescue StandardError => e
443
+ print "Could not fetch conversation with id #{conversationId}: " + e.message
444
+ end
445
+ end
446
+
447
+
448
+ # List Conversations
449
+ # http://developer.helpscout.net/conversations/
450
+ #
451
+ # Fetches conversations in a mailbox with a given status
452
+ #
453
+ # mailboxId Int id of the Mailbox being requested
454
+ # status String Filter by conversation status
455
+ # limit Int This function will page through
456
+ # CollectionsEnvelopes until all items are
457
+ # returned, unless a limit is specified.
458
+ # modifiedSince DateTime Returns conversations that have been modified
459
+ # since the given date/time.
460
+ #
461
+ # Possible values for status include:
462
+ # * CONVERSATION_FILTER_STATUS_ALL (Default)
463
+ # * CONVERSATION_FILTER_STATUS_ACTIVE
464
+ # * CONVERSATION_FILTER_STATUS_PENDING
465
+ #
466
+ # Request
467
+ # REST Method: GET
468
+ # URL: https://api.helpscout.net/v1/mailboxes/{mailboxId}/conversations.json
469
+ #
470
+ # Parameters:
471
+ # Name Type Required Default Notes
472
+ # page Int No 1
473
+ # status String No all Active/Pending only applies
474
+ # to the following folders:
475
+ # Unassigned
476
+ # My Tickets
477
+ # Drafts
478
+ # Assigned
479
+ # modifiedSince DateTime No Returns conversations that
480
+ # have been modified since the
481
+ # given date/time.
482
+ #
483
+ # Response
484
+ # Name Type
485
+ # items Array Collection of Conversation objects. Conversation threads
486
+ # are not returned on this call. To get the conversation
487
+ # threads, you need to retrieve the full conversation object
488
+ # via the Get Conversation call.
489
+
490
+ CONVERSATION_FILTER_STATUS_ACTIVE = "active"
491
+ CONVERSATION_FILTER_STATUS_ALL = "all"
492
+ CONVERSATION_FILTER_STATUS_PENDING = "pending"
493
+
494
+ def conversations(mailboxId, status, limit=0, modifiedSince)
495
+ url = "/mailboxes/#{mailboxId}/conversations.json"
496
+
497
+ page = 1
498
+ options = {}
499
+
500
+ if limit < 0
501
+ limit = 0
502
+ end
503
+
504
+ if status && (status == CONVERSATION_FILTER_STATUS_ACTIVE || status == CONVERSATION_FILTER_STATUS_ALL || status == CONVERSATION_FILTER_STATUS_PENDING)
505
+ options["status"] = status
506
+ end
507
+
508
+ if modifiedSince
509
+ options["modifiedSince"] = modifiedSince
510
+ end
511
+
512
+ conversations = []
513
+
514
+ begin
515
+ options["page"] = page
516
+ items = Client.requestItems(@auth, url, options)
517
+ items.each do |item|
518
+ conversations << Conversation.new(item)
519
+ end
520
+ page = page + 1
521
+ rescue StandardError => e
522
+ print "List Conversations Request failed: " + e.message
523
+ end while items && items.count > 0 && (limit == 0 || conversations.count < limit)
524
+
525
+ if limit > 0 && conversations.count > limit
526
+ conversations = conversations[0..limit-1]
527
+ end
528
+
529
+ conversations
530
+ end
531
+
532
+
533
+ # List Conversations in Folder
534
+ # http://developer.helpscout.net/conversations/
535
+ #
536
+ # Return conversations in a specific folder of a mailbox.
537
+ #
538
+ # mailboxId Int id of the Mailbox being requested
539
+ # folderId Int id of the Folder being requested
540
+ # status String Filter by conversation status
541
+ # limit Int This function will page through
542
+ # CollectionsEnvelopes until all items are
543
+ # returned, unless a limit is specified.
544
+ # modifiedSince DateTime Returns conversations that have been modified
545
+ # since the given date/time.
546
+ #
547
+ # Possible values for status include:
548
+ # * CONVERSATION_FILTER_STATUS_ALL (Default)
549
+ # * CONVERSATION_FILTER_STATUS_ACTIVE
550
+ # * CONVERSATION_FILTER_STATUS_PENDING
551
+ #
552
+ # Request
553
+ # REST Method: GET
554
+ # URL: https://api.helpscout.net/v1/mailboxes/{mailboxId}/folders/{folderId}/conversations.json
555
+ #
556
+ # Parameters:
557
+ # Name Type Required Default Notes
558
+ # page Int No 1
559
+ # status String No all Active/Pending only applies
560
+ # to the following folders:
561
+ # Unassigned
562
+ # My Tickets
563
+ # Drafts
564
+ # Assigned
565
+ # modifiedSince DateTime No Returns conversations that
566
+ # have been modified since the
567
+ # given date/time.
568
+ #
569
+ # Response
570
+ # Name Type
571
+ # items Array Collection of Conversation objects. Conversation threads
572
+ # are not returned on this call. To get the conversation
573
+ # threads, you need to retrieve the full conversation object
574
+ # via the Get Conversation call.
575
+
576
+ def conversationsInFolder(mailboxId, folderId, status, limit=0, modifiedSince)
577
+ url = "/mailboxes/#{mailboxId}/folders/#{folderId}/conversations.json"
578
+
579
+ page = 1
580
+ options = {}
581
+
582
+ if limit < 0
583
+ limit = 0
584
+ end
585
+
586
+ if status && (status == CONVERSATION_FILTER_STATUS_ACTIVE || status == CONVERSATION_FILTER_STATUS_ALL || status == CONVERSATION_FILTER_STATUS_PENDING)
587
+ options["status"] = status
588
+ end
589
+
590
+ if modifiedSince
591
+ options["modifiedSince"] = modifiedSince
592
+ end
593
+
594
+ conversations = []
595
+
596
+ begin
597
+ options["page"] = page
598
+ items = Client.requestItems(@auth, url, options)
599
+ items.each do |item|
600
+ conversations << Conversation.new(item)
601
+ end
602
+ page = page + 1
603
+ rescue StandardError => e
604
+ print "List Conversations In Folder Request failed: " + e.message
605
+ end while items && items.count > 0 && (limit == 0 || conversations.count < limit)
606
+
607
+ if limit > 0 && conversations.count > limit
608
+ conversations = conversations[0..limit-1]
609
+ end
610
+
611
+ conversations
612
+ end
613
+
614
+
615
+ # Conversation Count
616
+ # http://developer.helpscout.net/conversations/
617
+ #
618
+ # Returns a count for conversations in a mailbox with a given status
619
+ #
620
+ # mailboxId Int id of the Mailbox being requested
621
+ # status String Filter by conversation status
622
+ # modifiedSince DateTime id of the Mailbox being requested
623
+ #
624
+ # Possible values for status include:
625
+ # * CONVERSATION_FILTER_STATUS_ALL (Default)
626
+ # * CONVERSATION_FILTER_STATUS_ACTIVE
627
+ # * CONVERSATION_FILTER_STATUS_PENDING
628
+ #
629
+ # Request
630
+ # REST Method: GET
631
+ # URL: https://api.helpscout.net/v1/mailboxes/{mailboxId}/conversations.json
632
+ #
633
+ # Parameters:
634
+ # Name Type Required Default Notes
635
+ # page Int No 1
636
+ # status String No all Active/Pending only applies
637
+ # to the following folders:
638
+ # Unassigned
639
+ # My Tickets
640
+ # Drafts
641
+ # Assigned
642
+ # modifiedSince DateTime No Returns conversations that
643
+ # have been modified since the
644
+ # given date/time.
645
+ #
646
+ # Response
647
+ # Name Type
648
+ # count Integer Count of Conversation objects.
649
+
650
+ def conversationCount(mailboxId, status, modifiedSince)
651
+ url = "/mailboxes/#{mailboxId}/conversations.json"
652
+
653
+ page = 1
654
+ options = {}
655
+
656
+ if status && (status == CONVERSATION_FILTER_STATUS_ACTIVE || status == CONVERSATION_FILTER_STATUS_ALL || status == CONVERSATION_FILTER_STATUS_PENDING)
657
+ options["status"] = status
658
+ end
659
+
660
+ if modifiedSince
661
+ options["modifiedSince"] = modifiedSince
662
+ end
663
+
664
+ conversations = []
665
+
666
+ begin
667
+ options["page"] = page
668
+ count = Client.requestCount(@auth, url, options)
669
+ rescue StandardError => e
670
+ print "Conversation Count Request failed: " + e.message
671
+ end
672
+ end
673
+
674
+
675
+ # Get Attachment Data
676
+ # http://developer.helpscout.net/conversations/
677
+ #
678
+ # Fetches the AttachmentData from a given Attachment
679
+ #
680
+ # attachmentId Int id of the Attachment being requested
681
+ #
682
+ # Request
683
+ # REST Method: GET
684
+ # URL: https://api.helpscout.net/v1/attachments/{id}/data.json
685
+ #
686
+ # Response
687
+ # Name Type
688
+ # item Conversation::AttachmentData
689
+
690
+ def attachmentData(attachmentId)
691
+ url = "/attachments/#{attachmentId}/data.json"
692
+ item = Client.requestItem(@auth, url, nil)
693
+ attachmentData = nil
694
+ if item
695
+ attachmentData = Conversation::AttachmentData.new(item)
696
+ end
697
+
698
+ attachmentData
699
+ end
700
+
701
+
702
+ # Get Customer
703
+ # http://developer.helpscout.net/customers/
704
+ #
705
+ # Fetches a single Customer
706
+ #
707
+ # customerId Int id of the Customer being requested
708
+ #
709
+ # Request
710
+ # REST Method: GET
711
+ # URL: https://api.helpscout.net/v1/customers/{id}.json
712
+ #
713
+ # Response
714
+ # Name Type
715
+ # item Customer
716
+
717
+ def customer(customerId)
718
+ url = "/customers/#{customerId}.json"
719
+ item = Client.requestItem(@auth, url, nil)
720
+ customer = nil
721
+ if item
722
+ customer = Customer.new(item)
723
+ end
724
+
725
+ customer
726
+ end
727
+
728
+
729
+ # List Customers
730
+ # http://developer.helpscout.net/customers/
731
+ #
732
+ # Fetches all customers. Customers are returned by createdAt date, from
733
+ # newest to oldest.
734
+ #
735
+ # Request
736
+ # REST Method: GET
737
+ # URL: https://api.helpscout.net/v1/customers.json
738
+ #
739
+ # Parameters:
740
+ # Name Type Required Default Notes
741
+ # page Int No 1
742
+ #
743
+ # Response
744
+ # Name Type
745
+ # items Array Collection of Customer objects.
746
+
747
+ def customers
748
+ url = "/customers.json"
749
+ items = Client.requestItems(@auth, url, :page => 1)
750
+ customers = []
751
+ items.each do |item|
752
+ customers << Customer.new(item)
753
+ end
754
+
755
+ customers
756
+ end
757
+ end
758
+ end