frontapp 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f3e435b63630c56d64d442d07157db616154e354
4
+ data.tar.gz: 42a573b784d7888ab23cb8262315403b7215d1b8
5
+ SHA512:
6
+ metadata.gz: 5050cb6fb326a571606ab64594e4863b93112392cffb0d20c0843d7ec105756dc058ca865a93d4ce4abc995996bd75c6614022f4f3ae5663b94831675ef0da9b
7
+ data.tar.gz: d76fe968f65a4d7ea0e72771d3cf72c3f94adc4327e685369358f60e23b2617df8cbdcfca80fa86147dea30a2ce6f9decf1ff49ed97113921681127d0b887ead
@@ -0,0 +1,5 @@
1
+ require_relative 'frontapp/utils/hash.rb'
2
+ require_relative 'frontapp/client.rb'
3
+ require 'openssl'
4
+ require 'http'
5
+ require 'json'
@@ -0,0 +1,116 @@
1
+ require 'uri'
2
+ require 'http'
3
+ require 'json'
4
+ require_relative 'client/channels.rb'
5
+ require_relative 'client/comments.rb'
6
+ require_relative 'client/contact_groups.rb'
7
+ require_relative 'client/contacts.rb'
8
+ require_relative 'client/conversations.rb'
9
+ require_relative 'client/events.rb'
10
+ require_relative 'client/inboxes.rb'
11
+ require_relative 'client/messages.rb'
12
+ require_relative 'client/rules.rb'
13
+ require_relative 'client/tags.rb'
14
+ require_relative 'client/teammates.rb'
15
+
16
+ module Frontapp
17
+ class Client
18
+
19
+ include Frontapp::Client::Channels
20
+ include Frontapp::Client::Comments
21
+ include Frontapp::Client::ContactGroups
22
+ include Frontapp::Client::Contacts
23
+ include Frontapp::Client::Conversations
24
+ include Frontapp::Client::Events
25
+ include Frontapp::Client::Inboxes
26
+ include Frontapp::Client::Messages
27
+ include Frontapp::Client::Rules
28
+ include Frontapp::Client::Tags
29
+ include Frontapp::Client::Teammates
30
+
31
+ def initialize(options={})
32
+ auth_token = options[:auth_token]
33
+ @headers = HTTP.headers({
34
+ Accept: "application/json",
35
+ Authorization: "Bearer #{auth_token}"
36
+ })
37
+ end
38
+
39
+ def list(path, params = {})
40
+ items = []
41
+ last_page = false
42
+ query = format_query(params)
43
+ url = "#{base_url}#{path}?#{query}"
44
+ until last_page
45
+ res = @headers.get(url)
46
+ response = JSON.parse(res.to_s)
47
+ items.concat(response["_results"]) if response["_results"]
48
+ pagination = response["_pagination"]
49
+ if pagination.nil? || pagination["next"].nil?
50
+ last_page = true
51
+ else
52
+ url = pagination["next"]
53
+ end
54
+ end
55
+ items
56
+ end
57
+
58
+ def get(path)
59
+ res = @headers.get("#{base_url}#{path}")
60
+ JSON.parse(res.to_s)
61
+ end
62
+
63
+ def create(path, body)
64
+ res = @headers.post("#{base_url}#{path}", json: body)
65
+ response = JSON.parse(res.to_s)
66
+ if !res.status.success?
67
+ raise "Response: #{res.inspect}\n Body: #{res.body}\nRequest: #{body.to_json.inspect}"
68
+ end
69
+ response
70
+ end
71
+
72
+ def create_without_response(path, body)
73
+ res = @headers.post("#{base_url}#{path}", json: body)
74
+ if !res.status.success?
75
+ raise "Response: #{res.inspect}\n Body: #{res.body}\nRequest: #{body.to_json.inspect}"
76
+ end
77
+ end
78
+
79
+ def update(path, body)
80
+ res = @headers.patch("#{base_url}#{path}", json: body)
81
+ if !res.status.success?
82
+ raise "Response: #{res.inspect}\n Body: #{res.body}\nRequest: #{body.to_json.inspect}"
83
+ end
84
+ end
85
+
86
+ def delete(path, body = {})
87
+ res = @headers.delete("#{base_url}#{path}", json: body)
88
+ if !res.status.success?
89
+ raise "Response: #{res.inspect}\n Body: #{res.body}\nRequest: #{body.to_json.inspect}"
90
+ end
91
+ end
92
+
93
+ private
94
+ def format_query(params)
95
+ res = []
96
+ q = params.delete(:q)
97
+ if q && q.is_a?(Hash)
98
+ res << q.map do |k, v|
99
+ case v
100
+ when Symbol, String
101
+ "q[#{k}][]=#{URI.encode(v)}"
102
+ when Array then
103
+ v.map { |c| "q[#{k}][]=#{URI.encode(c)}" }.join("&")
104
+ end
105
+ end
106
+ end
107
+ res << params.map {|k,v| "#{k}=#{URI.encode(v)}"}
108
+ res.join("&")
109
+ end
110
+
111
+ def base_url
112
+ "https://api2.frontapp.com/"
113
+ end
114
+
115
+ end
116
+ end
@@ -0,0 +1,68 @@
1
+ module Frontapp
2
+ class Client
3
+ module Channels
4
+
5
+ def channels(params = {})
6
+ list("channels", params)
7
+ end
8
+
9
+ # Parameters
10
+ # Name Type Description
11
+ # -------------------------------
12
+ # channel_id string Id of the requested channel
13
+ # -------------------------------
14
+ def get_channel(channel_id)
15
+ get("channels/#{channel_id}")
16
+ end
17
+
18
+ # Only custom channels can be updated through the api!
19
+ #
20
+ # Parameters
21
+ # Name Type Description
22
+ # -------------------------------
23
+ # channel_id string Id of the requested channel
24
+ # -------------------------------
25
+ #
26
+ # Allowed attributes:
27
+ # Name Type Description
28
+ # ---------------------------------------------------
29
+ # settings object
30
+ # settings.webhook_url string (optional) custom type only. URL to which will be sent the replies of a custom message.
31
+ # ---------------------------------------------------
32
+ def update_channel!(channel_id, params = {})
33
+ cleaned = params.permit({ settings: [:webhook_url] })
34
+ update("channels/#{channel_id}", cleaned)
35
+ end
36
+
37
+ # Only custom channels can be created through the api!
38
+ #
39
+ # Parameters
40
+ # Name Type Description
41
+ # -----------------------------
42
+ # inbox_id string Id of the inbox into which the channel messages will go
43
+ # -----------------------------
44
+ #
45
+ # Allowed attributes:
46
+ # Name Type Description
47
+ # ----------------------------------------------------
48
+ # type enum Type of the channel.
49
+ # settings object
50
+ # settings.webhook_url string (optional) custom type only. URL to which will be sent the replies of a custom message.
51
+ # ----------------------------------------------------
52
+ def create_channel!(inbox_id, params = {})
53
+ cleaned = params.permit(:type, { settings: [:webhook_url] })
54
+ create("inboxes/#{inbox_id}/channels", cleaned)
55
+ end
56
+
57
+ # Parameters
58
+ # Name Type Description
59
+ # -------------------------------
60
+ # channel_id string Id of the requested channel
61
+ # -------------------------------
62
+ def get_channel_inbox(channel_id)
63
+ get("channels/#{channel_id}/inbox")
64
+ end
65
+
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,51 @@
1
+ module Frontapp
2
+ class Client
3
+ module Comments
4
+
5
+ # Parameters
6
+ # Name Type Description
7
+ # ------------------------------------
8
+ # conversation_id string Id of the requested conversation
9
+ # ------------------------------------
10
+ #
11
+ # Allowed attributes:
12
+ # Name Type Description
13
+ # ------------------------------
14
+ # author_id string Id of the teammate creating the comment
15
+ # body string Content of the comment
16
+ # ------------------------------
17
+ def create_comment!(conversation_id, params = {})
18
+ cleaned = params.permit(:author_id,:body)
19
+ create("conversations/#{conversation_id}/comments", cleaned)
20
+ end
21
+
22
+ # Parameters
23
+ # Name Type Description
24
+ # ------------------------------------
25
+ # conversation_id string Id of the requested conversation
26
+ # ------------------------------------
27
+ def get_conversation_comments(conversation_id)
28
+ list("conversations/#{conversation_id}/comments")
29
+ end
30
+
31
+ # Parameters
32
+ # Name Type Description
33
+ # -------------------------------
34
+ # comment_id string Id of the requested comment
35
+ # -------------------------------
36
+ def get_comment(comment_id)
37
+ get("comments/#{comment_id}")
38
+ end
39
+
40
+ # Parameters
41
+ # Name Type Description
42
+ # -------------------------------
43
+ # comment_id string Id of the requested comment
44
+ # -------------------------------
45
+ def get_comment_mentions(comment_id)
46
+ get("comments/#{comment_id}/mentions")
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,55 @@
1
+ module Frontapp
2
+ class Client
3
+ module ContactGroups
4
+
5
+ def contact_groups(params = {})
6
+ list("contact_groups", params)
7
+ end
8
+
9
+ # Allowed attributes:
10
+ # Name Type Description
11
+ # -------------------------------------------
12
+ # name string Name of the group
13
+ # -------------------------------------------
14
+ def create_contact_group!(params = {})
15
+ cleaned = params.permit(:name)
16
+ create("contact_groups", cleaned)
17
+ end
18
+
19
+ # Parameters
20
+ # Name Type Description
21
+ # -------------------------------
22
+ # group_id string Id of the requested group
23
+ # -------------------------------
24
+ def delete_contact_group!(group_id)
25
+ delete("contact_groups/#{group_id}")
26
+ end
27
+
28
+
29
+ # Parameters
30
+ # Name Type Description
31
+ # -------------------------------
32
+ # group_id string Id of the requested group
33
+ # -------------------------------
34
+ def get_contact_group_contacts(group_id)
35
+ get("contact_groups/#{group_id}/contacts")
36
+ end
37
+
38
+ # Parameters
39
+ # Name Type Description
40
+ # -------------------------------
41
+ # group_id string Id of the requested group
42
+ # -------------------------------
43
+ #
44
+ # Allowed attributes:
45
+ # Name Type Description
46
+ # --------------------------------------------
47
+ # contact_ids array List of ids or aliases of the contacts to add in the requested group
48
+ # --------------------------------------------
49
+ def add_contacts_to_contact_group!(group_id, params = {})
50
+ cleaned = params.permit(:contact_ids)
51
+ create_without_response("contact_groups/#{group_id}/contacts", cleaned)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,153 @@
1
+ module Frontapp
2
+ class Client
3
+ module Contacts
4
+
5
+ def contacts(params = {})
6
+ list("contacts", params)
7
+ end
8
+
9
+ # Parameters
10
+ # Name Type Description
11
+ # -------------------------------
12
+ # contact_id string Id or alias of the requested contact
13
+ # -------------------------------
14
+ def get_contact(contact_id)
15
+ get("contacts/#{contact_id}")
16
+ end
17
+
18
+ # Parameters
19
+ # Name Type Description
20
+ # -------------------------------
21
+ # contact_id string Id or alias of the requested contact
22
+ # -------------------------------
23
+ #
24
+ # Allowed attributes:
25
+ # Name Type Description
26
+ # --------------------------------------------
27
+ # name string (optional) Contact name
28
+ # description string (optional) Contact description
29
+ # avatar_url string (optional) URL of the contact’s avatar
30
+ # is_spammer boolean (optional) Whether or not the contact is marked as a spammer
31
+ # links array (optional) List of all the links of the contact
32
+ # group_names array (optional) List of all the group names the contact belongs to. It will automatically create missing groups.
33
+ # --------------------------------------------
34
+ def update_contact!(contact_id, params = {})
35
+ cleaned = params.permit(:name,
36
+ :description,
37
+ :avatar_url,
38
+ :is_spammer,
39
+ :links,
40
+ :group_names)
41
+ update("contacts/#{contact_id}", cleaned)
42
+ end
43
+
44
+ # Allowed attributes:
45
+ # Name Type Description
46
+ # --------------------------------------------
47
+ # name string (optional) Contact name
48
+ # description string (optional) Contact description
49
+ # avatar_url string (optional) URL of the contact’s avatar
50
+ # is_spammer boolean (optional) Whether or not the contact is marked as a spammer
51
+ # links array (optional) List of all the links of the contact
52
+ # group_names array (optional) List of all the group names the contact belongs to. It will automatically create missing groups.
53
+ # handles array List
54
+ # --------------------------------------------
55
+ def create_contact!(params = {})
56
+ cleaned = params.permit(:name,
57
+ :description,
58
+ :avatar_url,
59
+ :is_spammer,
60
+ :links,
61
+ :group_names,
62
+ :handles)
63
+ create("contacts", cleaned)
64
+ end
65
+
66
+ # Name Type Description
67
+ # -------------------------------
68
+ # contact_id string Id or alias of the requested contact
69
+ # -------------------------------
70
+ def delete_contact!(contact_id)
71
+ delete("contacts/#{contact_id}")
72
+ end
73
+
74
+ # Parameters
75
+ # Name Type Description
76
+ # -------------------------------
77
+ # contact_id string Id or alias of the requested contact
78
+ # -------------------------------
79
+ #
80
+ # Allowed params:
81
+ # Name Type Description
82
+ # ----------------------------------------------
83
+ # q object (optional) Search query.
84
+ # q.statuses array (optional) List of the statuses of the conversations you want to list
85
+ # ----------------------------------------------
86
+ def get_contact_conversations(contact_id, params = {})
87
+ cleaned = params.permit({ q: [:statuses] })
88
+ list("contacts/#{contact_id}/conversations", cleaned)
89
+ end
90
+
91
+ # Parameters
92
+ # Name Type Description
93
+ # -------------------------------
94
+ # contact_id string Id or alias of the requested contact
95
+ # -------------------------------
96
+ #
97
+ # Allowed attributes:
98
+ # Name Type Description
99
+ # ---------------------------
100
+ # handle string Handle used to reach the contact. Can be an email address, a twitter, handle, a phone number, …
101
+ # source enum Can be 'twitter’, 'email’ or 'phone’.
102
+ # ---------------------------
103
+ def add_contact_handle!(contact_id, params = {})
104
+ cleaned = params.permit(:handle, :source)
105
+ create_without_response("contacts/#{contact_id}/handles", cleaned)
106
+ end
107
+
108
+ # Parameters
109
+ # Name Type Description
110
+ # -------------------------------
111
+ # contact_id string Id or alias of the requested contact
112
+ # -------------------------------
113
+ #
114
+ # Allowed attributes:
115
+ # Name Type Description
116
+ # ---------------------------
117
+ # handle string Handle used to reach the contact. Can be an email address, a twitter, handle, a phone number, …
118
+ # source enum Can be 'twitter’, 'email’ or 'phone’.
119
+ # ---------------------------
120
+ def delete_contact_handle!(contact_id, params = {})
121
+ cleaned = params.permit(:handle, :source)
122
+ delete("contacts/#{contact_id}/handles", cleaned)
123
+ end
124
+
125
+ # Parameters
126
+ # Name Type Description
127
+ # -------------------------------
128
+ # contact_id string Id or alias of the requested contact
129
+ # -------------------------------
130
+ def get_contact_notes(contact_id)
131
+ list("contacts/#{contact_id}/notes")
132
+ end
133
+
134
+ # Parameters
135
+ # Name Type Description
136
+ # -------------------------------
137
+ # contact_id string Id or alias of the requested contact
138
+ # -------------------------------
139
+ #
140
+ # Allowed attributes:
141
+ # Name Type Description
142
+ # ------------------------------
143
+ # author_id string Id of the teammate creating the note
144
+ # body string Content of the note
145
+ # ------------------------------
146
+ def add_contact_note!(contact_id, params = {})
147
+ cleaned = params.permit(:author_id, :body)
148
+ create("contacts/#{contact_id}/notes", cleaned)
149
+ end
150
+
151
+ end
152
+ end
153
+ end
@@ -0,0 +1,74 @@
1
+ module Frontapp
2
+ class Client
3
+ module Conversations
4
+
5
+ def conversations(params = {})
6
+ list("conversations", params)
7
+ end
8
+
9
+ # Parameters
10
+ # Name Type Description
11
+ # ------------------------------------
12
+ # conversation_id string Id of the requested conversation
13
+ # ------------------------------------
14
+ def get_conversation(conversation_id)
15
+ get("conversations/#{conversation_id}")
16
+ end
17
+
18
+ # Parameters
19
+ # Name Type Description
20
+ # ------------------------------------
21
+ # conversation_id string Id of the requested conversation
22
+ # ------------------------------------
23
+ #
24
+ # Allowed attributes:
25
+ # Name Type Description
26
+ # ---------------------------------------------
27
+ # assignee_id string (optional) ID of the teammate to assign the conversation to. Set it to null to unassign.
28
+ # status enum (optional) New status of the conversation
29
+ # tags array (optional) List of all the tag names replacing the old conversation tags
30
+ # ---------------------------------------------
31
+ # The assignee id is their Frontapp handle, e.g. @username
32
+ def update_conversation!(conversation_id, params = {})
33
+ cleaned = params.permit(:assignee_id, :status, :tags)
34
+ update("conversations/#{conversation_id}", cleaned)
35
+ end
36
+
37
+ # Parameters
38
+ # Name Type Description
39
+ # --------------------------------
40
+ # conversation_id string Id or email of the requested conversation
41
+ # --------------------------------
42
+ def get_conversation_inboxes(conversation_id)
43
+ get("conversations/#{conversation_id}/inboxes")
44
+ end
45
+
46
+ # Parameters
47
+ # Name Type Description
48
+ # --------------------------------
49
+ # conversation_id string Id or email of the requested conversation
50
+ # --------------------------------
51
+ def get_conversation_followers(conversation_id)
52
+ get("conversations/#{conversation_id}/followers")
53
+ end
54
+
55
+ # Parameters
56
+ # Name Type Description
57
+ # --------------------------------
58
+ # conversation_id string Id or email of the requested conversation
59
+ # --------------------------------
60
+ def get_conversation_events(conversation_id)
61
+ list("conversations/#{conversation_id}/events")
62
+ end
63
+
64
+ # Parameters
65
+ # Name Type Description
66
+ # --------------------------------
67
+ # conversation_id string Id or email of the requested conversation
68
+ # --------------------------------
69
+ def get_conversation_messages(conversation_id)
70
+ list("conversations/#{conversation_id}/messages")
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,20 @@
1
+ module Frontapp
2
+ class Client
3
+ module Events
4
+
5
+ def events(params = {})
6
+ list("events", params)
7
+ end
8
+
9
+ # Parameters
10
+ # Name Type Description
11
+ # -----------------------------
12
+ # event_id string Id of the requested event
13
+ # -----------------------------
14
+ def get_event(event_id)
15
+ get("events/#{event_id}")
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,66 @@
1
+ module Frontapp
2
+ class Client
3
+ module Inboxes
4
+
5
+ def inboxes(params = {})
6
+ list("inboxes", params)
7
+ end
8
+
9
+ # Parameters
10
+ # Name Type Description
11
+ # -----------------------------
12
+ # inbox_id string Id of the requested inbox
13
+ # -----------------------------
14
+ def get_inbox(inbox_id)
15
+ get("inboxes/#{inbox_id}")
16
+ end
17
+
18
+ # Allowed attributes:
19
+ # Name Type Description
20
+ # -------------------------------------------
21
+ # name string Name of the inbox
22
+ # teammate_ids array (optional) List of all the teammate ids who will have access to this inbox. If omitted, it will automatically select all the administrators in your company.
23
+ # -------------------------------------------
24
+ def create_inbox!(params = {})
25
+ cleaned = params.permit(:name, :teammate_ids)
26
+ create("inboxes", cleaned)
27
+ end
28
+
29
+ # Parameters
30
+ # Name Type Description
31
+ # -----------------------------
32
+ # inbox_id string Id of the requested inbox
33
+ # -----------------------------
34
+ def get_inbox_channels(inbox_id)
35
+ get("inboxes/#{inbox_id}/channels")
36
+ end
37
+
38
+ # Parameters
39
+ # Name Type Description
40
+ # -----------------------------
41
+ # inbox_id string Id of the requested inbox
42
+ # -----------------------------
43
+ #
44
+ # Allowed attributes:
45
+ # Name Type Description
46
+ # ----------------------------------------------
47
+ # q object (optional) Search query.
48
+ # q.statuses array (optional) List of the statuses of the conversations you want to list
49
+ # ----------------------------------------------
50
+ def get_inbox_conversations(inbox_id, params = {})
51
+ cleaned = params.permit({ q: [:statuses] })
52
+ list("inboxes/#{inbox_id}/conversations", cleaned)
53
+ end
54
+
55
+ # Parameters
56
+ # Name Type Description
57
+ # -----------------------------
58
+ # inbox_id string Id of the requested inbox
59
+ # -----------------------------
60
+ def get_inbox_teammates(inbox_id)
61
+ get("inboxes/#{inbox_id}/teammates")
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,157 @@
1
+ module Frontapp
2
+ class Client
3
+ module Messages
4
+
5
+ # Parameters
6
+ # Name Type Description
7
+ # -------------------------------
8
+ # message_id string Id of the requested message
9
+ # -------------------------------
10
+ def get_message(message_id)
11
+ get("messages/#{message_id}")
12
+ end
13
+
14
+ # Parameters
15
+ # Name Type Description
16
+ # -------------------------------
17
+ # channel_id string Id or address of the channel from which to send the message
18
+ # -------------------------------
19
+ #
20
+ # Allowed attributes:
21
+ # Name Type Description
22
+ # ------------------------------------------------
23
+ # author_id string (optional) Id of the teammate on behalf of whom the answer is sent
24
+ # subject string (optional) Subject of the message for email message
25
+ # body string Body of the message
26
+ # text string (optional) Text version of the body for messages with non-text body
27
+ # options object (optional) Sending options
28
+ # options.tags array (optional) List of tag names to add to the conversation (unknown tags will automatically be created)
29
+ # options.archive boolean (optional) Archive the conversation right when sending the reply (Default: true)
30
+ # to array List of the recipient handles who will receive this message
31
+ # cc array (optional) List of the recipient handles who will receive a copy of this message
32
+ # bcc array (optional) List of the recipient handles who will receive a blind copy of this message
33
+ # ------------------------------------------------
34
+ def send_message(channel_id, params)
35
+ cleaned = params.permit(:author_id,
36
+ :subject,
37
+ :body,
38
+ :text,
39
+ { options: [:tags, :archive] },
40
+ :to,
41
+ :cc,
42
+ :bcc)
43
+ create("channels/#{channel_id}/messages", cleaned)
44
+ end
45
+
46
+ # Parameters
47
+ # Name Type Description
48
+ # ------------------------------------
49
+ # conversation_id string Id of the conversation
50
+ # ------------------------------------
51
+ #
52
+ # Allowed attributes:
53
+ # Name Type Description
54
+ # ------------------------------------------------
55
+ # author_id string (optional) ID of the teammate on behalf of whom the answer is sent
56
+ # subject string (optional) Subject of the message for email message
57
+ # body string Body of the message
58
+ # text string (optional) Text version of the body for messages with non-text body
59
+ # options object (optional) Sending options
60
+ # options.tags array (optional) List of tag names to add to the conversation (unknown tags will automatically be created)
61
+ # options.archive boolean (optional) Archive the conversation right when sending the reply (Default: true)
62
+ # channel_id string (optional) Channel through which to send the message. Defaults to the original conversation channel. For imported messages or messages received on multiple channels, you MUST specify a channel ID.
63
+ # to array (optional) List of the recipient handles who will receive this message. By default it will use the recipients of the last received message.
64
+ # cc array (optional) List of the recipient handles who will receive a copy of this message. By default it will use the cc'ed recipients of the last received message.
65
+ # bcc array (optional) List of the recipient handles who will receive a blind copy of this message
66
+ # ------------------------------------------------
67
+ def send_reply(conversation_id, params)
68
+ cleaned = params.permit(:author_id,
69
+ :subject,
70
+ :body,
71
+ :text,
72
+ { options: [:tags, :archive] },
73
+ :channel_id,
74
+ :to,
75
+ :cc,
76
+ :bcc)
77
+ create_without_response("conversations/#{conversation_id}/messages", cleaned)
78
+ end
79
+
80
+ # Parameters
81
+ # Name Type Description
82
+ # ------------------------------------
83
+ # channel_id string Id of the requested custom channel
84
+ # ------------------------------------
85
+ #
86
+ # Allowed attributes:
87
+ # Name Type Description
88
+ # ----------------------------------------------------
89
+ # sender object Data of the sender
90
+ # sender.contact_id string (optional) ID of the contact in Front corresponding to the sender
91
+ # sender.name string (optional) Name of the sender
92
+ # sender.handle string Handle of the sender. It can be any string used to uniquely identify the sender
93
+ # subject string (optional) Subject of the message
94
+ # body string Body of the message
95
+ # body_format enum (optional) Format of the message body. (Default: 'markdown')
96
+ # metadata object (optional)
97
+ # metadata.thread_ref string (optional) Custom reference which will be used to thread messages. If you ommit this field, we’ll thread by sender instead
98
+ # metadata.headers object (optional) Custom object where any internal information can be stored
99
+ # ----------------------------------------------------
100
+ def receive_custom_message(channel_id, params)
101
+ cleaned = params.permit({ sender: [:contact_id, :name, :handle] },
102
+ :subject,
103
+ :body,
104
+ :body_format,
105
+ { metadata: [:thread_ref, :headers] })
106
+ create("channels/#{channel_id}/incoming_messages", cleaned)
107
+ end
108
+
109
+ # Parameters
110
+ # Name Type Description
111
+ # -----------------------------
112
+ # inbox_id string Id of the inbox into which the message should be append.
113
+ # -----------------------------
114
+ #
115
+ # Allowed attributes:
116
+ # Name Type Description
117
+ # -----------------------------------------------------------
118
+ # sender object
119
+ # sender.handle string Handle used to reach the contact. Can be an email address, a twitter, handle, a phone number, …
120
+ # sender.name string (optional) Name of the contact.
121
+ # sender.author_id string (optional) Id of the teammate who is the author of the message. Ignored if the message is inbound.
122
+ # to array List of recipient handles who received the message.
123
+ # cc array (optional) List of recipient handles who received a copy of the message.
124
+ # bcc array (optional) List of the recipeient handles who received a blind copy of the message.
125
+ # subject string (optional) Subject of the message.
126
+ # body string Body of the message.
127
+ # body_format enum (optional) Format of the message body. Ignored if the message type is not email. (Default: 'markdown')
128
+ # external_id string External identifier of the message. Front won’t import two messages with the same external ID.
129
+ # created_at number Date at which the message as been sent or received.
130
+ # type enum (optional) Type of the message to import. (Default: 'email')
131
+ # assignee_id string (optional) Id of the teammate who will be assigned to the conversation.
132
+ # tags array (optional) List of tag names to add to the conversation (unknown tags will automatically be created).
133
+ # metadata object
134
+ # metadata.thread_ref string (optional) Custom reference which will be used to thread messages. If you ommit this field, we’ll thread by sender instead.
135
+ # metadata.is_inbound boolean Whether or not the message is received (inbound) or sent (outbound) by you.
136
+ # metadata.is_archived boolean (optional) Whether or not the message should be directly archived once imported. (Default: true)
137
+ # metadata.should_skip_rules boolean (optional) Whether or not the rules should apply to this message. (Default: true)
138
+ # -----------------------------------------------------------
139
+ def import_message(inbox_id, params)
140
+ cleaned = params.permit({ sender: [:handle, :name, :author_id] },
141
+ :to,
142
+ :cc,
143
+ :bcc,
144
+ :subject,
145
+ :body,
146
+ :body_format,
147
+ :external_id,
148
+ :created_at,
149
+ :type,
150
+ :assignee_id,
151
+ :tags,
152
+ { metadata: [:thread_ref, :is_inbound, :is_archived, :should_skip_rules] })
153
+ create("inboxes/#{inbox_id}/imported_messages", cleaned)
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,20 @@
1
+ module Frontapp
2
+ class Client
3
+ module Rules
4
+
5
+ def rules(params = {})
6
+ list("rules", params)
7
+ end
8
+
9
+ # Parameters
10
+ # Name Type Description
11
+ # ----------------------------
12
+ # rule_id string Id of the requested rule
13
+ # ----------------------------
14
+ def get_rule(rule_id)
15
+ get("rules/#{rule_id}")
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,46 @@
1
+ module Frontapp
2
+ class Client
3
+ module Tags
4
+
5
+ def tags(params = {})
6
+ list("tags", params)
7
+ end
8
+
9
+ # Parameters
10
+ # Name Type Description
11
+ # ---------------------------
12
+ # tag_id string Id of the requested tag
13
+ # ---------------------------
14
+ def get_tag(tag_id)
15
+ get("tags/#{tag_id}")
16
+ end
17
+
18
+ # Allowed attributes:
19
+ # Name Type Description
20
+ # -------------------------
21
+ # name string Name of the tag to create
22
+ # -------------------------
23
+ def create_tag!(params = {})
24
+ cleaned = params.permit(:name)
25
+ create("tags", cleaned)
26
+ end
27
+
28
+ # Parameters
29
+ # Name Type Description
30
+ # ---------------------------
31
+ # tag_id string Id of the requested tag
32
+ # ---------------------------
33
+ #
34
+ # Allowed params:
35
+ # Name Type Description
36
+ # ----------------------------------------------
37
+ # q object (optional) Search query.
38
+ # q.statuses array (optional) List of the statuses of the conversations you want to list
39
+ # ----------------------------------------------
40
+ def get_tag_conversations(tag_id, params = {})
41
+ cleaned = params.permit({ q: [:statuses] })
42
+ list("tags/#{tag_id}/conversations", cleaned)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,66 @@
1
+ module Frontapp
2
+ class Client
3
+ module Teammates
4
+
5
+ def teammates(params = {})
6
+ list("teammates", params)
7
+ end
8
+
9
+ # Parameters
10
+ # Name Type Description
11
+ # --------------------------------
12
+ # teammate_id string Id or email of the requested teammate
13
+ # --------------------------------
14
+ def get_teammate(teammate_id)
15
+ get("teammates/#{teammate_id}")
16
+ end
17
+
18
+ # Parameters
19
+ # Name Type Description
20
+ # --------------------------------
21
+ # teammate_id string Id or email of the requested teammate
22
+ # --------------------------------
23
+ #
24
+ # Allowed attributes:
25
+ # Name Type Description
26
+ # ----------------------------------------------
27
+ # username string (optional) New username. It must be unique and can only contains lowercase letters, numbers and underscores.
28
+ # first_name string (optional) New first name
29
+ # last_name string (optional) New last name
30
+ # is_admin boolean (optional) New admin status
31
+ # is_available boolean (optional) New availability status
32
+ # ----------------------------------------------
33
+ def update_teammate!(teammate_id, params = {})
34
+ cleaned = params.permit(:username, :first_name, :last_name, :is_admin, :is_available)
35
+ update("teammates/#{teammate_id}", cleaned)
36
+ end
37
+
38
+ # Parameters
39
+ # Name Type Description
40
+ # --------------------------------
41
+ # teammate_id string Id or email of the requested teammate
42
+ # --------------------------------
43
+ #
44
+ # Allowed params:
45
+ # Name Type Description
46
+ # ----------------------------------------------
47
+ # q object (optional) Search query.
48
+ # q.statuses array (optional) List of the statuses of the conversations you want to list
49
+ # ----------------------------------------------
50
+ def get_teammate_conversations(teammate_id, params = {})
51
+ cleaned = params.permit({ q: [:statuses] })
52
+ list("teammates/#{teammate_id}/conversations", cleaned)
53
+ end
54
+
55
+ # Parameters
56
+ # Name Type Description
57
+ # --------------------------------
58
+ # teammate_id string Id or email of the requested teammate
59
+ # --------------------------------
60
+ def get_teammate_inboxes(teammate_id)
61
+ get("teammates/#{teammate_id}/inboxes")
62
+ end
63
+
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,15 @@
1
+ class Hash
2
+ def permit(*filters)
3
+ res = {}
4
+ filters.flatten.each do |filter|
5
+ case filter
6
+ when Symbol, String
7
+ res[filter] = self[filter] if self.keys.include?(filter)
8
+ when Hash then
9
+ key = filter.keys.first
10
+ res[key] = self[key].permit(filter[key]) if self.keys.include?(key)
11
+ end
12
+ end
13
+ res
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frontapp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Niels van der Zanden
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.0'
69
+ description: Ruby client for Frontapp API
70
+ email: niels@phusion.nl
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - lib/frontapp.rb
76
+ - lib/frontapp/client.rb
77
+ - lib/frontapp/client/channels.rb
78
+ - lib/frontapp/client/comments.rb
79
+ - lib/frontapp/client/contact_groups.rb
80
+ - lib/frontapp/client/contacts.rb
81
+ - lib/frontapp/client/conversations.rb
82
+ - lib/frontapp/client/events.rb
83
+ - lib/frontapp/client/inboxes.rb
84
+ - lib/frontapp/client/messages.rb
85
+ - lib/frontapp/client/rules.rb
86
+ - lib/frontapp/client/tags.rb
87
+ - lib/frontapp/client/teammates.rb
88
+ - lib/frontapp/utils/hash.rb
89
+ homepage: https://github.com/phusion/frontapp
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.6.11
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Ruby client for Frontapp API
113
+ test_files: []