Class: Crm::Core::RestApi
- Inherits:
-
Object
- Object
- Crm::Core::RestApi
- Defined in:
- lib/crm/core/rest_api.rb
Constant Summary collapse
- METHOD_TO_NET_HTTP_CLASS =
{ :get => Net::HTTP::Get, :put => Net::HTTP::Put, :post => Net::HTTP::Post, :delete => Net::HTTP::Delete, }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #delete(resource_path, payload = nil, headers = {}) ⇒ Object
- #get(resource_path, payload = nil) ⇒ Object
-
#initialize(uri, login, api_key) ⇒ RestApi
constructor
A new instance of RestApi.
- #post(resource_path, payload) ⇒ Object
- #put(resource_path, payload, headers = {}) ⇒ Object
- #resolve_uri(url) ⇒ Object
Constructor Details
#initialize(uri, login, api_key) ⇒ RestApi
Returns a new instance of RestApi.
25 26 27 28 29 30 |
# File 'lib/crm/core/rest_api.rb', line 25 def initialize(uri, login, api_key) @uri = uri @login = login @api_key = api_key @connection_manager = ConnectionManager.new(uri) end |
Class Method Details
.instance ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/crm/core/rest_api.rb', line 17 def self.instance if @instance @instance else raise "Please run Crm.configure first" end end |
.instance=(instance) ⇒ Object
13 14 15 |
# File 'lib/crm/core/rest_api.rb', line 13 def self.instance=(instance) @instance = instance end |
Instance Method Details
#delete(resource_path, payload = nil, headers = {}) ⇒ Object
44 45 46 |
# File 'lib/crm/core/rest_api.rb', line 44 def delete(resource_path, payload = nil, headers = {}) response_for_request(:delete, resource_path, payload, headers) end |
#get(resource_path, payload = nil) ⇒ Object
32 33 34 |
# File 'lib/crm/core/rest_api.rb', line 32 def get(resource_path, payload = nil) response_for_request(:get, resource_path, payload, {}) end |
#post(resource_path, payload) ⇒ Object
40 41 42 |
# File 'lib/crm/core/rest_api.rb', line 40 def post(resource_path, payload) response_for_request(:post, resource_path, payload, {}) end |
#put(resource_path, payload, headers = {}) ⇒ Object
36 37 38 |
# File 'lib/crm/core/rest_api.rb', line 36 def put(resource_path, payload, headers = {}) response_for_request(:put, resource_path, payload, headers) end |
#resolve_uri(url) ⇒ Object
48 49 50 51 52 |
# File 'lib/crm/core/rest_api.rb', line 48 def resolve_uri(url) input_uri = Addressable::URI.parse(url) input_uri.path = Addressable::URI.escape(input_uri.path) @uri + input_uri.to_s end |