class Mozenda::Infrastructure::Connection
Public Class Methods
new()
click to toggle source
# File lib/mozenda/infrastructure/connection.rb, line 6 def initialize config = Mozenda::Configuration.instance default_params = { "WebServiceKey" => config.web_service_key, "Service" => config.service } @client = ::Faraday.new(url: config.base_uri, params: default_params) @multipart_client = ::Faraday.new(url: config.base_uri, params: default_params) do |builder| builder.request :multipart builder.request :url_encoded builder.adapter :net_http end end
Public Instance Methods
get(params)
click to toggle source
# File lib/mozenda/infrastructure/connection.rb, line 20 def get params send_request(:get, params) end
multipart(params, file_path)
click to toggle source
# File lib/mozenda/infrastructure/connection.rb, line 28 def multipart params, file_path file = ::Faraday::UploadIO.new(file_path, 'application/xml') @multipart_client.post do |request| request.params.merge!(params) request.body = { "file" => file } end end
post(params)
click to toggle source
# File lib/mozenda/infrastructure/connection.rb, line 24 def post params send_request(:post, params) end
Private Instance Methods
send_request(type, params)
click to toggle source
# File lib/mozenda/infrastructure/connection.rb, line 40 def send_request type, params @client.send(type) do |request| request.params.merge!(params) end end