Module: TelphinApi::API
- Defined in:
- lib/telphin_api/api.rb
Overview
A low-level module which handles the requests to Telphin API and returns their results as mashes.
It uses Faraday with middleware underneath the hood.
Class Method Summary collapse
-
.call(full_method, args = {}, token = nil) ⇒ Hashie::Mash
API method call.
-
.connection(options = {}) ⇒ Faraday::Connection
Faraday connection.
Class Method Details
.call(full_method, args = {}, token = nil) ⇒ Hashie::Mash
API method call.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/telphin_api/api.rb', line 12 def call(full_method, args = {}, token = nil) namespace = full_method.first action = full_method.last http_method = args.delete(:http_method) http_method ||= :get user_id = args.delete(:user_id) extension_number = args.delete(:extension_number) id = args.delete(:id) flat_arguments = Utils.flatten_arguments(args) url = [TelphinApi.site, namespace, user_id, extension_number, action].join('/') url = url + '/' + id unless id.nil? connection = connection(url: url, token: token) if flat_arguments.empty? connection.send(http_method).body else connection.send(http_method, flat_arguments).body end end |
.connection(options = {}) ⇒ Faraday::Connection
Faraday connection.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/telphin_api/api.rb', line 40 def connection( = {}) url = .delete(:url) token = .delete(:token) url = url + '?accessRequestToken=' + token Faraday.new(url, TelphinApi.) do |builder| builder.request :multipart builder.request :url_encoded builder.request :retry, TelphinApi.max_retries builder.response :telphin_logger builder.response :mashify builder.response :multi_json, preserve_raw: true builder.adapter TelphinApi.adapter end end |