frontapp 0.0.7 → 0.0.11

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: c573ee9e41c505f7ae67d76e311ec2ec123c2867
4
- data.tar.gz: 74e59d6e4ad2da9222f73f306ba72c48c25c4c39
3
+ metadata.gz: 39e2a2ed37f421a9e27a5d093b6b8edfabefe858
4
+ data.tar.gz: 11239032440cc8d9d85fc008944180325ed8c0f0
5
5
  SHA512:
6
- metadata.gz: e4fc9da700dc96567f72b1560a11618223ca1a0b6e11a26dab0f16c69fbb6b65185e6d53573a6c90a1ac1ae3fa5c968a04a95c41a48c5b2dd9adddc680bc313c
7
- data.tar.gz: 898cc2bec4f83d88f4d7f2476a6fef5a1921532531bc06d1a30d91c9f8cdcddd6e47c3d012991570ef62e3c069cdef541c6f335f398ddd727b2734bc96168e9e
6
+ metadata.gz: 4dcb5247a8e1efc3b367fe0f71852eb4c1676a7544446f640abe791d6c0b5b33c0f5ae26208d9f320ac9b95bd015b9f0ea2d08928952485f19eb1cf010b7f40e
7
+ data.tar.gz: 026dad6c0c6fd6ad2f5cfab7cf943f8dcf17174704f3f9b261e8ce4256eb41aeb3141c53017f53ad672bc1400233d39fb5f47031d642183a8e8cf18f02cb0ffe
@@ -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'
@@ -14,6 +15,7 @@ require_relative 'client/tags.rb'
14
15
  require_relative 'client/teammates.rb'
15
16
  require_relative 'client/teams.rb'
16
17
  require_relative 'client/topics.rb'
18
+ require_relative 'client/links.rb'
17
19
  require_relative 'client/exports.rb'
18
20
  require_relative 'error'
19
21
  require_relative 'version'
@@ -21,6 +23,7 @@ require_relative 'version'
21
23
  module Frontapp
22
24
  class Client
23
25
 
26
+ include Frontapp::Client::Attachments
24
27
  include Frontapp::Client::Channels
25
28
  include Frontapp::Client::Comments
26
29
  include Frontapp::Client::ContactGroups
@@ -34,6 +37,7 @@ module Frontapp
34
37
  include Frontapp::Client::Teammates
35
38
  include Frontapp::Client::Teams
36
39
  include Frontapp::Client::Topics
40
+ include Frontapp::Client::Links
37
41
  include Frontapp::Client::Exports
38
42
 
39
43
  def initialize(options={})
@@ -76,6 +80,24 @@ module Frontapp
76
80
  JSON.parse(res.to_s)
77
81
  end
78
82
 
83
+ def get_plain(path)
84
+ headers_copy = @headers.dup
85
+ res = @headers.accept("text/plain").get("#{base_url}#{path}")
86
+ if !res.status.success?
87
+ raise Error.from_response(res)
88
+ end
89
+ res.to_s
90
+ end
91
+
92
+ def get_raw(path)
93
+ headers_copy = @headers.dup
94
+ res = @headers.get("#{base_url}#{path}")
95
+ if !res.status.success?
96
+ raise Error.from_response(res)
97
+ end
98
+ res
99
+ end
100
+
79
101
  def create(path, body)
80
102
  res = @headers.post("#{base_url}#{path}", json: body)
81
103
  response = JSON.parse(res.to_s)
@@ -114,13 +136,15 @@ module Frontapp
114
136
  res << q.map do |k, v|
115
137
  case v
116
138
  when Symbol, String
117
- "q[#{k}][]=#{URI.encode(v)}"
139
+ "q[#{k}]=#{URI.encode(v)}"
118
140
  when Array then
119
- v.map { |c| "q[#{k}][]=#{URI.encode(c)}" }.join("&")
141
+ v.map { |c| "q[#{k}][]=#{URI.encode(c.to_s)}" }.join("&")
142
+ else
143
+ "q[#{k}]=#{URI.encode(v.to_s)}"
120
144
  end
121
145
  end
122
146
  end
123
- res << params.map {|k,v| "#{k}=#{URI.encode(v)}"}
147
+ res << params.map {|k,v| "#{k}=#{URI.encode(v.to_s)}"}
124
148
  res.join("&")
125
149
  end
126
150
 
@@ -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
@@ -70,6 +70,29 @@ module Frontapp
70
70
  def get_conversation_messages(conversation_id)
71
71
  list("conversations/#{conversation_id}/messages")
72
72
  end
