Permalink
Browse files

added support for groups

  • Loading branch information...
1 parent 65da365 commit b768eca54418844c17abbeeb2b7cec71a2ea6b9b @tstachl tstachl committed Feb 11, 2013
Showing with 124 additions and 0 deletions.
  1. +2 −0 lib/desk/client.rb
  2. +37 −0 lib/desk/client/group.rb
  3. +54 −0 spec/desk/client/group_spec.rb
  4. +8 −0 spec/fixtures/group.json
  5. +23 −0 spec/fixtures/groups.json
View
@@ -8,6 +8,7 @@ class Client < API
# order to avoid a superclass mismatch error, allowing those modules to be
# Client-namespaced.
require 'desk/client/user'
+ require 'desk/client/group'
require 'desk/client/interaction'
require 'desk/client/case'
require 'desk/client/customer'
@@ -18,6 +19,7 @@ class Client < API
alias :api_endpoint :endpoint
include Desk::Client::User
+ include Desk::Client::Group
include Desk::Client::Interaction
include Desk::Client::Case
include Desk::Client::Customer
View
@@ -0,0 +1,37 @@
+module Desk
+ class Client
+ # Defines methods related to groups
+ module Group
+ # Returns extended information of groups
+ #
+ # @option options [Boolean, String, Integer]
+ # @example Return extended information for 12345
+ # Desk.groups
+ # Desk.groups(:count => 5)
+ # Desk.groups(:count => 5, :page => 3)
+ # @format :json
+ # @authenticated true
+ # @see http://dev.desk.com/docs/api/groups
+ def groups(*args)
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ response = get("groups",options)
+ response
+ end
+
+ # Returns extended information on a single group
+ #
+ # @param id [Integer] a group ID
+ # @option options [Hash]
+ # @example Return extended information for 12345
+ # Desk.group(12345)
+ # @format :json
+ # @authenticated true
+ # @see http://dev.desk.com/docs/api/groups/show
+ def group(id)
+ response = get("groups/#{id}")
+ response.group
+ end
+
+ end
+ end
+end
@@ -0,0 +1,54 @@
+require 'helper'
+
+describe Desk::Client do
+ Desk::Configuration::VALID_FORMATS.each do |format|
+ context ".new(:format => '#{format}')" do
+ before do
+ @client = Desk::Client.new(:subdomain => "example", :format => format, :consumer_key => 'CK', :consumer_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
+ end
+
+ describe ".groups" do
+ context "lookup" do
+ before do
+ stub_get("groups.#{format}").
+ to_return(:body => fixture("groups.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
+ end
+
+ it "should get the correct resource" do
+ @client.groups
+ a_get("groups.#{format}").
+ should have_been_made
+ end
+
+ it "should return up to 100 groups worth of extended information" do
+ groups = @client.groups
+ groups.results.should be_a Array
+ groups.results.last.group.id.should == 2
+ groups.results.last.group.name.should == "Administrators"
+ end
+ end
+ end
+
+ describe ".group" do
+ context "lookup" do
+ before do
+ stub_get("groups/1.#{format}").
+ to_return(:body => fixture("group.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
+ end
+
+ it "should get the correct resource" do
+ @client.group(1)
+ a_get("groups/1.#{format}").
+ should have_been_made
+ end
+
+ it "should return up to 100 cases worth of extended information" do
+ group = @client.group(1)
+ group.id.should == 1
+ group.name.should == "Sales"
+ end
+ end
+ end
+ end
+ end
+end
View
@@ -0,0 +1,8 @@
+{
+ "group": {
+ "id": 1,
+ "name": "Sales",
+ "created_at": "2013-01-21T09:47:23Z",
+ "updated_at": "2013-01-21T09:47:23Z"
+ }
+}
View
@@ -0,0 +1,23 @@
+{
+ "results": [
+ {
+ "group": {
+ "id": 1,
+ "name": "Sales",
+ "created_at": "2013-01-21T09:47:23Z",
+ "updated_at": "2013-01-21T09:47:23Z"
+ }
+ },
+ {
+ "group": {
+ "id": 2,
+ "name": "Administrators",
+ "created_at": "2013-01-21T09:47:23Z",
+ "updated_at": "2013-01-21T09:47:23Z"
+ }
+ }
+ ],
+ "page": 1,
+ "count": 20,
+ "total": 2
+}

0 comments on commit b768eca

Please sign in to comment.