├── .coveralls.yml ├── .gitignore ├── .rspec ├── .travis.yml ├── Appraisals ├── CODEOWNERS ├── Gemfile ├── Guardfile ├── LICENSE.txt ├── README.md ├── Rakefile ├── desk_api.gemspec ├── gemfiles ├── 0.8.gemfile └── 0.9.gemfile ├── lib ├── desk.rb ├── desk_api.rb └── desk_api │ ├── client.rb │ ├── configuration.rb │ ├── default.rb │ ├── error.rb │ ├── error │ ├── bad_gateway.rb │ ├── bad_request.rb │ ├── client_error.rb │ ├── configuration_error.rb │ ├── conflict.rb │ ├── follow_redirect_error.rb │ ├── forbidden.rb │ ├── gateway_timeout.rb │ ├── internal_server_error.rb │ ├── method_not_allowed.rb │ ├── not_acceptable.rb │ ├── not_found.rb │ ├── parser_error.rb │ ├── server_error.rb │ ├── service_unavailable.rb │ ├── too_many_requests.rb │ ├── unauthorized.rb │ ├── unprocessable_entity.rb │ └── unsupported_media_type.rb │ ├── rate_limit.rb │ ├── request │ ├── encode_dates.rb │ ├── encode_json.rb │ ├── oauth.rb │ └── retry.rb │ ├── resource.rb │ ├── resource │ ├── download.rb │ ├── pagination.rb │ ├── query_params.rb │ └── scrud.rb │ ├── response │ ├── follow_redirects.rb │ ├── parse_dates.rb │ ├── parse_json.rb │ └── raise_error.rb │ └── version.rb └── spec ├── cassettes ├── DeskApi_Client │ ├── using_Basic_Authentication │ │ ├── _delete │ │ │ └── deletes_a_resource.yml │ │ ├── _get │ │ │ └── fetches_resources.yml │ │ ├── _patch │ │ │ └── updates_a_resource.yml │ │ └── _post │ │ │ └── creates_a_resource.yml │ └── using_OAuth │ │ ├── _delete │ │ └── deletes_a_resource.yml │ │ ├── _get │ │ └── fetches_resources.yml │ │ ├── _patch │ │ └── updates_a_resource.yml │ │ └── _post │ │ └── creates_a_resource.yml ├── DeskApi_Error │ ├── _from_response │ │ ├── can_be_created_from_a_faraday_response.yml │ │ └── uses_the_body_message_if_present.yml │ └── on_validation_error │ │ └── allows_access_to_error_hash.yml ├── DeskApi_Resource │ ├── _by_url │ │ └── finds_resources_by_url.yml │ ├── _exec_ │ │ ├── can_be_forced_to_reload.yml │ │ └── loads_the_current_resource.yml │ ├── _get_linked_resource │ │ ├── returns_linked_resources.yml │ │ ├── returns_nil_if_link_is_nil.yml │ │ └── saves_the_linked_resource_instead_of_the_url.yml │ ├── _load │ │ └── loads_the_resource_if_not_already_loaded.yml │ ├── _loaded_ │ │ └── returns_true_if_the_resource_is_loaded.yml │ ├── _method_missing │ │ ├── loads_the_resource_to_find_a_suitable_method.yml │ │ └── raises_an_error_if_method_does_not_exist.yml │ ├── _next_ │ │ ├── changes__definition_to_next_page.yml │ │ ├── returns_nil_on_non-page_resources.yml │ │ ├── returns_nil_on_the_last_page.yml │ │ └── throws_an_error_on_non-page_resources.yml │ ├── _request │ │ └── sends_request_through_a_client_and_returns_Faraday_Response.yml │ ├── _reset_ │ │ └── sets__links__embedded__changed_and__loaded_to_default_values.yml │ ├── _to_hash │ │ ├── converts_embedded_resources_to_hashes.yml │ │ └── returns_a_hash_for_a_desk_resource.yml │ └── prioritize_links_and_embeds │ │ ├── loads_the_resource_and_returns_the_name.yml │ │ └── returns_a_desk_resource.yml ├── DeskApi_Resource_Download │ ├── downloads_the_attachment.yml │ └── throws_an_error_on_non_attachment_resources.yml ├── DeskApi_Resource_Pagination │ ├── _all │ │ └── iterates_over_each_resource_on_each_page.yml │ └── _each_page │ │ ├── iterates_over_each_page.yml │ │ ├── raises_NoMethodError_is_called_on_non-page_resources.yml │ │ └── uses_a_default_per_page_of_1000.yml ├── DeskApi_Resource_QueryParams │ └── _page │ │ ├── keeps_the_resource_as_loaded.yml │ │ ├── returns_the_current_page_and_loads_if_page_not_defined.yml │ │ └── sets_the_resource_to_not_loaded.yml └── DeskApi_Resource_SCRUD │ ├── _create │ ├── creates_a_new_topic.yml │ └── throws_an_error_creating_a_user.yml │ ├── _delete │ ├── deletes_a_resource.yml │ └── throws_an_error_deleting_a_non_deletalbe_resource.yml │ ├── _find │ ├── has_an_alias_by_id.yml │ └── loads_the_requested_resource.yml │ ├── _search │ ├── allows_searching_on_search_enabled_resources.yml │ └── throws_an_error_if_search_is_not_enabled.yml │ └── _update │ ├── can_handle_action_params.yml │ ├── can_handle_links.yml │ ├── can_handle_update_action_params.yml │ ├── can_replace_instead_of_append.yml │ ├── can_update_without_a_hash.yml │ ├── throws_an_error_updating_a_user.yml │ └── updates_a_topic.yml ├── desk_api ├── client_spec.rb ├── configuration_spec.rb ├── default_spec.rb ├── error_spec.rb ├── rate_limit_spec.rb ├── request │ ├── encode_dates_spec.rb │ ├── encode_json_spec.rb │ ├── oauth_spec.rb │ └── retry_spec.rb ├── resource │ ├── download_spec.rb │ ├── pagination_spec.rb │ ├── query_params_spec.rb │ └── scrud_spec.rb ├── resource_spec.rb └── response │ ├── follow_redirects_spec.rb │ ├── parse_dates_spec.rb │ ├── parse_json_spec.rb │ └── raise_error_spec.rb ├── desk_api_spec.rb ├── spec_helper.rb └── stubs ├── article.json ├── case_embed_customer.json ├── cases_embed_assigned_user.json ├── file.jpg └── to_hash_embed.json /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | coverage 6 | InstalledFiles 7 | lib/bundler/man 8 | pkg 9 | rdoc 10 | spec/reports 11 | test/tmp 12 | test/version_tmp 13 | tmp 14 | .DS_Store 15 | # YARD artifacts 16 | .yardoc 17 | _yardoc 18 | doc/ 19 | Gemfile.lock 20 | .rvmrc 21 | *~ 22 | backup 23 | config.rb 24 | gemfiles/*.lock 25 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color --order rand --format documentation -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | 3 | rvm: 4 | - 2.0.0 5 | - 2.1.0 6 | - 2.2.0 7 | - 2.3.0 8 | - ruby-head 9 | - jruby-head 10 | - ree 11 | 12 | gemfile: 13 | - gemfiles/0.8.gemfile 14 | - gemfiles/0.9.gemfile 15 | 16 | jdk: 17 | - 18 | - openjdk7 19 | - oraclejdk7 20 | - openjdk6 21 | 22 | matrix: 23 | allow_failures: 24 | - rvm: ruby-head 25 | - rvm: rbx 26 | - rvm: ree 27 | - rvm: jruby-head 28 | 29 | exclude: 30 | # remove ree from jdk matrix 31 | - rvm: ree 32 | jdk: openjdk7 33 | - rvm: ree 34 | jdk: oraclejdk7 35 | - rvm: ree 36 | jdk: openjdk6 37 | 38 | # remove rbx from jdk matrix 39 | - rvm: rbx 40 | jdk: openjdk7 41 | - rvm: rbx 42 | jdk: oraclejdk7 43 | - rvm: rbx 44 | jdk: openjdk6 45 | 46 | # remove 2.0.0 from jdk matrix 47 | - rvm: 2.0.0 48 | jdk: openjdk7 49 | - rvm: 2.0.0 50 | jdk: oraclejdk7 51 | - rvm: 2.0.0 52 | jdk: openjdk6 53 | 54 | # remove 2.1.0 from jdk matrix 55 | - rvm: 2.1.0 56 | jdk: openjdk7 57 | - rvm: 2.1.0 58 | jdk: oraclejdk7 59 | - rvm: 2.1.0 60 | jdk: openjdk6 61 | 62 | # remove 2.2.0 from jdk matrix 63 | - rvm: 2.2.0 64 | jdk: openjdk7 65 | - rvm: 2.2.0 66 | jdk: oraclejdk7 67 | - rvm: 2.2.0 68 | jdk: openjdk6 69 | 70 | # remove 2.3.0 from jdk matrix 71 | - rvm: 2.3.0 72 | jdk: openjdk7 73 | - rvm: 2.3.0 74 | jdk: oraclejdk7 75 | - rvm: 2.3.0 76 | jdk: openjdk6 77 | 78 | # remove ruby-head from jdk matrix 79 | - rvm: ruby-head 80 | jdk: openjdk7 81 | - rvm: ruby-head 82 | jdk: oraclejdk7 83 | - rvm: ruby-head 84 | jdk: openjdk6 85 | 86 | # remove jruby-19mode and jruby-head from non-jdk matrix 87 | - rvm: jruby-head 88 | jdk: 89 | 90 | bundler_args: --without test 91 | -------------------------------------------------------------------------------- /Appraisals: -------------------------------------------------------------------------------- 1 | appraise '0.8' do 2 | gem 'faraday', '~> 0.8.0' 3 | gem 'desk_api', path: '../' 4 | end 5 | 6 | appraise '0.9' do 7 | gem 'faraday', '~> 0.9.0' 8 | gem 'desk_api', path: '../' 9 | end 10 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Comment line immediately above ownership line is reserved for related gus information. Please be careful while editing. 2 | #ECCN:Open Source 3 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | 5 | group :test do 6 | # Testing infrastructure 7 | gem 'pry' 8 | gem 'awesome_print' 9 | gem 'guard' 10 | gem 'guard-rspec' 11 | end 12 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | guard 'rspec', :version => 2 do 2 | watch(%r{^spec/.+_spec\.rb$}) 3 | watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } 4 | watch('spec/spec_helper.rb') { "spec" } 5 | end -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of Salesforce.com nor the names of its contributors may be 15 | used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | begin 3 | require 'bundler/setup' 4 | Bundler::GemHelper.install_tasks 5 | rescue 6 | puts 'although not required, bundler is recommened for running the tests' 7 | end 8 | 9 | require 'appraisal' 10 | require 'rspec/core/rake_task' 11 | RSpec::Core::RakeTask.new do |t| 12 | t.rspec_opts = ["--color", '--format doc'] 13 | end 14 | 15 | desc 'starts a console with the spec helpers preloaded' 16 | task :console do 17 | require 'desk_api' 18 | # require config if we have it 19 | require './config' rescue nil 20 | 21 | DeskApi.configure do |config| 22 | DeskApi::CONFIG.each do |key, value| 23 | config.send "#{key}=", value 24 | end 25 | end if DeskApi::CONFIG 26 | 27 | begin 28 | require 'pry' 29 | Pry.start binding, quiet: true 30 | rescue LoadError 31 | puts "Looks like pry is not installed or loaded." 32 | end 33 | end 34 | 35 | if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"] 36 | task default: :appraisal 37 | else 38 | task default: :spec 39 | end 40 | -------------------------------------------------------------------------------- /desk_api.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | $LOAD_PATH.unshift File.expand_path("../lib", __FILE__) 3 | require 'desk_api/version' 4 | 5 | Gem::Specification.new do |gem| 6 | gem.name = 'desk_api' 7 | gem.summary = 'A lightweight, flexible client for the desk.com APIv2.' 8 | 9 | gem.description = <<-EOF 10 | This is a lightweight, flexible ruby gem to interact with the desk.com APIv2. 11 | It allows to create, read and delete resources available through the API 12 | endpoints. It can be used either with OAuth or HTTP Basic Authentication. 13 | EOF 14 | 15 | gem.homepage = 'http://github.com/forcedotcom/salesforce-deskcom-api' 16 | gem.version = DeskApi::VERSION 17 | 18 | gem.authors = ['Thomas Stachl', 'Andrew Frauen'] 19 | gem.email = ['tstachl@salesforce.com', 'afrauen@salesforce.com'] 20 | 21 | gem.license = 'BSD 3-Clause License' 22 | 23 | gem.require_paths = ['lib'] 24 | gem.files = `git ls-files -- lib/*`.split("\n") + %w(LICENSE.txt README.md) 25 | gem.test_files = `git ls-files -- spec/*`.split("\n") 26 | gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } 27 | 28 | gem.extra_rdoc_files = ['README.md'] 29 | 30 | gem.add_runtime_dependency('faraday', '>= 0.8', '< 1.0') 31 | gem.add_runtime_dependency('simple_oauth', '>= 0.1', '< 0.4') 32 | gem.add_runtime_dependency('addressable', '>= 2.3', '< 2.6') 33 | 34 | gem.add_development_dependency('rake', '>= 10.1', '< 11.4') 35 | gem.add_development_dependency('rspec', '>= 2.6', '< 3.6') 36 | gem.add_development_dependency('vcr', '>= 2.0', '< 3.1') 37 | gem.add_development_dependency('simplecov', '>= 0.7', '< 0.13') 38 | gem.add_development_dependency('coveralls', '>= 0.6', '< 0.9') 39 | gem.add_development_dependency('appraisal', '>= 1.0.0', '< 2.2') 40 | 41 | gem.required_ruby_version = '>= 2.0.0' 42 | end 43 | -------------------------------------------------------------------------------- /gemfiles/0.8.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "faraday", "~> 0.8.0" 6 | gemspec :path => "../" 7 | 8 | group :test do 9 | gem "pry" 10 | gem "awesome_print" 11 | gem "guard" 12 | gem "guard-rspec" 13 | end 14 | -------------------------------------------------------------------------------- /gemfiles/0.9.gemfile: -------------------------------------------------------------------------------- 1 | # This file was generated by Appraisal 2 | 3 | source "https://rubygems.org" 4 | 5 | gem "faraday", "~> 0.9.0" 6 | gemspec :path => "../" 7 | 8 | group :test do 9 | gem "pry" 10 | gem "awesome_print" 11 | gem "guard" 12 | gem "guard-rspec" 13 | end 14 | -------------------------------------------------------------------------------- /lib/desk.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require File.dirname(__FILE__) + '/desk_api' 30 | -------------------------------------------------------------------------------- /lib/desk_api.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'uri' 30 | require 'faraday' 31 | require 'forwardable' 32 | 33 | # {DeskApi} allows for easy interaction with Desk.com's API. 34 | # It is the top level namespace and delegates all missing 35 | # methods to an automatically created client. This allows 36 | # you to use {DeskApi} as a client which is not recommended 37 | # if you have to connect to multiple Desk.com sites. 38 | # 39 | # @author Thomas Stachl 40 | # @copyright Copyright (c) 2013-2018 Salesforce.com 41 | # @license BSD 3-Clause License 42 | # 43 | # @example configure the {DeskApi} client 44 | # DeskApi.configure |config| 45 | # config.username = 'user@example.com' 46 | # config.password = 'mysecretpassword' 47 | # config.endpoint = 'https://example.desk.com' 48 | # end 49 | # 50 | # @example use {DeskApi} to send requests 51 | # my_cases = DeskApi.cases # GET '/api/v2/cases' 52 | module DeskApi 53 | require 'desk_api/version' 54 | require 'desk_api/configuration' 55 | require 'desk_api/client' 56 | 57 | class << self 58 | include DeskApi::Configuration 59 | 60 | # Returns the default {DeskApi::Client} 61 | # 62 | # @param options [Hash] optional configuration options 63 | # @return [DeskApi::Client] 64 | def client 65 | return @client if defined?(:@client) && @client.hash == options.hash 66 | @client = DeskApi::Client.new(options) 67 | end 68 | 69 | # Delegates missing methods to the default {DeskApi::Client} 70 | # 71 | # @return [DeskApi::Resource] 72 | def method_missing(method, *args, &block) 73 | client.send(method, *args, &block) 74 | end 75 | end 76 | 77 | # immediately reset the default client 78 | reset! 79 | end 80 | -------------------------------------------------------------------------------- /lib/desk_api/client.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/resource' 30 | require 'desk_api/error/parser_error' 31 | 32 | module DeskApi 33 | # The {DeskApi::Client} builds and performs the 34 | # http request using Faraday and the configured 35 | # adapter. It includes and has full access to 36 | # the configuration module. 37 | # 38 | # @author Thomas Stachl 39 | # @copyright Copyright (c) 2013-2018 Salesforce.com 40 | # @license BSD 3-Clause License 41 | class Client 42 | include DeskApi::Configuration 43 | 44 | # Initializes a new client object 45 | # 46 | # @param options [Hash] optional configuration hash 47 | # @return [DeskApi::Client] the new client 48 | def initialize(options = {}) 49 | DeskApi::Configuration.keys.each do |key| 50 | value = options[key] || DeskApi.instance_variable_get(:"@#{key}") 51 | instance_variable_set(:"@#{key}", value) 52 | end 53 | end 54 | 55 | # Perform an http request 56 | # 57 | # @param path [String] the url path to the resource 58 | # @param params [Hash] optional additional url params 59 | # @yield [Faraday::Response] for further request customizations. 60 | # @return [Faraday::Response] 61 | %w(get head delete post patch).each do |method| 62 | class_eval <<-RUBY, __FILE__, __LINE__ + 1 63 | def #{method}(path, params = {}, &block) 64 | request(:#{method}, path, params, &block) 65 | end 66 | RUBY 67 | end 68 | 69 | # Returns a new resource for the given path 70 | # 71 | # @param path [String] the url path to the resource 72 | # @return [DeskApi::Resource] 73 | def by_url(path) 74 | DeskApi::Resource.new(self, DeskApi::Resource.build_self_link(path)) 75 | end 76 | 77 | private 78 | 79 | # Returns a new resource based on the method you're trying to load: 80 | # 81 | # @example request cases 82 | # my_cases = client.cases # GET '/api/v2/cases' 83 | # @param method [Symbol] the method called 84 | # @param params [Hash] additional query params 85 | # @yield [DeskApi::Resource] 86 | # @return [DeskApi::Resource] 87 | def method_missing(method, params = {}) 88 | definition = DeskApi::Resource.build_self_link("/api/v2/#{method}") 89 | DeskApi::Resource.new(self, definition).tap do |res| 90 | res.query_params = params 91 | yield res if block_given? 92 | end 93 | end 94 | 95 | # Hands off the request to Faraday for further processing 96 | # 97 | # @param method [Symbol] the http method to call 98 | # @param path [String] the url path to the resource 99 | # @param params [Hash] optional additional url params 100 | # @yield [Faraday::Response] for further request customizations. 101 | # @return [Faraday::Response] 102 | # @raises [DeskApi::Error::ClientError] 103 | # @raises [DeskApi::Error::ParserError] 104 | def request(method, path, params = {}, &block) 105 | connection.send(method, path, params, &block) 106 | rescue Faraday::Error::ClientError => err 107 | raise DeskApi::Error::ClientError.new(err) 108 | rescue JSON::ParserError => err 109 | raise DeskApi::Error::ParserError.new(err) 110 | end 111 | 112 | # Builds and/or returns the Faraday client. 113 | # @returns [Faraday::Connection] 114 | def connection 115 | @connection ||= Faraday.new endpoint, connection_options, &middleware 116 | end 117 | end 118 | end 119 | -------------------------------------------------------------------------------- /lib/desk_api/default.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | # {DeskApi::Default} contains the default configuration for each 31 | # {DeskApi::Client}. 32 | # 33 | # @author Thomas Stachl 34 | # @copyright Copyright (c) 2013-2018 Salesforce.com 35 | # @license BSD 3-Clause License 36 | module Default 37 | CONNECTION_OPTIONS = { 38 | headers: { 39 | accept: 'application/json', 40 | user_agent: "desk.com Ruby Gem v#{DeskApi::VERSION}" 41 | }, 42 | request: { 43 | open_timeout: 5, 44 | timeout: 10 45 | } 46 | } unless defined? DeskApi::Default::CONNECTION_OPTIONS 47 | 48 | class << self 49 | # A hash of all the options 50 | # 51 | # @return [Hash] 52 | def options 53 | Hash[DeskApi::Configuration.keys.map { |key| [key, send(key)] }] 54 | end 55 | 56 | # The username if environmental variable is set 57 | # 58 | # @return [String] 59 | def username 60 | ENV['DESK_USERNAME'] 61 | end 62 | 63 | # The password if environmental variable is set 64 | # 65 | # @return [String] 66 | def password 67 | ENV['DESK_PASSWORD'] 68 | end 69 | 70 | # The consumer key if environmental variable is set 71 | # 72 | # @return [String] 73 | def consumer_key 74 | ENV['DESK_CONSUMER_KEY'] 75 | end 76 | 77 | # The consumer secret if environmental variable is set 78 | # 79 | # @return [String] 80 | def consumer_secret 81 | ENV['DESK_CONSUMER_SECRET'] 82 | end 83 | 84 | # The access token if environmental variable is set 85 | # 86 | # @return [String] 87 | def token 88 | ENV['DESK_TOKEN'] 89 | end 90 | 91 | # The access token secret if environmental variable is set 92 | # 93 | # @return [String] 94 | def token_secret 95 | ENV['DESK_TOKEN_SECRET'] 96 | end 97 | 98 | # The subdomain if environmental variable is set 99 | # 100 | # @return [String] 101 | def subdomain 102 | ENV['DESK_SUBDOMAIN'] 103 | end 104 | 105 | # The endpoint if environmental variable is set 106 | # 107 | # @return [String] 108 | def endpoint 109 | ENV['DESK_ENDPOINT'] 110 | end 111 | 112 | # The connection options hash 113 | # 114 | # @return [Hash] 115 | def connection_options 116 | CONNECTION_OPTIONS 117 | end 118 | end 119 | end 120 | end 121 | -------------------------------------------------------------------------------- /lib/desk_api/error.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/rate_limit' 30 | 31 | module DeskApi 32 | # {DeskApi::Error} is the base error for all {DeskApi} errors. 33 | # 34 | # @author Thomas Stachl 35 | # @copyright Copyright (c) 2013-2018 Salesforce.com 36 | # @license BSD 3-Clause License 37 | class Error < StandardError 38 | attr_reader :rate_limit 39 | attr_reader :response 40 | 41 | # Initializes a new Error object 42 | # 43 | # @param err [Exception, String] 44 | # @param response [Hash] 45 | # @return [DeskApi::Error] 46 | def initialize(err = $ERROR_INFO, response = {}) 47 | @response = response 48 | @rate_limit = ::DeskApi::RateLimit.new(@response[:response_headers]) 49 | @wrapped_err = err 50 | @code = @response[:status] 51 | @errors = error_hash(@response[:body]) 52 | err.respond_to?(:backtrace) ? super(err.message) : super(err.to_s) 53 | end 54 | 55 | # Returns the backtrace of the wrapped exception if exits. 56 | # 57 | # @return [String] 58 | def backtrace 59 | @wrapped_err.respond_to?(:backtrace) ? @wrapped_err.backtrace : super 60 | end 61 | 62 | private 63 | 64 | # @return [Hash/Nil] 65 | def error_hash(body = nil) 66 | if body && body.is_a?(Hash) 67 | body.key?('errors') ? body['errors'] : nil 68 | end 69 | end 70 | 71 | class << self 72 | # Create a new error from an HTTP response 73 | # 74 | # @param response [Hash] 75 | # @return [DeskApi::Error] 76 | def from_response(response) 77 | new(error_message(response[:body]), response) 78 | end 79 | 80 | # @return [Hash] 81 | def errors 82 | @errors ||= descendants.each_with_object({}) do |klass, hash| 83 | hash[klass::HTTP_STATUS_CODE] = klass if defined? klass::HTTP_STATUS_CODE 84 | end 85 | end 86 | 87 | # @return [Array] 88 | def descendants 89 | @descendants ||= [] 90 | end 91 | 92 | # @return [Array] 93 | def inherited(descendant) 94 | descendants << descendant 95 | end 96 | 97 | private 98 | 99 | # @return [String/Nil] 100 | def error_message(body = nil) 101 | if body && body.is_a?(Hash) 102 | body.key?('message') ? body['message'] : nil 103 | end 104 | end 105 | end 106 | end 107 | end 108 | -------------------------------------------------------------------------------- /lib/desk_api/error/bad_gateway.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/server_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when Desk returns the HTTP status code 502 34 | class BadGateway < DeskApi::Error::ServerError 35 | HTTP_STATUS_CODE = 502 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/bad_request.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/client_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns the HTTP status code 400 34 | class BadRequest < DeskApi::Error::ClientError 35 | HTTP_STATUS_CODE = 400 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/client_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns a 4xx HTTP status code or there's an error 34 | # in Faraday 35 | class ClientError < DeskApi::Error 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/configuration_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error' 30 | 31 | module DeskApi 32 | class Error 33 | class ConfigurationError < ::ArgumentError 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/desk_api/error/conflict.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/client_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns the HTTP status code 409 34 | class Conflict < DeskApi::Error::ClientError 35 | HTTP_STATUS_CODE = 409 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/follow_redirect_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns a 4xx HTTP status code or there's an error 34 | # in Faraday 35 | class FollowRedirectError < DeskApi::Error::ClientError 36 | def initialize(response) 37 | error = "Redirection limit reach, last redirect to: #{response['location']}" 38 | super(error, response) 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /lib/desk_api/error/forbidden.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/client_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns the HTTP status code 403 34 | class Forbidden < DeskApi::Error::ClientError 35 | HTTP_STATUS_CODE = 403 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/gateway_timeout.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/server_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when Desk returns the HTTP status code 504 34 | class GatewayTimeout < DeskApi::Error::ServerError 35 | HTTP_STATUS_CODE = 504 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/internal_server_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/server_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when Desk returns the HTTP status code 500 34 | class InternalServerError < DeskApi::Error::ServerError 35 | HTTP_STATUS_CODE = 500 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/method_not_allowed.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/client_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns the HTTP status code 405 34 | class MethodNotAllowed < DeskApi::Error::ClientError 35 | HTTP_STATUS_CODE = 405 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/not_acceptable.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/client_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns the HTTP status code 406 34 | class NotAcceptable < DeskApi::Error::ClientError 35 | HTTP_STATUS_CODE = 406 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/not_found.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/client_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns the HTTP status code 404 34 | class NotFound < DeskApi::Error::ClientError 35 | HTTP_STATUS_CODE = 404 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/parser_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when JSON parsing fails 34 | class ParserError < DeskApi::Error 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/desk_api/error/server_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when Desk returns a 5xx HTTP status code 34 | class ServerError < DeskApi::Error 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/desk_api/error/service_unavailable.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/server_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when Desk returns the HTTP status code 503 34 | class ServiceUnavailable < DeskApi::Error::ServerError 35 | HTTP_STATUS_CODE = 503 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/too_many_requests.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/client_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns the HTTP status code 429 34 | class TooManyRequests < DeskApi::Error::ClientError 35 | HTTP_STATUS_CODE = 429 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/unauthorized.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/client_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns the HTTP status code 401 34 | class Unauthorized < DeskApi::Error::ClientError 35 | HTTP_STATUS_CODE = 401 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/error/unprocessable_entity.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/client_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns the HTTP status code 422 34 | class UnprocessableEntity < DeskApi::Error::ClientError 35 | HTTP_STATUS_CODE = 422 36 | attr_reader :errors 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /lib/desk_api/error/unsupported_media_type.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/client_error' 30 | 31 | module DeskApi 32 | class Error 33 | # Raised when desk.com returns the HTTP status code 415 34 | class UnsupportedMediaType < DeskApi::Error::ClientError 35 | HTTP_STATUS_CODE = 415 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/desk_api/rate_limit.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | # {DeskApi::RateLimit} deciphers rate limiting headers in 31 | # responses from desk.com API. 32 | # 33 | # @author Thomas Stachl 34 | # @copyright Copyright (c) 2013-2018 Salesforce.com 35 | # @license BSD 3-Clause License 36 | class RateLimit 37 | def initialize(attrs = {}) 38 | @attrs = attrs 39 | end 40 | 41 | # Max requests that can be made in this period 42 | # 43 | # @return [Integer] 44 | def limit 45 | limit = @attrs['x-rate-limit-limit'] 46 | limit.to_i if limit 47 | end 48 | 49 | # Request that are remaining during this period 50 | # 51 | # @return [Integer] 52 | def remaining 53 | remaining = @attrs['x-rate-limit-remaining'] 54 | remaining.to_i if remaining 55 | end 56 | 57 | # Seconds until the rate limit will be reset 58 | # 59 | # @return [Integer] 60 | def reset_in 61 | reset_in = @attrs['x-rate-limit-reset'] 62 | reset_in.to_i if reset_in 63 | end 64 | alias_method :retry_after, :reset_in 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /lib/desk_api/request/encode_dates.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | module Request 31 | # {DeskApi::Request::EncodeJson} is the Faraday middleware 32 | # that dumps a json string from whatever is specified in 33 | # the request body. It also sets the "Content-Type" header. 34 | # 35 | # @author Thomas Stachl 36 | # @copyright Copyright (c) 2013-2018 Salesforce.com 37 | # @license BSD 3-Clause License 38 | class EncodeDates < Faraday::Middleware 39 | # Changes the request before it gets sent 40 | # 41 | # @param env [Hash] the request hash 42 | def call(env) 43 | if env[:body] && !env[:body].to_s.empty? 44 | env[:body] = encode_dates(env[:body]) 45 | end 46 | @app.call env 47 | end 48 | 49 | private 50 | 51 | # Encodes all {Date}, {DateTime} and {Time} values 52 | # to iso8601 53 | # 54 | # @param value [Mixed] the current body 55 | def encode_dates(value) 56 | case value 57 | when Hash 58 | value.each_pair do |key, element| 59 | value[key] = encode_dates element 60 | end 61 | when Array 62 | value.each_with_index do |element, index| 63 | value[index] = encode_dates element 64 | end 65 | when DateTime, Date, Time 66 | value.to_time.utc.iso8601 67 | else 68 | value 69 | end 70 | end 71 | end 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /lib/desk_api/request/encode_json.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | module Request 31 | # {DeskApi::Request::EncodeJson} is the Faraday middleware 32 | # that dumps a json string from whatever is specified in 33 | # the request body. It also sets the "Content-Type" header. 34 | # 35 | # @author Thomas Stachl 36 | # @copyright Copyright (c) 2013-2018 Salesforce.com 37 | # @license BSD 3-Clause License 38 | class EncodeJson < Faraday::Middleware 39 | dependency 'json' 40 | 41 | # Changes the request before it gets sent 42 | # 43 | # @param env [Hash] the request hash 44 | def call(env) 45 | env[:request_headers]['Content-Type'] = 'application/json' 46 | if env[:body] && !env[:body].to_s.empty? 47 | env[:body] = ::JSON.dump(env[:body]) 48 | end 49 | @app.call env 50 | end 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /lib/desk_api/request/oauth.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | module Request 31 | # {DeskApi::Request::OAuth} is the Faraday middleware to 32 | # sign requests with an OAuth header. 33 | # 34 | # @author Thomas Stachl 35 | # @copyright Copyright (c) 2013-2018 Salesforce.com 36 | # @license BSD 3-Clause License 37 | class OAuth < Faraday::Middleware 38 | dependency 'simple_oauth' 39 | 40 | # Initializies the middleware and sets options 41 | # 42 | # @param app [Hash] the faraday environment hash 43 | # @param options [Hash] additional options 44 | def initialize(app, options) 45 | super(app) 46 | @options = options 47 | end 48 | 49 | # Changes the request before it gets sent 50 | # 51 | # @param env [Hash] the request hash 52 | def call(env) 53 | env[:request_headers]['Authorization'] = oauth(env).to_s 54 | @app.call env 55 | end 56 | 57 | private 58 | 59 | # Returns the OAuth header 60 | # 61 | # @param env [Hash] the request hash 62 | # @return [String] 63 | def oauth(env) 64 | SimpleOAuth::Header.new env[:method], env[:url].to_s, {}, @options 65 | end 66 | end 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /lib/desk_api/request/retry.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | module Request 31 | # {DeskApi::Request::Retry} is a Faraday middleware that 32 | # retries failed requests up to 3 times. It also includes 33 | # desk.com's rate limiting which are retried only once. 34 | # 35 | # @author Thomas Stachl 36 | # @copyright Copyright (c) 2013-2018 Salesforce.com 37 | # @license BSD 3-Clause License 38 | class Retry < Faraday::Middleware 39 | class << self 40 | # Returns an array of errors that should be retried. 41 | # 42 | # @return [Array] 43 | def errors 44 | @exceptions ||= [ 45 | Errno::ETIMEDOUT, 46 | 'Timeout::Error', 47 | Faraday::Error::TimeoutError, 48 | DeskApi::Error::TooManyRequests, 49 | DeskApi::Error::BadRequest 50 | ] 51 | end 52 | end 53 | 54 | # Initializies the middleware and sets options 55 | # 56 | # @param app [Hash] the faraday environment hash 57 | # @param options [Hash] additional options 58 | def initialize(app, options = {}) 59 | @max = options[:max] || 3 60 | @interval = options[:interval] || 10 61 | super(app) 62 | end 63 | 64 | # Rescues exceptions and retries the request 65 | # 66 | # @param env [Hash] the request hash 67 | def call(env) 68 | retries = @max 69 | request_body = env[:body] 70 | begin 71 | env[:body] = request_body 72 | @app.call(env) 73 | rescue exception_matcher => err 74 | raise unless calc(err, retries) { |x| retries = x } > 0 75 | sleep interval(err) 76 | retry 77 | end 78 | end 79 | 80 | # Calculates the retries based on the error 81 | # 82 | # @param err [StandardError] the error that has been thrown 83 | # @param retries [Integer] current retry count 84 | # @return [Integer] 85 | def calc(err, retries, &block) 86 | # retry only once 87 | if err.kind_of?(DeskApi::Error::TooManyRequests) && retries == @max - 1 88 | block.call(0) 89 | else 90 | block.call(retries - 1) 91 | end 92 | end 93 | 94 | # Returns the interval for the specific error 95 | # 96 | # @param err [StandardError] the error that has been thrown 97 | # @return [Integer] 98 | def interval(err) 99 | if err.kind_of?(DeskApi::Error::TooManyRequests) 100 | err.rate_limit.reset_in 101 | else 102 | @interval 103 | end 104 | end 105 | 106 | # Returns an exception matcher 107 | # 108 | # @return [Module] 109 | def exception_matcher 110 | matcher = Module.new 111 | (class << matcher; self; end).class_eval do 112 | define_method(:===) do |error| 113 | Retry.errors.any? do |ex| 114 | ex.is_a?(Module) ? error.is_a?(ex) : error.class.to_s == ex.to_s 115 | end 116 | end 117 | end 118 | matcher 119 | end 120 | end 121 | end 122 | end 123 | -------------------------------------------------------------------------------- /lib/desk_api/resource/download.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | class Resource 31 | # {DeskApi::Resource::Download} is responsible for download helper methods 32 | # like `#download` 33 | # 34 | # @author Thomas Stachl 35 | # @copyright Copyright (c) 2013-2018 Salesforce.com 36 | # @license BSD 3-Clause License 37 | # 38 | # @example download an attachment {DeskApi::Resource} 39 | # DeskApi.cases.find(123).attachments.entries.first.download 40 | module Download 41 | 42 | # Download the attachment {DeskApi::Resource} 43 | # 44 | # @raise [NoMethodError] if self is not an attachment resource 45 | def download 46 | unless resource_type == 'attachment' 47 | raise NoMethodError, "#download is only available on attachment resources" 48 | end 49 | 50 | Tempfile.new(file_name).tap do |f| 51 | f.write(@_client.get(url).body) 52 | f.rewind 53 | end 54 | end 55 | end 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /lib/desk_api/resource/pagination.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | class Resource 31 | # {DeskApi::Resource::Pagination} is responsible for pagination helper 32 | # methods like `#each_page` or `#all` 33 | # 34 | # @author Thomas Stachl 35 | # @copyright Copyright (c) 2013-2018 Salesforce.com 36 | # @license BSD 3-Clause License 37 | # 38 | # @example search for cases {DeskApi::Resource} 39 | # DeskApi.cases.each_page{ |page, num| do_something(page) } 40 | module Pagination 41 | 42 | # Paginate through all the resources on a give page {DeskApi::Resource} 43 | # 44 | # @raise [NoMethodError] if self is not a page resource 45 | # @raise [ArgumentError] if no block is given 46 | # @yield [DeskApi::Resource] the current resource 47 | # @yield [Integer] the current page number 48 | def all 49 | raise ArgumentError, "Block must be given for #all" unless block_given? 50 | each_page do |page, page_num| 51 | page.entries.each { |resource| yield resource, page_num } 52 | end 53 | end 54 | 55 | # Paginate through each page on a give page {DeskApi::Resource} 56 | # 57 | # @raise [NoMethodError] if self is not a page resource 58 | # @raise [ArgumentError] if no block is given 59 | # @yield [DeskApi::Resource] the current page resource 60 | # @yield [Integer] the current page number 61 | def each_page 62 | raise ArgumentError, "Block must be given for #each_page" unless block_given? 63 | 64 | begin 65 | page = self.first.per_page(self.query_params['per_page'] || 1000).dup 66 | rescue NoMethodError => err 67 | raise NoMethodError, "#each_page and #all are only available on resources which offer pagination" 68 | end 69 | 70 | begin 71 | yield page, page.page 72 | end while page.next! 73 | end 74 | 75 | end 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /lib/desk_api/resource/query_params.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | class Resource 31 | # {DeskApi::Resource::QueryParams} specifies all the url query param 32 | # modifiers. 33 | # 34 | # @author Thomas Stachl 35 | # @copyright Copyright (c) 2013-2018 Salesforce.com 36 | # @license BSD 3-Clause License 37 | # 38 | # @example set the per page param {DeskApi::Resource} 39 | # first_page = DeskApi.cases.per_page(100) 40 | module QueryParams 41 | 42 | # Allows you to embed/sideload resources 43 | # 44 | # @example embed customers with their cases 45 | # my_cases = client.cases.embed(:customers) 46 | # @example embed assigned_user and assigned_group 47 | # my_cases = client.cases.embed(:assigned_user, :assigned_group) 48 | # @param embedds [Symbol/String] whatever you want to embed 49 | # @return [Desk::Resource] self 50 | def embed(*embedds) 51 | # make sure we don't try to embed anything that's not defined 52 | # add it to the query 53 | self.tap{ |res| res.query_params = { embed: embedds.join(',') } } 54 | end 55 | 56 | # Get/set the page and per_page query params 57 | # 58 | # @param value [Integer/Nil] the value to use 59 | # @return [Integer/DeskApi::Resource] 60 | %w(page per_page).each do |method| 61 | class_eval <<-RUBY, __FILE__, __LINE__ + 1 62 | def #{method}(value = nil) 63 | unless value 64 | exec! if query_params_include?('#{method}') == nil 65 | return query_params_include?('#{method}').to_i 66 | end 67 | tap{ |res| res.query_params = Hash['#{method}', value.to_s] } 68 | end 69 | RUBY 70 | end 71 | 72 | # Converts the current self href query params to a hash 73 | # 74 | # @return [Hash] current self href query params 75 | def query_params 76 | Addressable::URI.parse(href).query_values || {} 77 | end 78 | 79 | # Checks if the specified param is included 80 | # 81 | # @param param [String] the param to check for 82 | # @return [Boolean] 83 | def query_params_include?(param) 84 | query_params.include?(param) ? query_params[param] : nil 85 | end 86 | 87 | # Sets the query params based on the provided hash 88 | # 89 | # @param params [Hash] the query params 90 | # @return [String] the generated href 91 | def query_params=(params = {}) 92 | return href if params.empty? 93 | 94 | params.keys.each{ |key| params[key] = params[key].join(',') if params[key].is_a?(Array) } 95 | 96 | uri = Addressable::URI.parse(href) 97 | params = (uri.query_values || {}).merge(params) 98 | 99 | @_loaded = false unless params == uri.query_values 100 | 101 | uri.query_values = params 102 | self.href = uri.to_s 103 | end 104 | end 105 | end 106 | end 107 | -------------------------------------------------------------------------------- /lib/desk_api/response/follow_redirects.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/follow_redirect_error' 30 | 31 | module DeskApi 32 | module Response 33 | # The {DeskApi::Response::FollowRedirects} middleware 34 | # follows redirects automatically 35 | # 36 | # @author Thomas Stachl 37 | # @copyright Copyright (c) 2013-2018 Salesforce.com 38 | # @license BSD 3-Clause License 39 | class FollowRedirects < Faraday::Response::Middleware 40 | dependency 'uri' 41 | 42 | # Status codes we need to redirect 43 | REDIRECT_HTTP_CODES = Set.new [301, 302, 303, 307] 44 | # Redirection limit 45 | MAX_REDIRECT_LIMIT = 3 46 | 47 | # Wrapps the call to have a limit countdown 48 | def call(env) 49 | perform env, MAX_REDIRECT_LIMIT 50 | end 51 | 52 | private 53 | 54 | # Performs the call and checks and performs a redirect 55 | # if the status is one in 301, 302, 303 or 307 56 | # 57 | # @param env [Hash] 58 | # @param limit [Integer] 59 | # @raise DeskApi::Error::FollowRedirectError 60 | # @return [Faraday::Response] 61 | def perform(env, limit) 62 | body = env[:body] 63 | response = @app.call(env) 64 | 65 | response.on_complete do |env| 66 | if REDIRECT_HTTP_CODES.include? response.status 67 | raise ::DeskApi::Error::FollowRedirectError, response if limit.zero? 68 | env = reset_env(env, body, response) 69 | response = perform(env, limit - 1) 70 | end 71 | end 72 | 73 | response 74 | end 75 | 76 | # Changes the environment based on the response, eg. 77 | # it sets the new url, resets the body, ... 78 | # 79 | # @param env [Hash] 80 | # @param body [String] 81 | # @param response [Faraday::Response] 82 | # @return [Hash] 83 | def reset_env(env, body, response) 84 | env.tap do |env| 85 | location = ::URI.parse response['location'] 86 | 87 | # ugly hack so attachments will work 88 | if location.host != env[:url].host 89 | env[:request_headers] = {} 90 | end 91 | 92 | env[:url] = location 93 | env[:body] = body 94 | %w(status response response_headers).each{ |k| env.delete k } 95 | end 96 | end 97 | end 98 | end 99 | end 100 | -------------------------------------------------------------------------------- /lib/desk_api/response/parse_dates.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | module Response 31 | # The {DeskApi::Response::ParseDates} middleware 32 | # parses strings to dates if they look like ISO8601 33 | # 34 | # @author Thomas Stachl 35 | # @copyright Copyright (c) 2013-2018 Salesforce.com 36 | # @license BSD 3-Clause License 37 | class ParseDates < Faraday::Response::Middleware 38 | dependency 'time' 39 | 40 | # Calls the `parse_dates` method on the body 41 | def on_complete(env) 42 | env[:body] = parse_dates env[:body] 43 | end 44 | 45 | private 46 | 47 | # Checks the value and calls it self for Hash/Array, 48 | # parses strings that look like ISO8601 or 49 | # returns the value 50 | # 51 | # @return [Mixed] 52 | def parse_dates(value) 53 | case value 54 | when Hash 55 | value.each_pair do |key, element| 56 | value[key] = parse_dates element 57 | end 58 | when Array 59 | value.each_with_index do |element, index| 60 | value[index] = parse_dates element 61 | end 62 | when /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z\Z/m 63 | Time.parse value 64 | else 65 | value 66 | end 67 | end 68 | end 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /lib/desk_api/response/parse_json.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | module Response 31 | # The {DeskApi::Response::ParseJson} middleware 32 | # parses the json response body 33 | # 34 | # @author Thomas Stachl 35 | # @copyright Copyright (c) 2013-2018 Salesforce.com 36 | # @license BSD 3-Clause License 37 | class ParseJson < Faraday::Response::Middleware 38 | dependency 'json' 39 | 40 | # Parses the response only if the content type is set and 41 | # includes application/json 42 | def on_complete(env) 43 | content_type = env[:response_headers]['content-type'] 44 | if content_type && content_type.include?('application/json') \ 45 | && !env[:body].strip.empty? 46 | env[:body] = ::JSON.parse(env[:body]) 47 | end 48 | end 49 | end 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /lib/desk_api/response/raise_error.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'desk_api/error/bad_gateway' 30 | require 'desk_api/error/bad_request' 31 | require 'desk_api/error/conflict' 32 | require 'desk_api/error/forbidden' 33 | require 'desk_api/error/gateway_timeout' 34 | require 'desk_api/error/internal_server_error' 35 | require 'desk_api/error/method_not_allowed' 36 | require 'desk_api/error/not_acceptable' 37 | require 'desk_api/error/not_found' 38 | require 'desk_api/error/service_unavailable' 39 | require 'desk_api/error/too_many_requests' 40 | require 'desk_api/error/unauthorized' 41 | require 'desk_api/error/unprocessable_entity' 42 | require 'desk_api/error/unsupported_media_type' 43 | 44 | module DeskApi 45 | module Response 46 | # The {DeskApi::Response::RaiseError} middleware 47 | # raises errors that happen during the API request 48 | # 49 | # @author Thomas Stachl 50 | # @copyright Copyright (c) 2013-2018 Salesforce.com 51 | # @license BSD 3-Clause License 52 | class RaiseError < Faraday::Response::Middleware 53 | # Checks the status code and raises the error if there 54 | # is a error class found for the status code 55 | # 56 | # @raise [DeskApi::Error] 57 | def on_complete(env) 58 | status_code = env[:status].to_i 59 | error_class = @klass.errors[status_code] 60 | raise error_class.from_response(env) if error_class 61 | end 62 | 63 | # Initializes this middleware with the specific class. 64 | def initialize(app, klass) 65 | @klass = klass 66 | super(app) 67 | end 68 | end 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /lib/desk_api/version.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | module DeskApi 30 | VERSION = '0.6.2' 31 | end 32 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Client/using_Basic_Authentication/_delete/deletes_a_resource.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: delete 5 | uri: https://devel.desk.com/api/v2/topics/601117 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 204 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - no-cache 23 | date: 24 | - Thu, 12 Dec 2013 02:58:58 GMT 25 | status: 26 | - 204 No Content 27 | vary: 28 | - X-AppVersion 29 | x-appversion: 30 | - '15.4' 31 | x-frame-options: 32 | - SAMEORIGIN 33 | x-rate-limit-limit: 34 | - '60' 35 | x-rate-limit-remaining: 36 | - '58' 37 | x-rate-limit-reset: 38 | - '2' 39 | x-request-id: 40 | - a19af1baeafd23847d774bd067faa976 41 | connection: 42 | - Close 43 | body: 44 | encoding: US-ASCII 45 | string: '' 46 | http_version: 47 | recorded_at: Thu, 12 Dec 2013 02:58:58 GMT 48 | recorded_with: VCR 2.5.0 49 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Client/using_Basic_Authentication/_get/fetches_resources.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/cases/3014 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 200 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - must-revalidate, private, max-age=0 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 02:55:04 GMT 27 | etag: 28 | - '"395a414452c959227f314140cc36e470"' 29 | status: 30 | - 200 OK 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.4' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '59' 41 | x-rate-limit-reset: 42 | - '56' 43 | x-request-id: 44 | - 0a8b539721cd725fe77fa439da122db5 45 | content-length: 46 | - '1096' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"external_id":"","subject":"Testing Quick Case","priority":8,"locked_until":null,"description":"Some 52 | additional Description regarding this email.","status":"resolved","type":"email","labels":[],"language":"de","active_at":"2013-05-10T19:08:27Z","created_at":"2013-05-10T19:08:10Z","updated_at":"2013-09-10T21:34:34Z","received_at":null,"first_opened_at":null,"opened_at":null,"first_resolved_at":"2013-05-10T19:08:10Z","resolved_at":"2013-05-10T19:08:10Z","custom_fields":{"my_new_custom_field":null,"my_new_number_field":null,"my_new_date_field":null,"my_new_boolean_field":null,"my_new_list_field":null,"follow_up":null,"dependent":null},"_links":{"self":{"href":"/api/v2/cases/3014","class":"case"},"message":{"href":"/api/v2/cases/3014/message","class":"email"},"customer":{"href":"/api/v2/customers/37823480","class":"customer"},"assigned_user":null,"assigned_group":null,"locked_by":null,"replies":{"href":"/api/v2/cases/3014/replies","class":"reply"},"notes":{"href":"/api/v2/cases/3014/notes","class":"note"},"attachments":{"href":"/api/v2/cases/3014/attachments","class":"attachment"}}}' 53 | http_version: 54 | recorded_at: Thu, 12 Dec 2013 02:55:04 GMT 55 | recorded_with: VCR 2.5.0 56 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Client/using_Basic_Authentication/_patch/updates_a_resource.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: patch 5 | uri: https://devel.desk.com/api/v2/topics/601117 6 | body: 7 | encoding: UTF-8 8 | string: '{"name":"Test Updated Topic"}' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | Content-Type: 15 | - application/json 16 | response: 17 | status: 18 | code: 200 19 | message: 20 | headers: 21 | cache-control: 22 | - max-age=0, private, must-revalidate 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 02:58:58 GMT 27 | etag: 28 | - '"64b59205930afcb1a489c61fabd574d6"' 29 | server: 30 | - nginx 31 | status: 32 | - 200 OK 33 | vary: 34 | - X-AppVersion 35 | x-appversion: 36 | - '15.4' 37 | x-frame-options: 38 | - SAMEORIGIN 39 | x-rack-cache: 40 | - invalidate, pass 41 | x-rate-limit-limit: 42 | - '60' 43 | x-rate-limit-remaining: 44 | - '59' 45 | x-rate-limit-reset: 46 | - '2' 47 | x-request-id: 48 | - dca78f427747e926e7caf07aefff3526 49 | x-runtime: 50 | - '0.105739' 51 | x-ua-compatible: 52 | - IE=Edge,chrome=1 53 | content-length: 54 | - '408' 55 | connection: 56 | - Close 57 | body: 58 | encoding: UTF-8 59 | string: '{"name":"Test Updated Topic","description":null,"position":7,"allow_questions":true,"in_support_center":null,"created_at":"2013-12-12T02:55:04Z","updated_at":"2013-12-12T02:58:58Z","_links":{"self":{"href":"/api/v2/topics/601117","class":"topic"},"articles":{"href":"/api/v2/topics/601117/articles","class":"article"},"translations":{"href":"/api/v2/topics/601117/translations","class":"topic_translation"}}}' 60 | http_version: 61 | recorded_at: Thu, 12 Dec 2013 02:58:58 GMT 62 | recorded_with: VCR 2.5.0 63 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Client/using_Basic_Authentication/_post/creates_a_resource.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: post 5 | uri: https://devel.desk.com/api/v2/topics 6 | body: 7 | encoding: UTF-8 8 | string: '{"name":"Test Topic"}' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | Content-Type: 15 | - application/json 16 | response: 17 | status: 18 | code: 201 19 | message: 20 | headers: 21 | accept-ranges: 22 | - bytes 23 | cache-control: 24 | - max-age=0, private, must-revalidate 25 | content-type: 26 | - application/json; charset=utf-8 27 | date: 28 | - Thu, 12 Dec 2013 02:55:04 GMT 29 | etag: 30 | - '"c6eef667a6ffdaf9b6735ce798958e01"' 31 | location: 32 | - https://devel.desk.com/api/v2/topics/601117 33 | status: 34 | - 201 Created 35 | vary: 36 | - X-AppVersion 37 | x-appversion: 38 | - '15.4' 39 | x-frame-options: 40 | - SAMEORIGIN 41 | x-rate-limit-limit: 42 | - '60' 43 | x-rate-limit-remaining: 44 | - '58' 45 | x-rate-limit-reset: 46 | - '56' 47 | x-request-id: 48 | - 50d0f0c5c433dc6a8be48d26a54aa881 49 | content-length: 50 | - '400' 51 | connection: 52 | - Close 53 | body: 54 | encoding: UTF-8 55 | string: '{"name":"Test Topic","description":null,"position":7,"allow_questions":true,"in_support_center":null,"created_at":"2013-12-12T02:55:04Z","updated_at":"2013-12-12T02:55:04Z","_links":{"self":{"href":"/api/v2/topics/601117","class":"topic"},"articles":{"href":"/api/v2/topics/601117/articles","class":"article"},"translations":{"href":"/api/v2/topics/601117/translations","class":"topic_translation"}}}' 56 | http_version: 57 | recorded_at: Thu, 12 Dec 2013 02:55:04 GMT 58 | recorded_with: VCR 2.5.0 59 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Client/using_OAuth/_delete/deletes_a_resource.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: delete 5 | uri: https://devel.desk.com/api/v2/articles/1391017 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 204 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - no-cache 23 | date: 24 | - Thu, 12 Dec 2013 03:00:21 GMT 25 | status: 26 | - 204 No Content 27 | vary: 28 | - X-AppVersion 29 | x-appversion: 30 | - '15.4' 31 | x-frame-options: 32 | - SAMEORIGIN 33 | x-rate-limit-limit: 34 | - '60' 35 | x-rate-limit-remaining: 36 | - '57' 37 | x-rate-limit-reset: 38 | - '39' 39 | x-request-id: 40 | - 1d5c573fc81783c5d373063bdb742d9d 41 | connection: 42 | - Close 43 | body: 44 | encoding: US-ASCII 45 | string: '' 46 | http_version: 47 | recorded_at: Thu, 12 Dec 2013 03:00:21 GMT 48 | recorded_with: VCR 2.5.0 49 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Client/using_OAuth/_get/fetches_resources.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/articles/1391017 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 200 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - must-revalidate, private, max-age=0 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 03:00:20 GMT 27 | etag: 28 | - '"aa367323d958696d4588ca265bd79359"' 29 | status: 30 | - 200 OK 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.4' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '59' 41 | x-rate-limit-reset: 42 | - '40' 43 | x-request-id: 44 | - 601850387a48c63c488b6465c9bb23d8 45 | content-length: 46 | - '1007' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"subject":"Testing OAuth","body":"OAuth testing","body_email":"OAuth 52 | testing","body_email_auto":true,"body_chat":"OAuth testing","body_chat_auto":true,"body_web_callback":"OAuth 53 | testing","body_web_callback_auto":true,"body_twitter":"OAuth testing","body_twitter_auto":true,"body_qna":"OAuth 54 | testing","body_qna_auto":true,"body_phone":"OAuth testing","body_phone_auto":true,"body_facebook":"OAuth 55 | testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":null,"position":4,"quickcode":null,"in_support_center":null,"internal_notes":null,"publish_at":null,"created_at":"2013-12-12T02:55:05Z","updated_at":"2013-12-12T02:55:05Z","_links":{"self":{"href":"/api/v2/articles/1391017","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1391017/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}}' 56 | http_version: 57 | recorded_at: Thu, 12 Dec 2013 03:00:20 GMT 58 | recorded_with: VCR 2.5.0 59 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Client/using_OAuth/_patch/updates_a_resource.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: patch 5 | uri: https://devel.desk.com/api/v2/articles/1391017 6 | body: 7 | encoding: UTF-8 8 | string: '{"subject":"Testing Updated OAuth"}' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | Content-Type: 15 | - application/json 16 | response: 17 | status: 18 | code: 200 19 | message: 20 | headers: 21 | cache-control: 22 | - max-age=0, private, must-revalidate 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 03:00:20 GMT 27 | etag: 28 | - '"458ad713ecdd753dfd815cd8f7a34fa7"' 29 | server: 30 | - nginx 31 | status: 32 | - 200 OK 33 | vary: 34 | - X-AppVersion 35 | x-appversion: 36 | - '15.4' 37 | x-frame-options: 38 | - SAMEORIGIN 39 | x-rack-cache: 40 | - invalidate, pass 41 | x-rate-limit-limit: 42 | - '60' 43 | x-rate-limit-remaining: 44 | - '58' 45 | x-rate-limit-reset: 46 | - '40' 47 | x-request-id: 48 | - 7c31abfc3e51c82adf61c89be70cb8f3 49 | x-runtime: 50 | - '0.173775' 51 | x-ua-compatible: 52 | - IE=Edge,chrome=1 53 | content-length: 54 | - '1015' 55 | connection: 56 | - Close 57 | body: 58 | encoding: UTF-8 59 | string: '{"subject":"Testing Updated OAuth","body":"OAuth testing","body_email":"OAuth 60 | testing","body_email_auto":true,"body_chat":"OAuth testing","body_chat_auto":true,"body_web_callback":"OAuth 61 | testing","body_web_callback_auto":true,"body_twitter":"OAuth testing","body_twitter_auto":true,"body_qna":"OAuth 62 | testing","body_qna_auto":true,"body_phone":"OAuth testing","body_phone_auto":true,"body_facebook":"OAuth 63 | testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":null,"position":4,"quickcode":null,"in_support_center":null,"internal_notes":null,"publish_at":null,"created_at":"2013-12-12T02:55:05Z","updated_at":"2013-12-12T03:00:20Z","_links":{"self":{"href":"/api/v2/articles/1391017","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1391017/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}}' 64 | http_version: 65 | recorded_at: Thu, 12 Dec 2013 03:00:21 GMT 66 | recorded_with: VCR 2.5.0 67 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Client/using_OAuth/_post/creates_a_resource.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: post 5 | uri: https://devel.desk.com/api/v2/articles 6 | body: 7 | encoding: UTF-8 8 | string: '{"subject":"Testing OAuth","body":"OAuth testing","_links":{"topic":{"href":"/api/v2/topics/498301"}}}' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | Content-Type: 15 | - application/json 16 | response: 17 | status: 18 | code: 201 19 | message: 20 | headers: 21 | accept-ranges: 22 | - bytes 23 | cache-control: 24 | - max-age=0, private, must-revalidate 25 | content-type: 26 | - application/json; charset=utf-8 27 | date: 28 | - Thu, 12 Dec 2013 02:55:05 GMT 29 | etag: 30 | - '"aa367323d958696d4588ca265bd79359"' 31 | location: 32 | - https://devel.desk.com/api/v2/articles/1391017 33 | status: 34 | - 201 Created 35 | vary: 36 | - X-AppVersion 37 | x-appversion: 38 | - '15.4' 39 | x-frame-options: 40 | - SAMEORIGIN 41 | x-rate-limit-limit: 42 | - '60' 43 | x-rate-limit-remaining: 44 | - '54' 45 | x-rate-limit-reset: 46 | - '55' 47 | x-request-id: 48 | - 4d67b377839b367e3165bd121eba3ddb 49 | content-length: 50 | - '1007' 51 | connection: 52 | - Close 53 | body: 54 | encoding: UTF-8 55 | string: '{"subject":"Testing OAuth","body":"OAuth testing","body_email":"OAuth 56 | testing","body_email_auto":true,"body_chat":"OAuth testing","body_chat_auto":true,"body_web_callback":"OAuth 57 | testing","body_web_callback_auto":true,"body_twitter":"OAuth testing","body_twitter_auto":true,"body_qna":"OAuth 58 | testing","body_qna_auto":true,"body_phone":"OAuth testing","body_phone_auto":true,"body_facebook":"OAuth 59 | testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":null,"position":4,"quickcode":null,"in_support_center":null,"internal_notes":null,"publish_at":null,"created_at":"2013-12-12T02:55:05Z","updated_at":"2013-12-12T02:55:05Z","_links":{"self":{"href":"/api/v2/articles/1391017","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1391017/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}}' 60 | http_version: 61 | recorded_at: Thu, 12 Dec 2013 02:55:05 GMT 62 | recorded_with: VCR 2.5.0 63 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Error/_from_response/can_be_created_from_a_faraday_response.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: post 5 | uri: https://devel.desk.com/api/v2/articles 6 | body: 7 | encoding: UTF-8 8 | string: '{"subject":"Testing","body":"Testing"}' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | Content-Type: 15 | - application/json 16 | response: 17 | status: 18 | code: 422 19 | message: 20 | headers: 21 | accept-ranges: 22 | - bytes 23 | cache-control: 24 | - no-cache 25 | content-type: 26 | - application/json; charset=utf-8 27 | date: 28 | - Thu, 12 Dec 2013 19:20:50 GMT 29 | status: 30 | - 422 Unprocessable Entity 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '59' 41 | x-rate-limit-reset: 42 | - '10' 43 | x-request-id: 44 | - b72a910728f1d7c5a8cd82113371ced7 45 | content-length: 46 | - '71' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"message":"Validation Failed","errors":{"_links":{"topic":["blank"]}}}' 52 | http_version: 53 | recorded_at: Thu, 12 Dec 2013 19:20:51 GMT 54 | recorded_with: VCR 2.5.0 55 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Error/_from_response/uses_the_body_message_if_present.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: post 5 | uri: https://devel.desk.com/api/v2/articles 6 | body: 7 | encoding: UTF-8 8 | string: '{"subject":"Testing","body":"Testing"}' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | Content-Type: 15 | - application/json 16 | response: 17 | status: 18 | code: 422 19 | message: 20 | headers: 21 | accept-ranges: 22 | - bytes 23 | cache-control: 24 | - no-cache 25 | content-type: 26 | - application/json; charset=utf-8 27 | date: 28 | - Thu, 12 Dec 2013 19:21:22 GMT 29 | status: 30 | - 422 Unprocessable Entity 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '59' 41 | x-rate-limit-reset: 42 | - '38' 43 | x-request-id: 44 | - 17a744a71526509a869ed6e318f05c40 45 | content-length: 46 | - '71' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"message":"Validation Failed","errors":{"_links":{"topic":["blank"]}}}' 52 | http_version: 53 | recorded_at: Thu, 12 Dec 2013 19:21:22 GMT 54 | recorded_with: VCR 2.5.0 55 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Error/on_validation_error/allows_access_to_error_hash.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: post 5 | uri: https://devel.desk.com/api/v2/articles 6 | body: 7 | encoding: UTF-8 8 | string: '{"subject":"Testing","body":"Testing"}' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | Content-Type: 15 | - application/json 16 | response: 17 | status: 18 | code: 422 19 | message: 20 | headers: 21 | accept-ranges: 22 | - bytes 23 | cache-control: 24 | - no-cache 25 | content-type: 26 | - application/json; charset=utf-8 27 | date: 28 | - Thu, 12 Dec 2013 19:21:53 GMT 29 | status: 30 | - 422 Unprocessable Entity 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '58' 41 | x-rate-limit-reset: 42 | - '7' 43 | x-request-id: 44 | - bf5edc9c549849bad994ce6b4084c908 45 | content-length: 46 | - '71' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"message":"Validation Failed","errors":{"_links":{"topic":["blank"]}}}' 52 | http_version: 53 | recorded_at: Thu, 12 Dec 2013 19:21:53 GMT 54 | recorded_with: VCR 2.5.0 55 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource/_by_url/finds_resources_by_url.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/articles/1295677 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 200 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - must-revalidate, private, max-age=0 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 19:33:09 GMT 27 | etag: 28 | - '"93fc2ca7fb9e35fa06739e5a3d31bf67"' 29 | status: 30 | - 200 OK 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '59' 41 | x-rate-limit-reset: 42 | - '51' 43 | x-request-id: 44 | - 730279d818201bfeb87281b90e284d8f 45 | content-length: 46 | - '1825' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"subject":"Lecteur {Continuer ancien}","body":"Bonjour {{customer.first_name}}, 