73
+
74
+ # Parameters
75
+ # Name Type Description
76
+ # ----------------------------------------------
77
+ # conversation_id string The conversation Id
78
+ # link_ids array (optional) Link IDs to add Either link_ids or link_external_urls must be specified but not both
79
+ # link_external_urls array (optional) Link external urls to add. Creates links if necessary. Either link_ids or link_external_urls must be specified but not both
80
+ # ----------------------------------------------
81
+ def add_conversation_links!(conversation_id, params = {})
82
+ cleaned = params.permit(:link_ids, :link_external_urls)
83
+ create_without_response("conversations/#{conversation_id}/links", cleaned)
84
+ end
85
+
86
+ # Parameters
87
+ # Name Type Description
88
+ # ----------------------------------------------
89
+ # conversation_id string The conversation Id
90
+ # link_ids array of strings link IDs to remove
91
+ # ----------------------------------------------
92
+ def remove_conversation_links!(conversation_id, params = {})
93
+ cleaned = params.permit(:link_ids)
94
+ delete("conversations/#{conversation_id}/links", cleaned)
95
+ end
73
96
  end
74
97
  end
75
- end
98
+ end
@@ -0,0 +1,64 @@
1
+ module Frontapp
2
+ class Client
3
+ module Links
4
+
5
+ def links(params = {})
6
+ cleaned = params.permit({ q: [:statuses] })
7
+ list("links", cleaned)
8
+ end
9
+
10
+ # Parameters
11
+ # Name Type Description
12
+ # -------------------------------
13
+ # link_id string Id of the requested link
14
+ # -------------------------------
15
+ def get_link(link_id)
16
+ get("links/#{link_id}")
17
+ end
18
+
19
+ # Allowed attributes:
20
+ # Name Type Description
21
+ # ------------------------------------
22
+ # name string (optional) Name of the link. If none is specified, the external_url is used as a default
23
+ # external_url string Underlying identifying link/url of the link
24
+ # ------------------------------------
25
+ def create_link!(params = {})
26
+ cleaned = params.permit(:name, :external_url)
27
+ create("links", cleaned)
28
+ end
29
+
30
+ # Parameters
31
+ # Name Type Description
32
+ # -----------------------------
33
+ # link_id string Id of the requested link
34
+ # -----------------------------
35
+ #
36
+ # Allowed attributes:
37
+ # Name Type Description
38
+ # ------------------------------------
39
+ # name string New name of the link
40
+ # ------------------------------------
41
+ def update_link!(link_id, params = {})
42
+ cleaned = params.permit(:name)
43
+ update("links/#{link_id}", cleaned)
44
+ end
45
+
46
+ # Parameters
47
+ # Name Type Description
48
+ # -----------------------------
49
+ # link_id string Id of the requested link
50
+ # -----------------------------
51
+ #
52
+ # Allowed params:
53
+ # Name Type Description
54
+ # ------------------------------------------
55
+ # q object (optional) Search query.
56
+ # q.statuses array (optional) List of the statuses of the conversations you want to list
57
+ # ------------------------------------------
58
+ def get_link_conversations(link_id, params = {})
59
+ cleaned = params.permit({ q: [:statuses] })
60
+ list("links/#{link_id}/conversations", cleaned)
61
+ end
62
+ end
63
+ end
64
+ 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
  # -------------------------------
@@ -15,9 +15,10 @@ module Frontapp
15
15
  # q.statuses array (optional) List of the statuses of the conversations you want to list
16
16
  # ------------------------------------------
17
17
  def get_topic_conversations(topic_id, params = {})
18
- cleaned = params.permit({ q: [:statuses] })
19
- list("topics/#{topic_id}/conversations", cleaned)
18
+ warn "[DEPRECATION] `Topics` is deprecated. Please use `Links` instead."
19
+
20
+ get_link_conversations(topic_id, params)
20
21
  end
21
22
  end
22
23
  end
23
- end
24
+ end
@@ -6,6 +6,7 @@ module Frontapp
6
6
  when 401 then UnauthorizedError
7
7
  when 404 then NotFoundError
8
8
  when 409 then ConflictError
9
+ when 429 then TooManyRequestsError
9
10
  else self
10
11
  end
11
12
  error_class.new(response)
@@ -21,4 +22,5 @@ module Frontapp
21
22
  class NotFoundError < Error; end
22
23
  class ConflictError < Error; end
23
24
  class UnauthorizedError < Error; end
25
+ class TooManyRequestsError < Error; end
24
26
  end
@@ -1,3 +1,3 @@
1
1
  module Frontapp
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.11"
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.7
4
+ version: 0.0.11
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
@@ -82,6 +83,7 @@ files:
82
83
  - lib/frontapp/client/events.rb
83
84
  - lib/frontapp/client/exports.rb
84
85
  - lib/frontapp/client/inboxes.rb
86
+ - lib/frontapp/client/links.rb
85
87
  - lib/frontapp/client/messages.rb
86
88
  - lib/frontapp/client/rules.rb
87
89
  - lib/frontapp/client/tags.rb