class Sipwizard::Connection
Constants
- API_PATHS
- BASE_REST_API
Attributes
faraday_connection[RW]
Public Class Methods
new(options={})
click to toggle source
# File lib/sipwizard/connection.rb, line 14 def initialize(options={}) faraday_adapter = options.fetch(:adapter){ Faraday.default_adapter } api_type = options.fetch(:api_type){ :provisioning } params = options.fetch(:connection_params){{}} debug_enabled = options.fetch(:debug_enabled){ false } @faraday_connection = Faraday.new(API_PATHS[api_type], params ) do |faraday| faraday.request :url_encoded #for post/put params faraday.response :logger if debug_enabled faraday.response :raise_error faraday.response :json, content_type: /\bjson\z/ faraday.adapter faraday_adapter end @faraday_connection.headers['apikey'] = Sipwizard.config.api_key end
Public Instance Methods
get(path, params={})
click to toggle source
Public make a get request to the api
path - The path of the api params - The query parameters (default: {}):
Examples
get('cdr/count') get('cdr/count', { where: 'FromName="John Doe"'})
Returns Faraday::Response
# File lib/sipwizard/connection.rb, line 45 def get(path, params={}) self.faraday_connection.get(path, params).body end
post(path, params)
click to toggle source
# File lib/sipwizard/connection.rb, line 49 def post(path, params) self.faraday_connection.headers['Content-Type'] ='application/json; charset=utf-8' payload = params.to_json self.faraday_connection.post(path, payload).body end