Merci de nous avoir écrit. Vous pouvez continuer à 53 | utiliser toutes les versions du Lecteur Square pour accepter des paiements. 54 | Les lecteurs précédents ne comportent aucun défaut de 55 | conception. Vous pouvez aussi commander gratuitement un nouveau lecteur depuis 56 | le tableau de bord Square en ligne. 

Pour cela, connectez-vous 57 | à votre tableau de bord à l’adresse www.squareup.com/dashboard 58 | et cliquez sur « Obtenir un lecteur de carte » dans 59 | le menu déroulant situé dans le coin supérieur droit 60 | de la page.

N’hésitez pas à me contacter 61 | pour toute question supplémentaire. Je suis là pour vous aider.","body_email":"Testing","body_email_auto":true,"body_chat":"Testing","body_chat_auto":true,"body_web_callback":"
Testing
","body_web_callback_auto":true,"body_twitter":"Testing","body_twitter_auto":true,"body_qna":"Testing","body_qna_auto":true,"body_phone":"Testing","body_phone_auto":true,"body_facebook":"Testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":"","position":1,"quickcode":null,"in_support_center":false,"internal_notes":null,"publish_at":"2013-09-11T19:13:21Z","created_at":"2013-09-11T19:11:48Z","updated_at":"2013-09-11T19:13:21Z","_links":{"self":{"href":"/api/v2/articles/1295677","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1295677/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}}' 62 | http_version: 63 | recorded_at: Thu, 12 Dec 2013 19:33:09 GMT 64 | recorded_with: VCR 2.5.0 65 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource/_exec_/can_be_forced_to_reload.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/articles 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 200 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - must-revalidate, private, max-age=0 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 18:56:59 GMT 27 | etag: 28 | - '"1daa08a60cce691df71fcac04dedee89"' 29 | status: 30 | - 200 OK 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '55' 41 | x-rate-limit-reset: 42 | - '1' 43 | x-request-id: 44 | - ebe96c89fdc015806aa6c89cc0758f54 45 | content-length: 46 | - '3447' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"total_entries":3,"_links":{"self":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"first":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"last":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"previous":null,"next":null},"_embedded":{"entries":[{"subject":"Testing","body":"
Testing
","body_email":"Testing","body_email_auto":true,"body_chat":"Testing","body_chat_auto":true,"body_web_callback":"
Testing
","body_web_callback_auto":true,"body_twitter":"Testing","body_twitter_auto":true,"body_qna":"Testing","body_qna_auto":true,"body_phone":"Testing","body_phone_auto":true,"body_facebook":"Testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":"","position":1,"quickcode":null,"in_support_center":false,"internal_notes":"","publish_at":"2013-09-11T19:13:21Z","created_at":"2013-09-11T19:11:48Z","updated_at":"2013-09-11T19:13:21Z","_links":{"self":{"href":"/api/v2/articles/1295677","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1295677/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}},{"subject":"Testing","body":"\"\"","body_email":"","body_email_auto":true,"body_chat":"","body_chat_auto":true,"body_web_callback":"\"\"","body_web_callback_auto":true,"body_twitter":"","body_twitter_auto":true,"body_qna":"","body_qna_auto":true,"body_phone":"","body_phone_auto":true,"body_facebook":"","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":"","position":2,"quickcode":null,"in_support_center":true,"internal_notes":"","publish_at":"2013-10-28T23:00:22Z","created_at":"2013-10-28T22:59:19Z","updated_at":"2013-10-28T23:00:22Z","_links":{"self":{"href":"/api/v2/articles/1348945","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1348945/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}},{"subject":"Testing 56 | OAuth","body":"OAuth testing","body_email":"OAuth testing","body_email_auto":true,"body_chat":"OAuth 57 | testing","body_chat_auto":true,"body_web_callback":"OAuth testing","body_web_callback_auto":true,"body_twitter":"OAuth 58 | testing","body_twitter_auto":true,"body_qna":"OAuth testing","body_qna_auto":true,"body_phone":"OAuth 59 | testing","body_phone_auto":true,"body_facebook":"OAuth testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":null,"position":3,"quickcode":null,"in_support_center":null,"internal_notes":null,"publish_at":null,"created_at":"2013-12-12T02:52:01Z","updated_at":"2013-12-12T02:52:01Z","_links":{"self":{"href":"/api/v2/articles/1391016","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1391016/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}}]}}' 60 | http_version: 61 | recorded_at: Thu, 12 Dec 2013 18:56:59 GMT 62 | recorded_with: VCR 2.5.0 63 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource/_exec_/loads_the_current_resource.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/articles 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 200 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - must-revalidate, private, max-age=0 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 18:56:59 GMT 27 | etag: 28 | - '"1daa08a60cce691df71fcac04dedee89"' 29 | status: 30 | - 200 OK 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '56' 41 | x-rate-limit-reset: 42 | - '1' 43 | x-request-id: 44 | - 0178323f19c6662347f394bca27c880a 45 | content-length: 46 | - '3447' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"total_entries":3,"_links":{"self":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"first":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"last":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"previous":null,"next":null},"_embedded":{"entries":[{"subject":"Testing","body":"
Testing
","body_email":"Testing","body_email_auto":true,"body_chat":"Testing","body_chat_auto":true,"body_web_callback":"
Testing
","body_web_callback_auto":true,"body_twitter":"Testing","body_twitter_auto":true,"body_qna":"Testing","body_qna_auto":true,"body_phone":"Testing","body_phone_auto":true,"body_facebook":"Testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":"","position":1,"quickcode":null,"in_support_center":false,"internal_notes":"","publish_at":"2013-09-11T19:13:21Z","created_at":"2013-09-11T19:11:48Z","updated_at":"2013-09-11T19:13:21Z","_links":{"self":{"href":"/api/v2/articles/1295677","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1295677/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}},{"subject":"Testing","body":"\"\"","body_email":"","body_email_auto":true,"body_chat":"","body_chat_auto":true,"body_web_callback":"\"\"","body_web_callback_auto":true,"body_twitter":"","body_twitter_auto":true,"body_qna":"","body_qna_auto":true,"body_phone":"","body_phone_auto":true,"body_facebook":"","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":"","position":2,"quickcode":null,"in_support_center":true,"internal_notes":"","publish_at":"2013-10-28T23:00:22Z","created_at":"2013-10-28T22:59:19Z","updated_at":"2013-10-28T23:00:22Z","_links":{"self":{"href":"/api/v2/articles/1348945","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1348945/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}},{"subject":"Testing 56 | OAuth","body":"OAuth testing","body_email":"OAuth testing","body_email_auto":true,"body_chat":"OAuth 57 | testing","body_chat_auto":true,"body_web_callback":"OAuth testing","body_web_callback_auto":true,"body_twitter":"OAuth 58 | testing","body_twitter_auto":true,"body_qna":"OAuth testing","body_qna_auto":true,"body_phone":"OAuth 59 | testing","body_phone_auto":true,"body_facebook":"OAuth testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":null,"position":3,"quickcode":null,"in_support_center":null,"internal_notes":null,"publish_at":null,"created_at":"2013-12-12T02:52:01Z","updated_at":"2013-12-12T02:52:01Z","_links":{"self":{"href":"/api/v2/articles/1391016","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1391016/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}}]}}' 60 | http_version: 61 | recorded_at: Thu, 12 Dec 2013 18:56:59 GMT 62 | recorded_with: VCR 2.5.0 63 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource/_get_linked_resource/returns_nil_if_link_is_nil.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/articles 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 200 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - must-revalidate, private, max-age=0 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 22:01:57 GMT 27 | etag: 28 | - '"1daa08a60cce691df71fcac04dedee89"' 29 | status: 30 | - 200 OK 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '58' 41 | x-rate-limit-reset: 42 | - '4' 43 | x-request-id: 44 | - cccb60036e48fc9e40fb3b89f2f40928 45 | content-length: 46 | - '3447' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"total_entries":3,"_links":{"self":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"first":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"last":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"previous":null,"next":null},"_embedded":{"entries":[{"subject":"Testing","body":"
Testing
","body_email":"Testing","body_email_auto":true,"body_chat":"Testing","body_chat_auto":true,"body_web_callback":"
Testing
","body_web_callback_auto":true,"body_twitter":"Testing","body_twitter_auto":true,"body_qna":"Testing","body_qna_auto":true,"body_phone":"Testing","body_phone_auto":true,"body_facebook":"Testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":"","position":1,"quickcode":null,"in_support_center":false,"internal_notes":"","publish_at":"2013-09-11T19:13:21Z","created_at":"2013-09-11T19:11:48Z","updated_at":"2013-09-11T19:13:21Z","_links":{"self":{"href":"/api/v2/articles/1295677","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1295677/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}},{"subject":"Testing","body":"\"\"","body_email":"","body_email_auto":true,"body_chat":"","body_chat_auto":true,"body_web_callback":"\"\"","body_web_callback_auto":true,"body_twitter":"","body_twitter_auto":true,"body_qna":"","body_qna_auto":true,"body_phone":"","body_phone_auto":true,"body_facebook":"","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":"","position":2,"quickcode":null,"in_support_center":true,"internal_notes":"","publish_at":"2013-10-28T23:00:22Z","created_at":"2013-10-28T22:59:19Z","updated_at":"2013-10-28T23:00:22Z","_links":{"self":{"href":"/api/v2/articles/1348945","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1348945/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}},{"subject":"Testing 56 | OAuth","body":"OAuth testing","body_email":"OAuth testing","body_email_auto":true,"body_chat":"OAuth 57 | testing","body_chat_auto":true,"body_web_callback":"OAuth testing","body_web_callback_auto":true,"body_twitter":"OAuth 58 | testing","body_twitter_auto":true,"body_qna":"OAuth testing","body_qna_auto":true,"body_phone":"OAuth 59 | testing","body_phone_auto":true,"body_facebook":"OAuth testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":null,"position":3,"quickcode":null,"in_support_center":null,"internal_notes":null,"publish_at":null,"created_at":"2013-12-12T02:52:01Z","updated_at":"2013-12-12T02:52:01Z","_links":{"self":{"href":"/api/v2/articles/1391016","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1391016/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}}]}}' 60 | http_version: 61 | recorded_at: Thu, 12 Dec 2013 22:01:57 GMT 62 | recorded_with: VCR 2.5.0 63 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource/_method_missing/loads_the_resource_to_find_a_suitable_method.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/articles 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 200 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - must-revalidate, private, max-age=0 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 18:56:59 GMT 27 | etag: 28 | - '"1daa08a60cce691df71fcac04dedee89"' 29 | status: 30 | - 200 OK 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '54' 41 | x-rate-limit-reset: 42 | - '1' 43 | x-request-id: 44 | - 4d5dcb3f332396eccc3be1869f7b5e2b 45 | content-length: 46 | - '3447' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"total_entries":3,"_links":{"self":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"first":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"last":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"previous":null,"next":null},"_embedded":{"entries":[{"subject":"Testing","body":"
Testing
","body_email":"Testing","body_email_auto":true,"body_chat":"Testing","body_chat_auto":true,"body_web_callback":"
Testing
","body_web_callback_auto":true,"body_twitter":"Testing","body_twitter_auto":true,"body_qna":"Testing","body_qna_auto":true,"body_phone":"Testing","body_phone_auto":true,"body_facebook":"Testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":"","position":1,"quickcode":null,"in_support_center":false,"internal_notes":"","publish_at":"2013-09-11T19:13:21Z","created_at":"2013-09-11T19:11:48Z","updated_at":"2013-09-11T19:13:21Z","_links":{"self":{"href":"/api/v2/articles/1295677","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1295677/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}},{"subject":"Testing","body":"\"\"","body_email":"","body_email_auto":true,"body_chat":"","body_chat_auto":true,"body_web_callback":"\"\"","body_web_callback_auto":true,"body_twitter":"","body_twitter_auto":true,"body_qna":"","body_qna_auto":true,"body_phone":"","body_phone_auto":true,"body_facebook":"","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":"","position":2,"quickcode":null,"in_support_center":true,"internal_notes":"","publish_at":"2013-10-28T23:00:22Z","created_at":"2013-10-28T22:59:19Z","updated_at":"2013-10-28T23:00:22Z","_links":{"self":{"href":"/api/v2/articles/1348945","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1348945/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}},{"subject":"Testing 56 | OAuth","body":"OAuth testing","body_email":"OAuth testing","body_email_auto":true,"body_chat":"OAuth 57 | testing","body_chat_auto":true,"body_web_callback":"OAuth testing","body_web_callback_auto":true,"body_twitter":"OAuth 58 | testing","body_twitter_auto":true,"body_qna":"OAuth testing","body_qna_auto":true,"body_phone":"OAuth 59 | testing","body_phone_auto":true,"body_facebook":"OAuth testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":null,"position":3,"quickcode":null,"in_support_center":null,"internal_notes":null,"publish_at":null,"created_at":"2013-12-12T02:52:01Z","updated_at":"2013-12-12T02:52:01Z","_links":{"self":{"href":"/api/v2/articles/1391016","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1391016/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}}]}}' 60 | http_version: 61 | recorded_at: Thu, 12 Dec 2013 18:57:00 GMT 62 | recorded_with: VCR 2.5.0 63 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource/_method_missing/raises_an_error_if_method_does_not_exist.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/articles 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 200 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - must-revalidate, private, max-age=0 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 18:57:00 GMT 27 | etag: 28 | - '"1daa08a60cce691df71fcac04dedee89"' 29 | status: 30 | - 200 OK 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '53' 41 | x-rate-limit-reset: 42 | - '1' 43 | x-request-id: 44 | - 393d529f0eb869da821ae9ef83549311 45 | content-length: 46 | - '3447' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"total_entries":3,"_links":{"self":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"first":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"last":{"href":"/api/v2/articles?page=1&per_page=50","class":"page"},"previous":null,"next":null},"_embedded":{"entries":[{"subject":"Testing","body":"
Testing
","body_email":"Testing","body_email_auto":true,"body_chat":"Testing","body_chat_auto":true,"body_web_callback":"
Testing
","body_web_callback_auto":true,"body_twitter":"Testing","body_twitter_auto":true,"body_qna":"Testing","body_qna_auto":true,"body_phone":"Testing","body_phone_auto":true,"body_facebook":"Testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":"","position":1,"quickcode":null,"in_support_center":false,"internal_notes":"","publish_at":"2013-09-11T19:13:21Z","created_at":"2013-09-11T19:11:48Z","updated_at":"2013-09-11T19:13:21Z","_links":{"self":{"href":"/api/v2/articles/1295677","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1295677/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}},{"subject":"Testing","body":"\"\"","body_email":"","body_email_auto":true,"body_chat":"","body_chat_auto":true,"body_web_callback":"\"\"","body_web_callback_auto":true,"body_twitter":"","body_twitter_auto":true,"body_qna":"","body_qna_auto":true,"body_phone":"","body_phone_auto":true,"body_facebook":"","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":"","position":2,"quickcode":null,"in_support_center":true,"internal_notes":"","publish_at":"2013-10-28T23:00:22Z","created_at":"2013-10-28T22:59:19Z","updated_at":"2013-10-28T23:00:22Z","_links":{"self":{"href":"/api/v2/articles/1348945","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1348945/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}},{"subject":"Testing 56 | OAuth","body":"OAuth testing","body_email":"OAuth testing","body_email_auto":true,"body_chat":"OAuth 57 | testing","body_chat_auto":true,"body_web_callback":"OAuth testing","body_web_callback_auto":true,"body_twitter":"OAuth 58 | testing","body_twitter_auto":true,"body_qna":"OAuth testing","body_qna_auto":true,"body_phone":"OAuth 59 | testing","body_phone_auto":true,"body_facebook":"OAuth testing","body_facebook_auto":true,"rating":0,"rating_count":0,"rating_score":0,"keywords":null,"position":3,"quickcode":null,"in_support_center":null,"internal_notes":null,"publish_at":null,"created_at":"2013-12-12T02:52:01Z","updated_at":"2013-12-12T02:52:01Z","_links":{"self":{"href":"/api/v2/articles/1391016","class":"article"},"topic":{"href":"/api/v2/topics/498301","class":"topic"},"translations":{"href":"/api/v2/articles/1391016/translations","class":"article_translation"},"created_by":{"href":"/api/v2/users/16096734","class":"user"},"updated_by":{"href":"/api/v2/users/16096734","class":"user"}}}]}}' 60 | http_version: 61 | recorded_at: Thu, 12 Dec 2013 18:57:00 GMT 62 | recorded_with: VCR 2.5.0 63 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource_Download/throws_an_error_on_non_attachment_resources.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/cases/3065 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.6.2 14 | Content-Type: 15 | - application/json 16 | response: 17 | status: 18 | code: 200 19 | message: 20 | headers: 21 | content-type: 22 | - application/json; charset=utf-8 23 | date: 24 | - Tue, 22 Nov 2016 23:47:22 GMT 25 | server: 26 | - nginx 27 | vary: 28 | - Accept-Encoding 29 | x-api-version: 30 | - 3a076ef1b5f7538a46d7d7d46986a40109f3ba96 31 | x-rate-limit-limit: 32 | - '1000' 33 | x-rate-limit-remaining: 34 | - '999' 35 | x-rate-limit-reset: 36 | - '38' 37 | content-length: 38 | - '613' 39 | connection: 40 | - Close 41 | body: 42 | encoding: ASCII-8BIT 43 | string: '{"id":3065,"blurb":null,"changed_at":"2015-02-14T06:13:03Z","created_at":"2013-05-13T18:13:39Z","custom_fields":{"market":null,"sfdc_case_id":null,"application_stage":null},"description":null,"external_id":null,"first_opened_at":null,"first_resolved_at":"2015-01-26T18:24:09Z","label_ids":[],"labels":[],"language":null,"locked_until":null,"opened_at":"2015-01-26T18:24:29Z","priority":5,"received_at":null,"resolved_at":"2015-01-26T18:24:09Z","status":"open","subject":"Testing 44 | the Tank again","type":"email","updated_at":"2016-11-22T23:36:49Z","active_at":"2016-11-22T23:36:49Z","active_attachments_count":1,"active_notes_count":0,"has_pending_interactions":false,"has_failed_interactions":false,"route_status":"active","_links":{"labels":{"class":"label","href":"/api/v2/cases/3065/labels"},"assigned_group":null,"macro_preview":{"class":"macro_preview","href":"/api/v2/cases/3065/macros/preview"},"locked_by":{"class":"user","href":"/api/v2/users/16096734"},"case_links":{"class":"case_link","count":0,"href":"/api/v2/cases/3065/links"},"attachments":{"class":"attachment","count":1,"href":"/api/v2/cases/3065/attachments"},"history":{"class":"history","href":"/api/v2/cases/3065/history"},"feedbacks":null,"customer":{"class":"customer","href":"/api/v2/customers/86101780"},"replies":{"class":"reply","count":0,"href":"/api/v2/cases/3065/replies"},"draft":{"class":"reply","href":"/api/v2/cases/3065/replies/draft"},"notes":{"class":"note","count":0,"href":"/api/v2/cases/3065/notes"},"assigned_user":null,"self":{"class":"case","href":"/api/v2/cases/3065"},"message":{"class":"email","href":"/api/v2/cases/3065/message"}}}' 45 | http_version: 46 | recorded_at: Tue, 22 Nov 2016 23:47:22 GMT 47 | recorded_with: VCR 3.0.3 48 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource_SCRUD/_create/creates_a_new_topic.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: post 5 | uri: https://devel.desk.com/api/v2/topics 6 | body: 7 | encoding: UTF-8 8 | string: '{"name":"My new topic"}' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | Content-Type: 15 | - application/json 16 | response: 17 | status: 18 | code: 201 19 | message: 20 | headers: 21 | accept-ranges: 22 | - bytes 23 | cache-control: 24 | - max-age=0, private, must-revalidate 25 | content-type: 26 | - application/json; charset=utf-8 27 | date: 28 | - Thu, 12 Dec 2013 19:45:06 GMT 29 | etag: 30 | - '"26848664a35b2523eb6f170735e81932"' 31 | location: 32 | - https://devel.desk.com/api/v2/topics/601361 33 | status: 34 | - 201 Created 35 | vary: 36 | - X-AppVersion 37 | x-appversion: 38 | - '15.6' 39 | x-frame-options: 40 | - SAMEORIGIN 41 | x-rate-limit-limit: 42 | - '60' 43 | x-rate-limit-remaining: 44 | - '59' 45 | x-rate-limit-reset: 46 | - '54' 47 | x-request-id: 48 | - 690d0a354312e9bff3a9f5b06e640dea 49 | content-length: 50 | - '402' 51 | connection: 52 | - Close 53 | body: 54 | encoding: UTF-8 55 | string: '{"name":"My new topic","description":null,"position":7,"allow_questions":true,"in_support_center":null,"created_at":"2013-12-12T19:45:06Z","updated_at":"2013-12-12T19:45:06Z","_links":{"self":{"href":"/api/v2/topics/601361","class":"topic"},"articles":{"href":"/api/v2/topics/601361/articles","class":"article"},"translations":{"href":"/api/v2/topics/601361/translations","class":"topic_translation"}}}' 56 | http_version: 57 | recorded_at: Thu, 12 Dec 2013 19:45:06 GMT 58 | recorded_with: VCR 2.5.0 59 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource_SCRUD/_create/throws_an_error_creating_a_user.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: post 5 | uri: https://devel.desk.com/api/v2/users 6 | body: 7 | encoding: UTF-8 8 | string: '{"name":"Some User"}' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | Content-Type: 15 | - application/json 16 | response: 17 | status: 18 | code: 405 19 | message: 20 | headers: 21 | accept-ranges: 22 | - bytes 23 | cache-control: 24 | - no-cache 25 | content-type: 26 | - application/json; charset=utf-8 27 | date: 28 | - Thu, 12 Dec 2013 19:45:25 GMT 29 | status: 30 | - 405 Method Not Allowed 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '58' 41 | x-rate-limit-reset: 42 | - '35' 43 | x-request-id: 44 | - b5628738bab98ffa6426bc55e68bbda3 45 | content-length: 46 | - '32' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"message":"Method Not Allowed"}' 52 | http_version: 53 | recorded_at: Thu, 12 Dec 2013 19:45:25 GMT 54 | recorded_with: VCR 2.5.0 55 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource_SCRUD/_find/has_an_alias_by_id.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/cases/3065 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 200 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - must-revalidate, private, max-age=0 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 18:57:02 GMT 27 | etag: 28 | - '"92c7be66720ffca1abd8bc26f860b333"' 29 | status: 30 | - 200 OK 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '47' 41 | x-rate-limit-reset: 42 | - '58' 43 | x-request-id: 44 | - 0bbe4c9b9d0365c6fe8fbe9245006808 45 | content-length: 46 | - '1015' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"external_id":null,"subject":"Testing the Tank again","priority":5,"locked_until":null,"description":null,"status":"open","type":"email","labels":[],"language":"de","active_at":"2013-05-13T19:20:59Z","created_at":"2013-05-13T18:13:39Z","updated_at":"2013-09-10T21:34:42Z","received_at":null,"first_opened_at":null,"opened_at":null,"first_resolved_at":null,"resolved_at":null,"custom_fields":{"my_new_custom_field":null,"my_new_number_field":null,"my_new_date_field":null,"my_new_boolean_field":null,"my_new_list_field":null,"follow_up":null,"dependent":null},"_links":{"self":{"href":"/api/v2/cases/3065","class":"case"},"message":{"href":"/api/v2/cases/3065/message","class":"email"},"customer":{"href":"/api/v2/customers/86101780","class":"customer"},"assigned_user":null,"assigned_group":null,"locked_by":null,"replies":{"href":"/api/v2/cases/3065/replies","class":"reply"},"notes":{"href":"/api/v2/cases/3065/notes","class":"note"},"attachments":{"href":"/api/v2/cases/3065/attachments","class":"attachment"}}}' 52 | http_version: 53 | recorded_at: Thu, 12 Dec 2013 18:57:03 GMT 54 | recorded_with: VCR 2.5.0 55 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource_SCRUD/_find/loads_the_requested_resource.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/cases/3065 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 200 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - must-revalidate, private, max-age=0 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 18:57:02 GMT 27 | etag: 28 | - '"92c7be66720ffca1abd8bc26f860b333"' 29 | status: 30 | - 200 OK 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '48' 41 | x-rate-limit-reset: 42 | - '58' 43 | x-request-id: 44 | - 1485acbf84ac7c7ac676a9bce480469d 45 | content-length: 46 | - '1015' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"external_id":null,"subject":"Testing the Tank again","priority":5,"locked_until":null,"description":null,"status":"open","type":"email","labels":[],"language":"de","active_at":"2013-05-13T19:20:59Z","created_at":"2013-05-13T18:13:39Z","updated_at":"2013-09-10T21:34:42Z","received_at":null,"first_opened_at":null,"opened_at":null,"first_resolved_at":null,"resolved_at":null,"custom_fields":{"my_new_custom_field":null,"my_new_number_field":null,"my_new_date_field":null,"my_new_boolean_field":null,"my_new_list_field":null,"follow_up":null,"dependent":null},"_links":{"self":{"href":"/api/v2/cases/3065","class":"case"},"message":{"href":"/api/v2/cases/3065/message","class":"email"},"customer":{"href":"/api/v2/customers/86101780","class":"customer"},"assigned_user":null,"assigned_group":null,"locked_by":null,"replies":{"href":"/api/v2/cases/3065/replies","class":"reply"},"notes":{"href":"/api/v2/cases/3065/notes","class":"note"},"attachments":{"href":"/api/v2/cases/3065/attachments","class":"attachment"}}}' 52 | http_version: 53 | recorded_at: Thu, 12 Dec 2013 18:57:02 GMT 54 | recorded_with: VCR 2.5.0 55 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource_SCRUD/_search/allows_searching_on_search_enabled_resources.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/articles/search?text=Lorem+Ipsum 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 200 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - must-revalidate, private, max-age=0 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 18:57:00 GMT 27 | etag: 28 | - '"498b2a1a02496207b3b2c1f524be8349"' 29 | status: 30 | - 200 OK 31 | vary: 32 | - X-AppVersion 33 | x-appversion: 34 | - '15.6' 35 | x-frame-options: 36 | - SAMEORIGIN 37 | x-rate-limit-limit: 38 | - '60' 39 | x-rate-limit-remaining: 40 | - '59' 41 | x-rate-limit-reset: 42 | - '60' 43 | x-request-id: 44 | - bfeb1bee3a973fd4d5283e7ae721eec6 45 | content-length: 46 | - '293' 47 | connection: 48 | - Close 49 | body: 50 | encoding: UTF-8 51 | string: '{"total_entries":0,"_links":{"self":{"href":"/api/v2/articles?page=1&per_page=30","class":"page"},"first":{"href":"/api/v2/articles?page=1&per_page=30","class":"page"},"last":{"href":"/api/v2/articles?page=1&per_page=30","class":"page"},"previous":null,"next":null},"_embedded":{"entries":[]}}' 52 | http_version: 53 | recorded_at: Thu, 12 Dec 2013 18:57:00 GMT 54 | recorded_with: VCR 2.5.0 55 | -------------------------------------------------------------------------------- /spec/cassettes/DeskApi_Resource_SCRUD/_search/throws_an_error_if_search_is_not_enabled.yml: -------------------------------------------------------------------------------- 1 | --- 2 | http_interactions: 3 | - request: 4 | method: get 5 | uri: https://devel.desk.com/api/v2/users/search?test=something 6 | body: 7 | encoding: US-ASCII 8 | string: '' 9 | headers: 10 | Accept: 11 | - application/json 12 | User-Agent: 13 | - desk.com Ruby Gem v0.1.3 14 | response: 15 | status: 16 | code: 404 17 | message: 18 | headers: 19 | accept-ranges: 20 | - bytes 21 | cache-control: 22 | - no-cache, private 23 | content-type: 24 | - application/json; charset=utf-8 25 | date: 26 | - Thu, 12 Dec 2013 19:44:18 GMT 27 | status: 28 | - 404 Not Found 29 | vary: 30 | - X-AppVersion 31 | x-appversion: 32 | - '15.6' 33 | x-frame-options: 34 | - SAMEORIGIN 35 | x-rate-limit-limit: 36 | - '60' 37 | x-rate-limit-remaining: 38 | - '59' 39 | x-rate-limit-reset: 40 | - '42' 41 | x-request-id: 42 | - 2748ddc70cbf93e34fb6220557fb09e1 43 | content-length: 44 | - '32' 45 | connection: 46 | - Close 47 | body: 48 | encoding: UTF-8 49 | string: '{"message":"Resource Not Found"}' 50 | http_version: 51 | recorded_at: Thu, 12 Dec 2013 19:44:18 GMT 52 | recorded_with: VCR 2.5.0 53 | -------------------------------------------------------------------------------- /spec/desk_api/default_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | 31 | describe DeskApi::Default do 32 | context '#options' do 33 | it 'returns a hash with mostly nil values' do 34 | expect(DeskApi::Default.options).to eq({ 35 | consumer_key: nil, 36 | consumer_secret: nil, 37 | token: nil, 38 | token_secret: nil, 39 | username: nil, 40 | password: nil, 41 | subdomain: nil, 42 | endpoint: nil, 43 | connection_options: { 44 | headers: { 45 | accept: 'application/json', 46 | user_agent: "desk.com Ruby Gem v#{DeskApi::VERSION}" 47 | }, 48 | request: { 49 | open_timeout: 5, 50 | timeout: 10 51 | } 52 | } 53 | }) 54 | end 55 | 56 | it 'returns a hash with environmental variables' do 57 | ENV['DESK_CONSUMER_KEY'] = 'CK' 58 | ENV['DESK_CONSUMER_SECRET'] = 'CS' 59 | ENV['DESK_TOKEN'] = 'TOK' 60 | ENV['DESK_TOKEN_SECRET'] = 'TOKS' 61 | ENV['DESK_USERNAME'] = 'UN' 62 | ENV['DESK_PASSWORD'] = 'PW' 63 | ENV['DESK_SUBDOMAIN'] = 'SD' 64 | ENV['DESK_ENDPOINT'] = 'EP' 65 | 66 | expect(DeskApi::Default.options).to eq({ 67 | consumer_key: 'CK', 68 | consumer_secret: 'CS', 69 | token: 'TOK', 70 | token_secret: 'TOKS', 71 | username: 'UN', 72 | password: 'PW', 73 | subdomain: 'SD', 74 | endpoint: 'EP', 75 | connection_options: { 76 | headers: { 77 | accept: 'application/json', 78 | user_agent: "desk.com Ruby Gem v#{DeskApi::VERSION}" 79 | }, 80 | request: { 81 | open_timeout: 5, 82 | timeout: 10 83 | } 84 | } 85 | }) 86 | 87 | ENV['DESK_CONSUMER_KEY'] = nil 88 | ENV['DESK_CONSUMER_SECRET'] = nil 89 | ENV['DESK_TOKEN'] = nil 90 | ENV['DESK_TOKEN_SECRET'] = nil 91 | ENV['DESK_USERNAME'] = nil 92 | ENV['DESK_PASSWORD'] = nil 93 | ENV['DESK_SUBDOMAIN'] = nil 94 | ENV['DESK_ENDPOINT'] = nil 95 | end 96 | end 97 | end 98 | -------------------------------------------------------------------------------- /spec/desk_api/error_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | 31 | describe DeskApi::Error do 32 | subject do 33 | @client ||= DeskApi::Client.new DeskApi::CONFIG 34 | end 35 | 36 | context '.from_response' do 37 | it 'can be created from a faraday response', :vcr do 38 | expect( 39 | lambda { 40 | subject.articles.create({ subject: 'Testing', body: 'Testing' }) 41 | } 42 | ).to raise_error(DeskApi::Error::UnprocessableEntity) 43 | end 44 | 45 | it 'uses the body message if present', :vcr do 46 | begin 47 | subject.articles.create({ subject: 'Testing', body: 'Testing' }) 48 | rescue DeskApi::Error::UnprocessableEntity => e 49 | expect(e.message).to eq('Validation Failed') 50 | end 51 | end 52 | end 53 | 54 | context 'on validation error' do 55 | it 'allows access to error hash', :vcr do 56 | begin 57 | subject.articles.create({ subject: 'Testing', body: 'Testing' }) 58 | rescue DeskApi::Error::UnprocessableEntity => e 59 | expect(e.errors).to be_an_instance_of(Hash) 60 | expect(e.errors).to eq({"_links" => { "topic" => ["blank"]}}) 61 | end 62 | end 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /spec/desk_api/rate_limit_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | 31 | describe DeskApi::RateLimit do 32 | context "#limit" do 33 | it "returns an Integer when x-rate-limit-limit header is set" do 34 | rate_limit = DeskApi::RateLimit.new("x-rate-limit-limit" => "150") 35 | expect(rate_limit.limit).to be_an Integer 36 | expect(rate_limit.limit).to eq 150 37 | end 38 | 39 | it "returns nil when x-rate-limit-limit header is not set" do 40 | rate_limit = DeskApi::RateLimit.new 41 | expect(rate_limit.limit).to be_nil 42 | end 43 | end 44 | 45 | context "#remaining" do 46 | it "returns an Integer when x-rate-limit-remaining header is set" do 47 | rate_limit = DeskApi::RateLimit.new("x-rate-limit-remaining" => "149") 48 | expect(rate_limit.remaining).to be_an Integer 49 | expect(rate_limit.remaining).to eq 149 50 | end 51 | 52 | it "returns nil when x-rate-limit-remaining header is not set" do 53 | rate_limit = DeskApi::RateLimit.new 54 | expect(rate_limit.remaining).to be_nil 55 | end 56 | end 57 | 58 | context "#reset_in" do 59 | it "returns an Integer when x-rate-limit-reset header is set" do 60 | rate_limit = DeskApi::RateLimit.new("x-rate-limit-reset" => "36") 61 | expect(rate_limit.reset_in).to be_an Integer 62 | expect(rate_limit.reset_in).to eq 36 63 | end 64 | 65 | it "returns nil when x-rate-limit-reset header is not set" do 66 | rate_limit = DeskApi::RateLimit.new 67 | expect(rate_limit.reset_in).to be_nil 68 | end 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /spec/desk_api/request/encode_dates_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | require 'desk_api/request/encode_dates' 31 | 32 | describe DeskApi::Request::EncodeDates do 33 | before(:all) do 34 | VCR.turn_off! 35 | 36 | @time = Time.now 37 | @stubs = Faraday::Adapter::Test::Stubs.new 38 | @conn = Faraday.new do |builder| 39 | builder.request :desk_encode_dates 40 | builder.request :desk_encode_json 41 | builder.adapter :test, @stubs 42 | end 43 | end 44 | 45 | after(:all) do 46 | VCR.turn_on! 47 | end 48 | 49 | it 'encodes the date, datetime and time to iso8601' do 50 | @stubs.post('/echo') do |env| 51 | body = JSON.parse(env[:body], symbolize_names: true) 52 | expect(body[:date]).to eq(@time.to_date.to_time.utc.iso8601) 53 | expect(body[:datetime]).to eq(@time.utc.iso8601) 54 | expect(body[:time]).to eq(@time.utc.iso8601) 55 | end 56 | 57 | @conn.post('http://localhost/echo', { 58 | date: @time.to_date, 59 | datetime: @time.to_datetime, 60 | time: @time 61 | }) 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /spec/desk_api/request/encode_json_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | require 'desk_api/request/encode_json' 31 | 32 | describe DeskApi::Request::EncodeJson do 33 | before(:all) do 34 | VCR.turn_off! 35 | 36 | @stubs = Faraday::Adapter::Test::Stubs.new 37 | @conn = Faraday.new do |builder| 38 | builder.request :desk_encode_json 39 | builder.adapter :test, @stubs 40 | end 41 | end 42 | 43 | after(:all) do 44 | VCR.turn_on! 45 | end 46 | 47 | it 'sets the content type header' do 48 | @stubs.post('/echo') do |env| 49 | expect(env[:request_headers]).to have_key('Content-Type') 50 | expect(env[:request_headers]['Content-Type']).to eql('application/json') 51 | end 52 | @conn.post('http://localhost/echo', test: 'test') 53 | end 54 | 55 | it 'encodes the body into json' do 56 | @stubs.post('/echo') do |env| 57 | expect(!!JSON.parse(env[:body])).to eq(true) 58 | end 59 | @conn.post('http://localhost/echo', test: 'test') 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /spec/desk_api/request/oauth_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | require 'desk_api/request/oauth' 31 | 32 | describe DeskApi::Request::OAuth do 33 | before do 34 | VCR.turn_off! 35 | 36 | @stubs = Faraday::Adapter::Test::Stubs.new 37 | @conn = Faraday.new do |builder| 38 | builder.request :desk_oauth, { 39 | consumer_key: 'consumer_key', 40 | consumer_secret: 'consumer_secret', 41 | token: 'token', 42 | token_secret: "token_secret" 43 | } 44 | builder.adapter :test, @stubs 45 | end 46 | end 47 | 48 | after do 49 | VCR.turn_on! 50 | end 51 | 52 | it 'sets the authorization header' do 53 | @stubs.post('/echo') do |env| 54 | expect(env[:request_headers]).to have_key('Authorization') 55 | expect(env[:request_headers]['Authorization']).to include('OAuth') 56 | end 57 | @conn.post('http://localhost/echo') 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/desk_api/request/retry_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | require 'desk_api/request/retry' 31 | 32 | describe DeskApi::Request::Retry do 33 | before do 34 | VCR.turn_off! 35 | 36 | @stubs = Faraday::Adapter::Test::Stubs.new 37 | @conn = Faraday.new do |builder| 38 | builder.request :desk_retry, { interval: 0 } 39 | builder.adapter :test, @stubs 40 | end 41 | end 42 | 43 | after do 44 | VCR.turn_on! 45 | end 46 | 47 | it 'retries three times' do 48 | times_called = 0 49 | 50 | @stubs.post('/echo') do 51 | times_called += 1 52 | raise Faraday::Error::TimeoutError, 'Timeout' 53 | end 54 | 55 | @conn.post('http://localhost/echo') rescue nil 56 | expect(times_called).to eq(3) 57 | end 58 | 59 | it 'retries once if we have too many requests' do 60 | times_called = 0 61 | 62 | @stubs.post('/echo') do 63 | times_called += 1 64 | raise DeskApi::Error::TooManyRequests.from_response({ 65 | body: '{"message":"Too Many Requests"}', 66 | status: 429, 67 | response_headers: { 68 | 'status' => 429, 69 | 'x-rate-limit-limit' => '60', 70 | 'x-rate-limit-remaining' => '0', 71 | 'x-rate-limit-reset' => '0', 72 | 'content-length' => '31' 73 | } 74 | }) 75 | end 76 | 77 | @conn.post('http://localhost/echo') rescue nil 78 | expect(times_called).to eq(2) 79 | end 80 | end 81 | -------------------------------------------------------------------------------- /spec/desk_api/resource/download_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | require 'fileutils' 31 | 32 | describe DeskApi::Resource::Download do 33 | subject { @client ||= DeskApi::Client.new DeskApi::CONFIG } 34 | 35 | it 'throws an error on non attachment resources', :vcr do 36 | expect(lambda { subject.cases.find(3065).download }) 37 | .to raise_error(NoMethodError) 38 | end 39 | 40 | it 'downloads the attachment', :vcr do 41 | a = subject.cases.find(3065).attachments.entries.first.download 42 | b = File.open(File.join(RSpec.configuration.root_path, 'stubs', 'file.jpg')) 43 | expect(a.read).to eq(b.read) 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /spec/desk_api/resource/pagination_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | 31 | describe DeskApi::Resource::Pagination do 32 | subject { @client ||= DeskApi::Client.new DeskApi::CONFIG } 33 | 34 | context '#all' do 35 | it 'iterates over each resource on each page', :vcr do 36 | subject.cases.all do |resource, page_num| 37 | expect(resource).to be_an_instance_of(DeskApi::Resource) 38 | expect(resource.resource_type).to eq('case') 39 | expect(page_num).to be_an_instance_of(Fixnum) 40 | end 41 | end 42 | 43 | it 'raises an argument error if no block is given' do 44 | expect { subject.cases.all }.to raise_error(ArgumentError) 45 | end 46 | end 47 | 48 | context '#each_page' do 49 | it 'iterates over each page', :vcr do 50 | subject.cases.each_page do |page, page_number| 51 | expect(page).to be_an_instance_of(DeskApi::Resource) 52 | expect(page.resource_type).to eq('page') 53 | expect(page_number).to be_an_instance_of(Fixnum) 54 | end 55 | end 56 | 57 | it 'uses a default per_page of 1000', :vcr do 58 | subject.cases.each_page do |page, page_number| 59 | expect((page.query_params['per_page'].to_i % 10)).to eq(0) 60 | end 61 | end 62 | 63 | it 'uses per_page from query_params if present' do 64 | subject.cases.per_page(25) do |page, page_number| 65 | expect(page.query_params['per_page']).to eq(25) 66 | end 67 | end 68 | 69 | it 'raises ArgumentError if no block is given' do 70 | expect { subject.cases.each_page }.to raise_error(ArgumentError) 71 | end 72 | 73 | it 'raises NoMethodError is called on non-page resources', :vcr do 74 | expect { subject.cases.entries.first.each_page { |x| x } }.to raise_error(NoMethodError) 75 | end 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /spec/desk_api/response/follow_redirects_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | require 'desk_api/response/follow_redirects' 31 | 32 | describe DeskApi::Response::FollowRedirects do 33 | before do 34 | VCR.turn_off! 35 | 36 | @body = <<-eos 37 | 38 | 39 | You are being redirected. 40 | 41 | 42 | eos 43 | 44 | @headers = { 45 | "accept-ranges"=>"bytes", 46 | "cache-control"=>"no-cache, private", 47 | "content-type"=>"text/html; charset=utf-8", 48 | "date"=>"Mon, 07 Jul 2014 19:34:07 GMT", 49 | "location"=> "http://localhost/pong", 50 | "status"=>"302 Found", 51 | "vary"=>"X-AppVersion", 52 | "x-appversion"=>"15.99", 53 | "x-frame-options"=>"SAMEORIGIN", 54 | "x-rate-limit-limit"=>"300", 55 | "x-rate-limit-remaining"=>"299", 56 | "x-rate-limit-reset"=>"53", 57 | "x-request-id"=>"07f87191096f0ec3e94779020fe76721", 58 | "content-length"=>"371", 59 | "connection"=>"Close" 60 | } 61 | 62 | stubs = Faraday::Adapter::Test::Stubs.new do |stub| 63 | stub.get('/301') { [301, @headers, @body] } 64 | stub.get('/302') { [302, @headers, @body] } 65 | stub.get('/303') { [303, @headers, @body] } 66 | stub.get('/307') { [307, @headers, @body] } 67 | stub.get('/pong') { [200, { 'content-type' => 'application/json' }, "{}"] } 68 | 69 | stub.get('/one') { [302, { 'location' => 'http://localhost/two' }, '']} 70 | stub.get('/two') { [302, { 'location' => 'http://localhost/three' }, '']} 71 | stub.get('/three') { [302, { 'location' => 'http://localhost/four' }, '']} 72 | stub.get('/four') { [302, { 'location' => 'http://localhost/five' }, '']} 73 | stub.get('/five') { [200, { 'content-type' => 'application/json' }, '{}']} 74 | end 75 | 76 | @conn = Faraday.new do |builder| 77 | builder.response :desk_follow_redirects 78 | builder.adapter :test, stubs 79 | end 80 | end 81 | 82 | after do 83 | VCR.turn_on! 84 | end 85 | 86 | it 'redirects to pong' do 87 | %w(301 302 303 307).each do |status| 88 | expect(@conn.get("http://localhost/#{status}").env[:url].path).to eq('/pong') 89 | end 90 | end 91 | 92 | it 'redirects max 3 times' do 93 | expect{@conn.get("http://localhost/one")}.to raise_error(DeskApi::Error::FollowRedirectError) 94 | end 95 | end 96 | -------------------------------------------------------------------------------- /spec/desk_api/response/parse_dates_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | require 'desk_api/response/parse_dates' 31 | 32 | describe DeskApi::Response::ParseDates do 33 | before do 34 | VCR.turn_off! 35 | 36 | stubs = Faraday::Adapter::Test::Stubs.new do |stub| 37 | stub.get('/echo') do 38 | [ 39 | 200, 40 | { 'content-type' => 'application/json' }, 41 | File.open(File.join(RSpec.configuration.root_path, 'stubs', 'article.json')).read 42 | ] 43 | end 44 | end 45 | 46 | @conn = Faraday.new do |builder| 47 | builder.response :desk_parse_dates 48 | builder.response :desk_parse_json 49 | builder.adapter :test, stubs 50 | end 51 | end 52 | 53 | after do 54 | VCR.turn_on! 55 | end 56 | 57 | it 'parses iso 8601 strings to time' do 58 | created_at = @conn.get('http://localhost/echo').body['created_at'] 59 | expect(created_at).to be_instance_of(Time) 60 | expect(created_at).to eql(Time.parse('2013-12-12T02:55:05Z')) 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /spec/desk_api/response/parse_json_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | require 'desk_api/response/parse_json' 31 | 32 | describe DeskApi::Response::ParseJson do 33 | before do 34 | VCR.turn_off! 35 | 36 | @xml = <<-eos 37 | 38 | 39 | Tove 40 | Jani 41 | Reminder 42 | Don't forget me this weekend! 43 | 44 | eos 45 | @json = File.open(File.join(RSpec.configuration.root_path, 'stubs', 'article.json')).read 46 | 47 | stubs = Faraday::Adapter::Test::Stubs.new do |stub| 48 | stub.get('/json') { [200, { 'content-type' => 'application/json' }, @json] } 49 | stub.get('/xml') { [200, { 'content-type' => 'application/xml' }, @xml] } 50 | stub.get('/utf8') { [200, { 'content-type' => 'application/json; charset=utf-8' }, @json] } 51 | end 52 | 53 | @conn = Faraday.new do |builder| 54 | builder.response :desk_parse_json 55 | builder.adapter :test, stubs 56 | end 57 | end 58 | 59 | after do 60 | VCR.turn_on! 61 | end 62 | 63 | it 'parses the response body into a hash' do 64 | body = @conn.get('http://localhost/json').body 65 | compare = JSON.parse @json 66 | expect(body).to be_instance_of(Hash) 67 | expect(body).to eql(compare) 68 | end 69 | 70 | it 'looks at the content type header before parsing' do 71 | body = @conn.get('http://localhost/xml').body 72 | expect(body).to eql(@xml) 73 | end 74 | 75 | it 'deals with specified charsets in the content-type header' do 76 | body = @conn.get('http://localhost/utf8').body 77 | compare = JSON.parse @json 78 | expect(body).to be_instance_of(Hash) 79 | expect(body).to eql(compare) 80 | end 81 | end 82 | -------------------------------------------------------------------------------- /spec/desk_api/response/raise_error_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | require 'desk_api/response/raise_error' 31 | 32 | describe DeskApi::Response::RaiseError do 33 | before do 34 | VCR.turn_off! 35 | 36 | stubs = Faraday::Adapter::Test::Stubs.new do |stub| 37 | stub.get('/404'){ [404, {}, ''] } 38 | stub.get('/502'){ [502, {}, ''] } 39 | end 40 | 41 | @conn = Faraday.new do |builder| 42 | builder.response :desk_raise_error, DeskApi::Error::ClientError 43 | builder.response :desk_raise_error, DeskApi::Error::ServerError 44 | builder.adapter :test, stubs 45 | end 46 | end 47 | 48 | after do 49 | VCR.turn_on! 50 | end 51 | 52 | it 'raises the correct error for client side errors' do 53 | expect{ @conn.get('http://localhost/404') }.to raise_error(DeskApi::Error::NotFound) 54 | end 55 | 56 | it 'raises the correct error for server side errors' do 57 | expect{ @conn.get('http://localhost/502') }.to raise_error(DeskApi::Error::BadGateway) 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/desk_api_spec.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'spec_helper' 30 | 31 | describe DeskApi do 32 | describe '.method_missing' do 33 | it 'delegates config to DeskApi::Client' do 34 | expect(DeskApi.method_missing(:endpoint)).to be_a(String) 35 | end 36 | 37 | it 'delegates resource request to DeskApi::Client' do 38 | expect(DeskApi.method_missing(:cases)).to be_a(DeskApi::Resource) 39 | end 40 | end 41 | 42 | describe '.client' do 43 | it 'should return a client' do 44 | expect(DeskApi.client).to be_an_instance_of(DeskApi::Client) 45 | end 46 | 47 | context 'when the options do not change' do 48 | it 'caches the client' do 49 | expect(DeskApi.client).to eq(DeskApi.client) 50 | end 51 | end 52 | 53 | context 'when the options change' do 54 | it 'busts the cache' do 55 | client1 = DeskApi.client 56 | client1.configure do |config| 57 | config.username = 'test@example.com' 58 | config.password = 'password' 59 | end 60 | client2 = DeskApi.client 61 | expect(client1).not_to eq(client2) 62 | end 63 | end 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013-2018, Salesforce.com, Inc. 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without modification, 5 | # are permitted provided that the following conditions are met: 6 | # 7 | # * Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # * Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # * Neither the name of Salesforce.com nor the names of its contributors may be 15 | # used to endorse or promote products derived from this software without 16 | # specific prior written permission. 17 | # 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | require 'simplecov' 30 | require 'coveralls' 31 | 32 | SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ 33 | SimpleCov::Formatter::HTMLFormatter, 34 | Coveralls::SimpleCov::Formatter 35 | ] 36 | SimpleCov.start do 37 | add_filter '/spec/' 38 | add_filter 'config.rb' 39 | end 40 | 41 | require 'rspec' 42 | require 'vcr' 43 | require 'desk_api' 44 | 45 | begin 46 | require_relative '../config' 47 | rescue LoadError 48 | module DeskApi 49 | CONFIG = { 50 | username: 'devel@example.com', 51 | password: '1234password', 52 | subdomain: 'devel' 53 | } 54 | 55 | OAUTH_CONFIG = { 56 | consumer_key: 'my_consumer_key', 57 | consumer_secret: 'my_consumer_secret', 58 | token: 'my_token', 59 | token_secret: 'my_token_secret', 60 | subdomain: 'devel' 61 | } 62 | end 63 | end 64 | 65 | VCR.configure do |config| 66 | config.hook_into :faraday 67 | config.cassette_library_dir = 'spec/cassettes' 68 | config.configure_rspec_metadata! 69 | config.before_record { |i| i.request.headers.delete('Authorization') } 70 | config.ignore_request { |request| URI(request.uri).host == 'localhost' } 71 | end 72 | 73 | RSpec.configure do |config| 74 | config.add_setting :root_path, default: File.dirname(__FILE__) 75 | end 76 | -------------------------------------------------------------------------------- /spec/stubs/article.json: -------------------------------------------------------------------------------- 1 | { 2 | "subject": "Testing OAuth", 3 | "body": "OAuth testing", 4 | "body_email": "OAuth testing", 5 | "body_email_auto": true, 6 | "body_chat": "OAuth testing", 7 | "body_chat_auto": true, 8 | "body_web_callback": "OAuth testing", 9 | "body_web_callback_auto": true, 10 | "body_twitter": "OAuth testing", 11 | "body_twitter_auto": true, 12 | "body_qna": "OAuth testing", 13 | "body_qna_auto": true, 14 | "body_phone": "OAuth testing", 15 | "body_phone_auto": true, 16 | "body_facebook": "OAuth testing", 17 | "body_facebook_auto": true, 18 | "rating": 0, 19 | "rating_count": 0, 20 | "rating_score": 0, 21 | "keywords": null, 22 | "position": 4, 23 | "quickcode": null, 24 | "in_support_center": null, 25 | "internal_notes": null, 26 | "publish_at": null, 27 | "created_at": "2013-12-12T02:55:05Z", 28 | "updated_at": "2013-12-12T02:55:05Z", 29 | "_links": { 30 | "self": { 31 | "href": "/api/v2/articles/1391017", 32 | "class": "article" 33 | }, 34 | "topic": { 35 | "href": "/api/v2/topics/498301", 36 | "class": "topic" 37 | }, 38 | "translations": { 39 | "href": "/api/v2/articles/1391017/translations", 40 | "class": "article_translation" 41 | }, 42 | "created_by": { 43 | "href": "/api/v2/users/16096734", 44 | "class": "user" 45 | }, 46 | "updated_by": { 47 | "href": "/api/v2/users/16096734", 48 | "class": "user" 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /spec/stubs/case_embed_customer.json: -------------------------------------------------------------------------------- 1 | { 2 | "external_id": null, 3 | "subject": "", 4 | "priority": 9, 5 | "locked_until": null, 6 | "description": "", 7 | "status": "open", 8 | "type": "phone", 9 | "labels": [], 10 | "language": "en", 11 | "active_at": "2013-09-07T19:38:58Z", 12 | "created_at": "2013-05-09T17:02:16Z", 13 | "updated_at": "2013-09-07T19:39:07Z", 14 | "received_at": "2013-05-09T17:02:16Z", 15 | "custom_fields": { 16 | "my_new_custom_field": "", 17 | "my_new_number_field": "0", 18 | "my_new_date_field": "", 19 | "my_new_boolean_field": "0", 20 | "my_new_list_field": "Option 1" 21 | }, 22 | "_links": { 23 | "self": { 24 | "href": "/api/v2/cases/3011", 25 | "class": "case" 26 | }, 27 | "message": { 28 | "href": "/api/v2/cases/3011/message", 29 | "class": "phone" 30 | }, 31 | "customer": { 32 | "href": "/api/v2/customers/37823480", 33 | "class": "customer" 34 | }, 35 | "assigned_user": { 36 | "href": "/api/v2/users/16096734", 37 | "class": "user" 38 | }, 39 | "assigned_group": { 40 | "href": "/api/v2/groups/171213", 41 | "class": "group" 42 | }, 43 | "locked_by": null, 44 | "replies": { 45 | "href": "/api/v2/cases/3011/replies", 46 | "class": "reply" 47 | }, 48 | "notes": { 49 | "href": "/api/v2/cases/3011/notes", 50 | "class": "note" 51 | }, 52 | "attachments": { 53 | "href": "/api/v2/cases/3011/attachments", 54 | "class": "attachment" 55 | } 56 | }, 57 | "_embedded": { 58 | "customer": { 59 | "first_name": "Thomas", 60 | "last_name": "Stachl", 61 | "company": "stachl.me", 62 | "title": "Master of Script Artistry", 63 | "external_id": null, 64 | "background": "Some Background information.", 65 | "language": "de", 66 | "locked_until": null, 67 | "created_at": "2012-07-04T14:33:39Z", 68 | "updated_at": "2013-07-15T18:10:21Z", 69 | "custom_fields": { 70 | "my_custom_field": "", 71 | "my_number_field": "0", 72 | "my_boolean_field": "0", 73 | "my_date_field": "", 74 | "my_list_field": "Option 1" 75 | }, 76 | "emails": [ 77 | { 78 | "type": "home", 79 | "value": "thomas@stachl.me" 80 | }, 81 | { 82 | "type": "home", 83 | "value": "tstachl@salesforce.com" 84 | } 85 | ], 86 | "phone_numbers": [ 87 | { 88 | "type": "mobile", 89 | "value": "4156060761" 90 | } 91 | ], 92 | "addresses": [ 93 | { 94 | "type": "home", 95 | "value": "600 William Street #526\nOakland, CA 94612" 96 | } 97 | ], 98 | "_links": { 99 | "self": { 100 | "href": "/api/v2/customers/37823480", 101 | "class": "customer" 102 | }, 103 | "locked_by": null, 104 | "company": { 105 | "href": "/api/v2/companies/373760", 106 | "class": "company" 107 | }, 108 | "cases": { 109 | "href": "/api/v2/customers/37823480/cases", 110 | "class": "case" 111 | } 112 | } 113 | } 114 | } 115 | } -------------------------------------------------------------------------------- /spec/stubs/cases_embed_assigned_user.json: -------------------------------------------------------------------------------- 1 | { 2 | "total_entries": 329, 3 | "_links": { 4 | "self": { 5 | "href": "/api/v2/cases?page=1&per_page=1", 6 | "class": "page" 7 | }, 8 | "first": { 9 | "href": "/api/v2/cases?page=1&per_page=1", 10 | "class": "page" 11 | }, 12 | "last": { 13 | "href": "/api/v2/cases?page=329&per_page=1", 14 | "class": "page" 15 | }, 16 | "previous": null, 17 | "next": { 18 | "href": "/api/v2/cases?page=2&per_page=1", 19 | "class": "page" 20 | } 21 | }, 22 | "_embedded": { 23 | "entries": [ 24 | { 25 | "external_id": null, 26 | "subject": "", 27 | "priority": 9, 28 | "locked_until": null, 29 | "description": "", 30 | "status": "open", 31 | "type": "phone", 32 | "labels": [], 33 | "language": "en", 34 | "active_at": "2013-09-07T19:38:58Z", 35 | "created_at": "2013-05-09T17:02:16Z", 36 | "updated_at": "2013-09-07T19:39:07Z", 37 | "received_at": "2013-05-09T17:02:16Z", 38 | "custom_fields": { 39 | "my_new_custom_field": "", 40 | "my_new_number_field": "0", 41 | "my_new_date_field": "", 42 | "my_new_boolean_field": "0", 43 | "my_new_list_field": "Option 1" 44 | }, 45 | "_links": { 46 | "self": { 47 | "href": "/api/v2/cases/3011", 48 | "class": "case" 49 | }, 50 | "message": { 51 | "href": "/api/v2/cases/3011/message", 52 | "class": "phone" 53 | }, 54 | "customer": { 55 | "href": "/api/v2/customers/37823480", 56 | "class": "customer" 57 | }, 58 | "assigned_user": { 59 | "href": "/api/v2/users/16096734", 60 | "class": "user" 61 | }, 62 | "assigned_group": { 63 | "href": "/api/v2/groups/171213", 64 | "class": "group" 65 | }, 66 | "locked_by": null, 67 | "replies": { 68 | "href": "/api/v2/cases/3011/replies", 69 | "class": "reply" 70 | }, 71 | "notes": { 72 | "href": "/api/v2/cases/3011/notes", 73 | "class": "note" 74 | }, 75 | "attachments": { 76 | "href": "/api/v2/cases/3011/attachments", 77 | "class": "attachment" 78 | } 79 | }, 80 | "_embedded": { 81 | "assigned_user": { 82 | "name": "Thomas Stachl", 83 | "public_name": "Thomas Stachl", 84 | "email": "tstachl@salesforce.com", 85 | "level": "siteadmin_billing", 86 | "_links": { 87 | "self": { 88 | "href": "/api/v2/users/16096734", 89 | "class": "user" 90 | }, 91 | "preferences": { 92 | "href": "/api/v2/users/16096734/preferences", 93 | "class": "user_preference" 94 | }, 95 | "searches": { 96 | "href": "/api/v2/users/16096734/searches", 97 | "class": "search" 98 | } 99 | } 100 | } 101 | } 102 | } 103 | ] 104 | } 105 | } -------------------------------------------------------------------------------- /spec/stubs/file.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/forcedotcom/salesforce-deskcom-api/67a083618090efa3ebcdfefc2e11ae1caa02f1de/spec/stubs/file.jpg --------------------------------------------------------------------------------