desk 0.3.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.mkd +305 -106
- data/TRANSITION.mkd +133 -0
- data/desk.gemspec +1 -1
- data/lib/desk.rb +1 -1
- data/lib/desk/api.rb +5 -1
- data/lib/desk/client.rb +184 -10
- data/lib/desk/client/article.rb +4 -83
- data/lib/desk/client/brand.rb +11 -0
- data/lib/desk/client/case.rb +59 -42
- data/lib/desk/client/company.rb +11 -0
- data/lib/desk/client/custom_field.rb +10 -0
- data/lib/desk/client/customer.rb +26 -124
- data/lib/desk/client/facebook_user.rb +11 -0
- data/lib/desk/client/filter.rb +11 -0
- data/lib/desk/client/group.rb +3 -29
- data/lib/desk/client/insight.rb +17 -0
- data/lib/desk/client/integration_url.rb +11 -0
- data/lib/desk/client/job.rb +11 -0
- data/lib/desk/client/label.rb +11 -0
- data/lib/desk/client/macro.rb +3 -133
- data/lib/desk/client/mailbox.rb +26 -0
- data/lib/desk/client/rule.rb +14 -0
- data/lib/desk/client/site_setting.rb +11 -0
- data/lib/desk/client/system_message.rb +16 -0
- data/lib/desk/client/topic.rb +4 -81
- data/lib/desk/client/twitter_account.rb +11 -0
- data/lib/desk/client/twitter_user.rb +11 -0
- data/lib/desk/client/user.rb +3 -30
- data/lib/desk/configuration.rb +1 -1
- data/lib/desk/connection.rb +2 -1
- data/lib/desk/deash.rb +100 -0
- data/lib/desk/request.rb +33 -20
- data/lib/desk/version.rb +1 -1
- data/lib/faraday/request/oauth.rb +6 -3
- data/lib/faraday/response/deashify.rb +23 -0
- data/spec/desk/client/article_spec.rb +62 -117
- data/spec/desk/client/brand_spec.rb +18 -0
- data/spec/desk/client/case_spec.rb +182 -66
- data/spec/desk/client/companies_spec.rb +26 -0
- data/spec/desk/client/custom_fields_spec.rb +18 -0
- data/spec/desk/client/customer_spec.rb +16 -145
- data/spec/desk/client/facebook_users_spec.rb +17 -0
- data/spec/desk/client/filter_spec.rb +28 -0
- data/spec/desk/client/group_spec.rb +32 -49
- data/spec/desk/client/inbound_mailboxes_spec.rb +70 -0
- data/spec/desk/client/integration_url_spec.rb +28 -0
- data/spec/desk/client/job_spec.rb +32 -0
- data/spec/desk/client/label_spec.rb +31 -0
- data/spec/desk/client/macro_spec.rb +22 -185
- data/spec/desk/client/rule_spec.rb +18 -0
- data/spec/desk/client/site_setting_spec.rb +18 -0
- data/spec/desk/client/system_message_spec.rb +42 -0
- data/spec/desk/client/topic_spec.rb +31 -112
- data/spec/desk/client/twitter_account_spec.rb +32 -0
- data/spec/desk/client/twitter_user_spec.rb +27 -0
- data/spec/desk/client/user_spec.rb +19 -42
- data/spec/desk_spec.rb +2 -2
- data/spec/faraday/response_spec.rb +3 -6
- data/spec/fixtures/article +50 -0
- data/spec/fixtures/article_create +50 -0
- data/spec/fixtures/article_translation +29 -0
- data/spec/fixtures/article_translation_create +29 -0
- data/spec/fixtures/article_translation_update +29 -0
- data/spec/fixtures/article_translations +81 -0
- data/spec/fixtures/article_update +50 -0
- data/spec/fixtures/articles +123 -0
- data/spec/fixtures/articles_search +124 -0
- data/spec/fixtures/brand +11 -0
- data/spec/fixtures/brands +45 -0
- data/spec/fixtures/case +44 -0
- data/spec/fixtures/case_attachment +19 -0
- data/spec/fixtures/case_attachment_create +19 -0
- data/spec/fixtures/case_attachments +61 -0
- data/spec/fixtures/case_create +51 -0
- data/spec/fixtures/case_message +26 -0
- data/spec/fixtures/case_note +21 -0
- data/spec/fixtures/case_note_create +26 -0
- data/spec/fixtures/case_notes +65 -0
- data/spec/fixtures/case_replies +75 -0
- data/spec/fixtures/case_reply +26 -0
- data/spec/fixtures/case_reply_create +26 -0
- data/spec/fixtures/case_reply_update +26 -0
- data/spec/fixtures/case_update +49 -0
- data/spec/fixtures/cases +111 -0
- data/spec/fixtures/cases_search +113 -0
- data/spec/fixtures/companies +75 -0
- data/spec/fixtures/companies_search +76 -0
- data/spec/fixtures/company +26 -0
- data/spec/fixtures/company_create +26 -0
- data/spec/fixtures/company_search +76 -0
- data/spec/fixtures/company_update +27 -0
- data/spec/fixtures/custom_field +15 -0
- data/spec/fixtures/custom_fields +58 -0
- data/spec/fixtures/customer +60 -0
- data/spec/fixtures/customer_create +54 -0
- data/spec/fixtures/customer_update +60 -0
- data/spec/fixtures/customers +143 -0
- data/spec/fixtures/customers_search +143 -0
- data/spec/fixtures/facebook_user +16 -0
- data/spec/fixtures/facebook_users +55 -0
- data/spec/fixtures/filter +16 -0
- data/spec/fixtures/filter_cases +111 -0
- data/spec/fixtures/filters +55 -0
- data/spec/fixtures/group +9 -0
- data/spec/fixtures/group_filters +55 -0
- data/spec/fixtures/group_users +63 -0
- data/spec/fixtures/groups +42 -0
- data/spec/fixtures/inbound_mailbox +32 -0
- data/spec/fixtures/inbound_mailboxes +87 -0
- data/spec/fixtures/integration_url +15 -0
- data/spec/fixtures/integration_url_create +15 -0
- data/spec/fixtures/integration_url_update +15 -0
- data/spec/fixtures/integration_urls +54 -0
- data/spec/fixtures/job +17 -0
- data/spec/fixtures/job_create +17 -0
- data/spec/fixtures/jobs +57 -0
- data/spec/fixtures/label +17 -0
- data/spec/fixtures/label_create +17 -0
- data/spec/fixtures/label_update +17 -0
- data/spec/fixtures/labels +57 -0
- data/spec/fixtures/macro +20 -0
- data/spec/fixtures/macro_action +17 -0
- data/spec/fixtures/macro_action_update +17 -0
- data/spec/fixtures/macro_actions +57 -0
- data/spec/fixtures/macro_create +20 -0
- data/spec/fixtures/macro_update +20 -0
- data/spec/fixtures/macros +63 -0
- data/spec/fixtures/rule +13 -0
- data/spec/fixtures/rules +49 -0
- data/spec/fixtures/site_setting +10 -0
- data/spec/fixtures/site_settings +43 -0
- data/spec/fixtures/system_message +4 -0
- data/spec/fixtures/topic +23 -0
- data/spec/fixtures/topic_create +23 -0
- data/spec/fixtures/topic_translation +12 -0
- data/spec/fixtures/topic_translation_create +12 -0
- data/spec/fixtures/topic_translation_update +12 -0
- data/spec/fixtures/topic_translations +47 -0
- data/spec/fixtures/topic_update +23 -0
- data/spec/fixtures/topics +69 -0
- data/spec/fixtures/twitter_account +14 -0
- data/spec/fixtures/twitter_account_tweet +20 -0
- data/spec/fixtures/twitter_account_tweet_create +20 -0
- data/spec/fixtures/twitter_account_tweets +63 -0
- data/spec/fixtures/twitter_accounts +51 -0
- data/spec/fixtures/twitter_user +18 -0
- data/spec/fixtures/twitter_user_create +18 -0
- data/spec/fixtures/twitter_users +59 -0
- data/spec/fixtures/user +20 -0
- data/spec/fixtures/user_preference +18 -0
- data/spec/fixtures/user_preference_update +14 -0
- data/spec/fixtures/user_preferences +223 -0
- data/spec/fixtures/users +63 -0
- data/spec/helper.rb +12 -0
- data/spec/shared_context.rb +16 -0
- data/spec/shared_examples.rb +312 -0
- metadata +247 -181
- data/lib/desk/client/interaction.rb +0 -75
- data/spec/desk/client/interaction_spec.rb +0 -191
- data/spec/fixtures/article.json +0 -50
- data/spec/fixtures/article_create.json +0 -54
- data/spec/fixtures/article_destroy.json +0 -3
- data/spec/fixtures/article_update.json +0 -54
- data/spec/fixtures/articles.json +0 -58
- data/spec/fixtures/case.json +0 -59
- data/spec/fixtures/case_update.json +0 -59
- data/spec/fixtures/cases.json +0 -182
- data/spec/fixtures/customer.json +0 -58
- data/spec/fixtures/customer_create.json +0 -56
- data/spec/fixtures/customer_create_email.json +0 -15
- data/spec/fixtures/customer_update.json +0 -47
- data/spec/fixtures/customer_update_email.json +0 -15
- data/spec/fixtures/customers.json +0 -98
- data/spec/fixtures/group.json +0 -8
- data/spec/fixtures/groups.json +0 -23
- data/spec/fixtures/interaction_create.json +0 -126
- data/spec/fixtures/interactions.json +0 -139
- data/spec/fixtures/macro.json +0 -8
- data/spec/fixtures/macro_action.json +0 -9
- data/spec/fixtures/macro_action_update.json +0 -12
- data/spec/fixtures/macro_actions.json +0 -69
- data/spec/fixtures/macro_create.json +0 -13
- data/spec/fixtures/macro_destroy.json +0 -3
- data/spec/fixtures/macro_update.json +0 -13
- data/spec/fixtures/macros.json +0 -24
- data/spec/fixtures/topic.json +0 -9
- data/spec/fixtures/topic_create.json +0 -14
- data/spec/fixtures/topic_destroy.json +0 -3
- data/spec/fixtures/topic_update.json +0 -14
- data/spec/fixtures/topics.json +0 -35
- data/spec/fixtures/user.json +0 -15
- data/spec/fixtures/users.json +0 -24
@@ -0,0 +1,26 @@
|
|
1
|
+
module Desk
|
2
|
+
class Client
|
3
|
+
module Mailbox
|
4
|
+
|
5
|
+
def mailbox_list_inbound(*args)
|
6
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
7
|
+
get("mailboxes/inbound", options)
|
8
|
+
end
|
9
|
+
alias_method :inbound_mailboxes, :mailbox_list_inbound
|
10
|
+
alias_method :list_inbound_mailboxes, :mailbox_list_inbound
|
11
|
+
|
12
|
+
def mailbox_show_inbound(mailbox_id)
|
13
|
+
get("mailboxes/inbound/#{mailbox_id}")
|
14
|
+
end
|
15
|
+
alias_method :inbound_mailbox, :mailbox_show_inbound
|
16
|
+
alias_method :show_inbound_mailbox, :mailbox_show_inbound
|
17
|
+
|
18
|
+
def mailbox_id_inbound(href, parent_id = false)
|
19
|
+
return nil if parent_id
|
20
|
+
href.split("/")[5].to_i
|
21
|
+
end
|
22
|
+
alias_method :inbound_mailbox_id, :mailbox_id_inbound
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Desk
|
2
|
+
class Client
|
3
|
+
module SystemMessage
|
4
|
+
|
5
|
+
def show_system_message
|
6
|
+
get("system_message")
|
7
|
+
end
|
8
|
+
alias_method :system_message, :show_system_message
|
9
|
+
|
10
|
+
def system_message_id(href, parent_id = false)
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/desk/client/topic.rb
CHANGED
@@ -1,90 +1,13 @@
|
|
1
1
|
module Desk
|
2
2
|
class Client
|
3
|
-
# Defines methods related to topics
|
4
3
|
module Topic
|
5
|
-
# Returns extended information of topics
|
6
|
-
#
|
7
|
-
# @option options [Boolean, String, Integer]
|
8
|
-
# @example Return extended information for 12345
|
9
|
-
# Desk.topics
|
10
|
-
# Desk.topics(:count => 5)
|
11
|
-
# Desk.topics(:count => 5, :page => 3)
|
12
|
-
# @format :json
|
13
|
-
# @authenticated true
|
14
|
-
# @see http://dev.desk.com/docs/api/topics/show
|
15
|
-
def topics(*args)
|
16
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
17
|
-
response = get("topics",options)
|
18
|
-
response
|
19
|
-
end
|
20
|
-
|
21
|
-
# Returns extended information on a single topic
|
22
|
-
#
|
23
|
-
# @param id [Integer] a topic ID
|
24
|
-
# @option options [Hash]
|
25
|
-
# @example Return extended information for 12345
|
26
|
-
# Desk.topic(12345)
|
27
|
-
# Desk.topic(12345, :by => "external_id")
|
28
|
-
# @format :json
|
29
|
-
# @authenticated true
|
30
|
-
# @see http://dev.desk.com/docs/api/topics/show
|
31
|
-
def topic(id, *args)
|
32
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
33
|
-
response = get("topics/#{id}",options)
|
34
|
-
response.topic
|
35
|
-
end
|
36
4
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
# @example Creates a new topic
|
42
|
-
# Desk.create_topic("name")
|
43
|
-
# Desk.create_topic("name", :description => "description")
|
44
|
-
# @format :json
|
45
|
-
# @authenticated true
|
46
|
-
# @see http://dev.desk.com/docs/api/topics/create
|
47
|
-
def create_topic(name, *args)
|
48
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
49
|
-
response = post("topics",options)
|
50
|
-
if response['success']
|
51
|
-
return response['results']['topic']
|
52
|
-
else
|
53
|
-
return response
|
54
|
-
end
|
5
|
+
def topic_endpoints
|
6
|
+
[ :list, :show, :create, :update, :delete,
|
7
|
+
:list_translations, :show_translation, :create_translation,
|
8
|
+
:update_translation, :delete_translation ]
|
55
9
|
end
|
56
10
|
|
57
|
-
# Updates a single topic
|
58
|
-
#
|
59
|
-
# @param id [Integer] a topic ID
|
60
|
-
# @option options [String]
|
61
|
-
# @example Updates information for topic 12345
|
62
|
-
# Desk.update_topic(12345, :subject => "New Subject")
|
63
|
-
# @format :json
|
64
|
-
# @authenticated true
|
65
|
-
# @see http://dev.desk.com/docs/api/topics/update
|
66
|
-
def update_topic(id, *args)
|
67
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
68
|
-
response = put("topics/#{id}",options)
|
69
|
-
if response['success']
|
70
|
-
return response['results']['topic']
|
71
|
-
else
|
72
|
-
return response
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Deletes a single topic
|
77
|
-
#
|
78
|
-
# @param id [Integer] a topic ID
|
79
|
-
# @example Deletes topic 12345
|
80
|
-
# Desk.update_topic(12345, :subject => "New Subject")
|
81
|
-
# @format :json
|
82
|
-
# @authenticated true
|
83
|
-
# @see http://dev.desk.com/docs/api/topics/update
|
84
|
-
def delete_topic(id)
|
85
|
-
response = delete("topics/#{id}")
|
86
|
-
response
|
87
|
-
end
|
88
11
|
end
|
89
12
|
end
|
90
13
|
end
|
data/lib/desk/client/user.rb
CHANGED
@@ -1,38 +1,11 @@
|
|
1
1
|
module Desk
|
2
2
|
class Client
|
3
|
-
# Defines methods related to users
|
4
3
|
module User
|
5
|
-
# Returns extended information of a given user
|
6
|
-
#
|
7
|
-
# @overload user(user, options={})
|
8
|
-
# @param user [Integer] An Assitely user ID
|
9
|
-
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
|
10
|
-
# @return [Hashie::Mash] The requested user.
|
11
|
-
# @example Return extended information for 12345
|
12
|
-
# Desk.user(12345)
|
13
|
-
# @format :json, :xml
|
14
|
-
# @authenticated true
|
15
|
-
# @see http://dev.desk.com/docs/api/users/show
|
16
|
-
def user(id,*args)
|
17
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
18
|
-
response = get("users/#{id}",options)
|
19
|
-
response.user
|
20
|
-
end
|
21
4
|
|
22
|
-
|
23
|
-
|
24
|
-
# @format :json, :xml
|
25
|
-
# @authenticated true
|
26
|
-
# @rate_limited true
|
27
|
-
# @return [Array] The requested users.
|
28
|
-
# @see http://dev.desk.com/docs/api/users
|
29
|
-
# @example Return extended information account users
|
30
|
-
# Desk.users
|
31
|
-
def users(*args)
|
32
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
33
|
-
response = get('users', options)
|
34
|
-
response
|
5
|
+
def user_endpoints
|
6
|
+
[ :list, :show, :list_preferences, :show_preference, :update_preference ]
|
35
7
|
end
|
8
|
+
|
36
9
|
end
|
37
10
|
end
|
38
11
|
end
|
data/lib/desk/configuration.rb
CHANGED
@@ -64,7 +64,7 @@ module Desk
|
|
64
64
|
DEFAULT_USER_AGENT = "Desk.com Ruby Gem #{Desk::VERSION}".freeze
|
65
65
|
|
66
66
|
# The user agent that will be sent to the API endpoint if none is set
|
67
|
-
DEFAULT_VERSION = "
|
67
|
+
DEFAULT_VERSION = "v2".freeze
|
68
68
|
|
69
69
|
# By default, don't set a support email address
|
70
70
|
DEFAULT_SUPPORT_EMAIL = nil
|
data/lib/desk/connection.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'faraday_middleware'
|
2
2
|
require 'faraday/request/multipart_with_file'
|
3
|
+
require 'faraday/response/deashify'
|
3
4
|
require 'faraday/response/raise_http_4xx'
|
4
5
|
require 'faraday/response/raise_http_5xx'
|
5
6
|
|
@@ -22,7 +23,7 @@ module Desk
|
|
22
23
|
builder.use Faraday::Request::Multipart
|
23
24
|
builder.use Faraday::Request::UrlEncoded
|
24
25
|
builder.use Faraday::Response::RaiseHttp4xx
|
25
|
-
builder.use
|
26
|
+
builder.use FaradayMiddleware::Deashify unless raw
|
26
27
|
unless raw
|
27
28
|
case format.to_s.downcase
|
28
29
|
when 'json'
|
data/lib/desk/deash.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'hashie/mash'
|
2
|
+
|
3
|
+
module Hashie
|
4
|
+
class Links
|
5
|
+
|
6
|
+
def initialize(links)
|
7
|
+
@links = links
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(method, *args, &block)
|
11
|
+
if @links.key?(method)
|
12
|
+
return nil if !@links[method]
|
13
|
+
return Desk.get(@links[method].href.sub("/api/#{Desk.version}/", ""))
|
14
|
+
end
|
15
|
+
return super
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Deash < Mash
|
20
|
+
# Object#type is deprecated
|
21
|
+
Mash.send :undef_method, :type
|
22
|
+
|
23
|
+
def count
|
24
|
+
if includes_key_chain?("raw._embedded.entries")
|
25
|
+
self.raw._embedded['entries'].count
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def each
|
32
|
+
if includes_key_chain?("raw._embedded.entries")
|
33
|
+
self.raw._embedded['entries'].each do |entry|
|
34
|
+
yield entry
|
35
|
+
end
|
36
|
+
else
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def method_missing(method, *args, &block)
|
42
|
+
return self.[](method) if key?(method)
|
43
|
+
# TODO: Make this DRY
|
44
|
+
if includes_key_chain?("_links."+method.to_s)
|
45
|
+
return nil if !self._links[method]
|
46
|
+
return Desk.get(self._links[method].href.sub(Desk.api_path, ""))
|
47
|
+
elsif includes_key_chain?("raw._links."+method.to_s)
|
48
|
+
return nil if !self.raw._links[method]
|
49
|
+
return Desk.get(self.raw._links[method].href.sub(Desk.api_path, ""))
|
50
|
+
elsif includes_key_chain?("raw."+method.to_s)
|
51
|
+
return nil if !self.raw[method]
|
52
|
+
return self.raw[method]
|
53
|
+
end
|
54
|
+
return super
|
55
|
+
end
|
56
|
+
|
57
|
+
def id(parent_id = false)
|
58
|
+
id = nil
|
59
|
+
if includes_key_chain?("raw._links.self.href") ||
|
60
|
+
includes_key_chain?("_links.self.href")
|
61
|
+
c = self._links.self['class']
|
62
|
+
if Desk.respond_to? "#{c}_id"
|
63
|
+
id = Desk.send("#{c}_id", self._links.self.href, parent_id)
|
64
|
+
else
|
65
|
+
p = self._links.self.href.split("/")
|
66
|
+
if p.size > 5 && !parent_id
|
67
|
+
id = p[6]
|
68
|
+
elsif (p.size < 6 && !parent_id) || (p.size > 5 && parent_id)
|
69
|
+
id = p[4]
|
70
|
+
end
|
71
|
+
id = id.to_i if id.to_i != 0
|
72
|
+
end
|
73
|
+
end
|
74
|
+
id
|
75
|
+
end
|
76
|
+
|
77
|
+
def parent_id
|
78
|
+
id(true)
|
79
|
+
end
|
80
|
+
|
81
|
+
def includes_key_chain?(chain)
|
82
|
+
current_chain = self
|
83
|
+
chain.split(".").each do |k|
|
84
|
+
return false if !current_chain.key?(k)
|
85
|
+
current_chain = current_chain[k]
|
86
|
+
end
|
87
|
+
true
|
88
|
+
end
|
89
|
+
|
90
|
+
def links
|
91
|
+
Links.new(self._links) if key?("_links")
|
92
|
+
Links.new(self.raw._links) if includes_key_chain?("raw._links")
|
93
|
+
end
|
94
|
+
|
95
|
+
def results
|
96
|
+
self._embedded['entries'] if key?('_embedded') && self._embedded.key?('entries')
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
data/lib/desk/request.rb
CHANGED
@@ -1,34 +1,42 @@
|
|
1
1
|
module Desk
|
2
2
|
# Defines HTTP request methods
|
3
3
|
module Request
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
4
|
+
require 'json' unless defined?(::JSON)
|
5
|
+
REQUEST_METHODS = [
|
6
|
+
'get',
|
7
|
+
'patch',
|
8
|
+
'post',
|
9
|
+
'put',
|
10
|
+
'delete'
|
11
|
+
].freeze
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def method_missing(method_name, *args, &block)
|
14
|
+
if (REQUEST_METHODS.include? method_name.to_s) && (args.length > 0)
|
15
|
+
path = args[0]
|
16
|
+
options = args[1] ? args[1] : {}
|
17
|
+
raw = args[2] ? args[2] : false
|
18
|
+
request(method_name.to_sym, path, options, raw)
|
19
|
+
else
|
20
|
+
super
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
def respond_to?(method_name, include_private = false)
|
25
|
+
if (REQUEST_METHODS.include? method_name.to_s)
|
26
|
+
true
|
27
|
+
else
|
28
|
+
super
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
32
|
private
|
25
|
-
|
33
|
+
|
26
34
|
def before_request
|
27
35
|
if Desk.minute != Time.now.min
|
28
36
|
Desk.minute = Time.now.min
|
29
37
|
Desk.counter = 0
|
30
38
|
end
|
31
|
-
|
39
|
+
|
32
40
|
Desk.counter += 1
|
33
41
|
if Desk.use_max_requests
|
34
42
|
if Desk.counter > Desk.max_requests
|
@@ -44,16 +52,21 @@ module Desk
|
|
44
52
|
case method
|
45
53
|
when :get, :delete
|
46
54
|
request.url(formatted_path(path), options)
|
47
|
-
when :post, :put
|
55
|
+
when :patch, :post, :put
|
48
56
|
request.path = formatted_path(path)
|
49
|
-
request.
|
57
|
+
request.headers['Content-Type'] = 'application/json'
|
58
|
+
request.body = options.to_json unless options.empty?
|
50
59
|
end
|
51
60
|
end
|
52
61
|
raw ? response : response.body
|
53
62
|
end
|
54
63
|
|
55
64
|
def formatted_path(path)
|
56
|
-
|
65
|
+
if(self.version == "v1")
|
66
|
+
[path, format].compact.join('.')
|
67
|
+
else
|
68
|
+
path
|
69
|
+
end
|
57
70
|
end
|
58
71
|
end
|
59
72
|
end
|