postman_mta 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9938693c472befa38327970aaf030b2e9503c3ce
4
- data.tar.gz: 348e6ddb3215d6729219d91e690cf2b3c47bc53e
3
+ metadata.gz: 1bd93c122e3a75d39d6cdd8f4727cce9ebad4b72
4
+ data.tar.gz: 41a3fb2cfcd0512c8d3ac201a7c3cbbf692a5e76
5
5
  SHA512:
6
- metadata.gz: fba7a9a4fb3a8e42d2ba379b5b525591ab0834196cdb7678e5b7b650041815cd6acffb2317c68bab77d572687674c62a5f3e508aaa6e8538f37b18f45a035627
7
- data.tar.gz: 38bbdf1a06e0a7384aaabfdb6caa068debb7971d08aa06aafb3505c0570f14e4b1d1b62e3f448aac0b1d331fff406a33f82f3e7d67a9e9ace7086200383cb9aa
6
+ metadata.gz: 4d24f8d2bed37a32d1b99ab4733f95ec1ae06f49b0447a06669018be2df3a6e969dea9d270d5d001244a03fc4ff8907ca8076ba3e5c733883165e7504b7bfbf6
7
+ data.tar.gz: 35d13d052fbc4f36bfce501c4e23d780ec0d44fa7cd2e5e19e70a9317d492f4197a65480720630405ee2c48b0ccd86eed5a1ced4d08458f8b24c0bac9cfdba12
@@ -1,7 +1,13 @@
1
1
  module PostmanMta
2
2
  class AttachmentsController < ApplicationController
3
+ include ActionController::DataStreaming
4
+
3
5
  def show
4
- render attachment.find(params[:uuid])
6
+ response = attachment.find(params[:uuid]).deep_symbolize_keys
7
+ file = response.dig(:json, :attachment)
8
+ file_data = Base64.decode64(file[:body])
9
+
10
+ send_data(file_data, type: file[:content_type], filename: file[:filename], dispostion: 'attachment')
5
11
  end
6
12
 
7
13
  private
data/config.reek CHANGED
@@ -11,3 +11,4 @@ UnusedPrivateMethod:
11
11
  UtilityFunction:
12
12
  exclude:
13
13
  - "PostmanMta::Utils::Signature#digest"
14
+ - "PostmanMta::ApiClient#perform_request"
data/lib/postman_mta.rb CHANGED
@@ -13,6 +13,9 @@ module PostmanMta
13
13
  mattr_accessor :api_secret
14
14
  mattr_accessor :api_endpoint
15
15
 
16
+ # This block will be executed before request, and return value will be merged to params hash
17
+ mattr_accessor :before_request_hook
18
+
16
19
  def self.setup
17
20
  yield self
18
21
  end
@@ -1,10 +1,5 @@
1
- require 'httparty'
2
-
3
1
  module PostmanMta
4
2
  class ApiClient
5
- include ::HTTParty
6
- base_uri PostmanMta.api_endpoint
7
-
8
3
  [:get, :post, :put, :patch, :delete].each do |type|
9
4
  define_method type do |url, options = {}|
10
5
  perform_request(type.to_s.upcase, url, options)
@@ -14,15 +9,8 @@ module PostmanMta
14
9
  private
15
10
 
16
11
  def perform_request(request_type, path, options = {})
17
- headers = PostmanMta::Utils::SignedRequest.new(
18
- request_method: request_type.upcase, path: path
19
- ).headers
20
-
21
- response = self.class.send(
22
- request_type.downcase,
23
- path,
24
- { headers: headers, format: :json }.merge(options)
25
- )
12
+ api_request = ApiRequest.new(request_type, path, options)
13
+ response = api_request.perform
26
14
 
27
15
  { json: response.parsed_response, status: response.code }
28
16
  end
@@ -0,0 +1,43 @@
1
+ require 'httparty'
2
+
3
+ module PostmanMta
4
+ class ApiRequest
5
+ include ::HTTParty
6
+ base_uri PostmanMta.api_endpoint
7
+
8
+ attr_reader :request_type, :path, :options, :callback
9
+
10
+ def initialize(request_type, path, options = {})
11
+ @callback = PostmanMta.before_request_hook
12
+
13
+ @request_type = request_type
14
+ @path = path
15
+ @options = options
16
+ end
17
+
18
+ def perform
19
+ self.class.send(request_type.downcase, path, request_options)
20
+ end
21
+
22
+ private
23
+
24
+ def request_options
25
+ { headers: auth_headers, format: :json }.merge(merge_with_custom_options)
26
+ end
27
+
28
+ def auth_headers
29
+ PostmanMta::Utils::SignedRequest.new(request_method: request_type.upcase, path: path).headers
30
+ end
31
+
32
+ def merge_with_custom_options
33
+ return options unless callback
34
+
35
+ custom_options = callback.call
36
+ return options unless custom_options.is_a?(Hash)
37
+
38
+ options[:body] = (options[:body] || {}).merge(custom_options)
39
+
40
+ options
41
+ end
42
+ end
43
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PostmanMta
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postman_mta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Malinovskiy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-20 00:00:00.000000000 Z
11
+ date: 2017-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -139,6 +139,7 @@ files:
139
139
  - config/routes.rb
140
140
  - lib/postman_mta.rb
141
141
  - lib/postman_mta/api_client.rb
142
+ - lib/postman_mta/api_request.rb
142
143
  - lib/postman_mta/engine.rb
143
144
  - lib/postman_mta/utils/signature.rb
144
145
  - lib/postman_mta/utils/signed_request.rb