Class: Desk::Client

Inherits:
API
  • Object
show all
Includes:
Article, Brand, Case, Company, CustomField, Customer, FacebookUser, Filter, Group, Insight, IntegrationUrl, Job, Label, Macro, Mailbox, Rule, SiteSetting, SystemMessage, Topic, TwitterAccount, TwitterUser, User
Defined in:
lib/desk/client.rb,
lib/desk/client/job.rb,
lib/desk/client/case.rb,
lib/desk/client/rule.rb,
lib/desk/client/user.rb,
lib/desk/client/brand.rb,
lib/desk/client/group.rb,
lib/desk/client/label.rb,
lib/desk/client/macro.rb,
lib/desk/client/topic.rb,
lib/desk/client/filter.rb,
lib/desk/client/article.rb,
lib/desk/client/company.rb,
lib/desk/client/insight.rb,
lib/desk/client/mailbox.rb,
lib/desk/client/customer.rb,
lib/desk/client/custom_field.rb,
lib/desk/client/site_setting.rb,
lib/desk/client/twitter_user.rb,
lib/desk/client/facebook_user.rb,
lib/desk/client/system_message.rb,
lib/desk/client/integration_url.rb,
lib/desk/client/twitter_account.rb

Overview

Note:

All methods have been separated into modules and follow the same grouping used in the Desk.com API Documentation.

Wrapper for the Desk.com REST API

Defined Under Namespace

Modules: Article, Brand, Case, Company, CustomField, Customer, FacebookUser, Filter, Group, Insight, IntegrationUrl, Job, Label, Macro, Mailbox, Rule, SiteSetting, SystemMessage, Topic, TwitterAccount, TwitterUser, User

Constant Summary

Constants included from Request

Request::REQUEST_METHODS

Instance Method Summary collapse

Methods included from User

#user_endpoints

Methods included from TwitterUser

#twitter_user_endpoints

Methods included from TwitterAccount

#twitter_account_endpoints

Methods included from Topic

#topic_endpoints

Methods included from SystemMessage

#show_system_message, #system_message_id

Methods included from SiteSetting

#site_setting_endpoints

Methods included from Rule

#rule_endpoints

Methods included from Mailbox

#mailbox_id_inbound, #mailbox_list_inbound, #mailbox_show_inbound

Methods included from Macro

#macro_endpoints

Methods included from Label

#label_endpoints

Methods included from Job

#job_endpoints

Methods included from IntegrationUrl

#integration_url_endpoints

Methods included from Insight

#create_insights_report, #show_insights_meta

Methods included from Group

#group_endpoints

Methods included from Filter

#filter_endpoints

Methods included from FacebookUser

#facebook_user_endpoints

Methods included from Customer

#customer_add_address, #customer_add_email, #customer_add_key, #customer_add_phone_number, #customer_delete_address, #customer_delete_email, #customer_delete_key, #customer_delete_phone_number, #customer_endpoints

Methods included from CustomField

#custom_field_endpoints

Methods included from Company

#company_endpoints

Methods included from Case

#case_endpoints, #case_url, #create_case_message_attachment, #create_case_reply_attachment, #delete_case_message_attachment, #delete_case_reply_attachment, #list_case_message_attachments, #list_case_reply_attachments, #show_case, #show_case_message, #show_case_message_attachment, #show_case_reply_attachment

Methods included from Brand

#brand_endpoints

Methods included from Article

#article_endpoints

Methods included from Request

#method_missing, #respond_to?

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/desk/client.rb', line 59

def initialize(options={})
  if !self.respond_to? :endpoints_setup
    self.class.included_modules.each do |m|
      if r = m.name.match(/Desk::Client::([a-zA-z]+)/)
        base = r[1].gsub(/(.)([A-Z])/, '\1_\2').downcase
        if self.respond_to? "#{base}_endpoints"
          endpoints_list = send("#{base}_endpoints")
          setup_functions(base, endpoints_list)
        end
      end
    end
    self.class.send(:define_method, :endpoints_setup) {}
  end
  super(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Desk::Request

Instance Method Details



85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/desk/client.rb', line 85

def create_link(type, class_or_hash, id = nil, sub_class = nil, sub_id = nil)
  if class_or_hash.class == Hashie::Deash
    {type.to_sym => {
      :class => class_or_hash._links.self['class'],
      :href => class_or_hash._links.self['href']
    }}
  elsif class_or_hash.class == String
    href = Desk.api_path+plural(class_or_hash)+"/#{id}"
    href += "/"+plural(sub_class)+"/#{sub_id}" if sub_class != nil
    {type.to_sym => { :class => class_or_hash, :href => href }}
  else
    nil
  end
end

#plural(singular) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/desk/client.rb', line 75

def plural(singular)
  if singular[-1, 1] == "y"
    singular[0..-2]+"ies"
  elsif singular[-1, 1] == "x"
    singular+"es"
  else
    singular+"s"
  end
end