frontapp 0.0.5 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e74de615d1ace8618f995ce0726d5bfd7c04db4a
4
- data.tar.gz: 75e276ab77531bfa9b62f06133d6c9a4f5d1aa57
3
+ metadata.gz: 0b7ef8cbd97c8e2e8ea8e9688e0bfabdc7f6a5c9
4
+ data.tar.gz: a527bdfcd864d6d2bd086d6c0e4c063f7d21e46b
5
5
  SHA512:
6
- metadata.gz: cff32f334a4226301d08f8e35f84e22c43e490bfbd50dae690726130a84d4db21626a63369fa9edb4352d9e5688480d165dbdb4092ec2c7c2b604e710e7373e5
7
- data.tar.gz: 5bda12ca94202746d869934855e0fb979aea48eef57c0c95f502963b0f07f7e4ffe2a74b1fbf3f387fc8f94b7477d984dcbe9374d36bc7bfe48c0040ac1c7296
6
+ metadata.gz: 6a4ff932cc6d255323210d38cb9fe1a40d56af5101920d3f03299412efa50417e16b3ea3cc00237f36ec4875b95f3aeb8fa00686228ce49a3f91700f04805e97
7
+ data.tar.gz: 88a1cf071c6e3e202e18efb24660d36d301b8fdd5ac6cd5323342f9c56466a9e33173bd13b1eccd4f9389c75c1c82e7238915835bf1fc23ede98f2577c535d16
@@ -1,6 +1,7 @@
1
1
  require 'uri'
2
2
  require 'http'
3
3
  require 'json'
4
+ require_relative 'client/attachments.rb'
4
5
  require_relative 'client/channels.rb'
5
6
  require_relative 'client/comments.rb'
6
7
  require_relative 'client/contact_groups.rb'
@@ -21,6 +22,7 @@ require_relative 'version'
21
22
  module Frontapp
22
23
  class Client
23
24
 
25
+ include Frontapp::Client::Attachments
24
26
  include Frontapp::Client::Channels
25
27
  include Frontapp::Client::Comments
26
28
  include Frontapp::Client::ContactGroups
@@ -53,6 +55,9 @@ module Frontapp
53
55
  url = "#{base_url}#{path}?#{query}"
54
56
  until last_page
55
57
  res = @headers.get(url)
58
+ if !res.status.success?
59
+ raise Error.from_response(res)
60
+ end
56
61
  response = JSON.parse(res.to_s)
57
62
  items.concat(response["_results"]) if response["_results"]
58
63
  pagination = response["_pagination"]
@@ -73,6 +78,24 @@ module Frontapp
73
78
  JSON.parse(res.to_s)
74
79
  end
75
80
 
81
+ def get_plain(path)
82
+ headers_copy = @headers.dup
83
+ res = @headers.accept("text/plain").get("#{base_url}#{path}")
84
+ if !res.status.success?
85
+ raise Error.from_response(res)
86
+ end
87
+ res.to_s
88
+ end
89
+
90
+ def get_raw(path)
91
+ headers_copy = @headers.dup
92
+ res = @headers.get("#{base_url}#{path}")
93
+ if !res.status.success?
94
+ raise Error.from_response(res)
95
+ end
96
+ res
97
+ end
98
+
76
99
  def create(path, body)
77
100
  res = @headers.post("#{base_url}#{path}", json: body)
78
101
  response = JSON.parse(res.to_s)
@@ -111,13 +134,15 @@ module Frontapp
111
134
  res << q.map do |k, v|
112
135
  case v
113
136
  when Symbol, String
114
- "q[#{k}][]=#{URI.encode(v)}"
137
+ "q[#{k}]=#{URI.encode(v)}"
115
138
  when Array then
116
- v.map { |c| "q[#{k}][]=#{URI.encode(c)}" }.join("&")
139
+ v.map { |c| "q[#{k}][]=#{URI.encode(c.to_s)}" }.join("&")
140
+ else
141
+ "q[#{k}]=#{URI.encode(v.to_s)}"
117
142
  end
118
143
  end
119
144
  end
120
- res << params.map {|k,v| "#{k}=#{URI.encode(v)}"}
145
+ res << params.map {|k,v| "#{k}=#{URI.encode(v.to_s)}"}
121
146
  res.join("&")
122
147
  end
123
148
 
@@ -0,0 +1,15 @@
1
+ module Frontapp
2
+ class Client
3
+ module Attachments
4
+
5
+ # Parameters
6
+ # Name Type Description
7
+ # ----------------------------------------------------------
8
+ # attachment_link_id string Id of the requested attachment
9
+ # ----------------------------------------------------------
10
+ def download_attachment(attachment_link_id)
11
+ get_raw("download/#{attachment_link_id}")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -10,7 +10,17 @@ module Frontapp
10
10
  def get_message(message_id)
11
11
  get("messages/#{message_id}")
12
12
  end
13
-
13
+
14
+ # Parameters
15
+ # Name Type Description
16
+ # -------------------------------
17
+ # message_id string Id of the requested message
18
+ # -------------------------------
19
+ def get_message_source(message_id)
20
+ get_plain("messages/#{message_id}").b
21
+ # .b sets encoding to ASCII-8BIT, which is safer for raw emails than UTF-8
22
+ end
23
+
14
24
  # Parameters
15
25
  # Name Type Description
16
26
  # -------------------------------
@@ -41,6 +41,16 @@ module Frontapp
41
41
  cleaned = params.permit({ q: [:statuses] })
42
42
  list("tags/#{tag_id}/conversations", cleaned)
43
43
  end
44
+
45
+ # Parameters
46
+ # Name Type Description
47
+ # ---------------------------
48
+ # tag_id string Id of the requested tag
49
+ # ---------------------------
50
+ def delete_tag!(tag_id)
51
+ delete("tags/#{tag_id}")
52
+ end
53
+
44
54
  end
45
55
  end
46
56
  end
@@ -3,9 +3,11 @@ module Frontapp
3
3
  def self.from_response(response)
4
4
  error_class = case response.status
5
5
  when 400 then BadRequestError
6
+ when 401 then UnauthorizedError
6
7
  when 404 then NotFoundError
7
8
  when 409 then ConflictError
8
- else self.class
9
+ when 429 then TooManyRequestsError
10
+ else self
9
11
  end
10
12
  error_class.new(response)
11
13
  end
@@ -19,4 +21,6 @@ module Frontapp
19
21
  class BadRequestError < Error; end
20
22
  class NotFoundError < Error; end
21
23
  class ConflictError < Error; end
24
+ class UnauthorizedError < Error; end
25
+ class TooManyRequestsError < Error; end
22
26
  end
@@ -1,3 +1,3 @@
1
1
  module Frontapp
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.10"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frontapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niels van der Zanden
@@ -74,6 +74,7 @@ extra_rdoc_files: []
74
74
  files:
75
75
  - lib/frontapp.rb
76
76
  - lib/frontapp/client.rb
77
+ - lib/frontapp/client/attachments.rb
77
78
  - lib/frontapp/client/channels.rb
78
79
  - lib/frontapp/client/comments.rb
79
80
  - lib/frontapp/client/contact_groups.rb