Class: Freshdesk::Resource
- Inherits:
-
Object
- Object
- Freshdesk::Resource
- Defined in:
- lib/freshdesk/resource.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #api_url ⇒ Object
- #delete ⇒ Object
- #get ⇒ Object
-
#initialize(endpoint, params = {}, id = nil) ⇒ Resource
constructor
A new instance of Resource.
- #json_payload ⇒ Object
- #post ⇒ Object
- #put ⇒ Object
Constructor Details
#initialize(endpoint, params = {}, id = nil) ⇒ Resource
Returns a new instance of Resource.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/freshdesk/resource.rb', line 6 def initialize(endpoint, params = {}, id = nil) @endpoint = endpoint @params = params @id = id @domain = Freshdesk.domain @user_name_or_api_key = Freshdesk.user_name_or_api_key @password_or_x = Freshdesk.password_or_x @api_version = Freshdesk.api_version @resource ||= RestClient::Resource.new( api_url, @user_name_or_api_key, @password_or_x ) end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
22 23 24 |
# File 'lib/freshdesk/resource.rb', line 22 def endpoint @endpoint end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
22 23 24 |
# File 'lib/freshdesk/resource.rb', line 22 def params @params end |
Instance Method Details
#api_url ⇒ Object
24 25 26 |
# File 'lib/freshdesk/resource.rb', line 24 def api_url "https://#{@domain}.freshdesk.com/api/#{@api_version}#{@endpoint}" end |
#delete ⇒ Object
44 45 46 47 48 |
# File 'lib/freshdesk/resource.rb', line 44 def delete @resource.delete(accept: "application/json") rescue RestClient::Exception => e raise e, (e) end |
#get ⇒ Object
38 39 40 41 42 |
# File 'lib/freshdesk/resource.rb', line 38 def get @resource.get(accept: "application/json") rescue RestClient::Exception => e raise e, (e) end |
#json_payload ⇒ Object
28 29 30 |
# File 'lib/freshdesk/resource.rb', line 28 def json_payload @params.to_json end |
#post ⇒ Object
32 33 34 35 36 |
# File 'lib/freshdesk/resource.rb', line 32 def post @resource.post(json_payload, content_type: "application/json") rescue RestClient::Exception => e raise e, (e) end |
#put ⇒ Object
50 51 52 53 54 |
# File 'lib/freshdesk/resource.rb', line 50 def put @resource.put(json_payload, content_type: "application/json") rescue RestClient::Exception => e raise e, (e) end |